35 lines
944 B
CoffeeScript
35 lines
944 B
CoffeeScript
loop_run = ->
|
|
reset_layers()
|
|
calculate_lights()
|
|
|
|
draw_level(level)
|
|
update_player_position()
|
|
|
|
if config.lights
|
|
draw_lights('shadow')
|
|
draw_lights('enemy')
|
|
|
|
draw_player(player.position)
|
|
draw_hud()
|
|
|
|
loop_gamewin = ->
|
|
rect(0, 0, config.map.width*config.pixelsize, config.map.height*config.pixelsize+config.map.origin.y, '#ffffff')
|
|
write(250, 100, 'You won, awesome!', 20, '#000000')
|
|
|
|
loop_gameover = ->
|
|
rect(0, 0, config.map.width*config.pixelsize, config.map.height*config.pixelsize+config.map.origin.y, '#ff0000')
|
|
write(150, 100, 'Oh noes!', 20, '#ffffff')
|
|
|
|
loop_main = ->
|
|
switch config.gamestate
|
|
when gamestates.RUN then loop_run()
|
|
when gamestates.WIN then loop_gamewin()
|
|
when gamestates.OVER then loop_gameover()
|
|
|
|
setTimeout loop_main, 50
|
|
|
|
# load the first level and call the main loop for the first time
|
|
# those functioncalls are only used once
|
|
update_canvas()
|
|
load_level(current_level)
|
|
loop_main() |