Tuesday, October 26, 2010

So close.. yet... so far....

I can't believe it's been almost a week since my last post! I've been busy with midterms this week, so sadly I haven't been able to work on this asteroid clone much. I've been able to do little stuff, like returning the game back to the game menu when it's over and adding a score system that works. Here's what it looks like now:

So this is theoretically after I destroy all the asteroids. For some reason the last image of the game blinks in-between the menu, not sure what's going on there. So it LOOKS like I'm almost done, but I actually have a lot to do still. One of them being the movement of the ship, which I just realized I have to redesign the whole movement method to get it moving right =(. I also watched a YouTube video of the real asteroids game, and the meteors are supposed to break into smaller pieces, then smaller pieces again. So......

To do before game is finished:
  • Redesign ship movement
  • Detect collision between ship and asteroid
  • Have meteors break into smaller pieces, twice
  • Recreate meteors once all are destroyed
  • Add a "Life" system
  • Fix bullet - meteor detection
And my goal is to finish all this by December 1st, 2010 :).


Tuesday, October 19, 2010

Font Problems

Alright so I haven't updated in a few days because I've been having trouble with displaying text with SFML. I ran into the common sf::String bug, so I tried loading a font to use from memory. That specific line always made my program crash =(. I searched through the forums and couldn't find a problem similar to mine, or so I thought. So I tried doing the other fix to the sf::String bug, which is to use static libraries. Since I had no clue what I was doing it obviously didn't fix it. While searching the forum though, many problems were linking the wrong libraries or not installing SFML correctly. So I went back and linked the Debug system library of SFML and it fixed the font problem! I even screamed when the program successfully ran without crashing


I know it looks like crap, but it's better than the blank white screen I've been seeing these past few days. This error took a lot longer than I expected, so I'm just going to make a small list of what needs to get done before this game is fully functional.
  • Finalize the start menu
  • End game after all meteors are destroyed
  • Add point system

Saturday, October 16, 2010

Fixed collision

So I was able to fix checking if the bullet collided with the meteor. The previous function worked in theory, but because the point positions were still "local" (relative to when it was first drawn, so the x's and y's of my points were all under 150, and my window is 800x600). In the function I transformed the points of the shape to global and it worked! Although the hit boxes could use a little tinkering, that's another thing I'm going to fix later. I also added an "outofbounds" function to the meteor class, but it's based on if the center of the meteor shape is out of bounds, so it's very specific, later I'll fix it to check the individual points of the shape.

As of now, this is what "works":
  • The ship can move, shoot bullets, and move from the very bottom of the screen to the top
  • When the bullets collide with the meteors, both disappear
  • When meteors move out of bounds, they appear on the other side of the screen
And here's what I need to work on:
  • Adding a Start Menu before the game starts
  • End game after all meteors are destroyed
  • Some sort of point system
  • Adding different levels after all asteroids get killed
After that's done here's what needs to be fixed/added:
  • Acceleration of the ship
  • Hit boxes of meteors
  • Out of bounds function of meteors
  • A high score board
  • "Blowing up" animation for the meteors
  • Varying speed for meteors
Oh and no picture today, everything looks the same as the last post.

Thursday, October 14, 2010

Bullet Collision

So I'm extremely tired and have almost no brain power left. I think my exhaustion from the rest of the week have caught up with me tonight. This asteroid clone is taking me much longer than expected, but I'm determined to get it complete!

So my "meteors" weren't drawing because I was passing the meteor shape variable by value to my add point function, and not my reference. That would explain why the points didn't "save" themselves when the function was done. This simple mistake made me laugh when I realized how small it was, but now I just feel like I have so much to learn when it comes to C++.

Here's how it looks so far (I love pictures, haha.)

And yes, the meteors can move. But unfortunately I don't know much about the sf::Randomizer class and wrapping seeds, so they all move in the same general direction (the bottom right for some reason). I'm trying to get the functionality of my program to work and then I'll fix those little details.

So I tried writing function that would check if a point is the same as the meteors, for collision.

for(int i=0; i < (numofpoints-1); i++)
{
if (i == 0)
{
if(Y == meteorShape.GetPointPosition(i).y)
{
checkY = true;
break;
}
}
else if ((Y >= meteorShape.GetPointPosition(i).y) && (Y <= meteorShape.GetPointPosition(i+1).y))
{
checkY = true;
break;
}
}

So... it doesn't work. I'm not sure if it's because of this "checking point" function or something else, I'm almost positive the problem's here though. I'll find and fix it by the next post!

Monday, October 11, 2010

Problems with points

So the past couple nights I've been trying to get my meteors drawn in the game. It works in my sfmltest project (a project I have installed sfml on (because it was such a pain installing I keep this one) to test little functions). After running the debugger, I've found that after the points are added in the function of the class and the program returns to the main functions, the points are no longer there. So maybe using a call by reference? Or changing the points to global variables (something I've tried but I'm unsure if I'm doing it right)? All I know is those points are not transferring to the main functions.

I've tried picking the brains of a few people (graphitemaster and Wil) on the SFML IRC channel, but my current limited vocabulary stops me from conveying my problem/question correctly. But they were very helpful in suggesting ways to improve my code. One is changing this function:

void addpoints(sf::Shape meteor)

To:
void addpoints(const sf::Shape& meteor)

I'm not entirely sure why this is better, but graphitemaster says using the former will kill his RAM, I will read up more about that later. Wil also suggested I use iterators when using vectors/deques, so I will further read up on those and try to implement them.

These past couple of nights were really like a slap in the face, I still have a lot to learn before I can really do anything with SFML. I like working on this project before I go to bed, it drains me of all my brain power and I sleep like a rock. I'm going to potentially read up on books to improve my coding skills.

Edit:
As I was shutting down my computer last night, right after writing this post I was staring at the book holding up my monitor (my monitor's stand doesn't move up and down, and it's too short so I put a book under it). It was the book for my C++ class (it's been there since the beginning of the semester)! I'm going to try actually reading that book before buying any other C++ book.

Wednesday, October 6, 2010

Movin' Bullets

Alright, didn't have much time to work on my asteroids clone tonight since I got home at 10pm, but I was able to accomplish one thing: moving bullets!!

I also made an "check if out of bounds" function. But I'm not quite sure how to check if it works (have not tried the debugger yet). Also, I switched the vector bullet variable to a deque variable. Deque is a double ended que or something along those lines. While looking at ways to delete elements in a vector, I read it would be much easier to use a deque. I might have to change it back in the future who knows.

To do:
  • Have ship move from top to bottom, vice versa, and from right to left and vice versa
  • Plan asteroids and asteroid collision

Tuesday, October 5, 2010

Bullet drawing is a go!

Thanks to the very helpful people at the SFML-dev.org forum, I was able to draw bullets! Someone at the forum suggested that I use vectors instead of using arrays for my bullets. At first, I was like O.O. In my mind vectors = some sort of math and graphing = very hard to understand. As skeptical as I was, I am DETERMINED to finish this project, so I googled vectors. Turns out it's like an array, but it also has a lot of useful functions. Unfortunately I only looked up what vectors and it's function, push_back(), where so I don't understand them very well yet, but I'm sure it's only a matter of time.


Here's a pic of what my project looks like right now. Yes those white lines are the "bullets", I haven't been able to make them move yet, hopefully by my next post! I've also decided to make a to do list at the end of every post, so when I start working on my project tomorrow I don't waste time thinking about what needs to be done.

To do next:
  • Make bullets move
  • Detect collision with the barriers of the window
  • Plan out the "asteroids"

Sunday, October 3, 2010

Include guards!!

So in my previous post, I was having trouble with including multiple header files in my main.cpp. I searched Google for hours, and I stumbled upon include guards. These are used in header fines just to avoid that header file being included twice. When I first read about these include guards, I didn't really understand them but just started putting them on every file in my project. After that didn't work, I resorted back to Google, and kept stumbling upon include guards. This time I took my time to actually read what they were. You only put them in the header files, and only guard the header file you're putting them in. Once my project was able to build and execute successfully I felt like jumping up and down!... but then it wasn't drawing my "bullet" sprites when I pressed space bar. Actually, when I did press space bar the program crashed =(. So the bullets are my new obstacle.

Everytime I get stuck on something like these include guards, I feel like quitting, but after seeing that little triangle move when I pressed the arrow buttons, I felt motivated again.

Why SFML and Asteroids Clone

Hello, my name is Catrina and I'm going to blog about my experience learning SFML here. I'm trying to learn SFML (Simple Fast Media Library, a media library for C++) so I can start programming games. Over the summer I tried learning Python and Pygame, but got side tracked so I didn't get very far. I decided to switch over to SFML and C++ because I have taken a C++ intro course and am also taking a C++ Data Structures course. With Python/Pygame, I had to teach myself both as I went along which wasn't going well for me.

So this isn't my first time trying SFML, I attempted to use it back when I was taking my C++ intro course, but decided it was too advanced for me at the time. So after a few weeks into my Data Structures course I decided to try and learn SFML again. This went much better than last time. The first time I tried learning SFML, I was treating the SFML tutorials like a step - by - step guide on how to make a game or application, following each one in sequential order. This time I realized they were more like guidelines of what you could do in SFML, so I jumped around to the different tutorials I needed at the time, and was able to start the beginning of my first SFML project, an Asteroids clone.

After a couple of weeks (and many headaches mostly from installing SFML), I have a SFML application that creates a window with a black background, and loads a sprite, the ship, that can rotate and move forward. Unfortunately, I'm now stuck. I was recently taught about classes and how to use them in my C++ class, but we haven't gone over including multiple header files or including guards or header guards. The answer to my problems is probably found here : http://www.cplusplus.com/forum/articles/10627/ , but I have yet to read that through.

Hopefully, by my next post I will have working bullets and have figured out the header and include problems.