-
Notifications
You must be signed in to change notification settings - Fork 3
/
playerspawn.cpp
81 lines (73 loc) · 1.1 KB
/
playerspawn.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
#include "playerspawn.h"
#include "player.h"
PlayerSpawn::PlayerSpawn()
: Object(player_spawn)
{
}
void PlayerSpawn::init()
{
spr = 3;
y = MAP_SIZE;
spd.y = -4;
state = 0;
delay = 0;
solids = false;
hair.create_hair(this);
}
void PlayerSpawn::update()
{
Object::update();
// jumping
if (state == 0)
{
if (y < target + 16)
{
state = 1;
delay = 3;
}
}
// falling
else if (state == 1)
{
spd.y += 0.5;
if (spd.y > 0 && delay > 0)
{
spd.y = 0;
delay--;
}
if (spd.y > 0 && y > target)
{
y = target;
spd.x = 0;
spd.y = 0;
state = 2;
delay = 5;
}
}
// landing
else if (state == 2)
{
delay--;
spr = 6;
if (delay < 0)
{
destroy_object(this);
Player * p = new Player;
init_object(p, x, y);
}
}
}
void PlayerSpawn::draw()
{
hair.draw_hair(this, 1, max_djump);
drawSprite(spr, x, y, flip.x, flip.y);
}
void PlayerSpawn::setPosition(int new_x, int new_y)
{
setTarget(new_x, new_y);
}
void PlayerSpawn::setTarget(int tx, int ty)
{
x = tx;
target = ty;
}