How I improved my CS50x problem set 0 game

I was quite pleased with the game I made for problem set 0. The one thing I wasn’t happy with was the player movement, which was very fiddly and certainly not smooth.

I shared the game on twitter, and midway through this afternoon I got a message from @ArsenaliansCom saying thanking me for the game, but suggesting that the movement should be improved.

    1. ArsenaliansCom
      @martinlugton Nice program, but the movement could be made easier. That would help, a lot.
      Mon, Oct 22 2012 07:34:29
    2. martinlugton
      @arsenalianscom Agreed! Any tips on how I could do this? I tried allowing multiple key presses at once, but this didn’t really work :(
      Mon, Oct 22 2012 08:17:01
    3. ArsenaliansCom
      @martinlugton Allow multiple key presses, in an if-else if-else if-else if construct. I will send you a sample in a bit.
      Mon, Oct 22 2012 08:19:10
    4. ArsenaliansCom
      @martinlugton Sorry – if-if-if-if construct. Can’t have multiple keys in an if-else. Sorry about that.
      Mon, Oct 22 2012 08:20:18

I liked the suggestion that a series of ‘if’ statements could allow for smoother movement.

I got home and thought about how I could rework my code on this basis, converting my existing movement code into something using a single looping if statement structure.

The Academic Honesty agreement for this course states that “you may not share code”, so I won’t show you a ‘before and after’.

Whilst this restricts what I can write about here somewhat, I don’t actually think this is a bad thing. I would hate to ever use code that I hadn’t created or understood fully. So in implementing these improvements, I was very careful to only use the overarching advice – that using a set of if statements together could be helpful. Academic Honesty agreements aside, I want to figure out things  for myself, and to craft them myself, because that is how learning happens.

After introducing the initial change to the movement I had to change a few other things:

Player movement was a bit too fast, so I decreased sped and rotation speed.

It was hard to get the ghosts chasing at the right speed – there’s a fine balance between almost inevitably being caught and having an easy time of escaping. I got this as close as I could, and then added in another semi-randomly moving and bouncing mouth ghost. I found that having two of bouncing ghosts made things much trickier, so I had to increase player movement a bit to give them a fighting chance.

I’m pleased with the results of these improvements – the game is now much smoother:

Scratch Project

What improvements have the rest of you made to your games?

This entry was posted in Uncategorized and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s