2013-07-11 22:55:45 +02:00
|
|
|
loop_run = =>
|
2013-06-13 21:46:14 +02:00
|
|
|
reset_layers()
|
|
|
|
calculate_lights()
|
2013-06-10 16:59:29 +02:00
|
|
|
|
2013-06-13 21:46:14 +02:00
|
|
|
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')
|
|
|
|
|
2013-07-11 22:55:45 +02:00
|
|
|
loop_gameover = =>
|
2013-06-13 21:46:14 +02:00
|
|
|
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')
|
|
|
|
|
2013-07-11 22:55:45 +02:00
|
|
|
loop_main = =>
|
2013-06-13 21:46:14 +02:00
|
|
|
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
|
2013-07-11 22:55:45 +02:00
|
|
|
update_canvas(config.map.width*config.pixelsize, config.map.height*config.pixelsize+config.map.origin.y)
|
2013-06-13 21:15:18 +02:00
|
|
|
load_level(current_level)
|
2013-06-13 21:46:14 +02:00
|
|
|
loop_main()
|