Devember - SpaceRocks

Day 12 (A dark dark day of debugging)

Finally found the ‘feature’ in my code that caused the mysterious elusive power up phenomenon: -

class KinematicSprite (SceneSprite):

        Base class for sprites that will move throughout the scene as forces are applied
    def __init__ (self, x, y, frames, frame_index = 0, velocity = pygame.math.Vector2 (), 
                  max_velocity = pygame.math.Vector2 (1000, 1000)):

            :param x:               (int) Center position of sprite on x-axis
            :param y:               (int) Center position of sprite on y-axis
            :param frames:          (image[]) Array if image frames
            :param frame_index:     (int) Current frame index
            :param velocity:        (Vector2) Initial velocity
            :param max_velocity:    (Vector2) Maximum velocity

        super ().__init__ (x, y, frames, frame_index)

It turns out that mutable default arguments in Python don’t work the way one would expect if you have used the pattern in other languages.

Only one instance or ‘velocity’ and ‘max_velocity’ are created when the ‘def’ is first evaulated. Any subsequent uses that don’t specify the arguments (my PowerUp subclass) will just get a reference to the previous object instances.

Which explains why when I moved the player ship, the power up also moved … because it was sharing the same velocity vector object … Doh!

Even worse, apparently it’s a very common error for people new to Python.

Oh well, since one of my #devember goals was to improve my Python knowledge, I think this still counts … lesson learned :smiley:


Ah, I think it only looks that way because I’m kinda cheating, I have a bit a free time at the moment so I’m spending far too much time on #devember :grin:

1 Like

On top of that I am cheating by spending not enough time on it…
Still it looks like you are making way more progress that I will in the next few months…

1 Like

Meanwhile, I’m working on implementing threads.

I’m essentially making reddit.

1 Like

Day 13

Mostly bug fixing since yesterday, but did manage to get the new animated power ups in and spent some time thinking about some of the game mechanics I’d like to implement.

Things to do next (if I don’t get distracted by something else or find more bugs)

  1. Re-do the weapons. I’d like to have the ability to equip the ship with two different weapons. A primary photon cannon and some sort of secondary weapon. Power ups will grant different weapons or improve the stats (rate of fire/cooldown, velocity, range etc) of the currently equipped weapon.

  2. Change the ship graphics. The one I am currently using is from the Rice University course I took and I don’t think I’m allowed to use it outside of the course :hushed:

  3. Add stats to the ship. I might have a couple of different ships and would like each to have different stats.
    3.1 Amount of damage the ship can take
    3.2 Amount of energy the ship can store and how fast it’s regenerated (The ships shield and weapons will consume energy when used)
    3.3 Anything else I come up with

  4. I re-implemented drag for the ship, when it’s on the ship will gradually slow to a stop when not under acceleration. It’s still off by default but it helps while testing.

  5. Really need to start thinking about how to make it into an actual game. Hopefully after I redo the weapon system and tweak the speed I can get it to feel a bit more like a shoot’em up.

Here’s how the new power ups look anyway:



1 Like

Day 13 (FIRE!!!)

Finally got my head around the school level trigonometry I needed to implement the double shot weapon :rofl:

I also increased the velocity of the main weapon so it’s starting to feel a little more like an actual game now (I’m still using the bounding rectangles for collision detection which are far too large so even I can hit the rocks)


1 Like

Day 14 (New Toys)

As a bonus side effect of #devember, I’m getting a lot more experience with GNU Gimp. I still can’t draw but thanks to Skorpio’s excellent Space Ship Construction Kit on Open Game Art … I’ve got a new space ship :sunglasses:

It’s probably more efficient to draw all the different components of the ship separately at run time but I’m lazy and figured I might have issues placing the parts due to distortion when rotating the ship, so I decided put all the different combinations (stationary ship, ship with engines on, ship firing main cannon, ship firing main cannon with engines on etc) in one sprite sheet and see how it works out.


Day 14 (Some adjustments required)

Gonna need to tweak things a little, because I included the muzzle flashes and engine flames in the sprite sheet the center of rotation for the ship is off …

I can either make the sprites taller so that the ship is centered or maybe add an offset property to my KinematicSprite class.


Day 15

Got all my Christmas shopping done today and I’m off out for a pint so there was no code written at all today and depending on how the evening goes there may not be much written tomorrow :thinking:

I did do some research though. I am struggling to make Space Rocks feel like an actual game, to me it just seems a bit lifeless (when I add audio it should help a little) so I have been reading a lot about game mechanics and “feel”.

Even though the ship moves around the screen it doesn’t feel like it’s moving much at all because the background is static, so I am thinking of changing that.

I am playing around with the idea of adding a camera and viewport mechanism. The camera will follow the player ship (which will either be fixed in the center of the screen or contained in some sort of limited bounding box) and the background will scroll to give a better suggestion of movement.

If I go ahead with this there will be a lot of refactoring but I think it will make the ‘game’ feel much better and it also opens up the possibility of having a larger game world (the scene can be much bigger than the window/viewport), I can implement parallax scrolling to add a little dept (if I can find some nice graphics) and I might even add the screen shake effect I’ve seen in other shoot’em ups.

Anyway here is how it looks at the moment. I’ve added two ships (and started abstracting all the common movement code so different ships can have different behavours and stats) and also added code to break up the asteroids when they explode.



1 Like

Day 16

Did some more reading up on 2D cameras today and hacked together a small test application to see how the concept works.

It’s pretty rough and I still have to figure out if I can do screen wrap via the camera when the player runs off the edge of the game world (in the test app the viewport is 800x640 but the game world is 8192x8192)

I’ve added a very simple Camera class to my Scene manager but will need to make a few modifications to my game library code to integrate it nicely once I get the bugs ironed out.



Day 18 (I think)

Been playing around with the 2D camera code. I got it to work but it didn’t play nicely with the space ships screen wrapping code.

So I went back to the drawing board and added scrolling to the background scene node instead. It took a bit of figuring out but it can now handle infinite scrolling in all 4 directions.

For the moment I’ve set it up to scroll at 1/2 the negated velocity of the ship so it scrolls in the opposite direction to the ship.

I’d still like to have the 2D camera so might revisit it and see how it works when the background handles its own scrolling (The scene drawing code will need to exclude the background node from camera translations but I’ll need this for HUD anyway)

Anyway, here’s a quick demo



Day 19

I threw together a quick and dirty parallax scrolling scene node just to see how it would look. The art work is from LuminousDragonGames at and there were 8 layers in the set.

Using all 8 really kills the FPS so I dropped it down to 5 for the test where I can just about keep it running at around 60 FPS (when screen capturing with OBS the FPS drops through the floor though)

Still not sure if I will use it, perhaps just two top layers for some space debris… :thinking:

I really gotta move on and make this at least a little playable but motivation is lacking and playing around with the fancy graphics stuff is more appealing at the moment :neutral_face:



Day 21

Been playing around with some sounds just to keep myself interested.

Now that the I have parallax scrolling background layers at 1080p the FPS is really suffering when recording with OBS, but I guess that is to be expected because I’ve only got the on-board graphics of my i7-4470K to work with.

I’ve also changed the collision detection to use bounding circles instead of the sprite image bounding rectangles so bullets hitting the asteroids need to be a little more accurate (although this might not be apparent in the video because of the horrible lag)


Day ?

Just checking the code from a few days ago into my repo

I’ve added some sound effects for the lasers and asteroid explosions.

See … there are sounds now …

I didn’t bother with a video clip this time because of the issues I’m having with poor FPS when recording the “game” with OBS

Don’t think I will be doing much more on this. It did serve its purpose of getting me back into Python for a bit but I don’t think the code I wrote was very ‘pythonic’, just refreshed enough knowledge of the language syntax for me to get something up and running.


Day 23 (Maybe? Last day of #devember anyway)

Since it’s the last day of #devember I decided to do a little bit more on my Space Rocks game thing.

I just added a score counter and some fancy floating text to show the points scored for each asteroid destroyed.

Also, added the floating text to the power ups to display the name of the power up when it’s collected (Power ups are still just cosmetic and a work in progress as I haven’t applied them to the player yet)

The player is still invincible too, at some point I will have the ship take damage when it collides with an asteroid but I need to implement the shield feature first. My plan was to have the shield reduce the damage taken but for the shield strength to be reduced (recovering over time and via energy power ups). The ship would only be destroyed if enough damage was taken while the shield was depleted.

Anyway, here’s the state of play at the end of #devember

If anyone does want to try it out, you can hit the ‘Escape’ key to spawn more asteroids, ‘D’ toggles friction/drag on the ships movement (a feature I was playing about with) and ‘S’ to do nothing (at one point I was using this to test the ships shield)