Chicken vs. Egg! v0.1: Now with MORE movement!

It’s been several days since my last post, and I’ve been up to quite a bit – I don’t think I can cover it all in this post, but I’ll hit on the main points.

I took a little break from Chicken vs. Egg! to return to a website I first discovered probably a decade back when I was first learning Python – it’s called Python Challenge, and it ate up a lot of my coding time since I last posted. It’s a very basic-looking website with levels you can only clear by implementing a programming solution – for example, one level has a picture which links to another page when you click it. That page contains a picture which links to yet another page, and so on a couple hundred pages deep until you finally reach the solution. Sure, you could spend a decent chunk of time clicking through manually – but the idea here is to learn how to load up the pages via a script and click through automatically so the program does all the work for you. It truly is challenging, and I enjoy it quite a bit. That’s only one example; it gets steadily more challenging as you progress. I highly recommend it if you’re looking to increase your working knowledge of Python when applied to semi-real problems.

chicken-movement-demo-3

I ended up falling asleep early a few nights ago and broke my 100 Days of Code streak, but I got right back to it (here’s a link to day 15). Well, I’ll clarify – I’ve still been working on code every day, but I forgot to log and upload yesterday and didn’t feel like backtracking, so I just decided to write it off as a free day. Today I made some good progress on CvE! – I started refactoring the code into much-needed OOP format, starting with creating a class for the Chicken. I still need to handle the Egg, but now that I’ve got the Chicken class working, I think it’ll be a piece of cake.

Once I merged the branch I’d made for writing the chicken OOP code, I moved on to adding vertical movement for the chicken, which I was able to implement in no time (I’ve added a new GIF for your viewing pleasure). The program is still a baby, but it’s really starting to take shape. I decided to go ahead and call it v0.1 – the first program I’ve ever tagged with a version number! It’s something I want to get in the habit of doing.

In addition to learning how to tag the version on git, I also learned how to reset to a previous commit, how to compare code at various points (rather than the currently staged version vs. the previous commit), I’ve been getting better at branching regularly, I learned how to push a branch to Github (which I didn’t realize hadn’t been happening automatically), and I learned how to correct a prior commit message. I’m pretty amazed at the depth of this tool, and equally amazed that it’s available for free. It’s becoming less scary to me as it becomes less and less of an unknown quantity.

Tonight I finished refactoring my code to make the Egg class and an eggs array, where I should be able to store all of my eggs (once I have multiple flying across the screen at any given point). Next, I plan to work on collision detection, random generation of the eggs, and getting them to fly across the screen (perhaps with rotation). I also want something more than just a black background, but I’ll save that for the polish phase. I’ll check back within a few days to let you guys know how it’s going. In the meantime, you can check out the repo on Github here, if you’d like.

Chicken vs. Egg!: Now with movement!

The latest evolution of Chicken vs Egg! (yes, the exclamation point is part of the title!) sees the game’s protagonist – the humble chicken – gaining the ability to move about in two directions. (You can find CvE on Github here)[https://github.com/jaredcaraway/chicken-vs-egg].

I’m pretty excited about this development, because it works pretty well. I’ve detailed the latest changes in my 100 Days of Code log for today, which you can read here. Since I’ve got a separate branch aimed at setting it up in OOP mode, I went ahead and removed the unused classes from this branch, which I’d set up with the intent of getting the chicken to change direction according to corresponding arrow key presses). In my last blog post, I talked about a very simple text-based demo I wrote to practice some basic OOP concepts using dogs as my gimmick. My main goal at present is to just get this thing working, but I may find in the near future that I need to go ahead and refactor my code to provide for OOP functionality. For now, I think I’ll proceed procedurally.chicken-movement-demo

If I’m being honest, the main purpose of this post was to show you a GIF of my chicken in action (which I created using a nifty Linux tool I discovered tonight called Peek; couldn’t have been simpler to use). And so here you are: here’s my chicken in action, neatly constrained by the bounds of the window within which it lives.

Upcoming features I hope to implement soon include (but are not limited to):

  • Up/down movement
  • Sprite animation
  • Basic egg movement in a straight horizontal or vertical line from one offscreen side to the other
    • Make those eggs rotate, eventually
  • Collision detection
  • Background
  • Onscreen counter
  • High score functionality
  • Power-ups

As a side note, I wanted to say how much I appreciate you guys checking in to read my posts. I’d honestly be doing this anyway even without an audience, but knowing that I’ve got people out there who are actually interested in what I’m saying is a great motivator to keep doing it. It keeps me accountable. My audience is still relatively small, but it’s been growing steadily. So thanks, my dear reader friends (if you’re reading this right now, I’m talking to YOU)!

I’ll be back soon, probably with more GIF goodness.

 

A new theme, and introducing Chicken vs. Egg!

If you’re a returning reader (welcome back!), you may have noticed that I changed the theme on the blog (if you’re interested in specifics, I switched from Libretto to Tonal). If you’re a new reader, that bit of news is totally irrelevant – but welcome, all the same! As I mentioned previously, I was considering migrating to Jekyll, but I do think I’ll stick with WordPress.com until further notice. The interface works well enough for me, and I like the built-in community (it’s brought me a good number of readers thus far, and it’s a good feeling to know I’m not just shouting into the void).

Today, I decided to quit procrastinating, and I got started on my “dodge” game (put simply, you move a chicken around the screen to avoid getting hit by flying eggs). Since I knew there was a popular library in Python called Pygame, I decided to switch my focus from JavaScript to Python and take a break from Codewars problems.

I’m embracing my Shitty First Code philosophy once again with this project, embracing that what I crank out initially is going to inevitably suck. But it’s an iterative process; after I complete my objectives with each version, I’ll add more objectives and continue improving it until it’s something playable (if unoriginal). So far, I’ve accomplished the following:

  • Create a window onscreen with a solid background color
  • Create custom graphics for the chicken and the egg (using Gimp)
  • Display said graphics within the window
Screenshot of a window with a black background featuring a computer-drawn chicken and two eggs

Screenshot of my first game, Chicken vs. Egg!

Since I envision the game starting out slow and easy and ramping up in difficulty as the player’s score increases, I knew I’d need to be able to produce the egg image in multiple different sizes. Rather than producing individual art files for each size of egg, I simply cranked out one abnormally large egg which I scale via pygame’s transform module. I also incorporated this feature into the code via a separate branch in git, which is a habit I haven’t used many times to date (since the complexity of my previous scripts didn’t seem to warrant it). I also figured out how to diff (view the differences between) my previous commit and staged files in Terminal.

In its current state, my game (which I’ve aptly titled Chicken vs. Egg!) is merely a static image displayed onscreen. There’s no animation and no real logic in the game loop. Ultimately, I want the eggs to fly in from all sides of the screen at random angles with a size, velocity, and frequency that increase over time. I also want to add in a background image, I’ll need a score counter, and I’m thinking of a power-up or two to give it some added playability. Eventually, I might add in a start menu and a way to save a list of high scores and adjustable difficulty – so many ideas floating around in my head. It would be great if I could just make a working game, but it would be even better if the game was actually fun. I think I can do it…but one thing at a time.

If you aren’t already, please click the “Subscribe” button in the blog menu! There is also an option to subscribe and receive email notifications when I post (which is no more than a few times a week at most). Thanks for tuning in!