more cleanup and comment work

This commit is contained in:
Ruben Müller 2013-06-13 21:46:14 +02:00
parent 36e452b6ed
commit 76988a1af7
10 changed files with 66 additions and 56 deletions

View file

@ -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

View file

@ -1 +0,0 @@
coffee -o build -c src/main.coffee

View file

@ -1 +1,3 @@
README 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'.

View file

@ -1,9 +1,7 @@
+ items # bugfixes
- knicklicht * the outer glow of multiple intersecting lights are not added yet, they are overlapping
- feuerzeug
- fackel
+ schatten addieren # ideas
* glowstick
* lighter
+ include reihenfolge * torch

View file

@ -2,11 +2,15 @@ canvas = document.getElementById 'canvas'
context = canvas.getContext '2d' context = canvas.getContext '2d'
context.textAlign = 'center'; context.textAlign = 'center';
# the config gamestates =
RUN = 'RUN'
WIN = 'WIN'
OVER = 'OVER'
config = config =
gamewin: false gamestate: gamestates.RUN
gameover: false
pixelsize: 15 pixelsize: 15
debug_available: true
debug: false debug: false
lights: true lights: true
map: map:
@ -43,5 +47,4 @@ levels = []
current_level = 0 current_level = 0
level = null level = null
# tmp: level
shadow_layer = enemy_layer = null shadow_layer = enemy_layer = null

View file

@ -1,23 +1,26 @@
# get input
keymap = [] keymap = []
addEventListener 'keydown', (event) -> addEventListener 'keydown', (event) ->
keymap[event.keyCode] = true keymap[event.keyCode] = true
#console.log event.keyCode # key: plus
#if event.keyCode == 187 then player.lightrange++
if event.keyCode == 187 if event.keyCode == 187
config.pixelsize += 2 config.pixelsize += 2
update_canvas() update_canvas(config.map.width*config.pixelsize+config.map.origin.x, config.map.height*config.pixelsize+config.map.origin.y)
#current_level++
#load_level(current_level) # key: minus
#if event.keyCode == 189 then player.lightrange--
if event.keyCode == 189 if event.keyCode == 189
config.pixelsize -= 2 config.pixelsize -= 2
update_canvas() update_canvas(config.map.width*config.pixelsize+config.map.origin.x, config.map.height*config.pixelsize+config.map.origin.y)
if event.keyCode == 68 then config.debug = !config.debug
# 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 == 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) -> addEventListener 'keyup', (event) ->
keymap[event.keyCode] = false keymap[event.keyCode] = false

View file

@ -24,7 +24,7 @@ init_level = () ->
load_level = (number) -> load_level = (number) ->
if number is levels.length if number is levels.length
config.gamewin = true config.gamestate = gamestates.WIN
else else
init_level() init_level()
level = levels[number] level = levels[number]

View file

@ -1,8 +1,8 @@
# preparing the canvas # updates the canvas
update_canvas = () -> update_canvas = (width, height) ->
canvas.width = config.map.width*config.pixelsize+config.map.origin.x canvas.width = width
canvas.height = config.map.height*config.pixelsize+config.map.origin.y canvas.height = height
update_canvas()
# a range mapper which maps 's' to 'to' based on 'from'
map_range = (from, to, s) -> map_range = (from, to, s) ->
to[0] + (s-from[0]) * (to[1] - to[0]) / (from[1] - from[0]) to[0] + (s-from[0]) * (to[1] - to[0]) / (from[1] - from[0])

View file

@ -1,25 +1,35 @@
main_loop = -> loop_run = ->
if config.gamewin reset_layers()
rect(0, 0, config.map.width*config.pixelsize, config.map.height*config.pixelsize+config.map.origin.y, '#ffffff') calculate_lights()
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()
draw_level(level) draw_level(level)
update_player_position() update_player_position()
if config.lights if config.lights
draw_lights('shadow') draw_lights('shadow')
draw_lights('enemy') draw_lights('enemy')
draw_player(player.position) draw_player(player.position)
draw_hud() draw_hud()
setTimeout main_loop, 50
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) load_level(current_level)
main_loop() loop_main()

View file

@ -28,7 +28,7 @@ update_player_position = () ->
#console.log enemy_layer #console.log enemy_layer
if enemy_layer[new_position] > 0 and !config.debug 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 if level[new_position] in blocks.walkable then player.position = new_position