Player

playerWhat

This week I have been working with making a player class. The player class is so that an object of the player type can be made. It should include a vector2 of its position, a sprite to draw the player on screen and a rectangle to check collision with other objects. The class should include functions that return these variables. There should also be an update function that updates the players position.  In the update funtion I will take keyboard input to move the player. From a design perspective this is made so that the player can move the avatar around inside the game. And this also makes so that the player can colide with other objects in the game.

How

I start out by making the header file and making the function and variables that will be necessary. Then I create a cpp file which contains the constructor of the object and the functions objectives. The constructor takes a keyboard input, a sprite and the size of the screen. the size of the screen is used to make the character stay on screen. This is done in the update function by setting the position of the player to the last position inside the screen. The keyboard input is used for moving the character aound on the screen by changing the players position. The update function also takes a number variable so that it can update acording to all the other objects in the game. The object also has a deconstructor that deletes the hit box when for example the player is killed.

Why

I made the player class this way because of the structure of our engine. It has a update function, a draw function and a collission function. So I made the class to fit inside these function so to make it easy when we put everything togheter.

About Morgan Kringstad Håkansson

2015 Programming