Berlin Defendr


A tiny game from scratch

The problem set 0 of Harvard’s CS50x 2020 edition was to create a small application using MIT’s graphical programming interface Scratch. I decided to make this tiny (tiny!) game.

For many years, long before the trend of retro games, I thought someone needed to make a Defender clone set in a pixelated sky above the pixelated cities of the world. But no one did and I myself never got further than a few scribbles.

Fast forward to 2020, when I embarked on my journey to get back into software development after a long hiatus. I started with Harvard’s excellent CS50x while figuring out the way forward. The problem set of week 0 was to create a small program in Scratch under these requirements:

  • Your project must have at least two sprites, at least one of which must resemble something other than a cat.
  • Your project must have at least three scripts total (i.e., not necessarily three per sprite).
  • Your project must use at least one condition, one loop, and one variable.
  • Your project must use at least one sound.
  • Your project should be more complex than most of those demonstrated in lecture.

I knew immediately what to do: build a very simple version of that Defender clone I had in mind way back when. And that’s exactly what I did and you can play it here to save Berlin (where I am based) from over-tourism. Clearly this is a pre-Covid-19 scenario when tourism was still a thing.

Scratch code

Player sprite

The player sprite, a very basic rendition of Berlin’s iconic Brandenburg gate, can’t do much but move around an disappear when hit.

Scratch code for player

Bullet sprite

The bullet sprite handles the shooting. A hidden prototype is parented to the position of the player. Upon firing a clone is revealed and set in motion, only to be deleted when hitting an enemy or the screen edge.

Scratch code for bullet

Enemy sprite

The enemy sprite is the most interesting. A hidden prototype clones itself in ever shorter intervals. The clones on the other hand become faster as the game progresses. They disappear upon contact with the bullet and trigger a “game over” when they touch the opposite edge of the screen.

Scratch code for enemy