-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPlayer.cpp
73 lines (66 loc) · 1.57 KB
/
Player.cpp
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "Include/Player.h"
player::player()
{
init(LEVEL_WIDTH / 2, LEVEL_HEIGHT / 2, PLAYER_SIZE, -1);
speed = PLAYER_SPEED;
health = 100;
vx = 0;
vy = 0;
currentFrame = 0;
currentTotalFrame = 0;
currentWeapon = 0;
currentState = playerState::IDLE;
previousState = playerState::IDLE;
for (int i = 0; i < PLAYER_WEAPON_SLOT; i++)
{
myWeapon[i].init("temp", 0, 0, 0, 0, 0);
}
}
void player::initPlayer()
{
init(LEVEL_WIDTH / 2, LEVEL_HEIGHT / 2, SCREEN_HEIGHT / 7, -1);
speed = PLAYER_SPEED;
health = 100;
vx = 0;
vy = 0;
currentFrame = 0;
currentTotalFrame = 0;
currentWeapon = 0;
currentState = playerState::IDLE;
previousState = playerState::IDLE;
}
void player::calRotation(SDL_Rect& camera, int x, int y)
{
int deltaX;
int deltaY;
//If player reached the edge of the level
if (camera.x <= 0 || camera.y <= 0 || camera.x >= LEVEL_WIDTH - camera.w || camera.y >= LEVEL_HEIGHT - camera.h)
{
deltaX = px - camera.x - x;
deltaY = py - camera.y - y;
}
else
{
deltaX = (SCREEN_WIDTH / 2 - size / 2) - x;
deltaY = (SCREEN_HEIGHT / 2 - size / 2) - y;
}
rotation = 180 + (atan2(deltaY, deltaX) * 180.0000) / M_PI;
}
void player::cycleWeapon()
{
myWeapon[currentWeapon].stopReload();
currentWeapon++;
if (currentWeapon >= PLAYER_WEAPON_SLOT)
{
currentWeapon = 0;
}
}
void player::setAnimation(LTexture& targetTexture, SDL_Rect& targetClip)
{
currentTexture = &targetTexture;
currentClip = &targetClip;
}
void player::render(SDL_Rect& camera)
{
currentTexture->render(rx - camera.x, ry - camera.y, size, size, currentClip, rotation, NULL, SDL_FLIP_NONE);
}