-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblock.cpp
executable file
·161 lines (138 loc) · 2.68 KB
/
block.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
#include "headers/block.h"
Block::Block(int x, int y, float scale,SpawnType spawnType) : Sprite("../resources/empty_block.png",x,y,scale)
{
if(spawnType == SpawnRandom)
{
int randomNumber = rand() % 4;
switch(randomNumber)
{
case 0:
SetTexture("../resources/apple_block.png");
mType = Apple;
break;
case 1:
SetTexture("../resources/orange_block.png");
mType = Orange;
break;
case 2:
SetTexture("../resources/banana_block.png");
mType = Banana;
break;
case 3:
SetTexture("../resources/resin_block.png");
mType = Grape;
break;
}
}
else if(spawnType == SpawnStatic)
{
SetTexture("../resources/static_block.png");
mType = Static;
}
mZIndex = Index_Normal;
mX = x;
mY = y;
desiredXPos = x;
desiredYPos = y;
mDropVelocity = 100;
mIsMoving = false;
isTiltRight = false;
animationTimer = 0;
}
void Block::Update(double deltaTime)
{
mDropVelocity += 700 * deltaTime; //acceleration over time
int tempY = (int)mY; //maybe dis will change in the futur
int tempX = (int)mX;
if((desiredYPos != tempY || desiredXPos != tempX) && mType != Static)
{
if(desiredYPos != tempY)
{
mY += mDropVelocity * deltaTime;
mIsMoving = true;
if(abs(tempY - desiredYPos) < 8)
{
mY = desiredYPos;
//mIsMoving = false;
}
}
if(desiredXPos != tempX)
{
if(tempX < desiredXPos)
{
mX += 400 * deltaTime;
}
else if(tempX > desiredXPos)
{
mX -= 400 * deltaTime;
}
mIsMoving = true;
if(abs(tempX - desiredXPos) < 8)
{
mX = desiredXPos;
//mIsMoving = false;
}
}
}
else
{
mIsMoving = false;
mDropVelocity = 100;
}
//TiltRight(deltaTime);
//mX = mX - mWidth*mXScaleFactor*4*sin(SDL_GetTicks()/100) * deltaTime;
}
int Block::GetDesiredXPos() //in pixels
{
return desiredXPos;
}
int Block::GetDesiredYPos() //in pixels
{
return desiredYPos;
}
void Block::TiltRight(double deltaTime)
{
}
void Block::StartTiltRight()
{
isTiltRight = true;
}
void Block::SetDesiredPos(int x, int y) // in pixels
{
desiredXPos = x;
desiredYPos = y;
}
int Block::GetXPos() // in pixels
{
int temp = (int)mX;
return temp;
}
int Block::GetYPos()// in pixels
{
int temp = (int)mY;
return temp;
}
bool Block::IsMoving()
{
return mIsMoving;
}
Block::Type Block::GetType()
{
return mType;
}
Block::~Block()
{
}
int Block::GetYCoord()
{
return (int)(mY /(int)(mHeight*mYScaleFactor));
}
int Block::GetXCoord()
{
return (int)(mX/(int)(mWidth*mXScaleFactor));
}
void Block::GoToDesiredPos()
{
mX = desiredXPos;
mY = desiredYPos;
}