canvas = document.getElementById 'canvas' context = canvas.getContext '2d' context.textAlign = 'center'; # the config config = gamewin: false gameover: false pixelsize: 15 debug: false lights: true map: width: 60 height: 40 origin: x: 0 y: 50 player = position: 0 lightrange: 10 blocks = walkable: [1, 0, 4, 6, 7, 8] entities: [1, 2, 7, 5, 6, 8] colors = floor: '#eeeeee' wall: '#333333' player: '#850091' key: '#ffe91a' door: '#0883fd' exit: '#07fd0f' breakable: '#bf7d0b' levels = [] current_level = 0 level = null # 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() toxy = (position)-> x: position%config.map.width y: Math.floor(position/config.map.width) # function: rect drawing rect = (x, y, w, h, color) -> context.fillStyle = color context.fillRect x, y, w, h pixel = (position, w, h, color) -> x = config.pixelsize*toxy(position).x+config.map.origin.x y = config.pixelsize*toxy(position).y+config.map.origin.y rect(x, y, w, h, color) write = (x, y, text, size, color) -> context.textAlign = 'center'; context.fillStyle = color context.font = 'normal '+size+'pt Verdana' context.fillText(text, x, y) add_level = (map) -> levels.push map # tmp: level shadow_layer = enemy_layer = level = null