-
Notifications
You must be signed in to change notification settings - Fork 1
/
Player.cpp
112 lines (96 loc) · 1.91 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include "Player.h"
#include "Game.h"
Game game;
void Player::Render(SDL_Renderer* ren)
{
animationTimer++;
if (animationTimer < 16)
{
SDL_RenderCopyEx(ren, getTexture(), &getSrc(), &getDest(), 0, NULL, SDL_FLIP_NONE);
}
else if (animationTimer >= 16 && animationTimer <= 32)
{
SDL_RenderCopyEx(ren, Tex1, &getSrc(), &getDest(), 0, NULL, SDL_FLIP_NONE);
}
else if (animationTimer >= 32 && animationTimer <= 48)
{
SDL_RenderCopyEx(ren, Tex2, &getSrc(), &getDest(), 0, NULL, SDL_FLIP_NONE);
}
else if (animationTimer > 48)
{
SDL_RenderCopyEx(ren, Tex1, &getSrc(), &getDest(), 0, NULL, SDL_FLIP_NONE);
}
if (animationTimer > 54)
{
animationTimer = 0;
}
}
void Player::RenderDead(SDL_Renderer* ren)
{
SDL_RenderCopyEx(ren, Tex3, &getSrc(), &getDest(), 0, NULL, SDL_FLIP_NONE);
}
void Player::Gravity()
{
if (JumpState())
{
accelerator1 += 0.035;
accelerator2 += 0.035;
jumpHeight += gravity;
Ypos += gravity + accelerator1 + accelerator2 + jumpHeight;
setDest(220, Ypos, 60*3, 46 * 3);
if (jumpHeight > 0)
{
inJump = false;
jumpHeight = -10;
}
}
else
{
accelerator1 += 0.035;
accelerator2 += 0.035;
Ypos += gravity + accelerator1 + accelerator2;
setDest(220, Ypos, 60*3, 46*3);
}
}
int Player::Ypo()
{
return Ypos;
}
int Player::Xpo()
{
return Xpos;
}
void Player::Jump()
{
if (jumpTimer - lastJump > 180)
{
accelerator1 = 0;
accelerator2 = 0;
inJump = true;
lastJump = jumpTimer;
}
else
{
Gravity();
}
}
void Player::GetJumpTime()
{
jumpTimer = SDL_GetTicks();
}
bool Player::JumpState()
{
return inJump;
}
void Player::CreateTexture1(const char* address, SDL_Renderer* ren)
{
Tex1 = TextureManager::Texture(address, ren);
}
void Player::CreateTexture2(const char* address, SDL_Renderer* ren)
{
Tex2 = TextureManager::Texture(address, ren);
}
void Player::CreateTexture3(const char* address, SDL_Renderer* ren)
{
Tex3 = TextureManager::Texture(address, ren);
}