Pages

Categories

XNA Game Dev blog #3

2011
05.15
XNA Game Dev blog #3
Category: Uncategorized / Tags: no tag / Add Comment
Well I spent most of today re-doing all of my code. Now it correctly supports deriving from
classes. Before I just had a class for each object, each one was self contained, until today I
finally learned the correct way to create inheritance with classes. I created my baseObject
class, which has just the 2 basic functions as of now. The constructor function which has
parameters for the viewport, texture and position and then the draw method which is just a
basic spritebatch.Draw(texture, position, Color.White);
Doing all of this recoding has made the game so much more easier to work with, and I’m
getting very comfortable with the C# syntax. I finally got shooting of lasers done (although
no collision detection yet). While playing around with the shooting, I thought it would be a
good idea to be able to cycle through your weapons that you want to fire, rather than firing
everything all at once. The way lasers are done is when the space key is pressed down, it then
checks if the player can shoot (if x amount of seconds have passed since the last shot) then
adds a new instance of the laser object to a List. The List is the only reference point of the
laser object, and will also make it easier looping through all the lasers to draw/update and
soon check for collisions. Not only this but it will make it easier removing the laser object as
I just have to call the List.RemoveAt() method, (correct me if i’m wrong) removing the
reference point, passing it onto the garbage collection.
Funny error I came across when testing out the alien ships, the pink colour I used in the
original alien ship, is the colour XNA uses to mark as transparent. So upon drawing the aliens
only part of the ships were showing. As seen in the below image:

So now I’ll have to recolour
the alien ships. I still have to add the flame effect back onto the player ship for when it’s
moving forward, hopefully try get it animated as well. I will probably do the same for the
lasers, as right now you can’t really see them, so I may play with sprite effects later. But first
I’m going to get the game to a playable state with an actual goal. Then to start re-organising
my code and making it more efficient which I should have really done while I was coding it
all.