-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.cpp
More file actions
44 lines (39 loc) · 882 Bytes
/
Player.cpp
File metadata and controls
44 lines (39 loc) · 882 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "Player.h"
Player::Player(SDL_Renderer* renderer)
{
this->renderer = renderer;
current_texture = 0;
textures.push_back(IMG_LoadTexture(renderer, "assets/player1.png"));
textures.push_back(IMG_LoadTexture(renderer, "assets/player2.png"));
rect.x = 10;
rect.y = 20;
SDL_QueryTexture(textures[0], NULL, NULL, &rect.w, &rect.h);
}
Player::~Player()
{
//dtor
}
void Player::draw()
{
SDL_RenderCopy(renderer, textures[current_texture], NULL, &rect);
}
void Player::logic()
{
const Uint8* currentKeyStates = SDL_GetKeyboardState( NULL );
if(currentKeyStates[SDL_SCANCODE_UP])
{
rect.y--;
}
if(currentKeyStates[SDL_SCANCODE_DOWN])
{
rect.y++;
}
if(currentKeyStates[SDL_SCANCODE_LEFT])
{
rect.x--;
}
if(currentKeyStates[SDL_SCANCODE_RIGHT])
{
rect.x++;
}
}