Game programming wk.2

I thought that week one was intensive until we started week two. In five days we managed to learn functions, pointers and then jump straight in SDL() and make Pong.

While doing that we got to learn a new data structure called struct, struct is a group of data elements, these elements called members. Using struct increased efficiency when creating similar instances of a class or a struct.


struct Paddle

{

float x,y; //The X and Y coordinates of the paddle

//An array that has two elements [0] and [1], 

each element is assigned to a keyboard key to execute movement

bool input[2]; 

};


But you might ask there is on paddle while in original game there are two paddles, left and right. Instead of creating a new struct with the name Paddle_2, we create a struct called game that contains all the important data in the game.


struct Game

{

int game_width = 1024;

int game_height = 600;

Paddle left;

Paddle right;

};

We create the right paddle In struct Game or in programming language, we create and instance of type Paddle called right. Tune in next week for more C++.

-Marwan

Leave a comment