precious code
This commit is contained in:
parent
9d6426a6f1
commit
930cd7691e
5 changed files with 40 additions and 35 deletions
|
@ -38,7 +38,7 @@ map_range = function(from, to, s) {
|
||||||
return to[0] + (s - from[0]) * (to[1] - to[0]) / (from[1] - from[0]);
|
return to[0] + (s - from[0]) * (to[1] - to[0]) / (from[1] - from[0]);
|
||||||
};
|
};
|
||||||
// Generated by CoffeeScript 1.6.3
|
// Generated by CoffeeScript 1.6.3
|
||||||
var blocks, canvas, colors, config, context, current_level, enemy_layer, gamestates, inventar, level, levels, player, shadow_layer;
|
var blocks, canvas, colors, config, context, current_level, enemy_layer, gamestates, inventar, level, levels, player, selected_layer, shadow_layer;
|
||||||
|
|
||||||
canvas = document.getElementById('canvas');
|
canvas = document.getElementById('canvas');
|
||||||
|
|
||||||
|
@ -98,7 +98,11 @@ current_level = 0;
|
||||||
|
|
||||||
level = null;
|
level = null;
|
||||||
|
|
||||||
shadow_layer = enemy_layer = null;
|
shadow_layer = null;
|
||||||
|
|
||||||
|
enemy_layer = null;
|
||||||
|
|
||||||
|
selected_layer = null;
|
||||||
// Generated by CoffeeScript 1.6.3
|
// Generated by CoffeeScript 1.6.3
|
||||||
var add_level, draw_level, init_level, load_level, parse_levelentities, reset_layers;
|
var add_level, draw_level, init_level, load_level, parse_levelentities, reset_layers;
|
||||||
|
|
||||||
|
@ -136,15 +140,15 @@ draw_level = function(level) {
|
||||||
};
|
};
|
||||||
|
|
||||||
reset_layers = function() {
|
reset_layers = function() {
|
||||||
var enemy_layer, shadow_layer, _i, _j, _ref, _ref1, _results, _results1;
|
var _i, _j, _ref, _ref1, _results, _results1;
|
||||||
shadow_layer = (function() {
|
window.shadow_layer = (function() {
|
||||||
_results = [];
|
_results = [];
|
||||||
for (var _i = 0, _ref = config.map.width * config.map.height; 0 <= _ref ? _i <= _ref : _i >= _ref; 0 <= _ref ? _i++ : _i--){ _results.push(_i); }
|
for (var _i = 0, _ref = config.map.width * config.map.height; 0 <= _ref ? _i <= _ref : _i >= _ref; 0 <= _ref ? _i++ : _i--){ _results.push(_i); }
|
||||||
return _results;
|
return _results;
|
||||||
}).apply(this).map(function() {
|
}).apply(this).map(function() {
|
||||||
return 0;
|
return 0;
|
||||||
});
|
});
|
||||||
return enemy_layer = (function() {
|
return window.enemy_layer = (function() {
|
||||||
_results1 = [];
|
_results1 = [];
|
||||||
for (var _j = 0, _ref1 = config.map.width * config.map.height; 0 <= _ref1 ? _j <= _ref1 : _j >= _ref1; 0 <= _ref1 ? _j++ : _j--){ _results1.push(_j); }
|
for (var _j = 0, _ref1 = config.map.width * config.map.height; 0 <= _ref1 ? _j <= _ref1 : _j >= _ref1; 0 <= _ref1 ? _j++ : _j--){ _results1.push(_j); }
|
||||||
return _results1;
|
return _results1;
|
||||||
|
@ -166,17 +170,16 @@ init_level = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
load_level = function(number) {
|
load_level = function(number) {
|
||||||
var level;
|
|
||||||
if (number === levels.length) {
|
if (number === levels.length) {
|
||||||
return config.gamestate = gamestates.WIN;
|
return config.gamestate = gamestates.WIN;
|
||||||
} else {
|
} else {
|
||||||
init_level();
|
init_level();
|
||||||
level = levels[number];
|
window.level = levels[number];
|
||||||
return parse_levelentities(level);
|
return parse_levelentities(level);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
parse_levelentities = function() {
|
parse_levelentities = function(level) {
|
||||||
var block, position, _i, _len, _results;
|
var block, position, _i, _len, _results;
|
||||||
_results = [];
|
_results = [];
|
||||||
for (position = _i = 0, _len = level.length; _i < _len; position = ++_i) {
|
for (position = _i = 0, _len = level.length; _i < _len; position = ++_i) {
|
||||||
|
@ -282,16 +285,17 @@ break_walls = function(position) {
|
||||||
};
|
};
|
||||||
// Generated by CoffeeScript 1.6.3
|
// Generated by CoffeeScript 1.6.3
|
||||||
var calculate_lightray, calculate_lights, draw_lights, illuminate,
|
var calculate_lightray, calculate_lights, draw_lights, illuminate,
|
||||||
|
_this = this,
|
||||||
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
|
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
|
||||||
|
|
||||||
calculate_lightray = function(x1, y1, x2, y2, type) {
|
calculate_lightray = function(x1, y1, x2, y2, type) {
|
||||||
var dx, dy, hit_wall, pixel_x1, pixel_x2, pixel_y1, pixel_y2, s, selected_layer, t, _ref, _results;
|
var dx, dy, hit_wall, pixel_x1, pixel_x2, pixel_y1, pixel_y2, s, t, _ref, _results;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'enemy':
|
case 'enemy':
|
||||||
selected_layer = enemy_layer;
|
window.selected_layer = enemy_layer;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
selected_layer = shadow_layer;
|
window.selected_layer = shadow_layer;
|
||||||
}
|
}
|
||||||
pixel_x1 = x1 * config.pixelsize + (config.pixelsize / 2);
|
pixel_x1 = x1 * config.pixelsize + (config.pixelsize / 2);
|
||||||
pixel_y1 = y1 * config.pixelsize + (config.pixelsize / 2);
|
pixel_y1 = y1 * config.pixelsize + (config.pixelsize / 2);
|
||||||
|
@ -390,15 +394,15 @@ calculate_lights = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
draw_lights = function(type) {
|
draw_lights = function(type) {
|
||||||
var alpha, brightness, color, position, selected_layer, _i, _len, _ref, _results;
|
var alpha, brightness, color, position, _i, _len, _ref, _results;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'enemy':
|
case 'enemy':
|
||||||
color = '255, 0, 0';
|
color = '255, 0, 0';
|
||||||
selected_layer = enemy_layer;
|
window.selected_layer = enemy_layer;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
color = '0, 0, 0';
|
color = '0, 0, 0';
|
||||||
selected_layer = shadow_layer;
|
window.selected_layer = shadow_layer;
|
||||||
}
|
}
|
||||||
_results = [];
|
_results = [];
|
||||||
for (position = _i = 0, _len = selected_layer.length; _i < _len; position = ++_i) {
|
for (position = _i = 0, _len = selected_layer.length; _i < _len; position = ++_i) {
|
||||||
|
@ -449,7 +453,8 @@ addEventListener('keyup', function(event) {
|
||||||
return keymap[event.keyCode] = false;
|
return keymap[event.keyCode] = false;
|
||||||
});
|
});
|
||||||
// Generated by CoffeeScript 1.6.3
|
// Generated by CoffeeScript 1.6.3
|
||||||
var loop_gameover, loop_gamewin, loop_main, loop_run;
|
var loop_gameover, loop_gamewin, loop_main, loop_run,
|
||||||
|
_this = this;
|
||||||
|
|
||||||
loop_run = function() {
|
loop_run = function() {
|
||||||
reset_layers();
|
reset_layers();
|
||||||
|
@ -488,7 +493,7 @@ loop_main = function() {
|
||||||
return setTimeout(loop_main, 50);
|
return setTimeout(loop_main, 50);
|
||||||
};
|
};
|
||||||
|
|
||||||
update_canvas();
|
update_canvas(config.map.width * config.pixelsize, config.map.height * config.pixelsize + config.map.origin.y);
|
||||||
|
|
||||||
load_level(current_level);
|
load_level(current_level);
|
||||||
|
|
||||||
|
|
|
@ -46,5 +46,6 @@ inventar =
|
||||||
levels = []
|
levels = []
|
||||||
current_level = 0
|
current_level = 0
|
||||||
level = null
|
level = null
|
||||||
|
shadow_layer = null
|
||||||
shadow_layer = enemy_layer = null
|
enemy_layer = null
|
||||||
|
selected_layer = null
|
|
@ -14,12 +14,11 @@ draw_level = (level) ->
|
||||||
pixel(position, config.pixelsize, config.pixelsize, color)
|
pixel(position, config.pixelsize, config.pixelsize, color)
|
||||||
|
|
||||||
reset_layers = () ->
|
reset_layers = () ->
|
||||||
shadow_layer = [0..(config.map.width*config.map.height)].map -> 0
|
window.shadow_layer = [0..(config.map.width*config.map.height)].map -> 0
|
||||||
enemy_layer = [0..(config.map.width*config.map.height)].map -> 0
|
window.enemy_layer = [0..(config.map.width*config.map.height)].map -> 0
|
||||||
|
|
||||||
init_level = () ->
|
init_level = () ->
|
||||||
level = [0..(config.map.width*config.map.height)].map -> 0
|
level = [0..(config.map.width*config.map.height)].map -> 0
|
||||||
|
|
||||||
inventar.key = false
|
inventar.key = false
|
||||||
|
|
||||||
load_level = (number) ->
|
load_level = (number) ->
|
||||||
|
@ -27,10 +26,10 @@ load_level = (number) ->
|
||||||
config.gamestate = gamestates.WIN
|
config.gamestate = gamestates.WIN
|
||||||
else
|
else
|
||||||
init_level()
|
init_level()
|
||||||
level = levels[number]
|
window.level = levels[number]
|
||||||
parse_levelentities(level)
|
parse_levelentities(level)
|
||||||
|
|
||||||
parse_levelentities = ->
|
parse_levelentities = (level) ->
|
||||||
for block, position in level
|
for block, position in level
|
||||||
switch block
|
switch block
|
||||||
when 4
|
when 4
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
calculate_lightray = (x1, y1, x2, y2, type) ->
|
calculate_lightray = (x1, y1, x2, y2, type) =>
|
||||||
switch type
|
switch type
|
||||||
when 'enemy' then selected_layer = enemy_layer
|
when 'enemy' then window.selected_layer = enemy_layer
|
||||||
else selected_layer = shadow_layer
|
else window.selected_layer = shadow_layer
|
||||||
|
|
||||||
pixel_x1 = x1*config.pixelsize + (config.pixelsize/2)
|
pixel_x1 = x1*config.pixelsize + (config.pixelsize/2)
|
||||||
pixel_y1 = y1*config.pixelsize + (config.pixelsize/2)
|
pixel_y1 = y1*config.pixelsize + (config.pixelsize/2)
|
||||||
|
@ -61,7 +61,7 @@ calculate_lightray = (x1, y1, x2, y2, type) ->
|
||||||
|
|
||||||
t += s
|
t += s
|
||||||
|
|
||||||
illuminate = (x1, y1, range, type = 'shadow') ->
|
illuminate = (x1, y1, range, type = 'shadow') =>
|
||||||
r = 0
|
r = 0
|
||||||
|
|
||||||
while r < Math.PI*2
|
while r < Math.PI*2
|
||||||
|
@ -78,7 +78,7 @@ illuminate = (x1, y1, range, type = 'shadow') ->
|
||||||
calculate_lightray(x1, y1, x2, y2, type)
|
calculate_lightray(x1, y1, x2, y2, type)
|
||||||
r += 0.03
|
r += 0.03
|
||||||
|
|
||||||
calculate_lights = () ->
|
calculate_lights = () =>
|
||||||
#illuminate(8, 8, 5)
|
#illuminate(8, 8, 5)
|
||||||
illuminate(toxy(player.position).x, toxy(player.position).y, player.lightrange)
|
illuminate(toxy(player.position).x, toxy(player.position).y, player.lightrange)
|
||||||
|
|
||||||
|
@ -89,14 +89,14 @@ calculate_lights = () ->
|
||||||
when 8
|
when 8
|
||||||
illuminate(toxy(position).x, toxy(position).y, 4, 'enemy')
|
illuminate(toxy(position).x, toxy(position).y, 4, 'enemy')
|
||||||
|
|
||||||
draw_lights = (type) ->
|
draw_lights = (type) =>
|
||||||
switch type
|
switch type
|
||||||
when 'enemy'
|
when 'enemy'
|
||||||
color = '255, 0, 0'
|
color = '255, 0, 0'
|
||||||
selected_layer = enemy_layer
|
window.selected_layer = enemy_layer
|
||||||
else
|
else
|
||||||
color = '0, 0, 0'
|
color = '0, 0, 0'
|
||||||
selected_layer = shadow_layer
|
window.selected_layer = shadow_layer
|
||||||
|
|
||||||
for brightness, position in selected_layer
|
for brightness, position in selected_layer
|
||||||
switch type
|
switch type
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
loop_run = ->
|
loop_run = =>
|
||||||
reset_layers()
|
reset_layers()
|
||||||
calculate_lights()
|
calculate_lights()
|
||||||
|
|
||||||
|
@ -16,11 +16,11 @@ loop_gamewin = ->
|
||||||
rect(0, 0, config.map.width*config.pixelsize, config.map.height*config.pixelsize+config.map.origin.y, '#ffffff')
|
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')
|
write(250, 100, 'You won, awesome!', 20, '#000000')
|
||||||
|
|
||||||
loop_gameover = ->
|
loop_gameover = =>
|
||||||
rect(0, 0, config.map.width*config.pixelsize, config.map.height*config.pixelsize+config.map.origin.y, '#ff0000')
|
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')
|
write(150, 100, 'Oh noes!', 20, '#ffffff')
|
||||||
|
|
||||||
loop_main = ->
|
loop_main = =>
|
||||||
switch config.gamestate
|
switch config.gamestate
|
||||||
when gamestates.RUN then loop_run()
|
when gamestates.RUN then loop_run()
|
||||||
when gamestates.WIN then loop_gamewin()
|
when gamestates.WIN then loop_gamewin()
|
||||||
|
@ -30,6 +30,6 @@ loop_main = ->
|
||||||
|
|
||||||
# load the first level and call the main loop for the first time
|
# load the first level and call the main loop for the first time
|
||||||
# those functioncalls are only used once
|
# those functioncalls are only used once
|
||||||
update_canvas()
|
update_canvas(config.map.width*config.pixelsize, config.map.height*config.pixelsize+config.map.origin.y)
|
||||||
load_level(current_level)
|
load_level(current_level)
|
||||||
loop_main()
|
loop_main()
|
Loading…
Reference in a new issue