-
Notifications
You must be signed in to change notification settings - Fork 1
/
Pipe.chai
113 lines (103 loc) · 2.64 KB
/
Pipe.chai
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
class Pipe {
def serialize() {
return [
"opening": this.opening,
"x": this.x,
"y": this.y,
"scored": this.scored,
"width": this.width,
"height": this.height,
"top": this.top,
"openingHeight": this.openingHeight,
"quadx": this.sourcequad.x,
"quady": this.sourcequad.y,
"quadwidth": this.sourcequad.width,
"quadheight": this.sourcequad.height
]
}
def deserialize(obj) {
this.x = obj["x"]
this.y = obj["y"]
this.opening = obj["opening"]
this.scored = obj["scored"]
this.width = obj["width"]
this.height = obj["height"]
this.top = obj["top"]
this.openingHeight = obj["openingHeight"]
this.sourcequad.x = obj["quadx"]
this.sourcequad.y = obj["quady"]
this.sourcequad.width = obj["quadwidth"]
this.sourcequad.height = obj["quadheight"]
this.img := this.top ? assets["pipe-top"] : assets["pipe-bottom"]
return this
}
def Pipe(opening, top, openingHeight) {
this.scored = false
this.opening = opening
this.openingHeight = openingHeight
// Make sure the position is of floating point.
this.x = love.graphics.getWidth() * 1.0f
this.top = top
this.sourcequad = Quad()
if (top) {
this.y = 0
this.height = opening - this.openingHeight
this.img := assets["pipe-top"]
this.width = this.img.getWidth()
this.sourcequad.x = 0
this.sourcequad.y = this.img.getHeight() - this.height
this.sourcequad.width = this.img.getWidth()
this.sourcequad.height = this.height
}
else {
this.y = opening + this.openingHeight
this.height = landTop - this.y + 1
this.img := assets["pipe-bottom"]
this.width = this.img.getWidth()
this.sourcequad.x = 0
this.sourcequad.y = 0
this.sourcequad.width = this.img.getWidth()
this.sourcequad.height = this.height
}
}
def draw() {
love.graphics.draw(this.img, this.sourcequad, this.x, this.y)
}
def update(delta, speed) {
this.x -= delta * speed
if (this.x + this.width < 0) {
return false
}
// Difficulty level
/*
if (score >= 10) {
if (this.top) {
this.height += delta * score / 3.0f
this.sourcequad.height = this.height
this.sourcequad.y = this.img.getHeight() - this.height
}
else {
this.y -= delta * score / 3.0f
this.height = landTop - this.y + 1
this.sourcequad.height = this.height
}
}
*/
return true
}
def collide(bird) {
if (cheatNoClip) {
return false
}
if (this.x < bird.right() - bird.collisionPadding) {
if (this.x + this.width > bird.left() + bird.collisionPadding) {
if (this.y < bird.bottom() - bird.collisionPadding) {
if (this.y + this.height > bird.top() + bird.collisionPadding) {
return true
}
}
}
}
return false
}
}