Devember - SpaceRocks


This my blog for my Devember project SpaceRocks.

Back in 2014 I took an online “Coursera” course called An Introduction To Interactive Programming in Python offered by Rice University. Before the course I hadn’t done any Pyhton so learned a lot and really enjoyed the language, unfortunately, since then I haven’t had the opportunity to use Python very much so I have forgotten most of it.

The final project of the course was to write a simple space shooter type game (very like Asteroids) called Rice Rocks. This was a lot of fun and I ended up adding a few additional features to the game (some additional weapons and the basis for a power-up mechanic).

All the development for the course was done using the provided CodeSkulptor web based development environment, which is pretty cool and I’ve used it since when I need to prototype small pieces of code or algorithms quickly. But I’ve always wanted to write a standalone version of the game.

So, my plan is to rewrite my version of Rice Rock as a standalone game using the PyGame library and the PyCharm Python IDE.

The original game I plan to recreate is here


  1. Refresh my knowledge of Python and learn how to write in a more “pythonic” style
  2. Learn how to use the PyGame library
  3. Learn how to use the PyCharm IDE
  4. Improve my Linux knowledge (I’ve recently switched from Windows to Fedora on my my development PC)
  5. Maybe inspire others to give Python a go too (I’d highly recommend the Rice University Course)
  6. Have a little bit of fun

Oh and here is my Devember Contract


I, Shecks, will participate in the next Devember. My Devember will be a PyGame based game called Space Rocks. I promise I will program for my Devember for at least an hour, every day of the next December. I will also write a daily public devlog and will make the produced code publicly available on the internet. No matter what, I will keep my promise.

I think that’s it … as @Dynamic_Gravity has pointed out, I am a few days late so I’d better get started :slight_smile:





Day 1

Since it’s December 4th the project is already behind schedule, so I’m gonna have to put in some overtime … just like a real project :neutral_face:

Here’s what I got done so far:

  1. Installed PyGame and PyCharm
  2. Cobbled together the initial project structure
  3. Did a lot of Googling to figure out how to import Python modules from my own project
  4. Discovered that I actually already have a GitHub account but have forgotten my password
  5. Reset my GitHub password and managed to create a project for SpaceRocks and make an initial commit
  6. Figured out how to post on the Level1 Techs forum (I’ve been a read-only lurker up to now)

There’s not much to see yet but if anyone is interested my GitHub repo is here

And here’s the progress so far … a nice green window :smiley:





Day 2 (Well still day 1 but I am behind by 4 days)

Lots more Googling and a little bit more done:

  1. Fleshed out my ‘Scenegraph’ idea for the game a little more (May have to revisit this after reading up on PyGame Sprite module)
  2. Figured out how to load and draw images with PyGame
  3. Wrote a few utility classes to load and cache images as well as draw image sections from tile sheets
  4. Tested my scene updating (the background scrolling debris works now)
  5. Commited changes to my GitHub repo

Things to do next:

  1. Learn about PyGames Sprite module, seems I could be re-inventing the wheel a little bit. For the original project I wrote my own scene graph code (a fancy ordered array) to manage all my scene objects and render the screen using the painter algorithm. But it looks like something similar might already be available in PyGame
  2. Figure out how to do ‘imports’ in Python correctly. My idea is to have a simple game library with generic helper classes and I’d like to be able to reference classes like ‘gamelib.SceneGraph’ or ‘gamelib.TileSet’ but I can’t figure out how so there’s a lot of ‘scenegraph.SceneGraph’ and ‘game.Game’ references with seems very redundant

And the progress so far … space the final frontier

Screenshot from 2017-12-04 23-24-56

You’ll have to imagine the background debris scrolling to the right and the ship is currently experiencing engine difficulties :smiley:




This is awesome

Day 3 (Still day 2 but I’m still behind so still cheating)

Another day of Googling, refactoring and trying to remember basic math.

But got some stuff done:

  1. Read up on PyGames Sprite module and yes, there’s support for drawing sprite groups in layers so it will handle rendering the scene using the painter algorithm. The upshot is that my scene handling code had to go and I’ve changed my code to use the PyGame ‘Sprite’ class as the base class to all scene objects.
    2, Spent a lot of time figuring out how to rotate sprites/surfaces in PyGame, ended up swiping some code from the web but I need to review it. PyGame doesn’t seem to have a way to apply a transformation during blitting and I don’t think it’s very efficient to be creating new surfaces on every frame update … more research required.
  2. Started putting together the PlayerShip class and added basic movement and steering for the ship (currently Left, Right arrows and Up for the ships engines)
  3. Refactored my TileSet class to make it a little more efficient and so that it fit in with the changed I had to make when I switched the code to use PyGame.Sprite based scene objects
  4. Oh and pressing the ‘B’ key changes to a random background, just for testing :smiley:
  5. Pushed changed to my repo

Things to do next:

  1. Apply friction/drag to the ship … yep I know there’s no drag in space but it makes the ship easier to control. Perhaps there will be a ‘Power Down’ later in the game to turn it off and make things a bit more tricky. I had some code in place to apply friction against the ships velocity but it’s not working they way I want.
  2. Finish out the ships movement and start on the ships weapons, a simple single shot gun for the moment, more math , angles, vectors etc … yay

And the progress so far … Scotty has done sterling work and got the engines working!

Screenshot from 2017-12-05 21-18-34

Ok, you’ll have to imagine everything moving again … I don’t know how to make a GIF (or try the code :slight_smile: )



1 Like

Day 3.2 (Getting serious … or in my case desperate)

It’s never a good sign when the game physics book is out :thinking:



1 Like

Try recording your screen using Open Broadcaster (OBS). It’ll generate a video you could post to youtube and then post here. :slight_smile:

Thanks for the suggestion @kreestuh :slight_smile:

Open Broadcaster is pretty cool and it turns out it was much easier to capture the video on Linux than the last time I did it on Windows.

Here’s a video of the ship movement and some of the space backgrounds I have. The ship still has no friction applied so it’s like trying to drive a shopping trolley with a broken wheel :rofl: the only way to slowdown or stop is to turn the opposite way … although I guess that’s how spaceships without reverse thrusters would work.


This is exactly as it should be. Don’t change a thing, except maybe the force of the thrusters. IMO, of course. It’s your game. You do you. :slight_smile:

1 Like

Day 4 (Still behind schedule so day 5 will be this evening)

I really don’t like the PyGame documentation, ended up having to dig through the source code to find out that the ‘sprite.Group’ and family of classes don’t really do what I thought so I’ve had to re-think my scene management again (wondering if I should have stayed with my original ‘poor mans’ scene management)

Anyway, I did get some stuff done in between cursing the PyGame docs:

  1. Added friction/drag to the player space ship movement. I know there’s no friction in space but the ship can get really out of control with out it (@Levitance I’ve included a toggle to turn friction on and off at the moment , it’s on by default but the ‘F’ key will toggle it. It’s still not working how I would like either but it will do for the moment)
  2. Made a start on the player ship weapons. I have a rough idea in place and have implemented a simple single shot missile weapon just to see how to get it working with PyGames sprite and sprite groups
  3. Did a little bit of refactoring
  4. Commited the code to my repo

Things to do next:

  1. Lots of refactoring, the code is getting messy
  2. Clean up the player ship weapon code a little and add DoubleShot and RadialShot primary weapons
  3. Start thinking about adding rocks to shoot at and collision detection
  4. Think a little bit adding support for different scenes in the game. At the moment the game class just works with a single scene. I’d like to be able to create multiple scenes and have the game class run one depending on game state (e.g. Intro/Splash screen scene, game play or level scene, high score table scene etc …)

And the progress so far … FIRE!!! (those little green things)

Screenshot from 2017-12-06 16-07-08

Yep those photon missile thingies are pointing the wrong way … need to rotate them using the ships forward vector (or cheat and find round missiles :smiley: )




Day 5 (Last of the overtime?)

Not much of an update this time.

  1. Added basic single shot primary weapon. I think this will be the beginner weapon and will be improved by power ups (velocity, time to live and cool down times will be tweaked by collecting power ups)
  2. Added a secondary weapon that fires multiple missiles in a circular pattern from the shop (I think this will be the first of a few different secondary weapons that can be picked up from power ups dropped by destroying asteroids)
  3. A bit more code clean up, but there’s still lots of test code in there from trying different ideas.
  4. Committed the code to my repo

Things to do next:

  1. Finnish the ‘DoubleShot’ weapon. Firing two missiles from the wings of the spaceship while it’s rotating is trickier than I thought.
  2. Need to do more research … the game physics book might be out again :confused:
  3. Get some sleep and come back to it tomorrow

There’s short demo video here. It demonstrates flying the ship with and without friction being applied and the two new weapons ‘SingleShot’ and ‘RadialShot’

There’s still a bug in the code to apply friction as the ship doesn’t come to a complete stop as it should.



1 Like

Day 6 (ish?)

Nothing to see here … just a lot of code feng shui today.

  1. Refactored a bit of code
  2. Abstracted the image cache (AssetCache base) because I will need a cache for audio files at some point
  3. Did some re-working of the scene nodes and scene renedering code so I will be able to switch between different scenes depending on game state (E.g. Intro Scene, Level Scene etc…)
  4. Checked the code into my repo

Things to do next:

  1. All the stuff I said I’d do yesterday
  2. Think about getting rid of all those cheesy backgrounds. I’d like to make the window a bit bigger (or re-sizable) but scaling up background images causes performance issues (probably because I am blitting the entire background on each frame at the moment). Thinking about some sort of tile-able space background so the window is not restricted to size of the background image and I’d like it to scroll as the player ship moves … kind of like a parallax effect … just gotta find some free art.

Visually pretty much the same as yesterday … but I do have some fancy sprite bounding rectangles for when I get to writing and debugging collision detection.

Screenshot from 2017-12-08 02-22-31



1 Like

Day 7

Spent a bit of time today looking for royalty free graphics and reading the PyGame docs, but made a little bit of progress with the game.

  1. Decided to get rid of the old backgrounds and went with a static background for the moment. I found some royalty free tile-able 1024x1024 space background so I am going to use those. That way I will be able to run the game at different resolutions by tiling the background.
  2. Added animation support to my Sprite scene nodes so that I can have animated asteroids, explosions etc
  3. Started work on the asteroid sprites and spawned a few for testing.
  4. Turned off the FPS lock because I was getting lag (even though the game does nothing at the moment … not a good sign), it now runs at full speed but I need to do more research here. Locking at 100 FPS seem OK in the 1280x1040 window but at full screen it’s terrible.

Things to do next:

  1. Finish the asteroid sprites and create an asteroid spawner (I’d like to have support for large, medium and small asteroids as when the large asteroids exploded I want them to break into smaller pieces)
  2. Add sprites for a couple of different types of explosions.
  3. Try to find some more graphics for the asteroids. I like the ones I have because they are animated in a way that makes them look 3D but they are too small and I only have them in one colour. I am not very good with graphics but might see if I can get away with tweaking them a little bit myself.

So here is how it stands now (haven’t done any work on collision detection yet)

If anyone knows where I can find some nice free graphics especially some animated asteroids please let me know (I might need to change the ship too, it’s from the art supplied with original Python course I took and I am not sure I can use it)



1 Like

Day 8 (I might be back on schedule so this could really be day 9 I guess)

Lots more code refactoring today.

  1. Added different sized asteroids (just resized the assets I had and they came out ok)
  2. Added a couple of explosion sprites
  3. Added the new tiled backgrounds (there are 7 different ones, currently the ‘B’ key chooses a random one)
  4. Added simple collision detection for testing (you can now shoot asteroids)
  5. Checked the code into my repo

Stuff to do:

  1. Too much :frowning:
  2. Clean up all the hacks
  3. Look into using a joystick to control the game (and add WASD keys too)

Here’s a video of the current game play … just using the massive sprite bounding rectangles for collision detection at the moment … and I still can’t hit them :smiley:



1 Like

Glad that progress is being made :slight_smile:

Day 9 (or something)

Not a lot of progress today. I am not happy with the hacked together physics I have been using for the movement of the various sprites in the game so spent most of my dev time reading 2D game physics and reworking my code. I really should know this basic math.

But I did manage to get the following done:

  1. Added little helper factory classes for creating Asteroid and Explosion sprites to make the code a little cleaner.
  2. Added a factory to create power ups when asteroids are destroyed (for test purposes there’s a power up spawned for each asteroid destroyed)
  3. Looked into the availability of a small physics library for PyGame because my code sucks

I haven’t checked in any code today because it’s pretty broken

Things to do next:

  1. Finish cleaning up the sprite movement code
  2. Add code to have the asteroids collide and bound off each other
  3. Add code to allow the player to collide with and collect power ups
  4. Add code to handle when asteroids collide with the ship (need to think about how I want this to work, e.g does the ship get destroyed immediately, does it take damage based on the size of the asteroid, what happens if the ship has a shield etc)

Anyway here’s a short video of the power up testing

Oh, and there seems to be a problem with the first frame of one of the explosion animations I am using. There’s a strange square shaped alpha showing, if anyone knows how I can fix this I would really appreciate it.



1 Like

Day 11

Didn’t check in any code yesterday or post an update as the code was pretty broken while I did more refactoring.

  1. Decided that using a 3rd party physics library would be overkill for such a small game so instead I refactored my sprite code and re-worked the small bit of 2D physics I need for the moment. I now have a set of base classes for the different sprites to handle movement by integrating forces and applying the resulting velocity to the sprite. The base class also handles simple frame animation so I don’t have to worry about that anymore. I still need to integrate drag into the velocity calculation but I am pretty happy that the code does what I need for now.

  2. Fixed a graphical problem with one of the explosion sprite sheets I was using that was annoying me.

  3. The asteroids and power ups now rotate … since I get that for free with my new KinematicSprite class (which I’ve just realized I’ve spelled wrong in the code)

  4. Added a new ‘SceneText’ scene node so I can start adding some HUD elements (I’ve added an FPS counter to test it)

  5. Since I’ve fixed my sprite movement (I think), I’ve gone back to having the game frame locked at approx. 60 FPS

  6. Checked the code into my repo

Anyway, most of the changes were to the code so there’s not a whole lot to see … but here’s a screenie with lots of explosions and power ups.




This is awesome to see.

Day 12 (WTF?)

I think there will be a bit of debugging required today … this is a really strange bug. I was just testing some new graphics for my games power ups and have managed to somehow link two completely separate scene objects together :smiley:

I have no idea how the ships position is affecting the power up position.

Perhaps I can use this as an ‘interesting’ game mechanic … the elusive power up :rofl:


1 Like

You are putting my game development efforts to shame :rofl:

1 Like