Welcome!

Hey, I'm Skylar, a kid aspiring to become a competent programmer. This blog is here to detail my dabbles in development.

My dream is to one day become a professional programmer and do some game development in my spare time.

Thanks for visiting my blog, and I hope you'll come back!

Pages

A New Week, and A New Project





Well it's a new week and I've started a new project. After finishing Pong, I thought about what project I wanted to take on next. So I thought for a while, and thought Break Out or Galaga would be good ones, but after reading a comment on my Pong video from youtube, I decided to go with a Galaga type game. I've also decided to be a bit more 'artistic' and stray from exactly what Galaga is, so I'm calling it Charge. For now I think Charge is a temporary name, because I think all the different weapons (I'm planning power-ups, so that is plural) will have something to do with electricity. The other two games I have made took only about a week, but I am sure this one will take significantly longer. I'm excited from what will come of this game, because all the different things I'm going to work with that I haven't really worked with before.

The things I'm really aiming to implement in this right now are:

-Projectile System
-Particle Engine
-AI

Those are three huge things in game developement, and it's pretty important that I work with them. I read a little bit about particle systems, and it doesn't seem like it will be too hard to implement a simple particle engine. The AI will probably be the toughest thing, though. I don't want it to have incredibly dumb AI, I want it to actually be relatively good. Of course there will be other stuff in the game, but I don't want to blab all about concepts, so let's get onto what I got done today.

Early today, I did some set-up and created the state machine, and separated everything into files, and just made a project that compiled and created the screen. I then made some place holder graphics, one space-ish background, a red square to represent the ship, and a yellow square to represent the bullet.

I then created a Play state, but one thing that grazed my mind was how I am going to implement levels, I'm still thinking about it, but I'm sure I'll come up with something semi-intelligent. Once I had my Play state mapped out, I created a Ship and Bullet class. I'm using pointers a lot in this one so everything isn't on the stack, I'm finally starting to allocate some memory on the heap =D. I soon found that it proses a few problems, you have to be very careful in that everything that is allocated, is deallocated. When I ran the first 'build' (I'm using that term VERY loosely), the movement was out of control, and when you shot a bullet it would travel just as I had expected. I then kept pressing Space (Note: Space is the button to shoot) repeatedly to see the effect. The effect was that the bullet in the air disappeared and it seemed to revert back at the ship. I knew better than that though.

When I handled events for the ship, I had a switch block like this:

switch(event.key.keysym.sym)
{
case ...
...
...
...
case SDLK_SPACE:
bullet = new Bullet();
break;
}



See if you can spot the problem here...

The memory allocated, was never deallocated, so it just keeps using more and more memory while the old memory is lost forever. I pulled an easy fix making sure to not let the player create another bullet if another was already active, I'll be sure to add in more bullets later, but for testing purposes I'll stick to one.


The next problem I faced had me stuck for about a half hour. I could shoot, and it wouldn't let me shoot until the bullet was NULL. I assumed when you use the keyword 'delete' that the pointer is automatically assigned the value of NULL, I guess not though.

So what actually happened is the bullet would travel outside of the room, get deleted and now I have a stray pointer, then I have a statement that says something like:

if(bullet == NULL)
{
bullet = new Bullet();
}


So pointer doesn't actually equate to NULL, because I didn't explicitly set it to NULL. After I figured that out, I set it to NULL, and now the projectile system somewhat works.


So that's what I got done today, here's what I have planned for tomorrow:

Add in stationary enemies (So Enemies with no AI)
Add in collisions between the Bullet and Enemies
Add in collisions between the player and enemies

At the moment I'm thinking that a collision will result in destruction of both objects, and if at any time there is no player, the game will end, but when I get further in development to create a lives system, I'll just have a life be subtracted.


But another little thing I've had my mind on is how I'm going to handle collisions, I'm going to have to look into it a bit more, because there's going to be an abundance of enemies in the actual game most likely, so I don't want to check for a collision between every object, so I'm going to have to find a more efficient way to do so.

0 Response to "A New Week, and A New Project"

Post a Comment