-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMole.cpp
More file actions
84 lines (73 loc) · 1.83 KB
/
Copy pathMole.cpp
File metadata and controls
84 lines (73 loc) · 1.83 KB
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
#include "Mole.h"
Mole::Mole(long time, bool state)
{
update(time, state);
currentMoleStatus = DOWN;
lastAnimTimeMillis = 0;
}
bool Mole::getState()
{
return isUp;
}
long Mole::getTime()
{
return currentStateTime;
}
void Mole::setState(bool toChange)
{
isUp = toChange;
}
void Mole::setTime(long toChange)
{
currentStateTime = toChange;
}
void Mole::update(long Time, bool State)
{
setState(State);
setTime(Time);
}
bool Mole::onCollision(Collideable * c)
{
return (collisionBox->isOverlap(c->collisionBox) || c->collisionBox->isOverlap(collisionBox))&& isUp;
}
unsigned long long getCurrentTime()
{
chrono::milliseconds ms = chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now().time_since_epoch());
return (unsigned long long)ms.count();
}
int Mole::draw()
{
int currentGlIndex = getAnim()->at(animationIndex)->it;
int newGlIndex = 0;
if((currentMoleStatus == RISING || currentMoleStatus == FALLING )&& getCurrentTime() - lastAnimTimeMillis > animPeriodMillis)
{
++getAnim()->at(animationIndex)->it;
newGlIndex = Collideable::draw();
lastAnimTimeMillis = getCurrentTime();
}
else
{
newGlIndex = Collideable::draw();
}
//cout << "changed iterator is: " << newGlIndex << endl;
getAnim()->at(animationIndex)->it = newGlIndex;
if(currentGlIndex > newGlIndex)
{
//cout << "&&&&&&&&" << endl;
//cout << "animationIndex was: " << animationIndex << endl;
if(currentMoleStatus == RISING)
{
//cout << "THE MOLE IS RISINGGGGA;FJSAD;LFAJEWO;RHAJEWOSFJAEWSO;FJAEWOSIFHESADLOGHAO;" << endl;
animationIndex = 1;
currentMoleStatus = ANGRY;
}
else if(currentMoleStatus == FALLING)
{
//cout << "TEHRE GOES DA MOLE FALLING AGAIN!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
animationIndex = 0;
currentMoleStatus = DOWN;
}
//cout << "animationIndex is now: " << animationIndex << endl;
}
return true;
}