Space Invader Clone Progress Update – Day 7

Leave a comment

Day 7

Added Handling varying movemnet speed of the invaders using Microsoft Excel to graph, and calcuate a formalae,
to scale the speed at which the invaders move based on the number of invaders left. So less invaders, the faster they move.

The following was done between between Day 6 and Day 7. was a 15 minute job, to remove a game over variable as its redundant by checking if the number of lives is equal to 0.
Next had to implement the animation of the invaders, each invader graphic has 2 frames, so we alternate between them, I had wrote this code earlier but the limiting code, didn’t
get around to write the limiting code till now, so it was commented out previously.

The idea is to setup so once you clear the invaders it will reset, so revert the invaders, and increment them down a starting position, for the next level.
This was really easy, seperate out the code in the InitGame which initalises each invaders to alive, and the number of invaders alive in total, rows and columns.
After hte last invader is killed, we check if there are no more invaders left, then run this ResetLevel. Added a varible so each time u call ResetLevel(), it will start the invaders from the next line.
And quite proud got that done before midnight, so about two hours maybe two and a half hours of work. That was implemented so now I have have an actual game which, you can keep playing getting more score until game over.

The next step being the bonus ship, which isn’t that tricky or complicated, so will leave that for next time, then invaders firing/ sheild blocks.

Advertisements

Space Invader Clone Progress Update – Day 6

Leave a comment

Day 6

The better late then never progress update.
This is really backlogged entry, since it was actually done after Day 5, i just never got around to writing it up.

First things first, I changed a few things such that it will use the window headers for non debug builds on windows, so you can make a Windows Application rather then Console. (so it doesn’t have a terminal present).

Secondly added the code that causes the game to pause when you Alt+Tab / or in general loose focus of the window.

Thirdly applied the apporitate tweak such that the invaders will move down when they reach the edges of the screen as they move across.

Fourthly added the skeleton for the game over screen, and added a new invadersAlive varible for counting the number of invaders alive in each row. to save computation, and for testing where to take “the bottom of the invaders” from to determine if they have reached the bottom of the screen.

I mentioned in last update that “went they touch the the bottom, you loose a live and it restarts the level”, however after seeing how the arcade version plays, you just get game over when this happens, so lives are just for getting shot at.

Lastly I added the rendering code to display the information to the Game Over screen, and so I did manage to get that all done, and one little code cleanup to remove the need for a specific Boolean for game over. However since i never posted this 🙂 i never considered what I would do next so haven’t done anything since.

Current full list of TO DO: Is limit the movement speed of invaders based on number of Vader left, add the shields that you can hide behind, allow the Vader to shoot you and add the bonus invader

Space Invader Clone Progress Update – Day 5

Leave a comment

The fifth day of development.

First things first i correctly the oops that i forgot to do sooner, which was set the inital number of lives when you start a game.

Implemented a improved EnforceVaderBounds which is responsible for detecting when the Invaders have hit the edges of the screen, and change direction.
Firstly I fixed a slight problem in PlayerShootVaderDetection() which was not doing equality checks on the boundary just > and <. Secondly split up the index calcuation to provide the X index (so column), and added an array which for each column stores the number of invaders remaining alive, and so when one is hit it decrements using the X index from this array.

This allowed the implementation for EnforceVaderBounds(), which provides more accurate ability to bounce off of the sides, instead of just being the first and last column we consider first if the nearest column has invaders left if not we go by the start of the next column.

Using the lovely piece of code below, the right way is the same but goes from 10 to 0.

// Calculates the left most column with any invaders still living.
for (i = 0; i < 11 && invadersAlive == 0; i++);

Next on the todo list was the Pause screen this included creating a new state, and then overcoming a problem. At the time when the state changed we call the deinit method for that state then when we return we call the init. So when going from Game -> Pause we would loose all the information then Pause -> Game would start a new game. The solution was add a boolean to the ChangeState that defines weather this state change is to a cleanState (eg will deinit and init be called), so a un-cleanState would be the pause which leaves the Game State still set. finally added how to draw the pause screen.

Accidentally forgot to commit the 🙂 new files as per usual with new states (like i did with the game state for quite some time)

I had considered a “Demo” as a Windows release but I think i will hold out until final.

Next time: Game Over State, Invader vertical movement so they move down, and went touch the just above you, you loose a live and it restarts the level. Hopefully I will get enough time tomorrow to handle all of that.

Donno Signing Off.

Space Invader Clone Progress Update – Day 4

Leave a comment

Day Four

Skipped an actual day of the week (Did no work on space invaders during the 2nd of December) with other work.

Got into it today, the thing i wanted working today is human movement and firing.

Started by first solving a memory access area I was facing due to not setting a pointer (SDL_Surface) to NULL after freeing it. Added a struct for representing all the invaders on the field, this was as followed, it has a boolean which is is it alive or dead (can be considered as visible or invisible), and the invader instance, this is a pointer to either topInvader, middleInvader or bottomInvader. Each of those 3 are an Invader struct which has a pointer to the surfaces for frame1 and frame2, granted this could really be inline so it doesn’t have to go find the other struct (but this way saves a little bit of memory). The invader struct was created before when the images were to be loaded on the Initialization of the game state.

struct Invader {
SDL_Surface *frame1;
SDL_Surface *frame2;
};
struct InvaderInstance {
struct Invader *invader;
bool alive;
};

Also did some cosmetics changes, fixed some assets, and added the background to the game window, and introduced a structure for the Player information (position and surface), might consider moving score and lives into this. So added the code to load the player image on init, and then display it to the screen, then changed the event handler so escape will quit, left and right will move left and right. Originally I was using the SDL function to Repeat keys so if you hold a key down for a certain time it triggers a repeat which will generate that event multiple times at a set interval, this would of been good as it meant Time Based rather than frame rate depend movement. I then later changed it to be Frame based, so when you hold the arrow key it will remember that and if u keep doing it each frame it will move you a pixel. While reading the SDL documentation I found there is a method called SDL_DisplayFormat which will create a new surface from an existing one but Covert it to use the same modes as the current display. Otherwise each time you bit the surface to the screen it will have to perform the conversion.

Had a kind of big and frustrating setback, a bug in the movement code, it ended up being I had forgotten the break statement after the LEFT arrow key handler so it was then performing the RIGHT arrow key handler. Got side tracked a lot after this thinking how best to handle the Fire event, i had considered making use of a custom ‘user’ SDL event, so, when you press fire it creates the event, puts it on the event queue, and then have a handler so if fire, then we decrease the Y (moving it to the top of the screen), and also then handle the collision detection there, so its in the event handler, and if its not out of screen bound or hit something then Push it back n the queue so it gets called next time. Okay that wasn’t entirely true, that what i have in mind now and i actually like that idea as it moves the detection/handling of a fire into the Event Handler and out of the Rendering code. At the time i was thinking of a Timer which would generate the Fire events every X seconds. At the time of writing this im thinking when i get time I will indeed replace the fire stuff with an event, which it will process in the event handler.

For the collision detection i choose to do 4 prelim condition statements, first consider if the bullet is Inside the frame of invaders so the Bullets Y is below the bottom of the bounding box of all the invaders as a whole, then did if Bullet is pass the top of the invaders, then is it to the left of the bounding box, then to the right. Really i should switch that around so it does the pass the top. last. because if its with in above the bottom, and not within in the x it wll wait till it gets to the top to ignore it, so it will keep doing the y ones then the x, where other way around it will exit sooner on the case where you shoot outside and if you not within the sides (X and X + width), then there is no point of testing if you above it.

Very last thing i did was added the the scoring since Weesals mentioned it, which was quite easy based on the row which the invader we hit is in, add that to the score.

%ATTACHMENT: si_g4.jpg%

So still plenty to do, like the changing of how firing works to use events, make the Vader MOVE, (just a matter of incrementing the position base, and dealing with wrapping bouncing etc), thou Vaders movements are suppose to be timed based on the number left, so should be fun.

Then once that done if they reach the end decrease a life and TRY again, then Vader firing, the shields, loosing a life if a Vader hits you. Also just noticed I initializes the lives to 0 😛 will make that 3 or 5. Oh also forgot I need to do the PAUSE screen, and will need a Game Over screen.

Really want to do the pause screen first, but if the vaders move then, that version can be shared as a demo since it has a some point.

Space Invader Clone Progress Update – Day 3

Leave a comment

Day Three

Continuing from where I left off. I forgot to document what i did on the second day.

I started the day, separating the current source file into separate units, and header files, so once for Home/About, and then one for the Game, and updating the Visual Studio Solution and GNU Makefile to match. Next I finally wrote the lines that would be displayed in the About and added the code to render them to the screen.

As I was writing the framework/skeleton for the Game file, I realized i had a limitation in my current design that was it wasn’t flexible enough for more actions on the States, since there was just 2 arrays, 1 for the Events Handling, and 1 for the Rendering, so I re factored this up to be an Array of a State Structure which contains pointers to the event and rendering functions, and added a initialization and deinitialization callback. Following that instead of having all the different functions like DrawMenu, DrawAbout, EventMenu, being seen by the rest, I exposed a SetupMenu, SetupAbout which takes a state structure pointer, and then that is responsible for setting the callback handler to those methods. This made the header for the Home [Menu and About], just 2 functions instead of 4 (it would of been 6 functions with the Init/Deinit). Few other little things in the design was changed to lock things down further.

The whole time I forgot to actually commit the C source and header for the actually Game State, my bad. Final thing for the day was implement the rendering and displaying of the Score and Lives, followed by fixing some memory leaks of un-freed memory.

Sorry no screen shots for this, the game screen is not much to look at.

Space Invader Clone

Leave a comment

Thought I would post about my current game developing for the current academic break (summer 2009 to 2010)

I decided to keep it simple, and non complex so I opted to go with re-creating an old classic. Space Invaders. I will probably change the name before its completed/released 🙂

So in case you were born yesterday, Space Invaders is a game in which you control a turret that can only move left or right, and can fire up at invaders from Space. There are a series of rows of invaders coming down which move across the screen with the goal of landing (this is the game over scenario). They can also fire down at you.

The graphics for the game are not my own, they were made by Chokemaniac for the XBMC Skin – Project Mayhem III.

The font used is BitStream Vera Sans a free used by the Gnome Project

Most of work on this will be based from the Space Invader Clone I wrote as a XBMC Script, but using the things I have learnt from that and the things since, I intend on making it nicer to work with. If I get around to completing this, I have considered making an OpenGL ‘version’. so have a 3D aspect to them, and a slightly movable camera.

About the Project

Name: Space Invaders (Current Working Title)
Language: C
Operating System: Microsoft Windows and Canonical Ubuntu
Libraries: SDL, SDL_ttf, SDL_image which load freetype, libpng and zlib

Tools used:

  • Microsoft Visual C++ 2008 – This time i went for Visual Studio instead of just SciTe (Scintilla Text Editor), as it has intellsense among other things.
  • Git – Version Control system
  • GNU Make – For building the project with GNU Compiler Collection (GCC) in Ubuntu and with the MingW Compilers.
  • valgrind – For helping find memory leaks, where I forgot to free memory.

Current Progress

Splash Screen is displayed, Main Menu is displayed and navigable (can use the Up/Down) keys to go to the previous or next item, and Enter can select, also Alt+F4 and the Quit item on the Menu both close the game. The about button shows the about dialog (at the moment with out text). So so far the menu is almost complete. I am still in the process of fine tuning some of the system design, I expect to do a minor refactor to improve it once I start the Play Game :). The next thing on my todo list is fill out the About dialog, then shuffle the code/separate it out to separate files and get started on the Game Logic.

Screenshot of the Menu:

%SpaceInvadersMenu.jpg%

Sorry, I am currently not looking for any help on this project, I intend it just as a personal/1 man team project.

I will try my best to keep posting updates about my progress here, sometimes I usually write Blog-like posts while I develop for later posting, and I will try to do the same as I go from now on.

Day One

I didn’t really mention much about day 1, so ill go through it now considered of was sorting out the file layout and committing it to git’s version control. This included the images for the menu, the font and the splash and the source just initialized SDL and loaded the font, the next change was to display the Splash, and the initial gameloop which loops until Quit event is raised. Which spanned about an hour to hour and a half.