-
Notifications
You must be signed in to change notification settings - Fork 3
/
fallfloor.cpp
69 lines (64 loc) · 969 Bytes
/
fallfloor.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
#include "fallfloor.h"
#include "spring.h"
FallFloor::FallFloor()
: Object(fall_floor)
{
}
void FallFloor::init()
{
state = 0;
delay = 0;
}
void FallFloor::update()
{
if (state == 0)
{
if (check(player, 0, -1) || check(player, -1, 0) || check(player, 1, 0))
{
break_fall_floor();
}
}
else if (state == 1)
{
delay--;
if (delay <= 0)
{
state = 2;
delay = 60;
collideable = false;
}
}
else if(state == 2)
{
delay--;
if (delay <= 0 && !check(player, 0, 0))
{
state = 0;
collideable = true;
}
}
}
void FallFloor::draw()
{
if (state == 0)
{
drawSprite(23, x, y);
}
else if (state == 1)
{
drawSprite(23 + (15 - delay) / 5, x, y);
}
}
void FallFloor::break_fall_floor()
{
if (state == 0)
{
state = 1;
delay = 15;
Object * hit = collide(spring, 0, -1);
if (hit)
{
static_cast<Spring*>(hit)->break_spring();
}
}
}