Since I'm going back to Stockholm during week 3's classes, I asked for the assignments in advance so I could brush up on my old C++ knowledge.
Firstly though, we made pong with SDL(Simple Directmedia Library). A programming library is a set of predefined functions and classes which can aid you in different ways. If I want to make a game, I don't necessarily need to know how to program the graphics card, but SDL do and helps me with that process. The back end takes care of the hard stuff and I can just write
Window win = CreateWindow();
Now, with the library in place and our instructors initial program, we made pong. The process was mostly figuring out how the objects in the game should act and then define that behavior in code.
Paddles move by pixels when the player press up or down, that is easy. But the paddle cannot move outside the screen! If it does we send it back before redrawing it on the screen. Also if we move the paddle every frame, slower computers will have slower movement. We don't want that! So if we base the movement around time we can have a global measure to go after.
And for the ball we need to define movement in two directions, vertical and horizontal. And to make the ball bounce, we need to define that when touching the upper and lower screen, the vertical speed is reversed, and when touching a paddle the horizontal speed is reversed. And when touching the left and right border the score count for the correct player should go up.
One more thing to add is game states. This game of pong is either running or paused. To start the game from pause you need to press enter. To pause the game a player needs to score. Game states are good for enabling a certain behavior at a certain time. You should not be able to move during pause and neither should the ball.
I also went through classes again and there were several new things I ran into. Classes are good for several reasons. In a class we define what an object of this type of class looks like so we can use that for the purposes we define. Bullets in shooters are objects defined by a bullet class and every time someone shoots, bullet objects are created.
It sounds easy as a concept, but defining exactly what you want can be pretty hard. I made a card class which can hold suit and number. Then I made a deck class which creates 52 cards in a array to mirror a real deck of cards. Then I made a class which holds a hand of 5 cards and can do things like discard a card and draw a new card.
The process isn't too easy for a beginner and I do feel like I'm learning a lot of new stuff every week. I'm glad that I'm ahead in this course so I can reinforce my knowledge even further. The next step in the program above should be something like making a game of poker, but that is for another update.
No comments:
Post a Comment