Second week of programming, Introduction to SDL.

So the second week of C++ programming has gone by, this has been a lot more difficult with a lot more things to learn. Including dynamic memory and pointers. We have also made a pong game using the SDL library, or well we did not do it from scratch. We followed our teachers instructions.

Here is some examples of what we have learned, that i did not know before.

& is a pointer for a specific variables memory address.

* points at the memory address and reaches the variable through it.

-> is some kind of struct or class call within SDL. ( Structs were a part of C and not C++)

a struct is a kind of class with multiple variables or functions within (a structure containing many things).

Within SDL we have also learned: Simple collision checking, the code below checks collision with ball objects and paddles.


bool check_collision(Paddle*paddle, Ball*gameBall)
{
if (paddle->x + 20.0f < gameBall->x || paddle->x>gameBall->x+ 20.0f)
return false;
if (paddle->y + 100.0f < gameBall->y || paddle->y > gameBall->y + 20.0f)
return false;
return true;

}

user input with keyboard, drawing a screen,

making structs, below are two important structs.


struct Ball //struct for ball
{
float dirx, diry;                          //The speed of which the ball moves in x and y directions
float x, y;                                  //the position of the ball
};
struct Paddle //struct for the paddles
{
float paddleSpeed = 700.0f;   //the speed of which you can move the paddles up and down
bool input[2];                          //used for the controlling of the paddles, 0 =upward, and 1 = down;
float x, y;                                //The position of the paddles
};

confirmation on how pointers work. How we make the game timebased intead of framebased, so the game runs in the same speed on all computers. And lastly a way to pause or start the game.

I have a feeling the next week will be even more intense.

About Gabriel Ajuwa

2014  Programming