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
- knicklicht
- feuerzeug
- fackel
# bugfixes
* the outer glow of multiple intersecting lights are not added yet, they are overlapping
+ schatten addieren
+ include reihenfolge
# ideas
* glowstick
* lighter
* torch

View file

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

View file

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

View file

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

View file

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

View file

@ -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()
draw_player(player.position)
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)
main_loop()
loop_main()

View file

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