forked from galah4d/pacman-cx
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrender.cx
More file actions
201 lines (166 loc) · 5.33 KB
/
render.cx
File metadata and controls
201 lines (166 loc) · 5.33 KB
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
package main
// Game Object render functions
/* Function : renderGame
Input : OpenGL program (program i32)
Description : Responsible for managing the rendering process of all the game
objects.
*/
func renderGame(program i32) {
var i i32
var j i32
gl.Clear(gl.COLOR_BUFFER_BIT)
renderBoard()
renderPlayer()
// Render Points
for i=0; i<points_count; i++ {
if bool.eq(points[i].active, true) {
renderPoint(points[i])
}
}
// Render Ghosts
for i=0; i<4; i++ {
renderGhost(ghosts[i])
}
renderLives()
renderLevel()
renderGhostEaterMeter()
}
/* Function : renderGhostEaterMeter
Description : makes it clear how much time you have to eat ghosts
*/
var left f32 = -1.0
var right f32 = 1.0
func renderGhostEaterMeter() {
if bool.not(isTimerOver(
GHOST_FRIGHTENED_TIMER,
GHOST_FRIGHTENED_LIMIT)) {
var posL graphical2d.Position2D
var posR graphical2d.Position2D
var dim graphical2d.Dimensions2D
var col graphical2d.Color
var f f64 = f64.sub(glfw.GetTime(), GHOST_FRIGHTENED_TIMER)
f = f64.div(f, GHOST_FRIGHTENED_LIMIT)
var fraction f32 = f64.f32(f)
posL = graphical2d.Position2D{ x: f32.add(left, CELL_HALF_HEIGHT), y: 0.0 }
posR = graphical2d.Position2D{ x: f32.sub(right, CELL_HALF_HEIGHT), y: 0.0 }
// blinking red background
dim = graphical2d.Dimensions2D{ width: CELL_HALF_HEIGHT, height: 2.0 }
col = graphical2d.Color{ red: 1.0, green: 0.0, blue: 0.0 }
if blinkStatusOn() {
if player.position.x < 0.0 {
graphical2d.drawRectangle(posL, dim, col)
}else{
graphical2d.drawRectangle(posR, dim, col)
}
}
// shrinking green bar
dim.height = f32.sub(2.0, fraction * 2.0)
col.red = 0.0
col.green = 1.0
if player.position.x < 0.0 {
graphical2d.drawRectangle(posL, dim, col)
}else{
graphical2d.drawRectangle(posR, dim, col)
}
}
}
/* Function : renderBoard
Description : Renders the game board
*/
func renderBoard() {
for i:=0; i<y_cells; i++ {
for j:=0; j<x_cells; j++ {
graphical2d.drawRectangle(cells[i][j].position, cells[i][j].dimensions, cells[i][j].color)
}
}
}
/* Function : renderPlayer
Description : Renders the player
*/
func renderPlayer() {
var pos Position2D = player.position
if gameMode == GAMEMODE_GETREADY {
pos = getLerpTween(nextLifePos, pos,
GETREADY_TIMER, GETREADY_LIMIT)
}
pos.x = f32.add(pos.x, player.cell_pos.x)
pos.y = f32.add(pos.y, player.cell_pos.y)
graphical2d.drawPlayer(pos, player.radius, player.color, false)
/*
var heartCol graphical2d.Color = graphical2d.newColor(LIFE_COLOR_RED, LIFE_COLOR_GREEN, LIFE_COLOR_BLUE)
graphical2d.drawLife(player.position, LIFE_RADIUS, heartCol)
*/
}
/* Function : renderGhost
Description : Renders a ghost
*/
func renderGhost(ghost Ghost) {
var color graphical2d.Color
if i32.eq(ghost.status, GHOST_MODE_FRIGHTENED) {
if bool.and(isTimerOver(GHOST_ANIMATION_TIMER, GHOST_ANIMATION_SEMI_LIMIT), isTimerOver(GHOST_FRIGHTENED_TIMER, GHOST_FRIGHTENED_SEMI_LIMIT)) {
color = graphical2d.newColor(1.0, 1.0, 1.0)
} else {
color = graphical2d.newColor(0.0, 0.0, 1.0)
}
} else {
color = ghost.color
}
if isTimerOver(GHOST_ANIMATION_TIMER, GHOST_ANIMATION_SEMI_LIMIT) {
graphical2d.drawGhost(ghost.position, ghost.radius, color, 0.5) // FIX ME DrawGhost()
} else {
graphical2d.drawGhost(ghost.position, ghost.radius, color, 1.5) // FIX ME DrawGhost2()
}
if isTimerOver(GHOST_ANIMATION_TIMER, GHOST_ANIMATION_LIMIT) {
GHOST_ANIMATION_TIMER = glfw.GetTime()
}
}
/* Function : renderPoint
Description : Renders a point
*/
func renderPoint(point Point) () {
if isTimerOver(POINT_ANIMATION_TIMER, POINT_ANIMATION_SEMI_LIMIT) {
if i32.eq(point.ptype, PATH_CELL_WITH_SUPER_POINT) {
graphical2d.drawCircle(point.position, f32.add(point.radius, 0.005), point.color)
}
if i32.eq(point.ptype, PATH_CELL_WITH_SIMPLE_POINT) {
graphical2d.drawCircle(point.position, point.radius, point.color)
}
} else {
graphical2d.drawCircle(point.position, point.radius, point.color)
}
if isTimerOver(POINT_ANIMATION_TIMER, POINT_ANIMATION_LIMIT) {
POINT_ANIMATION_TIMER = glfw.GetTime()
}
}
/* Function : renderLives
Description : Renders the player lives
*/
func renderLives() {
var position graphical2d.Position2D
var heartCol Color
var pacCol Color
var numHearts i32 = PLAYER_LIVES
var numPacs i32 = PLAYER_LIVES - 1
if gameMode != GAMEMODE_GETREADY {
numHearts--
}
heartCol = graphical2d.newColor(LIFE_COLOR_RED, LIFE_COLOR_GREEN, LIFE_COLOR_BLUE)
pacCol = graphical2d.newColor(1.0, 1.0, 0.0)
for i:=0; i<numPacs; i++ {
position = coords2position(LIFE_SPAWN_LINE, i32.sub(LIFE_SPAWN_COLUMN, i))
graphical2d.drawPlayer(position, CELL_HALF_WIDTH - 0.01, pacCol, true)
}
for i:=0; i<numHearts; i++ {
position = coords2position(LIFE_SPAWN_LINE, i32.sub(LIFE_SPAWN_COLUMN, i))
graphical2d.drawLife(position, LIFE_RADIUS, heartCol)
}
}
func renderLevel() {
var color Color
color = graphical2d.newColor(0.0, 0.0, 1.0)
var position graphical2d.Position2D
for i:=0; i<GAME_LEVEL; i++ {
position = coords2position(30, i32.add(1, i))
graphical2d.drawSkycoin(position, 0.025, 0.0125, color)
}
}