-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayerPlatform.cpp
167 lines (153 loc) · 3.52 KB
/
PlayerPlatform.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#include "PlayerPlatform.h"
#include <iostream>
//constructor
PlayerPlatform::PlayerPlatform()
:SpritesLogic("data/55-Breakout-Tiles.png") {}
//deconstructor
PlayerPlatform::~PlayerPlatform() {}
/**
* @brief seting default values for platform
* Default Width,Height, position, and time which is used to calculate how long does buffs/debuffs last
*/
void PlayerPlatform::GameSetup(int Width, int Height)
{
baseSize = Width* 0.2;
baseHeight = Height * 0.05;
Size = baseSize;
MAX_SIZE = baseSize * 2;
MIN_SIZE = baseSize * 0.5;
SetSize(baseSize, baseHeight);
//Set platform position directly in the middle of X axis
SetPosition((Width / 2)-SpriteRect.width / 2, Height - SpriteRect.height);
timeElapsed = getTickCount();
}
/**
* @brief increase size by 40%
* MAX_SIZE == 200% of original size
*/
void PlayerPlatform::IncreaseSize()
{
if (Size) { SetSize(Size += Size * 0.4, baseHeight); }
if (Size > MAX_SIZE) { Size = MAX_SIZE; SetSize(Size, baseHeight); }
bBuffActive = true;
buffStacks++;
//debug line
//std::cout << "IncRease Size: " << Size << "\n";
}
/**
* @brief decrease size by 40%
* MIN_SIZE == 50% of original size
*/
void PlayerPlatform::DecreaseSize()
{
if (Size > MIN_SIZE) { SetSize(Size -= Size * 0.4, 30); }
else if (Size <= MIN_SIZE) { Size = MIN_SIZE; SetSize(Size, 30); }
if(Size <= MIN_SIZE) { Size = MIN_SIZE; SetSize(Size, 30); }
bBuffActive = true;
buffStacks++;
//debug line
//std::cout << "DecreaseSize: " << Size << "\n";
}
/**
* @brief sets size to default value
*/
void PlayerPlatform::DefaultSize()
{
Size = baseSize;
buffStacks = 0;
bBuffActive = false;
SetSize(Size, 30);
}
/**
* @brief checks if player is out of map
* handles movement
* and handles time (how much time does function last)
* @param movementInput handles player input
*/
void PlayerPlatform::Update(PlayerMovementStruct& movementInput, int Width)
{
PlayerMovement(movementInput);
MapBorders(Width);
if (buffStacks == 0)
{
timeElapsed = getTickCount();
}
else if(buffStacks == 1 && bBuffActive)
{
if (GetTime() >= 20)
{
DefaultSize();
timeElapsed = getTickCount();
}
}
else if (buffStacks > 1)
{
if (buffStacks != placeHolder)
{
placeHolder = buffStacks;
timeHolder = GetTime();
timeElapsed = getTickCount();
}
if (timeHolder > 20)
{
if (GetTime() >= 40)
{
std::cout << timeHolder << '\n';
DefaultSize();
timeElapsed = getTickCount();
}
}
else if (GetTime() >= 40-timeHolder)
{
DefaultSize();
timeElapsed = getTickCount();
}
}
}
/**
* @brief handling player movement input
* @param move - is player pressing key if yes move platform
*/
void PlayerPlatform::PlayerMovement(PlayerMovementStruct& move)
{
if (move.bIsMovingRight) MoveSprite(movementSpeed, 0);
else if (move.bIsMovingLeft) MoveSprite(-movementSpeed, 0);
}
/**
* @brief borders for player platform
*/
void PlayerPlatform::MapBorders(int Width)
{
if (SpriteRect.XLocation < 0) SetPosition(0, SpriteRect.YLocation);
else if (SpriteRect.XLocation > Width-Size) SetPosition(Width - Size, SpriteRect.YLocation);
}
//getters
int PlayerPlatform::GetPlatformSize()
{
return Size;
}
int PlayerPlatform::GetPlatformXLocation()
{
return SpriteRect.XLocation;
}
int PlayerPlatform::GetPlatformYLocation()
{
return SpriteRect.YLocation;
}
/**
* @brief time in seconds
* @return
*/
int PlayerPlatform::GetTime()
{
return (getTickCount() - timeElapsed)/1000;
}
//setters
void PlayerPlatform::SetTickTime(int Time)
{
this->timeElapsed = Time;
}
void PlayerPlatform::SetbBuffActive()
{
bBuffActive = false;
}