From 76988a1af7f58ce1fa294d447b112a1d283b3506 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ruben=20M=C3=BCller?= Date: Thu, 13 Jun 2013 21:46:14 +0200 Subject: [PATCH] more cleanup and comment work --- Cakefile | 5 ----- compile.sh | 1 - docs/README | 4 +++- docs/TODO | 14 +++++------- src/config.coffee | 11 ++++++---- src/input.coffee | 23 ++++++++++--------- src/level.coffee | 2 +- src/lib/helpers.coffee | 10 ++++----- src/main.coffee | 50 +++++++++++++++++++++++++----------------- src/player.coffee | 2 +- 10 files changed, 66 insertions(+), 56 deletions(-) delete mode 100644 Cakefile delete mode 100755 compile.sh diff --git a/Cakefile b/Cakefile deleted file mode 100644 index 583a820..0000000 --- a/Cakefile +++ /dev/null @@ -1,5 +0,0 @@ -{exec} = require 'child_process' -task 'sbuild', 'Build project from ./src/*.coffee to ./build/*.js', -> - exec 'coffee --output ./build/ --join game.js --compile ./src/', (err, stdout, stderr) -> - throw err if err - console.log stdout + stderr \ No newline at end of file diff --git a/compile.sh b/compile.sh deleted file mode 100755 index a8858f5..0000000 --- a/compile.sh +++ /dev/null @@ -1 +0,0 @@ -coffee -o build -c src/main.coffee \ No newline at end of file diff --git a/docs/README b/docs/README index 100b938..888b892 100644 --- a/docs/README +++ b/docs/README @@ -1 +1,3 @@ -README \ No newline at end of file +Not So Alone In The Dark + +This game was created for the BaconGameJam 5 on June, the 8th and 9th in 2013 by Aaron Müller (dev), Jonas Müller (maps) and Ruben Müller (dev). The theme for the gamejam was 'Lights out'. \ No newline at end of file diff --git a/docs/TODO b/docs/TODO index 9e6883d..ebf9b8b 100644 --- a/docs/TODO +++ b/docs/TODO @@ -1,9 +1,7 @@ -+ items - - knicklicht - - feuerzeug - - fackel +# bugfixes +* the outer glow of multiple intersecting lights are not added yet, they are overlapping -+ schatten addieren - - -+ include reihenfolge \ No newline at end of file +# ideas +* glowstick +* lighter +* torch \ No newline at end of file diff --git a/src/config.coffee b/src/config.coffee index bac64f5..2763c47 100644 --- a/src/config.coffee +++ b/src/config.coffee @@ -2,11 +2,15 @@ canvas = document.getElementById 'canvas' context = canvas.getContext '2d' context.textAlign = 'center'; -# the config +gamestates = + RUN = 'RUN' + WIN = 'WIN' + OVER = 'OVER' + config = - gamewin: false - gameover: false + gamestate: gamestates.RUN pixelsize: 15 + debug_available: true debug: false lights: true map: @@ -43,5 +47,4 @@ levels = [] current_level = 0 level = null -# tmp: level shadow_layer = enemy_layer = null \ No newline at end of file diff --git a/src/input.coffee b/src/input.coffee index f8fa7f9..1ac812a 100644 --- a/src/input.coffee +++ b/src/input.coffee @@ -1,23 +1,26 @@ -# get input keymap = [] addEventListener 'keydown', (event) -> keymap[event.keyCode] = true - #console.log event.keyCode - #if event.keyCode == 187 then player.lightrange++ + # key: plus if event.keyCode == 187 config.pixelsize += 2 - update_canvas() - #current_level++ - #load_level(current_level) - #if event.keyCode == 189 then player.lightrange-- + update_canvas(config.map.width*config.pixelsize+config.map.origin.x, config.map.height*config.pixelsize+config.map.origin.y) + + # key: minus if event.keyCode == 189 config.pixelsize -= 2 - update_canvas() - if event.keyCode == 68 then config.debug = !config.debug + update_canvas(config.map.width*config.pixelsize+config.map.origin.x, config.map.height*config.pixelsize+config.map.origin.y) + + # key: d + if event.keyCode == 68 and config.debug_available then config.debug = !config.debug + + # key: space if event.keyCode == 32 then break_walls(player.position) - if event.keyCode == 76 then config.lights = !config.lights + + # key: l + if event.keyCode == 76 and config.debug_available then config.lights = !config.lights addEventListener 'keyup', (event) -> keymap[event.keyCode] = false \ No newline at end of file diff --git a/src/level.coffee b/src/level.coffee index 30869de..05bfb77 100644 --- a/src/level.coffee +++ b/src/level.coffee @@ -24,7 +24,7 @@ init_level = () -> load_level = (number) -> if number is levels.length - config.gamewin = true + config.gamestate = gamestates.WIN else init_level() level = levels[number] diff --git a/src/lib/helpers.coffee b/src/lib/helpers.coffee index e45d583..e7c6ce9 100644 --- a/src/lib/helpers.coffee +++ b/src/lib/helpers.coffee @@ -1,8 +1,8 @@ -# preparing the canvas -update_canvas = () -> - canvas.width = config.map.width*config.pixelsize+config.map.origin.x - canvas.height = config.map.height*config.pixelsize+config.map.origin.y -update_canvas() +# updates the canvas +update_canvas = (width, height) -> + canvas.width = width + canvas.height = height +# a range mapper which maps 's' to 'to' based on 'from' map_range = (from, to, s) -> to[0] + (s-from[0]) * (to[1] - to[0]) / (from[1] - from[0]) \ No newline at end of file diff --git a/src/main.coffee b/src/main.coffee index 4588ec0..a37f2d0 100644 --- a/src/main.coffee +++ b/src/main.coffee @@ -1,25 +1,35 @@ -main_loop = -> - if config.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') - else if config.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') - else - reset_layers() - calculate_lights() +loop_run = -> + reset_layers() + calculate_lights() - draw_level(level) - update_player_position() + draw_level(level) + update_player_position() - if config.lights - draw_lights('shadow') - draw_lights('enemy') + if config.lights + draw_lights('shadow') + draw_lights('enemy') - draw_player(player.position) - draw_hud() - - setTimeout main_loop, 50 + 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) -main_loop() \ No newline at end of file +loop_main() \ No newline at end of file diff --git a/src/player.coffee b/src/player.coffee index 002d272..02fa65f 100644 --- a/src/player.coffee +++ b/src/player.coffee @@ -28,7 +28,7 @@ update_player_position = () -> #console.log enemy_layer if enemy_layer[new_position] > 0 and !config.debug - config.gameover = true + config.gamestate = gamestates.OVER if level[new_position] in blocks.walkable then player.position = new_position