-
Notifications
You must be signed in to change notification settings - Fork 3
/
flyfruit.cpp
77 lines (68 loc) · 1.13 KB
/
flyfruit.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
#include "flyfruit.h"
#include "player.h"
#include "lifeup.h"
FlyFruit::FlyFruit()
: Object(fly_fruit)
{
spr = 28;
if_not_fruit = true;
}
void FlyFruit::init()
{
start = y;
fly = false;
step = 0.5;
solids = false;
}
void FlyFruit::update()
{
Object::update();
// fly away
if (fly)
{
spd.y = appr(spd.y, -3.5f, 0.25f);
if (y < -SCREEN_H_OFFSET)
{
destroy_object(this);
}
}
// wait
else
{
if (has_dashed)
{
fly = true;
step += 0.5;
spd.y = sin(step) * 0.5;
}
}
// collect
Object * hit = collide(player, 0, 0);
if (hit)
{
static_cast<Player*>(hit)->djump = max_djump;
got_fruit[1 + level_index()] = true;
LifeUp * lifeup = new LifeUp;
init_object(lifeup, x, y);
destroy_object(this);
}
}
void FlyFruit::draw()
{
float off = 0;
if (!fly)
{
float dir = sin(step);
if (dir < 0)
{
off = 1 + max(0, sign (y - start));
}
else
{
off = static_cast<int>(off + 0.25) % 3;
}
}
drawSprite(45 + off, x - 6, y - 2, true, false);
drawSprite(spr, x, y);
drawSprite(45 + off, x + 6, y - 2);
}