Blog Week 5: Player

The Player class has been my task for a couple of days leading up to me writing this post. It has been a task where I have been lost for a while but have learned allot from. What I have implemented have been both an audio feedback and an implementation of the player’s animation when hen is moving the player and, in the future, when a shot is fired by said person playing the game.

What we agreed on with our graphical artists was to separate the torso from the legs and only animate the legs when walking. This would make the sprite smaller and you would be able to turn the player at angles in a way that resembles reality. A sound effect was implemented in the GameState for when the player got hurt. This is a way to tell the person playing the game that it isn’t a good idea to stand around doing nothing while there is a horde of monsters crawling towards you.

The visual feedback has I already explained in detail in an earlier blog. What I want to talk about is how the player class will function and how it is implemented right now. As you might think, I assigned movement speed, and a basic if statement for the WASD keys so that the player can be moved. A vector called heading was created to represent the direction of the player when a key representing that direction is pressed. The vector was assigned two floats that you can insert a direction, (0,-1) for up, (0, 1) for down etc. To make the movement speed match the game speed a variable called moveSpeed containing the speed of the player times the gameSpeed called deltaTime was added to the heading of the character. It looked like this (heding*=moveSpeed * deltaTime).

When the movement was done I added a draw function and created a pointer to the DrawManager class called drawManager. There I pointed to the drawcall function in whichplayer can hold a sprite and a float that represent the layer of which the sprite is to be drawn in. Here the torso, legs and “hud” lights were put so that when I call on the draw function of the player class they will be drawn in the right order. Right now, at this moment, they aren’t draw
n properly, the reason for this is as of right now unknown.

So there it is. I haven’t done a lot for the player this week but it is almost done.

About Peter Camerini

2015 Programming