-
Notifications
You must be signed in to change notification settings - Fork 0
/
player.cpp
147 lines (129 loc) · 3.83 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#include "player.hpp"
#include "input.hpp"
#include "audio.hpp"
#include "debug.hpp"
#include "engine.hpp"
#include "window.hpp"
#include "game.hpp"
Player::Player() {
for (int i = 0; i < 6; i++) {
EvolutionSprite[i] = Asset::RequestBlock("player size " + std::to_string(i));
}
Transform.Position.xy = { 512.0f, 512.0f };
Asset::Request("evolve", &EvolutionSFX);
EatTimer.Start();
}
void Player::Update() {
if (Health < 0.0f) {
return;
}
Sprite = EvolutionSprite[Evolution + HasUpgrade[UPGRADE_PLANE]];
SpriteAsset* AssetSprite = SpriteAsset::Get(Sprite);
if (AssetSprite) {
Transform.Scale.x = (float) AssetSprite->Texture.Size.x / (float) AssetSprite->Properties.Frames;
Transform.Scale.y = (float) AssetSprite->Texture.Size.y;
}
float MinAngleSpeed = 0.05f;
float MaxAngleSpeed = 0.08f;
float AngleTurnSpeedDivider = 10.0f;
if (KeyIsDown(KEY_W)) {
Transform.Position.x += std::cos(Transform.Rotation.z) * Speed.x;
Transform.Position.y -= std::sin(Transform.Rotation.z) * Speed.y;
Acceleration += AccelerationRate;
if (EatTimer.GetMilliseconds() > 5) {
GameLoop* Loop = (GameLoop*) GetLoop();
TextureAsset* WeedTexture = TextureAsset::Get(Loop->WeedTexture);
vector2f WeedSize = { (float) WeedTexture->Size.x, (float) WeedTexture->Size.y };
for (auto& CurrentChunk : Loop->ChunksInView) {
for (auto& CurrentWeed : CurrentChunk->Weeds) {
if (IsTransformOver(&Transform, CurrentWeed.Position, WeedSize)) {
Growth += 1;
EatTimer.Start();
break;
}
}
}
}
}
if (KeyIsDown(KEY_A)) {
if (!KeyIsDown(KEY_W)) {
Transform.Rotation.z += MinAngleSpeed;
Transform.Position.y += std::sin(-Transform.Rotation.z) * Speed.y / AngleTurnSpeedDivider;
} else {
Transform.Rotation.z += MaxAngleSpeed;
}
Transform.Position.x += std::cos(-Transform.Rotation.z) * Speed.x / AngleTurnSpeedDivider;
}
if (KeyIsDown(KEY_S)) {
Transform.Rotation.z += MinAngleSpeed;
Transform.Position.x -= std::cos(Transform.Rotation.z) * 0.01f;
Transform.Position.y += std::sin(Transform.Rotation.z) * 1.0f;
}
if (KeyIsDown(KEY_D)) {
if (!KeyIsDown(KEY_W)) {
Transform.Rotation.z -= MinAngleSpeed;
Transform.Position.y += std::sin(-Transform.Rotation.z) * Speed.y / AngleTurnSpeedDivider;
} else {
Transform.Rotation.z -= MaxAngleSpeed;
}
Transform.Position.x += std::cos(-Transform.Rotation.z) * Speed.x / AngleTurnSpeedDivider;
}
UpdateAcceleration();
InOil = false;
}
bool Player::CanGrow() {
int EvolutionAfford = Evolution;
if (Growth > EVOLUTION_GROWTH_4) {
if (Evolution < 4) {
EvolutionAfford = 4;
}
} else if (Growth > EVOLUTION_GROWTH_3) {
if (Evolution < 3) {
EvolutionAfford = 3;
}
} else if (Growth > EVOLUTION_GROWTH_2) {
if (Evolution < 2) {
EvolutionAfford = 2;
}
} else if (Growth > EVOLUTION_GROWTH_1) {
if (Evolution < 1) {
EvolutionAfford = 1;
}
}
return Evolution != EvolutionAfford;
}
int Player::GrowCost() {
if (Growth > EVOLUTION_GROWTH_4) {
return EVOLUTION_GROWTH_4;
} else if (Growth > EVOLUTION_GROWTH_3) {
return EVOLUTION_GROWTH_3;
} else if (Growth > EVOLUTION_GROWTH_2) {
return EVOLUTION_GROWTH_2;
} else if (Growth > EVOLUTION_GROWTH_1) {
return EVOLUTION_GROWTH_1;
}
return EVOLUTION_GROWTH_4 * 2;
}
void Player::Grow() {
int EvolutionBefore = Evolution;
if (Growth > EVOLUTION_GROWTH_4) {
Evolution = Max(Evolution, 4);
} else if (Growth > EVOLUTION_GROWTH_3) {
Evolution = Max(Evolution, 3);
} else if (Growth > EVOLUTION_GROWTH_2) {
Evolution = Max(Evolution, 2);
} else if (Growth > EVOLUTION_GROWTH_1) {
Evolution = Max(Evolution, 1);
} else {
Evolution = Max(Evolution, 0);
}
if (Evolution != EvolutionBefore) {
PlaySound(EvolutionSFX);
SetSoundVolume(EvolutionSFX, 100);
}
}
void Player::EquipUpgrade(int Upgrade) {
if (Upgrade == UPGRADE_CHEW) {
} else if (Upgrade == UPGRADE_SHELL) {
}
}