This repository has been archived by the owner on Nov 21, 2018. It is now read-only.
/
Ladder.cpp
83 lines (75 loc) · 2.12 KB
/
Ladder.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
/* Justin Robb
* 3-27-14
* JetPack
*/
#include "Ladder.h"
#include "Enums.h"
const int SWITCH_SPEED = 2;
Ladder::Ladder(float x, float y, float w, float h, const Sprites *s) {
const Rectangle r = Rectangle(x, y, w, h);
Init(r, s);
}
Ladder::Ladder(const Rectangle r, const Sprites *s) {
Init(r, s);
}
void Ladder::Init(const Rectangle r, const Sprites *s) {
assert(s);
bounds = new Rectangle(r.position_x, r.position_y, r.width, r.height);
name = "Ladder";
type = TYPE_LADDER;
sprites = s;
def_sprite = SPRITE_LADDER;
is_solid = false;
is_collectable = false;
direction = -1;
gen_type = NONSOLID;
switch_time = SWITCH_SPEED;
}
Ladder::~Ladder(){
delete bounds;
}
void Ladder::setDirection(int code) {
if (code == UP) {
direction = UP;
type = TYPE_LADDERUP;
def_sprite = SPRITE_LADDER3;
name = "Ladder moving up";
} else if (code == DOWN) {
direction = DOWN;
type = TYPE_LADDERDOWN;
def_sprite = SPRITE_LADDER2;
name = "Ladder moving down";
}
}
void Ladder::draw() {
if (switch_time > 0) {
switch_time--;
} else if (direction == DOWN && def_sprite == SPRITE_LADDER) {
switch_time = SWITCH_SPEED;
def_sprite = SPRITE_LADDER2;
} else if (direction == DOWN && def_sprite == SPRITE_LADDER2) {
switch_time = SWITCH_SPEED;
def_sprite = SPRITE_LADDER3;
} else if (direction == DOWN && def_sprite == SPRITE_LADDER3) {
switch_time = SWITCH_SPEED;
def_sprite = SPRITE_LADDER4;
} else if (direction == DOWN && def_sprite == SPRITE_LADDER4) {
switch_time = SWITCH_SPEED;
def_sprite = SPRITE_LADDER;
} else if (direction == UP && def_sprite == SPRITE_LADDER) {
switch_time = SWITCH_SPEED;
def_sprite = SPRITE_LADDER4;
} else if (direction == UP && def_sprite == SPRITE_LADDER2) {
switch_time = SWITCH_SPEED;
def_sprite = SPRITE_LADDER;
} else if (direction == UP && def_sprite == SPRITE_LADDER3) {
switch_time = SWITCH_SPEED;
def_sprite = SPRITE_LADDER2;
} else if (direction == UP && def_sprite == SPRITE_LADDER4) {
switch_time = SWITCH_SPEED;
def_sprite = SPRITE_LADDER3;
}
glBindTexture(GL_TEXTURE_2D, sprites->getSprite(def_sprite));
bounds->draw();
glBindTexture(GL_TEXTURE_2D, 0);
}