Correct Line Feeds
parent
907ae03a0c
commit
b408272150
1348
LICENSE.txt
1348
LICENSE.txt
File diff suppressed because it is too large
Load Diff
1450
assets/content.js
1450
assets/content.js
File diff suppressed because it is too large
Load Diff
452
assets/editor.js
452
assets/editor.js
|
@ -1,226 +1,226 @@
|
|||
/*
|
||||
* part of PUZZLE PLATFORMER
|
||||
* by rubenwardy (rubenwardy@gmail.com)
|
||||
* Licensed under GNU GPL 3.0 or later. See LICENSE.txt
|
||||
*/
|
||||
|
||||
game.after_load = "editor";
|
||||
game.is_editor = true;
|
||||
|
||||
function ed_save(){
|
||||
console.log("Exporting...");
|
||||
var maps = map.save();
|
||||
map.getDim();
|
||||
var cakes = map.getCakes();
|
||||
|
||||
var res = "define.map({\n";
|
||||
res += "\tspawn:{\n";
|
||||
res += "\t\tx: 1,\n";
|
||||
res += "\t\ty: 2\n";
|
||||
res += "\t},\n";
|
||||
res += "\twidth: "+map.map_data.width+",\n";
|
||||
res += "\theight: "+map.map_data.height+",\n";
|
||||
res += "\tcakes: "+cakes+",\n";
|
||||
res += "\tmap: [\n";
|
||||
res += maps;
|
||||
res += "\n\t]\n";
|
||||
res += "});";
|
||||
|
||||
$("#load_dia").remove();
|
||||
var out = '<div id="load_dia"><h2>Save Level</h2><textarea id="load_code">'+res+'</textarea>';
|
||||
out += '<p><a onClick="$(\'#load_dia\').remove();">Close</a></p></div>';
|
||||
$("body").append(out);
|
||||
}
|
||||
|
||||
function ed_load(){
|
||||
$("#load_dia").remove();
|
||||
var out = '<div id="load_dia"><h2>Load level</h2><textarea id="load_code"></textarea>';
|
||||
out += '<p><a onClick="ed_doload();">Load</a> - <a onClick="$(\'#load_dia\').remove();">Close</a></p></div>';
|
||||
$("body").append(out);
|
||||
}
|
||||
|
||||
var NEXT_MAP = {
|
||||
spawn:{
|
||||
x: 1,
|
||||
y: 2
|
||||
},
|
||||
width: 4,
|
||||
height: 4,
|
||||
cakes:1,
|
||||
map: [
|
||||
["blank","blank","blank","blank"],
|
||||
["blank","cake","","blank"],
|
||||
["blank","","","blank"],
|
||||
["blank","blank","blank","blank"]
|
||||
]
|
||||
};
|
||||
|
||||
function ed_doload(){
|
||||
code = $("#load_code").val();
|
||||
console.log(code);
|
||||
$("#load_dia").remove();
|
||||
eval(code);
|
||||
NEXT_MAP = define._map[define._map.length-1];
|
||||
Crafty.scene("editor");
|
||||
}
|
||||
|
||||
render_grid = function(c){
|
||||
var topx = (Crafty.viewport.x%64)-10;
|
||||
var topy = (Crafty.viewport.y%64)+5;
|
||||
c.beginPath();
|
||||
for (var x = topx; x<($(window).width()); x+=64){
|
||||
if (x>0){
|
||||
if (Crafty.viewport.x-10 == x){
|
||||
c.strokeStyle="white";
|
||||
c.stroke();
|
||||
c.beginPath();
|
||||
c.moveTo(190+x+0.5,0);
|
||||
c.lineTo(190+x+0.5,$(window).height());
|
||||
c.strokeStyle="black";
|
||||
c.stroke();
|
||||
c.beginPath();
|
||||
}else{
|
||||
c.moveTo(190+x+0.5,0);
|
||||
c.lineTo(190+x+0.5,$(window).height());
|
||||
}
|
||||
}
|
||||
}
|
||||
for (var x = topy; x<($(window).height()); x+=64){
|
||||
if (Crafty.viewport.y+5 == x){
|
||||
c.strokeStyle="white";
|
||||
c.stroke();
|
||||
c.beginPath();
|
||||
c.moveTo(192,x-0.5);
|
||||
c.lineTo($(window).width(),x-0.5);
|
||||
c.strokeStyle="black";
|
||||
c.stroke();
|
||||
c.beginPath();
|
||||
}else{
|
||||
c.moveTo(192,x-0.5);
|
||||
c.lineTo($(window).width(),x-0.5);
|
||||
}
|
||||
}
|
||||
c.strokeStyle="white";
|
||||
c.stroke();
|
||||
};
|
||||
|
||||
var EDMODE = "rubber";
|
||||
var EDTOOL = "pencil";
|
||||
|
||||
function ed_updatetoolbar(){
|
||||
$("#tools").children('ul').children('li').each(function(){
|
||||
console.log("Removing...");
|
||||
$(this).children('a').removeClass('selected');
|
||||
});
|
||||
$("#"+EDMODE).addClass('selected');
|
||||
$("#tool_"+EDTOOL).addClass('selected');
|
||||
}
|
||||
|
||||
function change_mode(name){
|
||||
EDMODE = name;
|
||||
ed_updatetoolbar();
|
||||
}
|
||||
|
||||
function dotool(x,y){
|
||||
if (x<0 || y<0)
|
||||
return;
|
||||
|
||||
if (EDMODE == "rubber"){
|
||||
map.set(x,y,'');
|
||||
}else if (EDMODE == "player"){
|
||||
|
||||
}else{
|
||||
map.set(x,y,EDMODE);
|
||||
}
|
||||
}
|
||||
|
||||
// Editor
|
||||
var prev;
|
||||
Crafty.scene("editor", function () {
|
||||
game.player = null;
|
||||
map = Map();
|
||||
map.load(NEXT_MAP);
|
||||
Crafty.viewport.x = 75;
|
||||
Crafty.viewport.y = 60;
|
||||
|
||||
// Debugging background:
|
||||
// warns user that the script has not finished.
|
||||
Crafty.background("#ffcccc");
|
||||
var tmp = 'Level Editor<hr style="border: 0;height:1px;background:black;">';//'<div id="editor">';
|
||||
tmp += '<a onClick=\"ed_save();\" style="text-decoration:underline;">Save</a> - ';
|
||||
tmp += '<a onClick=\"ed_load();\" style="text-decoration:underline;">Load</a>';
|
||||
tmp += ' - <a href=\"index.html\">Exit</a>';
|
||||
//tmp += '</div>';
|
||||
$("#fps").html(tmp);
|
||||
tmp = '<div id="tools">';
|
||||
tmp += '<ul>';
|
||||
tmp += '<li><a id="tool_pencil" onClick="change_tool(\'pencil\');">Pencil</a></li>';
|
||||
tmp += '<li><a id="tool_rect" onClick="change_tool(\'pencil\');">Rectangle</a></li>';
|
||||
tmp += '<li><hr style="border: 0;height:1px;background:black;"></li>';
|
||||
tmp += '<li><a id="rubber" onClick="change_mode(\'rubber\');">Rubber</a></li>';
|
||||
tmp += '<li><a id="player" onClick="change_mode(\'player\');">Player</a></li>';
|
||||
tmp += '<li><hr style="border: 0;height:1px;background:black;"></li>';
|
||||
for (key in define._bloc) {
|
||||
var b = define._bloc[key];
|
||||
if (b.desc)
|
||||
tmp += '<li><a id="'+b.name+'" onClick="change_mode(\''+b.name+'\');">'+b.desc+'</a></li>';
|
||||
else
|
||||
tmp += '<li><a id="'+b.name+'" onClick="change_mode(\''+b.name+'\');">'+b.name+'</a></li>';
|
||||
}
|
||||
tmp += '</ul>';
|
||||
tmp += '</div>';
|
||||
$("#panel").append(tmp);
|
||||
|
||||
// FPS counter
|
||||
/*var fps = Crafty.e("FPS")
|
||||
.bind("MessureFPS",function(fps){
|
||||
var res = "Map Editor<br>";
|
||||
res += "FPS: " + fps.value;
|
||||
$("#fps").html(res);
|
||||
});*/
|
||||
|
||||
Crafty.e("Keyboard").bind("EnterFrame",function(){
|
||||
var cur = (new Date).getTime();
|
||||
var dt = (cur - prev) / 1000;
|
||||
prev = cur;
|
||||
|
||||
var sp = 128;
|
||||
if ((Crafty.keydown[Crafty.keys['W']] || Crafty.keydown[Crafty.keys['UP_ARROW']])){
|
||||
Crafty.viewport.y += sp * dt;
|
||||
}
|
||||
if ((Crafty.keydown[Crafty.keys['D']] || Crafty.keydown[Crafty.keys['RIGHT_ARROW']])){
|
||||
Crafty.viewport.x -= sp * dt;
|
||||
}
|
||||
if ((Crafty.keydown[Crafty.keys['S']] || Crafty.keydown[Crafty.keys['DOWN_ARROW']])){
|
||||
Crafty.viewport.y -= sp * dt;
|
||||
}
|
||||
if ((Crafty.keydown[Crafty.keys['A']] || Crafty.keydown[Crafty.keys['LEFT_ARROW']])){
|
||||
Crafty.viewport.x += sp * dt;
|
||||
}
|
||||
render_bg();
|
||||
});
|
||||
|
||||
var win = $(window)[0];
|
||||
win.addEventListener('mousemove', function(e) {
|
||||
game.mouse = {
|
||||
x: e.clientX,
|
||||
y: e.clientY
|
||||
};
|
||||
});
|
||||
win.addEventListener('click', function(e){
|
||||
if (game.mouse.x > 190 && !$("#load_dia")[0]){
|
||||
dotool(
|
||||
Math.floor((game.mouse.x-Crafty.viewport.x-180)/64),
|
||||
Math.floor((game.mouse.y-Crafty.viewport.y)/64)
|
||||
);
|
||||
}
|
||||
}, false);
|
||||
|
||||
// Initiate the inventory
|
||||
ed_updatetoolbar();
|
||||
//dotool(0,0);
|
||||
Crafty.background("transparent");
|
||||
},function(){
|
||||
$('#tools').remove();
|
||||
$('#editor').remove();
|
||||
});
|
||||
/*
|
||||
* part of PUZZLE PLATFORMER
|
||||
* by rubenwardy (rubenwardy@gmail.com)
|
||||
* Licensed under GNU GPL 3.0 or later. See LICENSE.txt
|
||||
*/
|
||||
|
||||
game.after_load = "editor";
|
||||
game.is_editor = true;
|
||||
|
||||
function ed_save(){
|
||||
console.log("Exporting...");
|
||||
var maps = map.save();
|
||||
map.getDim();
|
||||
var cakes = map.getCakes();
|
||||
|
||||
var res = "define.map({\n";
|
||||
res += "\tspawn:{\n";
|
||||
res += "\t\tx: 1,\n";
|
||||
res += "\t\ty: 2\n";
|
||||
res += "\t},\n";
|
||||
res += "\twidth: "+map.map_data.width+",\n";
|
||||
res += "\theight: "+map.map_data.height+",\n";
|
||||
res += "\tcakes: "+cakes+",\n";
|
||||
res += "\tmap: [\n";
|
||||
res += maps;
|
||||
res += "\n\t]\n";
|
||||
res += "});";
|
||||
|
||||
$("#load_dia").remove();
|
||||
var out = '<div id="load_dia"><h2>Save Level</h2><textarea id="load_code">'+res+'</textarea>';
|
||||
out += '<p><a onClick="$(\'#load_dia\').remove();">Close</a></p></div>';
|
||||
$("body").append(out);
|
||||
}
|
||||
|
||||
function ed_load(){
|
||||
$("#load_dia").remove();
|
||||
var out = '<div id="load_dia"><h2>Load level</h2><textarea id="load_code"></textarea>';
|
||||
out += '<p><a onClick="ed_doload();">Load</a> - <a onClick="$(\'#load_dia\').remove();">Close</a></p></div>';
|
||||
$("body").append(out);
|
||||
}
|
||||
|
||||
var NEXT_MAP = {
|
||||
spawn:{
|
||||
x: 1,
|
||||
y: 2
|
||||
},
|
||||
width: 4,
|
||||
height: 4,
|
||||
cakes:1,
|
||||
map: [
|
||||
["blank","blank","blank","blank"],
|
||||
["blank","cake","","blank"],
|
||||
["blank","","","blank"],
|
||||
["blank","blank","blank","blank"]
|
||||
]
|
||||
};
|
||||
|
||||
function ed_doload(){
|
||||
code = $("#load_code").val();
|
||||
console.log(code);
|
||||
$("#load_dia").remove();
|
||||
eval(code);
|
||||
NEXT_MAP = define._map[define._map.length-1];
|
||||
Crafty.scene("editor");
|
||||
}
|
||||
|
||||
render_grid = function(c){
|
||||
var topx = (Crafty.viewport.x%64)-10;
|
||||
var topy = (Crafty.viewport.y%64)+5;
|
||||
c.beginPath();
|
||||
for (var x = topx; x<($(window).width()); x+=64){
|
||||
if (x>0){
|
||||
if (Crafty.viewport.x-10 == x){
|
||||
c.strokeStyle="white";
|
||||
c.stroke();
|
||||
c.beginPath();
|
||||
c.moveTo(190+x+0.5,0);
|
||||
c.lineTo(190+x+0.5,$(window).height());
|
||||
c.strokeStyle="black";
|
||||
c.stroke();
|
||||
c.beginPath();
|
||||
}else{
|
||||
c.moveTo(190+x+0.5,0);
|
||||
c.lineTo(190+x+0.5,$(window).height());
|
||||
}
|
||||
}
|
||||
}
|
||||
for (var x = topy; x<($(window).height()); x+=64){
|
||||
if (Crafty.viewport.y+5 == x){
|
||||
c.strokeStyle="white";
|
||||
c.stroke();
|
||||
c.beginPath();
|
||||
c.moveTo(192,x-0.5);
|
||||
c.lineTo($(window).width(),x-0.5);
|
||||
c.strokeStyle="black";
|
||||
c.stroke();
|
||||
c.beginPath();
|
||||
}else{
|
||||
c.moveTo(192,x-0.5);
|
||||
c.lineTo($(window).width(),x-0.5);
|
||||
}
|
||||
}
|
||||
c.strokeStyle="white";
|
||||
c.stroke();
|
||||
};
|
||||
|
||||
var EDMODE = "rubber";
|
||||
var EDTOOL = "pencil";
|
||||
|
||||
function ed_updatetoolbar(){
|
||||
$("#tools").children('ul').children('li').each(function(){
|
||||
console.log("Removing...");
|
||||
$(this).children('a').removeClass('selected');
|
||||
});
|
||||
$("#"+EDMODE).addClass('selected');
|
||||
$("#tool_"+EDTOOL).addClass('selected');
|
||||
}
|
||||
|
||||
function change_mode(name){
|
||||
EDMODE = name;
|
||||
ed_updatetoolbar();
|
||||
}
|
||||
|
||||
function dotool(x,y){
|
||||
if (x<0 || y<0)
|
||||
return;
|
||||
|
||||
if (EDMODE == "rubber"){
|
||||
map.set(x,y,'');
|
||||
}else if (EDMODE == "player"){
|
||||
|
||||
}else{
|
||||
map.set(x,y,EDMODE);
|
||||
}
|
||||
}
|
||||
|
||||
// Editor
|
||||
var prev;
|
||||
Crafty.scene("editor", function () {
|
||||
game.player = null;
|
||||
map = Map();
|
||||
map.load(NEXT_MAP);
|
||||
Crafty.viewport.x = 75;
|
||||
Crafty.viewport.y = 60;
|
||||
|
||||
// Debugging background:
|
||||
// warns user that the script has not finished.
|
||||
Crafty.background("#ffcccc");
|
||||
var tmp = 'Level Editor<hr style="border: 0;height:1px;background:black;">';//'<div id="editor">';
|
||||
tmp += '<a onClick=\"ed_save();\" style="text-decoration:underline;">Save</a> - ';
|
||||
tmp += '<a onClick=\"ed_load();\" style="text-decoration:underline;">Load</a>';
|
||||
tmp += ' - <a href=\"index.html\">Exit</a>';
|
||||
//tmp += '</div>';
|
||||
$("#fps").html(tmp);
|
||||
tmp = '<div id="tools">';
|
||||
tmp += '<ul>';
|
||||
tmp += '<li><a id="tool_pencil" onClick="change_tool(\'pencil\');">Pencil</a></li>';
|
||||
tmp += '<li><a id="tool_rect" onClick="change_tool(\'pencil\');">Rectangle</a></li>';
|
||||
tmp += '<li><hr style="border: 0;height:1px;background:black;"></li>';
|
||||
tmp += '<li><a id="rubber" onClick="change_mode(\'rubber\');">Rubber</a></li>';
|
||||
tmp += '<li><a id="player" onClick="change_mode(\'player\');">Player</a></li>';
|
||||
tmp += '<li><hr style="border: 0;height:1px;background:black;"></li>';
|
||||
for (key in define._bloc) {
|
||||
var b = define._bloc[key];
|
||||
if (b.desc)
|
||||
tmp += '<li><a id="'+b.name+'" onClick="change_mode(\''+b.name+'\');">'+b.desc+'</a></li>';
|
||||
else
|
||||
tmp += '<li><a id="'+b.name+'" onClick="change_mode(\''+b.name+'\');">'+b.name+'</a></li>';
|
||||
}
|
||||
tmp += '</ul>';
|
||||
tmp += '</div>';
|
||||
$("#panel").append(tmp);
|
||||
|
||||
// FPS counter
|
||||
/*var fps = Crafty.e("FPS")
|
||||
.bind("MessureFPS",function(fps){
|
||||
var res = "Map Editor<br>";
|
||||
res += "FPS: " + fps.value;
|
||||
$("#fps").html(res);
|
||||
});*/
|
||||
|
||||
Crafty.e("Keyboard").bind("EnterFrame",function(){
|
||||
var cur = (new Date).getTime();
|
||||
var dt = (cur - prev) / 1000;
|
||||
prev = cur;
|
||||
|
||||
var sp = 128;
|
||||
if ((Crafty.keydown[Crafty.keys['W']] || Crafty.keydown[Crafty.keys['UP_ARROW']])){
|
||||
Crafty.viewport.y += sp * dt;
|
||||
}
|
||||
if ((Crafty.keydown[Crafty.keys['D']] || Crafty.keydown[Crafty.keys['RIGHT_ARROW']])){
|
||||
Crafty.viewport.x -= sp * dt;
|
||||
}
|
||||
if ((Crafty.keydown[Crafty.keys['S']] || Crafty.keydown[Crafty.keys['DOWN_ARROW']])){
|
||||
Crafty.viewport.y -= sp * dt;
|
||||
}
|
||||
if ((Crafty.keydown[Crafty.keys['A']] || Crafty.keydown[Crafty.keys['LEFT_ARROW']])){
|
||||
Crafty.viewport.x += sp * dt;
|
||||
}
|
||||
render_bg();
|
||||
});
|
||||
|
||||
var win = $(window)[0];
|
||||
win.addEventListener('mousemove', function(e) {
|
||||
game.mouse = {
|
||||
x: e.clientX,
|
||||
y: e.clientY
|
||||
};
|
||||
});
|
||||
win.addEventListener('click', function(e){
|
||||
if (game.mouse.x > 190 && !$("#load_dia")[0]){
|
||||
dotool(
|
||||
Math.floor((game.mouse.x-Crafty.viewport.x-180)/64),
|
||||
Math.floor((game.mouse.y-Crafty.viewport.y)/64)
|
||||
);
|
||||
}
|
||||
}, false);
|
||||
|
||||
// Initiate the inventory
|
||||
ed_updatetoolbar();
|
||||
//dotool(0,0);
|
||||
Crafty.background("transparent");
|
||||
},function(){
|
||||
$('#tools').remove();
|
||||
$('#editor').remove();
|
||||
});
|
||||
|
|
|
@ -1,246 +1,246 @@
|
|||
/*
|
||||
* part of PUZZLE PLATFORMER
|
||||
* by rubenwardy (rubenwardy@gmail.com)
|
||||
* Licensed under GNU GPL 3.0 or later. See LICENSE.txt
|
||||
*/
|
||||
|
||||
Crafty.c("ParticleSystem",{
|
||||
init: function(){},
|
||||
particles: function(data){
|
||||
this.requires("2D");
|
||||
this.data = data;
|
||||
this.start = new Date().getTime();
|
||||
this.last = this.start;
|
||||
this.bind("EnterFrame",this.tick);
|
||||
return this;
|
||||
},
|
||||
tick: function(){
|
||||
var now = new Date().getTime();
|
||||
if (this.data && this.data.expire && now > (this.start+this.data.expire)){
|
||||
console.log("Deleting particle spawner");
|
||||
this.destroy();
|
||||
}
|
||||
|
||||
if (now > this.last + this.data.delay){
|
||||
this.last = now;
|
||||
var amt = 1;
|
||||
if (this.data.spawn && this.data.spawn.amt)
|
||||
amt = this.data.spawn.amt;
|
||||
for (var i=0;i<amt;i++){
|
||||
this.addParticle();
|
||||
}
|
||||
}
|
||||
},
|
||||
addParticle: function(){
|
||||
var an = (Math.random() * 0.25 * Math.PI)-0.6*Math.PI;
|
||||
var spawnpos = {x:this.x,y:this.y};
|
||||
|
||||
if (this.data.spawn && this.data.spawn.pos){
|
||||
if (this.data.spawn.pos.type == "range"){
|
||||
spawnpos.x += (
|
||||
this.data.spawn.pos.from[0]+
|
||||
(this.data.spawn.pos.to[0]-this.data.spawn.pos.from[0])
|
||||
* Math.random()
|
||||
);
|
||||
spawnpos.y += (
|
||||
this.data.spawn.pos.from[1]+
|
||||
(this.data.spawn.pos.to[1]-this.data.spawn.pos.from[1])
|
||||
* Math.random()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
var clr = this.data.color;
|
||||
if (this.data.color instanceof Array) {
|
||||
clr = this.data.color[Math.round(Math.random()*(this.data.color.length-1))];
|
||||
}
|
||||
if (!clr || clr==""){
|
||||
clr = "red";
|
||||
}
|
||||
|
||||
var velo = {x:0,y:0};
|
||||
if(this.data.spawn && this.data.spawn.velocity && this.data.spawn.velocity.constructor == Object){
|
||||
velo = {x:this.data.spawn.velocity.x,y:this.data.spawn.velocity.y};
|
||||
}else if (this.data.spawn && this.data.spawn.angle){
|
||||
var an = 0;
|
||||
|
||||
if (this.data.spawn.angle.type == "range"){
|
||||
an = this.data.spawn.angle.from + (this.data.spawn.angle.to-this.data.spawn.angle.from)*Math.random();
|
||||
}
|
||||
|
||||
velo = {x:this.data.spawn.velocity * Math.cos(an*Math.PI),y:this.data.spawn.velocity * Math.sin(an*Math.PI)};
|
||||
}
|
||||
|
||||
var acc = {x:0, y:9.81};
|
||||
if (this.data.spawn && this.data.spawn.acc)
|
||||
acc = {x:this.data.spawn.acc.x,y:this.data.spawn.acc.y};
|
||||
|
||||
//console.log("Adding particle ");
|
||||
Crafty.e("2D, drawmode, TheParticle, Color")
|
||||
.attr(spawnpos)
|
||||
.attr({w:10,h:10,z:this.z})
|
||||
.color(clr)
|
||||
.particle(
|
||||
velo,
|
||||
acc,
|
||||
this.data.decay
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
Crafty.c("TheParticle",{
|
||||
init: function(){},
|
||||
particle: function(vel,acc,ex){
|
||||
this.vel = vel;
|
||||
this.acc = acc;
|
||||
this.start = new Date().getTime();
|
||||
this.last = this.start;
|
||||
this.expire = ex;
|
||||
if (!this.expire.fo)
|
||||
this.expire.fo = 0;
|
||||
|
||||
this.decay = -1;
|
||||
this.bind("EnterFrame",this.tick);
|
||||
},
|
||||
tick: function(){
|
||||
var now = new Date().getTime();
|
||||
if (
|
||||
(this.expire && this.expire.t && now > (this.start+this.expire.t)) ||
|
||||
(this.expire && this.expire.vy_gt && this.vel.y > this.expire.vy_gt) ||
|
||||
(this.expire && this.expire.vy_lt && this.vel.y < this.expire.vy_lt) ||
|
||||
(this.expire && this.expire.vx_gt && this.vel.x > this.expire.vx_gt) ||
|
||||
(this.expire && this.expire.vx_lt && this.vel.x < this.expire.vx_lt)
|
||||
){
|
||||
if (this.decay == -1)
|
||||
this.decay = now;
|
||||
}
|
||||
if (this.decay != -1){
|
||||
if (now > (this.decay + this.expire.fo)){
|
||||
this.destroy();
|
||||
return;
|
||||
}
|
||||
var perc = 1-((now-this.decay)/this.expire.fo);
|
||||
this.alpha = perc;
|
||||
this.visible = (perc>0);
|
||||
}
|
||||
var dtime = (now - this.last)/1000;
|
||||
this.x += this.vel.x * dtime;
|
||||
this.y += this.vel.y * dtime;
|
||||
this.vel.x += this.acc.x * 32 * dtime;
|
||||
this.vel.y += this.acc.y * 32 * dtime;
|
||||
|
||||
this.last = now;
|
||||
}
|
||||
});
|
||||
|
||||
function ParticleExplosion(pos, speed, tcolor, g, timeout, width, amt){
|
||||
if (!width)
|
||||
width = 64;
|
||||
if (!amt)
|
||||
amt = 8;
|
||||
|
||||
for (var x=0;x<amt;x++){
|
||||
for (var y=0;y<amt;y++){
|
||||
var xcolor = tcolor;
|
||||
|
||||
if (xcolor instanceof Array) {
|
||||
xcolor = xcolor[Math.round(Math.random()*(xcolor.length-1))];
|
||||
}
|
||||
|
||||
var an = Math.random() * 2 * 3.1415;
|
||||
var e = Crafty.e("2D, drawmode, TheParticle, Color")
|
||||
.attr({x:pos.x + x*(width/amt),y:pos.y + y*(width/amt)})
|
||||
.attr({w:(width/amt),h:(width/amt),z:1002})
|
||||
.color(xcolor);
|
||||
|
||||
e.particle(
|
||||
{x:speed * Math.cos(an),y:speed * Math.sin(an)},
|
||||
{x:0,y:g},
|
||||
{t:timeout}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Crafty.c("CloudSystem",{
|
||||
init: function(){
|
||||
this.requires("2D");
|
||||
console.log("Creating cloud system.");
|
||||
this.last = new Date().getTime();
|
||||
this.delay = 0;
|
||||
this.current_y = 0;
|
||||
this.old_y = 0;
|
||||
},
|
||||
clouds: function(data){
|
||||
this.data = data;
|
||||
this.last = new Date().getTime();
|
||||
this.delay = 0;
|
||||
|
||||
var width = Crafty.viewport.width;
|
||||
if (this.data.width)
|
||||
width = this.data.width;
|
||||
var left = 0;
|
||||
if (this.data.left)
|
||||
left = this.data.left
|
||||
|
||||
var res = 16;
|
||||
if (this.data.res)
|
||||
res = this.data.res;
|
||||
|
||||
for (var i=0; i<=res+1; i++){
|
||||
this.placeCloud((i/res) * width + left)
|
||||
}
|
||||
this.bind("EnterFrame",this.tick);
|
||||
},
|
||||
tick: function(){
|
||||
var now = new Date().getTime();
|
||||
if (now > this.last + 4000){
|
||||
this.last = now;
|
||||
this.placeCloud(Crafty.viewport.width + 100);
|
||||
}
|
||||
},
|
||||
placeCloud: function(x){
|
||||
var top = 0;
|
||||
if (this.data.top)
|
||||
top = this.data.top;
|
||||
var height = 200;
|
||||
if (this.data.height)
|
||||
height = this.data.height;
|
||||
|
||||
//this.current_y = (this.current_y + 59) % 200;
|
||||
var cloud = Crafty.e("Cloud");
|
||||
var new_y = this.old_y;
|
||||
while (Math.abs(new_y-this.old_y) < 80){
|
||||
new_y = Math.random() * height + top;
|
||||
}
|
||||
cloud.attr({
|
||||
x: x,
|
||||
y: new_y // this.current_y + top
|
||||
});
|
||||
this.old_y = new_y;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Crafty.c("Cloud",{
|
||||
init: function(){
|
||||
this.requires("2D, drawmode, Sprite, CloudS");
|
||||
this.attr({z:-10});
|
||||
this.sprite(0,0,128,64);
|
||||
this.crop(0,0,128,64);
|
||||
this.last = new Date().getTime();
|
||||
this.speed = 25;
|
||||
this.bind("EnterFrame",this.tick);
|
||||
},
|
||||
tick: function(){
|
||||
var now = new Date().getTime();
|
||||
var dtime = (now - this.last)/1000;
|
||||
this.last = now;
|
||||
|
||||
this.x -= this.speed * dtime;
|
||||
|
||||
if (this.x < -(Crafty.viewport.width/2)){
|
||||
this.destroy();
|
||||
}
|
||||
},
|
||||
});
|
||||
/*
|
||||
* part of PUZZLE PLATFORMER
|
||||
* by rubenwardy (rubenwardy@gmail.com)
|
||||
* Licensed under GNU GPL 3.0 or later. See LICENSE.txt
|
||||
*/
|
||||
|
||||
Crafty.c("ParticleSystem",{
|
||||
init: function(){},
|
||||
particles: function(data){
|
||||
this.requires("2D");
|
||||
this.data = data;
|
||||
this.start = new Date().getTime();
|
||||
this.last = this.start;
|
||||
this.bind("EnterFrame",this.tick);
|
||||
return this;
|
||||
},
|
||||
tick: function(){
|
||||
var now = new Date().getTime();
|
||||
if (this.data && this.data.expire && now > (this.start+this.data.expire)){
|
||||
console.log("Deleting particle spawner");
|
||||
this.destroy();
|
||||
}
|
||||
|
||||
if (now > this.last + this.data.delay){
|
||||
this.last = now;
|
||||
var amt = 1;
|
||||
if (this.data.spawn && this.data.spawn.amt)
|
||||
amt = this.data.spawn.amt;
|
||||
for (var i=0;i<amt;i++){
|
||||
this.addParticle();
|
||||
}
|
||||
}
|
||||
},
|
||||
addParticle: function(){
|
||||
var an = (Math.random() * 0.25 * Math.PI)-0.6*Math.PI;
|
||||
var spawnpos = {x:this.x,y:this.y};
|
||||
|
||||
if (this.data.spawn && this.data.spawn.pos){
|
||||
if (this.data.spawn.pos.type == "range"){
|
||||
spawnpos.x += (
|
||||
this.data.spawn.pos.from[0]+
|
||||
(this.data.spawn.pos.to[0]-this.data.spawn.pos.from[0])
|
||||
* Math.random()
|
||||
);
|
||||
spawnpos.y += (
|
||||
this.data.spawn.pos.from[1]+
|
||||
(this.data.spawn.pos.to[1]-this.data.spawn.pos.from[1])
|
||||
* Math.random()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
var clr = this.data.color;
|
||||
if (this.data.color instanceof Array) {
|
||||
clr = this.data.color[Math.round(Math.random()*(this.data.color.length-1))];
|
||||
}
|
||||
if (!clr || clr==""){
|
||||
clr = "red";
|
||||
}
|
||||
|
||||
var velo = {x:0,y:0};
|
||||
if(this.data.spawn && this.data.spawn.velocity && this.data.spawn.velocity.constructor == Object){
|
||||
velo = {x:this.data.spawn.velocity.x,y:this.data.spawn.velocity.y};
|
||||
}else if (this.data.spawn && this.data.spawn.angle){
|
||||
var an = 0;
|
||||
|
||||
if (this.data.spawn.angle.type == "range"){
|
||||
an = this.data.spawn.angle.from + (this.data.spawn.angle.to-this.data.spawn.angle.from)*Math.random();
|
||||
}
|
||||
|
||||
velo = {x:this.data.spawn.velocity * Math.cos(an*Math.PI),y:this.data.spawn.velocity * Math.sin(an*Math.PI)};
|
||||
}
|
||||
|
||||
var acc = {x:0, y:9.81};
|
||||
if (this.data.spawn && this.data.spawn.acc)
|
||||
acc = {x:this.data.spawn.acc.x,y:this.data.spawn.acc.y};
|
||||
|
||||
//console.log("Adding particle ");
|
||||
Crafty.e("2D, drawmode, TheParticle, Color")
|
||||
.attr(spawnpos)
|
||||
.attr({w:10,h:10,z:this.z})
|
||||
.color(clr)
|
||||
.particle(
|
||||
velo,
|
||||
acc,
|
||||
this.data.decay
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
Crafty.c("TheParticle",{
|
||||
init: function(){},
|
||||
particle: function(vel,acc,ex){
|
||||
this.vel = vel;
|
||||
this.acc = acc;
|
||||
this.start = new Date().getTime();
|
||||
this.last = this.start;
|
||||
this.expire = ex;
|
||||
if (!this.expire.fo)
|
||||
this.expire.fo = 0;
|
||||
|
||||
this.decay = -1;
|
||||
this.bind("EnterFrame",this.tick);
|
||||
},
|
||||
tick: function(){
|
||||
var now = new Date().getTime();
|
||||
if (
|
||||
(this.expire && this.expire.t && now > (this.start+this.expire.t)) ||
|
||||
(this.expire && this.expire.vy_gt && this.vel.y > this.expire.vy_gt) ||
|
||||
(this.expire && this.expire.vy_lt && this.vel.y < this.expire.vy_lt) ||
|
||||
(this.expire && this.expire.vx_gt && this.vel.x > this.expire.vx_gt) ||
|
||||
(this.expire && this.expire.vx_lt && this.vel.x < this.expire.vx_lt)
|
||||
){
|
||||
if (this.decay == -1)
|
||||
this.decay = now;
|
||||
}
|
||||
if (this.decay != -1){
|
||||
if (now > (this.decay + this.expire.fo)){
|
||||
this.destroy();
|
||||
return;
|
||||
}
|
||||
var perc = 1-((now-this.decay)/this.expire.fo);
|
||||
this.alpha = perc;
|
||||
this.visible = (perc>0);
|
||||
}
|
||||
var dtime = (now - this.last)/1000;
|
||||
this.x += this.vel.x * dtime;
|
||||
this.y += this.vel.y * dtime;
|
||||
this.vel.x += this.acc.x * 32 * dtime;
|
||||
this.vel.y += this.acc.y * 32 * dtime;
|
||||
|
||||
this.last = now;
|
||||
}
|
||||
});
|
||||
|
||||
function ParticleExplosion(pos, speed, tcolor, g, timeout, width, amt){
|
||||
if (!width)
|
||||
width = 64;
|
||||
if (!amt)
|
||||
amt = 8;
|
||||
|
||||
for (var x=0;x<amt;x++){
|
||||
for (var y=0;y<amt;y++){
|
||||
var xcolor = tcolor;
|
||||
|
||||
if (xcolor instanceof Array) {
|
||||
xcolor = xcolor[Math.round(Math.random()*(xcolor.length-1))];
|
||||
}
|
||||
|
||||
var an = Math.random() * 2 * 3.1415;
|
||||
var e = Crafty.e("2D, drawmode, TheParticle, Color")
|
||||
.attr({x:pos.x + x*(width/amt),y:pos.y + y*(width/amt)})
|
||||
.attr({w:(width/amt),h:(width/amt),z:1002})
|
||||
.color(xcolor);
|
||||
|
||||
e.particle(
|
||||
{x:speed * Math.cos(an),y:speed * Math.sin(an)},
|
||||
{x:0,y:g},
|
||||
{t:timeout}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Crafty.c("CloudSystem",{
|
||||
init: function(){
|
||||
this.requires("2D");
|
||||
console.log("Creating cloud system.");
|
||||
this.last = new Date().getTime();
|
||||
this.delay = 0;
|
||||
this.current_y = 0;
|
||||
this.old_y = 0;
|
||||
},
|
||||
clouds: function(data){
|
||||
this.data = data;
|
||||
this.last = new Date().getTime();
|
||||
this.delay = 0;
|
||||
|
||||
var width = Crafty.viewport.width;
|
||||
if (this.data.width)
|
||||
width = this.data.width;
|
||||
var left = 0;
|
||||
if (this.data.left)
|
||||
left = this.data.left
|
||||
|
||||
var res = 16;
|
||||
if (this.data.res)
|
||||
res = this.data.res;
|
||||
|
||||
for (var i=0; i<=res+1; i++){
|
||||
this.placeCloud((i/res) * width + left)
|
||||
}
|
||||
this.bind("EnterFrame",this.tick);
|
||||
},
|
||||
tick: function(){
|
||||
var now = new Date().getTime();
|
||||
if (now > this.last + 4000){
|
||||
this.last = now;
|
||||
this.placeCloud(Crafty.viewport.width + 100);
|
||||
}
|
||||
},
|
||||
placeCloud: function(x){
|
||||
var top = 0;
|
||||
if (this.data.top)
|
||||
top = this.data.top;
|
||||
var height = 200;
|
||||
if (this.data.height)
|
||||
height = this.data.height;
|
||||
|
||||
//this.current_y = (this.current_y + 59) % 200;
|
||||
var cloud = Crafty.e("Cloud");
|
||||
var new_y = this.old_y;
|
||||
while (Math.abs(new_y-this.old_y) < 80){
|
||||
new_y = Math.random() * height + top;
|
||||
}
|
||||
cloud.attr({
|
||||
x: x,
|
||||
y: new_y // this.current_y + top
|
||||
});
|
||||
this.old_y = new_y;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Crafty.c("Cloud",{
|
||||
init: function(){
|
||||
this.requires("2D, drawmode, Sprite, CloudS");
|
||||
this.attr({z:-10});
|
||||
this.sprite(0,0,128,64);
|
||||
this.crop(0,0,128,64);
|
||||
this.last = new Date().getTime();
|
||||
this.speed = 25;
|
||||
this.bind("EnterFrame",this.tick);
|
||||
},
|
||||
tick: function(){
|
||||
var now = new Date().getTime();
|
||||
var dtime = (now - this.last)/1000;
|
||||
this.last = now;
|
||||
|
||||
this.x -= this.speed * dtime;
|
||||
|
||||
if (this.x < -(Crafty.viewport.width/2)){
|
||||
this.destroy();
|
||||
}
|
||||
},
|
||||
});
|
||||
|
|
333
assets/engine.js
333
assets/engine.js
|
@ -1,167 +1,166 @@
|
|||
/*
|
||||
* part of PUZZLE PLATFORMER
|
||||
* by rubenwardy (rubenwardy@gmail.com)
|
||||
* Licensed under GNU GPL 3.0 or later. See LICENSE.txt
|
||||
*/
|
||||
|
||||
var game = {
|
||||
player: null,
|
||||
inventory: {},
|
||||
next_map: "not-ready"
|
||||
};
|
||||
var AUDIO_CARDB_CRUSH = "boxCrush1";
|
||||
var AUDIO_DEATH = "playerDie";
|
||||
var DEBUG = true;
|
||||
|
||||
function assert(cond) {
|
||||
if (!cond)
|
||||
throw("Assertion Failed!");
|
||||
}
|
||||
|
||||
var define = {
|
||||
// Private definition tables
|
||||
_bloc: {},
|
||||
_map: [],
|
||||
_sprite: {},
|
||||
_alias: {},
|
||||
|
||||
// Define map
|
||||
map: function(data){
|
||||
data.id = this._map.length;
|
||||
this._map.push(data);
|
||||
},
|
||||
|
||||
// Define block
|
||||
block: function(data){
|
||||
if (game.is_editor && data.editor){
|
||||
for (key in data.editor){
|
||||
data[key] = data.editor[key];
|
||||
}
|
||||
data.editor = null;
|
||||
}
|
||||
|
||||
this._bloc[data.name] = data;
|
||||
},
|
||||
|
||||
sprite: function(name,file){
|
||||
this._sprite[name] = file;
|
||||
},
|
||||
|
||||
alias: function(old, newn){
|
||||
this._alias[old] = newn;
|
||||
}
|
||||
};
|
||||
|
||||
var map = Map();
|
||||
var bg_render = 0;
|
||||
|
||||
var render_grid = 0;
|
||||
|
||||
function render_bg(){
|
||||
if (
|
||||
bg_render == 0 ||
|
||||
bg_render.width != $(window).width() ||
|
||||
bg_render.height != $(window).height() ||
|
||||
Crafty.viewport.y > bg_render.y + 20 || Crafty.viewport.y < bg_render.y - 20 ||
|
||||
game.is_editor
|
||||
){
|
||||
bg_render = {
|
||||
width: $(window).width(),
|
||||
height: $(window).height(),
|
||||
y: Crafty.viewport.y
|
||||
};
|
||||
var ce = $("#bg")[0];
|
||||
ce.width = $(window).width();
|
||||
ce.height = $(window).height();
|
||||
var c = ce.getContext("2d");
|
||||
if (!game.is_editor){
|
||||
var skygrad= c.createLinearGradient(0,(ce.height/4)+Crafty.viewport.y/5,0,ce.height);
|
||||
skygrad.addColorStop(0,"#87C1EB");
|
||||
skygrad.addColorStop(1,"#9DDDF2");
|
||||
c.fillStyle = skygrad;
|
||||
}else{
|
||||
c.fillStyle = "#87CEEB";
|
||||
}
|
||||
c.fillRect(0,0,ce.width,ce.height);
|
||||
//c.fillStyle="#4b4b33";
|
||||
|
||||
if (render_grid!=0)
|
||||
render_grid(c);
|
||||
}
|
||||
}
|
||||
|
||||
// Auto mode select
|
||||
Crafty.c("drawmode",{
|
||||
init: function(){
|
||||
this.requires("2D, DOM");
|
||||
}
|
||||
});
|
||||
|
||||
// Load
|
||||
Crafty.scene("Load", function() {
|
||||
$("body").prepend("<canvas id='bg' style='position:absolute;'></canvas>");
|
||||
|
||||
if (!game.is_editor) {
|
||||
Crafty.background("transparent");
|
||||
setInterval(render_bg, 1000/20);
|
||||
|
||||
Crafty.e("2D, DOM, Image, logo")
|
||||
.attr({x: Crafty.viewport.width / 2 - 92, y: Crafty.viewport.height / 2 - 190, w: 186})
|
||||
.image("assets/sprites/rubenwardy.jpg");
|
||||
Crafty.e("2D, DOM, Text, logo")
|
||||
.attr({x: Crafty.viewport.width / 2 - 92, y: Crafty.viewport.height / 2, w: 186})
|
||||
//.textColor("#ffffff")
|
||||
.textFont({ family: 'Arial', size: '20px'})
|
||||
.css("text-align", "center")
|
||||
.text("rubenwardy");
|
||||
} else {
|
||||
Crafty.background("#000");
|
||||
}
|
||||
|
||||
var resources = [
|
||||
"assets/sprites/player_body.png",
|
||||
"assets/sprites/player_head.png",
|
||||
"assets/sprites/DeadPlayer.png",
|
||||
"assets/sprites/cloud.png",
|
||||
"assets/sounds/cboxCrush.wav",
|
||||
"assets/sounds/playerDie.wav"
|
||||
];
|
||||
|
||||
for (key in define._sprite){
|
||||
resources.push(define._sprite[key]);
|
||||
}
|
||||
|
||||
var time_before = new Date().getTime();
|
||||
// Load stuff
|
||||
Crafty.load(resources,function() {
|
||||
Crafty.audio.add(AUDIO_CARDB_CRUSH, "assets/sounds/cboxCrush.wav");
|
||||
Crafty.audio.add(AUDIO_DEATH, "assets/sounds/playerDie.wav");
|
||||
Crafty.sprite(27,21,"assets/sprites/player_body.png", {
|
||||
PlayerBody:[0,0]
|
||||
});
|
||||
Crafty.sprite(20,13,"assets/sprites/player_head.png", {
|
||||
PlayerHead:[0,0]
|
||||
});
|
||||
Crafty.sprite(31,28,"assets/sprites/DeadPlayer.png", {
|
||||
DeadPlayer:[0,0]
|
||||
});
|
||||
Crafty.sprite(128,64,"assets/sprites/cloud.png", {
|
||||
CloudS:[0,0]
|
||||
});
|
||||
for (key in define._sprite){
|
||||
console.log("Loading '"+key+"' from '"+define._sprite[key]+"'");
|
||||
var ind = {};
|
||||
ind[key] = [0, 0];
|
||||
Crafty.sprite(80, 80,define._sprite[key], ind, 0, 0);
|
||||
}
|
||||
if (game.is_editor)
|
||||
Crafty.scene(game.after_load);
|
||||
else {
|
||||
Crafty.e("CloudSystem").clouds({top:0, height: 350, res: 23});
|
||||
setTimeout(function() {
|
||||
$(".logo").fadeOut();
|
||||
setTimeout(function(){Crafty.scene(game.after_load);}, 500);
|
||||
}, 700 - (new Date().getTime() - time_before));
|
||||
}
|
||||
});
|
||||
});
|
||||
/*
|
||||
* part of PUZZLE PLATFORMER
|
||||
* by rubenwardy (rubenwardy@gmail.com)
|
||||
* Licensed under GNU GPL 3.0 or later. See LICENSE.txt
|
||||
*/
|
||||
|
||||
var game = {
|
||||
player: null,
|
||||
inventory: {},
|
||||
next_map: "not-ready"
|
||||
};
|
||||
var AUDIO_CARDB_CRUSH = "boxCrush1";
|
||||
var AUDIO_DEATH = "";
|
||||
var DEBUG = true;
|
||||
|
||||
function assert(cond) {
|
||||
if (!cond)
|
||||
throw("Assertion Failed!");
|
||||
}
|
||||
|
||||
var define = {
|
||||
// Private definition tables
|
||||
_bloc: {},
|
||||
_map: [],
|
||||
_sprite: {},
|
||||
_alias: {},
|
||||
|
||||
// Define map
|
||||
map: function(data){
|
||||
data.id = this._map.length;
|
||||
this._map.push(data);
|
||||
},
|
||||
|
||||
// Define block
|
||||
block: function(data){
|
||||
if (game.is_editor && data.editor){
|
||||
for (key in data.editor){
|
||||
data[key] = data.editor[key];
|
||||
}
|
||||
data.editor = null;
|
||||
}
|
||||
|
||||
this._bloc[data.name] = data;
|
||||
},
|
||||
|
||||
sprite: function(name,file){
|
||||
this._sprite[name] = file;
|
||||
},
|
||||
|
||||
alias: function(old, newn){
|
||||
this._alias[old] = newn;
|
||||
}
|
||||
};
|
||||
|
||||
var map = Map();
|
||||
var bg_render = 0;
|
||||
|
||||
var render_grid = 0;
|
||||
|
||||
function render_bg(){
|
||||
if (
|
||||
bg_render == 0 ||
|
||||
bg_render.width != $(window).width() ||
|
||||
bg_render.height != $(window).height() ||
|
||||
Crafty.viewport.y > bg_render.y + 20 || Crafty.viewport.y < bg_render.y - 20 ||
|
||||
game.is_editor
|
||||
){
|
||||
bg_render = {
|
||||
width: $(window).width(),
|
||||
height: $(window).height(),
|
||||
y: Crafty.viewport.y
|
||||
};
|
||||
var ce = $("#bg")[0];
|
||||
ce.width = $(window).width();
|
||||
ce.height = $(window).height();
|
||||
var c = ce.getContext("2d");
|
||||
if (!game.is_editor){
|
||||
var skygrad= c.createLinearGradient(0,(ce.height/4)+Crafty.viewport.y/5,0,ce.height);
|
||||
skygrad.addColorStop(0,"#87C1EB");
|
||||
skygrad.addColorStop(1,"#9DDDF2");
|
||||
c.fillStyle = skygrad;
|
||||
}else{
|
||||
c.fillStyle = "#87CEEB";
|
||||
}
|
||||
c.fillRect(0,0,ce.width,ce.height);
|
||||
//c.fillStyle="#4b4b33";
|
||||
|
||||
if (render_grid!=0)
|
||||
render_grid(c);
|
||||
}
|
||||
}
|
||||
|
||||
// Auto mode select
|
||||
Crafty.c("drawmode",{
|
||||
init: function(){
|
||||
this.requires("2D, DOM");
|
||||
}
|
||||
});
|
||||
|
||||
// Load
|
||||
Crafty.scene("Load", function() {
|
||||
$("body").prepend("<canvas id='bg' style='position:absolute;'></canvas>");
|
||||
|
||||
if (!game.is_editor) {
|
||||
Crafty.background("transparent");
|
||||
setInterval(render_bg, 1000/20);
|
||||
|
||||
Crafty.e("2D, DOM, Image, logo")
|
||||
.attr({x: Crafty.viewport.width / 2 - 92, y: Crafty.viewport.height / 2 - 190, w: 186})
|
||||
.image("assets/sprites/rubenwardy.jpg");
|
||||
Crafty.e("2D, DOM, Text, logo")
|
||||
.attr({x: Crafty.viewport.width / 2 - 92, y: Crafty.viewport.height / 2, w: 186})
|
||||
//.textColor("#ffffff")
|
||||
.textFont({ family: 'Arial', size: '20px'})
|
||||
.css("text-align", "center")
|
||||
.text("rubenwardy");
|
||||
} else {
|
||||
Crafty.background("#000");
|
||||
}
|
||||
|
||||
var resources = [
|
||||
"assets/sprites/player_body.png",
|
||||
"assets/sprites/player_head.png",
|
||||
"assets/sprites/DeadPlayer.png",
|
||||
"assets/sprites/cloud.png",
|
||||
"assets/sounds/cboxCrush.wav"
|
||||
];
|
||||
|
||||
for (key in define._sprite){
|
||||
resources.push(define._sprite[key]);
|
||||
}
|
||||
|
||||
var time_before = new Date().getTime();
|
||||
// Load stuff
|
||||
Crafty.load(resources,function() {
|
||||
Crafty.audio.add(AUDIO_CARDB_CRUSH, "assets/sounds/cboxCrush.wav");
|
||||
Crafty.audio.add(AUDIO_DEATH, "assets/sounds/playerDie.wav");
|
||||
Crafty.sprite(27,21,"assets/sprites/player_body.png", {
|
||||
PlayerBody:[0,0]
|
||||
});
|
||||
Crafty.sprite(20,13,"assets/sprites/player_head.png", {
|
||||
PlayerHead:[0,0]
|
||||
});
|
||||
Crafty.sprite(31,28,"assets/sprites/DeadPlayer.png", {
|
||||
DeadPlayer:[0,0]
|
||||
});
|
||||
Crafty.sprite(128,64,"assets/sprites/cloud.png", {
|
||||
CloudS:[0,0]
|
||||
});
|
||||
for (key in define._sprite){
|
||||
console.log("Loading '"+key+"' from '"+define._sprite[key]+"'");
|
||||
var ind = {};
|
||||
ind[key] = [0, 0];
|
||||
Crafty.sprite(80, 80,define._sprite[key], ind, 0, 0);
|
||||
}
|
||||
if (game.is_editor)
|
||||
Crafty.scene(game.after_load);
|
||||
else {
|
||||
Crafty.e("CloudSystem").clouds({top:0, height: 350, res: 23});
|
||||
setTimeout(function() {
|
||||
$(".logo").fadeOut();
|
||||
setTimeout(function(){Crafty.scene(game.after_load);}, 500);
|
||||
}, 700 - (new Date().getTime() - time_before));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
324
assets/game.js
324
assets/game.js
|
@ -1,162 +1,162 @@
|
|||
/*
|
||||
* part of PUZZLE PLATFORMER
|
||||
* by rubenwardy (rubenwardy@gmail.com)
|
||||
* Licensed under GNU GPL 3.0 or later. See LICENSE.txt
|
||||
*/
|
||||
|
||||
game.after_load = "menu";
|
||||
|
||||
/*
|
||||
* Menu
|
||||
*/
|
||||
|
||||
Crafty.scene("menu", function() {
|
||||
// Set up style
|
||||
Crafty.background("transparent");
|
||||
Crafty.e("CloudSystem").clouds({top:0, height: 350, res: 23});
|
||||
|
||||
Crafty.e("2D, DOM, Image")
|
||||
.attr({x: -20, y: Crafty.viewport.height - 110})
|
||||
.image("assets/sprites/pp.png");
|
||||
Crafty.e("2D, DOM, Image")
|
||||
.attr({x: Crafty.viewport.width - 190, y: Crafty.viewport.height - 115})
|
||||
.image("assets/sprites/pp_right.png");
|
||||
Crafty.e("2D, DOM, Text, logo")
|
||||
.attr({x: 0, y: 20, w: Crafty.viewport.width})
|
||||
.textFont({ family: 'Arial', size: '40px'})
|
||||
.css("text-align", "center")
|
||||
.text("Puzzle Platformer");
|
||||
|
||||
$("#fps").hide();
|
||||
var d = "<ul id=\"menu\">\n";
|
||||
d += "<li><a onClick=\"play_game(-1);\">Play Game</a></li>\n";
|
||||
d += "<li><a onClick=\"Crafty.scene('level_select');\">Level Select</a></li>\n";
|
||||
d += "<li><a href=\"editor.html\">Map Editor</a></li>\n";
|
||||
d += "<li><a onClick=\"$('#help').fadeToggle(100);\">Help</a></li>\n";
|
||||
d += "</ul>\n";
|
||||
d += "<div id=\"help\" style=\"display:none;\">\n";
|
||||
d += "<b>Help</b>\n";
|
||||
d += "<p>Get all the cakes to win!</p>";
|
||||
d += "<b>WASD</b> to Move<br>";
|
||||
d += "<b>Space</b> to Jump<br>";
|
||||
d += "</div>\n";
|
||||
|
||||
$("body").append(d);
|
||||
$("#menu").css("left", (Crafty.viewport.width/2 - $("#menu").width()/2 + 20) + "px");
|
||||
},function(){
|
||||
$("#menu").remove();
|
||||
$("#fps").fadeIn();
|
||||
});
|
||||
|
||||
Crafty.scene("level_select", function() {
|
||||
// Set up style
|
||||
Crafty.background("transparent");
|
||||
Crafty.e("CloudSystem").clouds({top:0, height: 350, res: 23});
|
||||
|
||||
Crafty.e("2D, DOM, Image")
|
||||
.attr({x: -20, y: Crafty.viewport.height - 110})
|
||||
.image("assets/sprites/pp.png");
|
||||
Crafty.e("2D, DOM, Image")
|
||||
.attr({x: Crafty.viewport.width - 190, y: Crafty.viewport.height - 115})
|
||||
.image("assets/sprites/pp_right.png");
|
||||
Crafty.e("2D, DOM, Text, logo")
|
||||
.attr({x: 0, y: 20, w: Crafty.viewport.width})
|
||||
.textFont({ family: 'Arial', size: '40px'})
|
||||
.css("text-align", "center")
|
||||
.text("Puzzle Platformer");
|
||||
|
||||
$("#fps").hide();
|
||||
var d = "<ul id=\"level_select\">\n";
|
||||
|
||||
for (var i = 0; i < define._map.length; i++) {
|
||||
var map = define._map[i];
|
||||
if (map.title)
|
||||
d += "<li><a onClick=\"play_game(" + i + ");\">" + map.title + "</a></li>\n";
|
||||
else
|
||||
d += "<li><a onClick=\"play_game(" + i + ");\">Untitled Map " + i + "</a></li>\n";
|
||||
}
|
||||
d += "</ul>";
|
||||
$("body").append(d);
|
||||
$("#level_select").css("left", (Crafty.viewport.width/2 - $("#level_select").width()/2 + 20) + "px");
|
||||
},function(){
|
||||
$("#level_select").remove();
|
||||
$("#fps").fadeIn();
|
||||
});
|
||||
|
||||
function play_game(map_id){
|
||||
if (!map_id || map_id < 0){
|
||||
game.next_map = define._map[0];
|
||||
}else{
|
||||
game.next_map = define._map[map_id];
|
||||
}
|
||||
|
||||
Crafty.scene("play");
|
||||
}
|
||||
var prev = 0;
|
||||
game.fpsco = 10000;
|
||||
|
||||
|
||||
Crafty.c('FPS_TICK', {
|
||||
init: function() {
|
||||
this.ticks = 0;
|
||||
this.lastReportedOn = new Date().getTime();
|
||||
|
||||
this.bind('MeasureRenderTime', function(elapsed) {
|
||||
this.ticks += 1;
|
||||
});
|
||||
|
||||
this.bind('EnterFrame', function() {
|
||||
var now = new Date().getTime();
|
||||
var seconds = (now - this.lastReportedOn) / 1000;
|
||||
|
||||
if (seconds >= 0.5) {
|
||||
$("#fps").html(
|
||||
"Puzzle Platform<br>" +
|
||||
"CAKE: " + game.inventory.cake +
|
||||
"<br>FPS: " + Math.round(this.ticks / seconds) +
|
||||
"<br>Facing: " + ((game.player.facing==FACING_RIGHT)?"right":"left")
|
||||
);
|
||||
this.ticks = 0;
|
||||
this.lastReportedOn = now;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Play scene
|
||||
Crafty.scene("play", function () {
|
||||
// Debuging background: warns user that the script has not finished.
|
||||
Crafty.background("#ffcccc");
|
||||
|
||||
// Create player
|
||||
game.inventory = {};
|
||||
game.player = Crafty.e("2D, Player, Keyboard").player();
|
||||
|
||||
// follow player
|
||||
Crafty.viewport.clampToEntities = false;
|
||||
Crafty.viewport.follow(game.player, 0, 0);
|
||||
|
||||
// Load test_map
|
||||
map = Map();
|
||||
map.load(game.next_map);
|
||||
|
||||
// Set up physics
|
||||
game.player.physics();
|
||||
|
||||
// FPS counter
|
||||
var fps = Crafty.e("2D, FPS_TICK");
|
||||
|
||||
// Initiate the inventory
|
||||
game.inventory = {cake:0};
|
||||
|
||||
/*Crafty.e("CloudSystem").clouds({
|
||||
left:-Crafty.viewport.width/2,
|
||||
width: 2*Crafty.viewport.width,
|
||||
top:-Crafty.viewport.height/2,
|
||||
height: 2 * Crafty.viewport.height / 3,
|
||||
res: 32
|
||||
});*/
|
||||
|
||||
$("#fps").html("Puzzle Platform");
|
||||
Crafty.background("transparent");
|
||||
});
|
||||
/*
|
||||
* part of PUZZLE PLATFORMER
|
||||
* by rubenwardy (rubenwardy@gmail.com)
|
||||
* Licensed under GNU GPL 3.0 or later. See LICENSE.txt
|
||||
*/
|
||||
|
||||
game.after_load = "menu";
|
||||
|
||||
/*
|
||||
* Menu
|
||||
*/
|
||||
|
||||
Crafty.scene("menu", function() {
|
||||
// Set up style
|
||||
Crafty.background("transparent");
|
||||
Crafty.e("CloudSystem").clouds({top:0, height: 350, res: 23});
|
||||
|
||||
Crafty.e("2D, DOM, Image")
|
||||
.attr({x: -20, y: Crafty.viewport.height - 110})
|
||||
.image("assets/sprites/pp.png");
|
||||
Crafty.e("2D, DOM, Image")
|
||||
.attr({x: Crafty.viewport.width - 190, y: Crafty.viewport.height - 115})
|
||||
.image("assets/sprites/pp_right.png");
|
||||
Crafty.e("2D, DOM, Text, logo")
|
||||
.attr({x: 0, y: 20, w: Crafty.viewport.width})
|
||||
.textFont({ family: 'Arial', size: '40px'})
|
||||
.css("text-align", "center")
|
||||
.text("Puzzle Platformer");
|
||||
|
||||
$("#fps").hide();
|
||||
var d = "<ul id=\"menu\">\n";
|
||||
d += "<li><a onClick=\"play_game(-1);\">Play Game</a></li>\n";
|
||||
d += "<li><a onClick=\"Crafty.scene('level_select');\">Level Select</a></li>\n";
|
||||
d += "<li><a href=\"editor.html\">Map Editor</a></li>\n";
|
||||
d += "<li><a onClick=\"$('#help').fadeToggle(100);\">Help</a></li>\n";
|
||||
d += "</ul>\n";
|
||||
d += "<div id=\"help\" style=\"display:none;\">\n";
|
||||
d += "<b>Help</b>\n";
|
||||
d += "<p>Get all the cakes to win!</p>";
|
||||
d += "<b>WASD</b> to Move<br>";
|
||||
d += "<b>Space</b> to Jump<br>";
|
||||
d += "</div>\n";
|
||||
|
||||
$("body").append(d);
|
||||
$("#menu").css("left", (Crafty.viewport.width/2 - $("#menu").width()/2 + 20) + "px");
|
||||
},function(){
|
||||
$("#menu").remove();
|
||||
$("#fps").fadeIn();
|
||||
});
|
||||
|
||||
Crafty.scene("level_select", function() {
|
||||
// Set up style
|
||||
Crafty.background("transparent");
|
||||
Crafty.e("CloudSystem").clouds({top:0, height: 350, res: 23});
|
||||
|
||||
Crafty.e("2D, DOM, Image")
|
||||
.attr({x: -20, y: Crafty.viewport.height - 110})
|
||||
.image("assets/sprites/pp.png");
|
||||
Crafty.e("2D, DOM, Image")
|
||||
.attr({x: Crafty.viewport.width - 190, y: Crafty.viewport.height - 115})
|
||||
.image("assets/sprites/pp_right.png");
|
||||
Crafty.e("2D, DOM, Text, logo")
|
||||
.attr({x: 0, y: 20, w: Crafty.viewport.width})
|
||||
.textFont({ family: 'Arial', size: '40px'})
|
||||
.css("text-align", "center")
|
||||
.text("Puzzle Platformer");
|
||||
|
||||
$("#fps").hide();
|
||||
var d = "<ul id=\"level_select\">\n";
|
||||
|
||||
for (var i = 0; i < define._map.length; i++) {
|
||||
var map = define._map[i];
|
||||
if (map.title)
|
||||
d += "<li><a onClick=\"play_game(" + i + ");\">" + map.title + "</a></li>\n";
|
||||
else
|
||||
d += "<li><a onClick=\"play_game(" + i + ");\">Untitled Map " + i + "</a></li>\n";
|
||||
}
|
||||
d += "</ul>";
|
||||
$("body").append(d);
|
||||
$("#level_select").css("left", (Crafty.viewport.width/2 - $("#level_select").width()/2 + 20) + "px");
|
||||
},function(){
|
||||
$("#level_select").remove();
|
||||
$("#fps").fadeIn();
|
||||
});
|
||||
|
||||
function play_game(map_id){
|
||||
if (!map_id || map_id < 0){
|
||||
game.next_map = define._map[0];
|
||||
}else{
|
||||
game.next_map = define._map[map_id];
|
||||
}
|
||||
|
||||
Crafty.scene("play");
|
||||
}
|
||||
var prev = 0;
|
||||
game.fpsco = 10000;
|
||||
|
||||
|
||||
Crafty.c('FPS_TICK', {
|
||||
init: function() {
|
||||
this.ticks = 0;
|
||||
this.lastReportedOn = new Date().getTime();
|
||||
|
||||
this.bind('MeasureRenderTime', function(elapsed) {
|
||||
this.ticks += 1;
|
||||
});
|
||||
|
||||
this.bind('EnterFrame', function() {
|
||||
var now = new Date().getTime();
|
||||
var seconds = (now - this.lastReportedOn) / 1000;
|
||||
|
||||
if (seconds >= 0.5) {
|
||||
$("#fps").html(
|
||||
"Puzzle Platform<br>" +
|
||||
"CAKE: " + game.inventory.cake +
|
||||
"<br>FPS: " + Math.round(this.ticks / seconds) +
|
||||
"<br>Facing: " + ((game.player.facing==FACING_RIGHT)?"right":"left")
|
||||
);
|
||||
this.ticks = 0;
|
||||
this.lastReportedOn = now;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Play scene
|
||||
Crafty.scene("play", function () {
|
||||
// Debuging background: warns user that the script has not finished.
|
||||
Crafty.background("#ffcccc");
|
||||
|
||||
// Create player
|
||||
game.inventory = {};
|
||||
game.player = Crafty.e("2D, Player, Keyboard").player();
|
||||
|
||||
// follow player
|
||||
Crafty.viewport.clampToEntities = false;
|
||||
Crafty.viewport.follow(game.player, 0, 0);
|
||||
|
||||
// Load test_map
|
||||
map = Map();
|
||||
map.load(game.next_map);
|
||||
|
||||
// Set up physics
|
||||
game.player.physics();
|
||||
|
||||
// FPS counter
|
||||
var fps = Crafty.e("2D, FPS_TICK");
|
||||
|
||||
// Initiate the inventory
|
||||
game.inventory = {cake:0};
|
||||
|
||||
/*Crafty.e("CloudSystem").clouds({
|
||||
left:-Crafty.viewport.width/2,
|
||||
width: 2*Crafty.viewport.width,
|
||||
top:-Crafty.viewport.height/2,
|
||||
height: 2 * Crafty.viewport.height / 3,
|
||||
res: 32
|
||||
});*/
|
||||
|
||||
$("#fps").html("Puzzle Platform");
|
||||
Crafty.background("transparent");
|
||||
});
|
||||
|
|
File diff suppressed because one or more lines are too long
838
assets/map.js
838
assets/map.js
|
@ -1,419 +1,419 @@
|
|||
/*
|
||||
* part of PUZZLE PLATFORMER
|
||||
* by rubenwardy (rubenwardy@gmail.com)
|
||||
* Licensed under GNU GPL 3.0 or later. See LICENSE.txt
|
||||
*/
|
||||
|
||||
function Map(){
|
||||
return {
|
||||
tiles: null,
|
||||
map_data: null,
|
||||
load: function(data){
|
||||
if (!data){
|
||||
throw("MapNotFound");
|
||||
return;
|
||||
}
|
||||
|
||||
this.tiles = [];
|
||||
this.map_data = data;
|
||||
|
||||
for (var y = data.map.length-1; y >= 0; y--) {
|
||||
this.tiles[y] = [];
|
||||
for (var x = 0; x < data.map[y].length; x++) {
|
||||
if (data.map[y][x] != ''){
|
||||
this.tiles[y][x] = Crafty.e("2D, Tile")
|
||||
.tile(data.map[y][x],x,y,data.width,data.height);
|
||||
}else{
|
||||
this.tiles[y][x] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (game.player){
|
||||
game.player.newSpawn(data.spawn);
|
||||
game.player.attr({x: data.spawn.x*64+15,y: data.spawn.y*64+25});
|
||||
}
|
||||
|
||||
if (this.map_data.help)
|
||||
this.show_bubble(this.map_data.help[0]);
|
||||
},
|
||||
get: function(x,y){
|
||||
return this.tiles[y][x];
|
||||
},
|
||||
set: function(x,y,data){
|
||||
while (y>=this.tiles.length){
|
||||
this.tiles.push([]);
|
||||
}
|
||||
while (x>=this.tiles[y].length){
|
||||
this.tiles[y].push(null);
|
||||
}
|
||||
if (this.tiles[y][x]){
|
||||
this.tiles[y][x].destroy();
|
||||
this.tiles[y][x] = null;
|
||||
}
|
||||
if (data != ''){
|
||||
this.tiles[y][x] = Crafty.e("Tile").tile(data,x,y,this.map_data.width,this.map_data.height);
|
||||
}else{
|
||||
this.tiles[y][x] = null;
|
||||
}
|
||||
//this.debug();
|
||||
},
|
||||
debug: function(){
|
||||
var res = "";
|
||||
for (var y=0;y<this.tiles.length;y++){
|
||||
for (var x=0;x<this.tiles[y].length;x++){
|
||||
if (this.tiles[y][x] && this.tiles[y][x].tile_meta && this.tiles[y][x].tile_data.ascii)
|
||||
res += this.tiles[y][x].tile_data.ascii;
|
||||
else
|
||||
res += ".";
|
||||
}
|
||||
res += "\n";
|
||||
}
|
||||
$('#console').remove();
|
||||
var out = '<textarea id="console" style="font-family: Courier New, Courier, monospace;height:200px;background:transparent;border: 0;margin-left:180px;';
|
||||
out += 'position:fixed;bottom:0;left:0;right:0;padding:1em;">';
|
||||
out += res;
|
||||
out += '</textarea>';
|
||||
$('body').append(out);
|
||||
},
|
||||
getDim: function(){
|
||||
var h = this.tiles.length;
|
||||
var w = 0;
|
||||
for (var y=0;y<this.tiles.length;y++){
|
||||
if (this.tiles[y].length > w)
|
||||
w = this.tiles[y].length;
|
||||
}
|
||||
this.map_data.width = w;
|
||||
this.map_data.height = h;
|
||||
},
|
||||
getCakes: function(){
|
||||
var c = 0;
|
||||
for (var y=0;y<this.tiles.length;y++){
|
||||
for (var x=0;x<this.tiles[y].length;x++){
|
||||
if (this.tiles[y][x] && this.tiles[y][x].tile_meta && this.tiles[y][x].tile_meta.node == "cake")
|
||||
c++;
|
||||
}
|
||||
}
|
||||
return c;
|
||||
},
|
||||
save: function(){
|
||||
var res = "";
|
||||
for (var y=0;y<this.tiles.length;y++){
|
||||
if (res != "")
|
||||
res += ",\n";
|
||||
var row = "";
|
||||
for (var x=0;x<this.tiles[y].length;x++){
|
||||
if (row!="")
|
||||
row += ", ";
|
||||
|
||||
if (this.tiles[y][x] && this.tiles[y][x].tile_meta && this.tiles[y][x].tile_meta.node)
|
||||
row += '"' + this.tiles[y][x].tile_meta.node + '"';
|
||||
else
|
||||
row += '""';
|
||||
}
|
||||
res += "\t\t["+row+"]";
|
||||
}
|
||||
return res;
|
||||
},
|
||||
raycast_player: function(from, to, rect, step){
|
||||
function interRect(one, other) {
|
||||
return !(
|
||||
other.x > one.x + one.w ||
|
||||
other.x + other.w < one.x ||
|
||||
other.y > one.y + one.h ||
|
||||
other.y + other.h < one.y
|
||||
);
|
||||
};
|
||||
|
||||
var distance = Math.sqrt( Math.pow(from.x - to.x, 2) + Math.pow(from.y - to.y, 2) );
|
||||
var direction = Math.atan((to.y - from.y) / (to.x - from.x));
|
||||
for (var i = 0; i < distance; i += step){
|
||||
var pos = {
|
||||
x: from.x + Math.cos(direction) * i,
|
||||
y: from.y + Math.sin(direction) * i,
|
||||
w: 27,
|
||||
h: 29
|
||||
};
|
||||
if (interRect(rect, pos))
|
||||
return true;
|
||||
}
|
||||
if (interRect(rect, {x: to.x, y: to.y, w: 27, h: 29}))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
},
|
||||
show_bubble: function(data){
|
||||
Crafty.e("Bubble_E").bubble(data);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
var BUBBLES = 0;
|
||||
Crafty.c("Bubble_E",{
|
||||
init: function(){
|
||||
this.bub_id = BUBBLES;
|
||||
BUBBLES = BUBBLES + 1;
|
||||
},
|
||||
bubble: function(data){
|
||||
if (data.at){
|
||||
this.requires("2D, DOM, bubble, Text");
|
||||
this.text(data.msg);
|
||||
this.attr({
|
||||
x: data.at.x * 64,
|
||||
y: data.at.y * 64 + 10,
|
||||
z: 1000
|
||||
});
|
||||
if (data.behind)
|
||||
this.attr({z: 0});
|
||||
if (data.at.w)
|
||||
this.attr({w: data.at.w});
|
||||
if (data.at.h)
|
||||
this.attr({h: data.at.h});
|
||||
|
||||
}else{
|
||||
$("#bubble").remove();
|
||||
$("body").append("<div id=\"bubble_" + this.bub_id + "\" class=\"bubble\">" + data.msg + "</div>");
|
||||
if (data.behind)
|
||||
$("#bubble").css("z-index", "0");
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Crafty.c("LayerDebug", {
|
||||
init: function() {
|
||||
return;
|
||||
this.text = Crafty.e("2D, DOM, Text")
|
||||
.attr({x: -40, y: 40, w: 64, z: 1999})
|
||||
.textFont({ family: 'Arial', size: '10px'})
|
||||
.css("text-align", "center")
|
||||
.text(this.z);
|
||||
this.attach(this.text);
|
||||
|
||||
this.bind("EnterFrame", function() {
|
||||
this.text.text(this.z);
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// Tile components
|
||||
Crafty.c("Tile",{
|
||||
// Tile properties
|
||||
tile_data: null, // The tile definition
|
||||
tile_meta: null, // The tile meta data
|
||||
tile_p: null, // The tile position
|
||||
|
||||
show: function(){
|
||||
this.visible = true;
|
||||
},
|
||||
hide: function(){
|
||||
this.visible = false;
|
||||
},
|
||||
|
||||
// Set up functions
|
||||
tile: function(_tile, _x, _y, mapwidth, mapheight) {
|
||||
this.mapwidth = mapwidth;
|
||||
this.mapheight = mapheight;
|
||||
this.get_def(_tile, _x, _y);
|
||||
|
||||
// Check stuff
|
||||
if (!this.tile_data)
|
||||
return null;
|
||||
|
||||
// Load required components
|
||||
this.addComponent(this.require());
|
||||
|
||||
// Set position
|
||||
var z_shift = this.tile_data.z_shift;
|
||||
if (!z_shift)
|
||||
z_shift = 0;
|
||||
this.attr({
|
||||
x: (this.tile_p.x * 64) - 10,
|
||||
y: (this.tile_p.y * 64) - 10,
|
||||
z: (_x + (mapheight - _y) * mapwidth) * 2 + z_shift
|
||||
});
|
||||
|
||||
this.bind("move",function() {
|
||||
var z_shift = this.tile_data.z_shift;
|
||||
if (!z_shift)
|
||||
z_shift = 0;
|
||||
this.attr({z: Math.round(((this.x + 10) / 64 + (this.mapheight - (this.y + 10) / 65) * this.mapwidth) * 2 + z_shift)});
|
||||
});
|
||||
|
||||
// Do draw type
|
||||
this.addComponent("Tile" + this.tile_data.drawtype);
|
||||
|
||||
|
||||
// Init physics
|
||||
if (this.tile_meta && this.tile_meta.visible == false) {
|
||||
this.hide();
|
||||
} else {
|
||||
if (this.init_physics)
|
||||
this.init_physics();
|
||||
}
|
||||
|
||||
// Run function, if needed
|
||||
if ((game.player && this.tile_data.init) || this.tile_data.init_req)
|
||||
if (this.tile_data.init(this)==false)
|
||||
return null;
|
||||
|
||||
return this;
|
||||
},
|
||||
require: function(){
|
||||
var def = "2D, drawmode, LayerDebug";
|
||||
// Extra components
|
||||
if (this.tile_data.c)
|
||||
def += ", "+this.tile_data.c;
|
||||
|
||||
// Standard components
|
||||
if (this.tile_data.physics)
|
||||
def += ", TilePhysics";
|
||||
|
||||
return def;
|
||||
},
|
||||
get_def: function(_tile,_x,_y){
|
||||
var tile;
|
||||
|
||||
if (typeof(_tile) == "string"){
|
||||
tile=_tile;
|
||||
this.tile_meta = {node:tile};
|
||||
}else{
|
||||
tile=_tile.node;
|
||||
this.tile_meta = _tile;
|
||||
}
|
||||
|
||||
this.tile_data = define._bloc[tile];
|
||||
|
||||
if (!this.tile_data && define._alias[tile]){
|
||||
this.tile_meta.node = define._alias[tile];
|
||||
this.tile_data = define._bloc[define._alias[tile]];
|
||||
}
|
||||
|
||||
// Give the position
|
||||
this.tile_p = {
|
||||
x:_x,
|
||||
y:_y
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
// THESE DEFINE BUILT IN TILE DRAW TYPES
|
||||
// -------------------------------------
|
||||
// Drawtypes:
|
||||
// * Tile - Adds a sprite that fits behind.
|
||||
// * Block - Does above and makes a perspective block.
|
||||
// * Anim - Defines an animated sprite.
|
||||
// -------------------------------------
|
||||
|
||||
Crafty.c("TileTile",{
|
||||
spritemap: null,
|
||||
init: function(){
|
||||
if (this.tile_data.tile && this.tile_data.tile.tile)
|
||||
this.spritemap = this.tile_data.tile.tile;
|
||||
else
|
||||
this.spritemap = "default";
|
||||
|
||||
if (this.tile_data.tile && this.tile_data.tile.ani) {
|
||||
this.applyAnimation(this.tile_data.tile, this);
|
||||
}else{
|
||||
this.requires("Sprite");
|
||||
this.addComponent(this.spritemap);
|
||||
this.sprite(this.tile_data.tile.x, this.tile_data.tile.y, 80, 80);
|
||||
this.crop(0, 0, 80, 80);
|
||||
}
|
||||
|
||||
if (game.is_editor && this.tile_data.drawtype=="Block")
|
||||
this.visible = false;
|
||||
|
||||
return this;
|
||||
},
|
||||
applyAnimation: function(tile_data, sprite){
|
||||
sprite.requires("SpriteAnimation");
|
||||
sprite.addComponent(this.spritemap);
|
||||
var frames = [];
|
||||
if (tile_data.ani.frames) {
|
||||
frames = tile_data.ani.frames;
|
||||
} else {
|
||||
for (var i = 0; i < tile_data.ani.l; i++) {
|
||||
frames.push([tile_data.x + i, tile_data.y]);
|
||||
}
|
||||
}
|
||||
sprite.reel("normal", tile_data.ani.dur, frames);
|
||||
sprite.animate("normal", -1);
|
||||
}
|
||||
});
|
||||
|
||||
Crafty.c("TileBlock",{
|
||||
front: null,
|
||||
init: function(){
|
||||
this.addComponent("TileTile");
|
||||
this.front = Crafty.e("2D, drawmode");
|
||||
if (this.tile_data.tile && this.tile_data.tile.ani)
|
||||
this.applyAnimation(this.tile_data.tile, this.front);
|
||||
else{
|
||||
this.front.requires("Sprite");
|
||||
this.front.addComponent(this.spritemap);
|
||||
this.front.sprite(this.tile_data.tile.x, this.tile_data.tile.y, 80, 80);
|
||||
}
|
||||
function getOrDef(one, two){
|
||||
if (one!=null)
|
||||
return one;
|
||||
else
|
||||
return two
|
||||
}
|
||||
var height = getOrDef(this.tile_data.top, 15);
|
||||
var right = getOrDef(this.tile_data.right, 64);
|
||||
var bottom = getOrDef(this.tile_data.bottom, 80);
|
||||
this.front.crop(0, height, right, bottom - height);
|
||||
this.front.attr({
|
||||
x: (this.tile_p.x*64)-10,
|
||||
y: (this.tile_p.y*64)-10+height,
|
||||
z: 1000
|
||||
});
|
||||
this.attach(this.front);
|
||||
return this;
|
||||
},
|
||||
show: function(){
|
||||
this.visible = true;
|
||||
this.front.visible = true;
|
||||
},
|
||||
hide: function(){
|
||||
this.visible = false;
|
||||
this.front.visible = false;
|
||||
},
|
||||
});
|
||||
|
||||
Crafty.c("TilePhysics",{
|
||||
_physics: null,
|
||||
init_physics: function(){
|
||||
// Get physics object def
|
||||
this._physics = this.tile_data.physics;
|
||||
|
||||
if (!this._physics.isSensor){
|
||||
this.addComponent("Obstacle");
|
||||
}
|
||||
|
||||
|
||||
this.addComponent("Box2D");
|
||||
|
||||
|
||||
// Create physics object, if not defined
|
||||
if (!this._physics)
|
||||
return;
|
||||
|
||||
// Set body type, if not defined
|
||||
if (!this._physics.bodyType)
|
||||
this._physics.bodyType = "static";
|
||||
|
||||
// Set shape, if not defined
|
||||
if (!this._physics.shape)
|
||||
this._physics.shape = [[10,10],[72,10],[72,72],[10,72]];
|
||||
|
||||
// Add Box2D physics, if needed
|
||||
if (this.box2d)
|
||||
this.box2d(this._physics,true);
|
||||
|
||||
return this;
|
||||
}
|
||||
});
|
||||
/*
|
||||
* part of PUZZLE PLATFORMER
|
||||
* by rubenwardy (rubenwardy@gmail.com)
|
||||
* Licensed under GNU GPL 3.0 or later. See LICENSE.txt
|
||||
*/
|
||||
|
||||
function Map(){
|
||||
return {
|
||||
tiles: null,
|
||||
map_data: null,
|
||||
load: function(data){
|
||||
if (!data){
|
||||
throw("MapNotFound");
|
||||
return;
|
||||
}
|
||||
|
||||
this.tiles = [];
|
||||
this.map_data = data;
|
||||
|
||||
for (var y = data.map.length-1; y >= 0; y--) {
|
||||
this.tiles[y] = [];
|
||||
for (var x = 0; x < data.map[y].length; x++) {
|
||||
if (data.map[y][x] != ''){
|
||||
this.tiles[y][x] = Crafty.e("2D, Tile")
|
||||
.tile(data.map[y][x],x,y,data.width,data.height);
|
||||
}else{
|
||||
this.tiles[y][x] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (game.player){
|
||||
game.player.newSpawn(data.spawn);
|
||||
game.player.attr({x: data.spawn.x*64+15,y: data.spawn.y*64+25});
|
||||
}
|
||||
|
||||
if (this.map_data.help)
|
||||
this.show_bubble(this.map_data.help[0]);
|
||||
},
|
||||
get: function(x,y){
|
||||
return this.tiles[y][x];
|
||||
},
|
||||
set: function(x,y,data){
|
||||
while (y>=this.tiles.length){
|
||||
this.tiles.push([]);
|
||||
}
|
||||
while (x>=this.tiles[y].length){
|
||||
this.tiles[y].push(null);
|
||||
}
|
||||
if (this.tiles[y][x]){
|
||||
this.tiles[y][x].destroy();
|
||||
this.tiles[y][x] = null;
|
||||
}
|
||||
if (data != ''){
|
||||
this.tiles[y][x] = Crafty.e("Tile").tile(data,x,y,this.map_data.width,this.map_data.height);
|
||||
}else{
|
||||
this.tiles[y][x] = null;
|
||||
}
|
||||
//this.debug();
|
||||
},
|
||||
debug: function(){
|
||||
var res = "";
|
||||
for (var y=0;y<this.tiles.length;y++){
|
||||
for (var x=0;x<this.tiles[y].length;x++){
|
||||
if (this.tiles[y][x] && this.tiles[y][x].tile_meta && this.tiles[y][x].tile_data.ascii)
|
||||
res += this.tiles[y][x].tile_data.ascii;
|
||||
else
|
||||
res += ".";
|
||||
}
|
||||
res += "\n";
|
||||
}
|
||||
$('#console').remove();
|
||||
var out = '<textarea id="console" style="font-family: Courier New, Courier, monospace;height:200px;background:transparent;border: 0;margin-left:180px;';
|
||||
out += 'position:fixed;bottom:0;left:0;right:0;padding:1em;">';
|
||||
out += res;
|
||||
out += '</textarea>';
|
||||
$('body').append(out);
|
||||
},
|
||||
getDim: function(){
|
||||
var h = this.tiles.length;
|
||||
var w = 0;
|
||||
for (var y=0;y<this.tiles.length;y++){
|
||||
if (this.tiles[y].length > w)
|
||||
w = this.tiles[y].length;
|
||||
}
|
||||
this.map_data.width = w;
|
||||
this.map_data.height = h;
|
||||
},
|
||||
getCakes: function(){
|
||||
var c = 0;
|
||||
for (var y=0;y<this.tiles.length;y++){
|
||||
for (var x=0;x<this.tiles[y].length;x++){
|
||||
if (this.tiles[y][x] && this.tiles[y][x].tile_meta && this.tiles[y][x].tile_meta.node == "cake")
|
||||
c++;
|
||||
}
|
||||
}
|
||||
return c;
|
||||
},
|
||||
save: function(){
|
||||
var res = "";
|
||||
for (var y=0;y<this.tiles.length;y++){
|
||||
if (res != "")
|
||||
res += ",\n";
|
||||
var row = "";
|
||||
for (var x=0;x<this.tiles[y].length;x++){
|
||||
if (row!="")
|
||||
row += ", ";
|
||||
|
||||
if (this.tiles[y][x] && this.tiles[y][x].tile_meta && this.tiles[y][x].tile_meta.node)
|
||||
row += '"' + this.tiles[y][x].tile_meta.node + '"';
|
||||
else
|
||||
row += '""';
|
||||
}
|
||||
res += "\t\t["+row+"]";
|
||||
}
|
||||
return res;
|
||||
},
|
||||
raycast_player: function(from, to, rect, step){
|
||||
function interRect(one, other) {
|
||||
return !(
|
||||
other.x > one.x + one.w ||
|
||||
other.x + other.w < one.x ||
|
||||
other.y > one.y + one.h ||
|
||||
other.y + other.h < one.y
|
||||
);
|
||||
};
|
||||
|
||||
var distance = Math.sqrt( Math.pow(from.x - to.x, 2) + Math.pow(from.y - to.y, 2) );
|
||||
var direction = Math.atan((to.y - from.y) / (to.x - from.x));
|
||||
for (var i = 0; i < distance; i += step){
|
||||
var pos = {
|
||||
x: from.x + Math.cos(direction) * i,
|
||||
y: from.y + Math.sin(direction) * i,
|
||||
w: 27,
|
||||
h: 29
|
||||
};
|
||||
if (interRect(rect, pos))
|
||||
return true;
|
||||
}
|
||||
if (interRect(rect, {x: to.x, y: to.y, w: 27, h: 29}))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
},
|
||||
show_bubble: function(data){
|
||||
Crafty.e("Bubble_E").bubble(data);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
var BUBBLES = 0;
|
||||
Crafty.c("Bubble_E",{
|
||||
init: function(){
|
||||
this.bub_id = BUBBLES;
|
||||
BUBBLES = BUBBLES + 1;
|
||||
},
|
||||
bubble: function(data){
|
||||
if (data.at){
|
||||
this.requires("2D, DOM, bubble, Text");
|
||||
this.text(data.msg);
|
||||
this.attr({
|
||||
x: data.at.x * 64,
|
||||
y: data.at.y * 64 + 10,
|
||||
z: 1000
|
||||
});
|
||||
if (data.behind)
|
||||
this.attr({z: 0});
|
||||
if (data.at.w)
|
||||
this.attr({w: data.at.w});
|
||||
if (data.at.h)
|
||||
this.attr({h: data.at.h});
|
||||
|
||||
}else{
|
||||
$("#bubble").remove();
|
||||
$("body").append("<div id=\"bubble_" + this.bub_id + "\" class=\"bubble\">" + data.msg + "</div>");
|
||||
if (data.behind)
|
||||
$("#bubble").css("z-index", "0");
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Crafty.c("LayerDebug", {
|
||||
init: function() {
|
||||
return;
|
||||
this.text = Crafty.e("2D, DOM, Text")
|
||||
.attr({x: -40, y: 40, w: 64, z: 1999})
|
||||
.textFont({ family: 'Arial', size: '10px'})
|
||||
.css("text-align", "center")
|
||||
.text(this.z);
|
||||
this.attach(this.text);
|
||||
|
||||
this.bind("EnterFrame", function() {
|
||||
this.text.text(this.z);
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// Tile components
|
||||
Crafty.c("Tile",{
|
||||
// Tile properties
|
||||
tile_data: null, // The tile definition
|
||||
tile_meta: null, // The tile meta data
|
||||
tile_p: null, // The tile position
|
||||
|
||||
show: function(){
|
||||
this.visible = true;
|
||||
},
|
||||
hide: function(){
|
||||
this.visible = false;
|
||||
},
|
||||
|
||||
// Set up functions
|
||||
tile: function(_tile, _x, _y, mapwidth, mapheight) {
|
||||
this.mapwidth = mapwidth;
|
||||
this.mapheight = mapheight;
|
||||
this.get_def(_tile, _x, _y);
|
||||
|
||||
// Check stuff
|
||||
if (!this.tile_data)
|
||||
return null;
|
||||
|
||||
// Load required components
|
||||
this.addComponent(this.require());
|
||||
|
||||
// Set position
|
||||
var z_shift = this.tile_data.z_shift;
|
||||
if (!z_shift)
|
||||
z_shift = 0;
|
||||
this.attr({
|
||||
x: (this.tile_p.x * 64) - 10,
|
||||
y: (this.tile_p.y * 64) - 10,
|
||||
z: (_x + (mapheight - _y) * mapwidth) * 2 + z_shift
|
||||
});
|
||||
|
||||
this.bind("move",function() {
|
||||
var z_shift = this.tile_data.z_shift;
|
||||
if (!z_shift)
|
||||
z_shift = 0;
|
||||
this.attr({z: Math.round(((this.x + 10) / 64 + (this.mapheight - (this.y + 10) / 65) * this.mapwidth) * 2 + z_shift)});
|
||||
});
|
||||
|
||||
// Do draw type
|
||||
this.addComponent("Tile" + this.tile_data.drawtype);
|
||||
|
||||
|
||||
// Init physics
|
||||
if (this.tile_meta && this.tile_meta.visible == false) {
|
||||
this.hide();
|
||||
} else {
|
||||
if (this.init_physics)
|
||||
this.init_physics();
|
||||
}
|
||||
|
||||
// Run function, if needed
|
||||
if ((game.player && this.tile_data.init) || this.tile_data.init_req)
|
||||
if (this.tile_data.init(this)==false)
|
||||
return null;
|
||||
|
||||
return this;
|
||||
},
|
||||
require: function(){
|
||||
var def = "2D, drawmode, LayerDebug";
|
||||
// Extra components
|
||||
if (this.tile_data.c)
|
||||
def += ", "+this.tile_data.c;
|
||||
|
||||
// Standard components
|
||||
if (this.tile_data.physics)
|
||||
def += ", TilePhysics";
|
||||
|
||||
return def;
|
||||
},
|
||||
get_def: function(_tile,_x,_y){
|
||||
var tile;
|
||||
|
||||
if (typeof(_tile) == "string"){
|
||||
tile=_tile;
|
||||
this.tile_meta = {node:tile};
|
||||
}else{
|
||||
tile=_tile.node;
|
||||
this.tile_meta = _tile;
|
||||
}
|
||||
|
||||
this.tile_data = define._bloc[tile];
|
||||
|
||||
if (!this.tile_data && define._alias[tile]){
|
||||
this.tile_meta.node = define._alias[tile];
|
||||
this.tile_data = define._bloc[define._alias[tile]];
|
||||
}
|
||||
|
||||
// Give the position
|
||||
this.tile_p = {
|
||||
x:_x,
|
||||
y:_y
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
// THESE DEFINE BUILT IN TILE DRAW TYPES
|
||||
// -------------------------------------
|
||||
// Drawtypes:
|
||||
// * Tile - Adds a sprite that fits behind.
|
||||
// * Block - Does above and makes a perspective block.
|
||||
// * Anim - Defines an animated sprite.
|
||||
// -------------------------------------
|
||||
|
||||
Crafty.c("TileTile",{
|
||||
spritemap: null,
|
||||
init: function(){
|
||||
if (this.tile_data.tile && this.tile_data.tile.tile)
|
||||
this.spritemap = this.tile_data.tile.tile;
|
||||
else
|
||||
this.spritemap = "default";
|
||||
|
||||
if (this.tile_data.tile && this.tile_data.tile.ani) {
|
||||
this.applyAnimation(this.tile_data.tile, this);
|
||||
}else{
|
||||
this.requires("Sprite");
|
||||
this.addComponent(this.spritemap);
|
||||
this.sprite(this.tile_data.tile.x, this.tile_data.tile.y, 80, 80);
|
||||
this.crop(0, 0, 80, 80);
|
||||
}
|
||||
|
||||
if (game.is_editor && this.tile_data.drawtype=="Block")
|
||||
this.visible = false;
|
||||
|
||||
return this;
|
||||
},
|
||||
applyAnimation: function(tile_data, sprite){
|
||||
sprite.requires("SpriteAnimation");
|
||||
sprite.addComponent(this.spritemap);
|
||||
var frames = [];
|
||||
if (tile_data.ani.frames) {
|
||||
frames = tile_data.ani.frames;
|
||||
} else {
|
||||
for (var i = 0; i < tile_data.ani.l; i++) {
|
||||
frames.push([tile_data.x + i, tile_data.y]);
|
||||
}
|
||||
}
|
||||
sprite.reel("normal", tile_data.ani.dur, frames);
|
||||
sprite.animate("normal", -1);
|
||||
}
|
||||
});
|
||||
|
||||
Crafty.c("TileBlock",{
|
||||
front: null,
|
||||
init: function(){
|
||||
this.addComponent("TileTile");
|
||||
this.front = Crafty.e("2D, drawmode");
|
||||
if (this.tile_data.tile && this.tile_data.tile.ani)
|
||||
this.applyAnimation(this.tile_data.tile, this.front);
|
||||
else{
|
||||
this.front.requires("Sprite");
|
||||
this.front.addComponent(this.spritemap);
|
||||
this.front.sprite(this.tile_data.tile.x, this.tile_data.tile.y, 80, 80);
|
||||
}
|
||||
function getOrDef(one, two){
|
||||
if (one!=null)
|
||||
return one;
|
||||
else
|
||||
return two
|
||||
}
|
||||
var height = getOrDef(this.tile_data.top, 15);
|
||||
var right = getOrDef(this.tile_data.right, 64);
|
||||
var bottom = getOrDef(this.tile_data.bottom, 80);
|
||||
this.front.crop(0, height, right, bottom - height);
|
||||
this.front.attr({
|
||||
x: (this.tile_p.x*64)-10,
|
||||
y: (this.tile_p.y*64)-10+height,
|
||||
z: 1000
|
||||
});
|
||||
this.attach(this.front);
|
||||
return this;
|
||||
},
|
||||
show: function(){
|
||||
this.visible = true;
|
||||
this.front.visible = true;
|
||||
},
|
||||
hide: function(){
|
||||
this.visible = false;
|
||||
this.front.visible = false;
|
||||
},
|
||||
});
|
||||
|
||||
Crafty.c("TilePhysics",{
|
||||
_physics: null,
|
||||
init_physics: function(){
|
||||
// Get physics object def
|
||||
this._physics = this.tile_data.physics;
|
||||
|
||||
if (!this._physics.isSensor){
|
||||
this.addComponent("Obstacle");
|
||||
}
|
||||
|
||||
|
||||
this.addComponent("Box2D");
|
||||
|
||||
|
||||
// Create physics object, if not defined
|
||||
if (!this._physics)
|
||||
return;
|
||||
|
||||
// Set body type, if not defined
|
||||
if (!this._physics.bodyType)
|
||||
this._physics.bodyType = "static";
|
||||
|
||||
// Set shape, if not defined
|
||||
if (!this._physics.shape)
|
||||
this._physics.shape = [[10,10],[72,10],[72,72],[10,72]];
|
||||
|
||||
// Add Box2D physics, if needed
|
||||
if (this.box2d)
|
||||
this.box2d(this._physics,true);
|
||||
|
||||
return this;
|
||||
}
|
||||
});
|
||||
|
|
670
assets/player.js
670
assets/player.js
|
@ -1,335 +1,335 @@
|
|||
/*
|
||||
* part of PUZZLE PLATFORMER
|
||||
* by rubenwardy (rubenwardy@gmail.com)
|
||||
* Licensed under GNU GPL 3.0 or later. See LICENSE.txt
|
||||
*/
|
||||
|
||||
var FACING_RIGHT = 0;
|
||||
var FACING_LEFT = 1;
|
||||
var FACING_FORWARD = 2;
|
||||
var PLAYER_Z = 700;
|
||||
|
||||
// Player component
|
||||
// Handles player related stuff
|
||||
Crafty.c("Player",{
|
||||
pbody: null,
|
||||
deadbody: null,
|
||||
lastSpawn: {x:1,y:1},
|
||||
pulling: null,
|
||||
head: null,
|
||||
pbody: null,
|
||||
foot: null,
|
||||
left_hand: null,
|
||||
right_hand: null,
|
||||
facing: FACING_RIGHT,
|
||||
lock_turn: 0,
|
||||
health: 10,
|
||||
freeze: false,
|
||||
data: {
|
||||
head: 'default',
|
||||
body: 'default'
|
||||
},
|
||||
hit: function(amt){
|
||||
if (this.health == 0 && this.dstart){
|
||||
return;
|
||||
}
|
||||
|
||||
this.health -= amt;
|
||||
|
||||
var f = $("#flash");
|
||||
f.show();
|
||||
f.fadeOut();
|
||||
|
||||
if (this.health <= 0){
|
||||
this.kill();
|
||||
}
|
||||
},
|
||||
kill: function(){
|
||||
if (this.health == 0 && this.dstart){
|
||||
return;
|
||||
}
|
||||
console.log("Player has died!");
|
||||
Crafty.trigger("PlayerDeath", null);
|
||||
this.head.visible = false;
|
||||
this.pbody.visible = false;
|
||||
this.deadbody.visible = true;
|
||||
$(".DeadPlayer").show();
|
||||
this.health = 0;
|
||||
this.freeze = true;
|
||||
this.dstart = new Date().getTime();
|
||||
this.body.SetAwake(false);
|
||||
},
|
||||
revive: function(){
|
||||
console.log("Reviving player");
|
||||
this.goto(this.lastSpawn);
|
||||
this.attr({x: this.body.GetPosition().x, y: this.body.GetPosition().y});
|
||||
this.head.visible = true;
|
||||
this.pbody.visible = true;
|
||||
this.deadbody.visible = false;
|
||||
$(".DeadPlayer").hide();
|
||||
setTimeout(function(){
|
||||
console.log("Unfrozen");
|
||||
game.player.health = 10;
|
||||
game.player.freeze = false;
|
||||
game.player.body.SetAwake(true);
|
||||
}, 10);
|
||||
},
|
||||
goto: function(pos){
|
||||
console.log("Going to tile ("+pos.x+","+pos.y+")");
|
||||
this.body.SetPosition({x: pos.x,y: pos.y});
|
||||
this.body.SetAwake(true);
|
||||
},
|
||||
newSpawn: function(pos){
|
||||
console.log("Last spawn position changed");
|
||||
this.lastSpawn = pos;
|
||||
},
|
||||
init: function(){
|
||||
this.requires("Box2D");
|
||||
return this;
|
||||
},
|
||||
player: function(){
|
||||
// Set up physics
|
||||
this.attr({w:20,h:46,z:PLAYER_Z});
|
||||
|
||||
// Create body parts
|
||||
this.head = Crafty.e("2D, drawmode, SpriteAnimation, PlayerHead")
|
||||
.attr({x:3,z: PLAYER_Z + 1});
|
||||
this.pbody = Crafty.e("2D, drawmode, SpriteAnimation, PlayerBody")
|
||||
.attr({y:8,z: PLAYER_Z});
|
||||
this.deadbody = Crafty.e("2D, drawmode, SpriteAnimation, DeadPlayer");
|
||||
this.deadbody.attr({y:8,x:-2,z: PLAYER_Z});
|
||||
|
||||
// Attach body parts
|
||||
this.attach(this.head);
|
||||
this.attach(this.pbody);
|
||||
this.attach(this.deadbody);
|
||||
this.deadbody.visible=false;
|
||||
$(".DeadPlayer").hide();
|
||||
|
||||
// Bind to events
|
||||
/*this.head.bind("NewDirection",function (direction) {
|
||||
if (direction.x < 0) {
|
||||
if (!this.isPlaying("walk"))
|
||||
this.stop().animate("walk", 10, -1);
|
||||
}
|
||||
if (direction.x > 0 ) {
|
||||
if (!this.isPlaying("walk"))
|
||||
this.stop().animate("walk", 10, -1);
|
||||
}
|
||||
if(!direction.x && !direction.y) {
|
||||
this.stop();
|
||||
}
|
||||
});*/
|
||||
this.bind("EnterFrame",this._enterframe);
|
||||
this.bind("KeyDown", function(e) {
|
||||
if (!this.body || this.freeze)
|
||||
return;
|
||||
|
||||
// Punch
|
||||
if (e.key == Crafty.keys.K) {
|
||||
if (this.facing == FACING_RIGHT) {
|
||||
var contact = this.contactWithFixture("crushable", this.right_hand);
|
||||
if (contact)
|
||||
contact[0].obj.crush();
|
||||
} else if (this.facing == FACING_LEFT) {
|
||||
var contact = this.contactWithFixture("crushable", this.left_hand);
|
||||
if (contact)
|
||||
contact[0].obj.crush();
|
||||
}
|
||||
}
|
||||
|
||||
// Use
|
||||
if (e.key == Crafty.keys.E) {
|
||||
if (this.facing == FACING_RIGHT) {
|
||||
var contact = this.contactWithFixture("usable", this.right_hand);
|
||||
if (contact) {
|
||||
Crafty.trigger("using", contact[0].obj);
|
||||
contact[0].obj.use();
|
||||
}
|
||||
} else if (this.facing == FACING_LEFT) {
|
||||
var contact = this.contactWithFixture("usable", this.left_hand);
|
||||
if (contact)
|
||||
contact[0].obj.use();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return this;
|
||||
},
|
||||
_enterframe: function() {
|
||||
// Progress to next level
|
||||
if (game.inventory.cake >= map.map_data.cakes && !game.switching){
|
||||
game.switching = true;
|
||||
setTimeout(function(){
|
||||
game.switching = false;
|
||||
game.next_map = define._map[map.map_data.id + 1];
|
||||
|
||||
if (game.next_map)
|
||||
Crafty.scene("play");
|
||||
else
|
||||
Crafty.scene("menu");
|
||||
}, 2000);
|
||||
return;
|
||||
}
|
||||
|
||||
// Die and revive
|
||||
if (this.health <= 0){
|
||||
if (!this.dstart)
|
||||
this.kill();
|
||||
|
||||
if (new Date().getTime() > this.dstart + 500)
|
||||
this.revive();
|
||||
return;
|
||||
}
|
||||
if (!this.body || this.freeze)
|
||||
return;
|
||||
|
||||
// Die if falling too far
|
||||
if (this.y > (map.map_data.height + 5)* 64){
|
||||
this.kill();
|
||||
return;
|
||||
}
|
||||
this.update_player();
|
||||
},
|
||||
update_player: function() {
|
||||
assert(this.lock_turn >= 0);
|
||||
|
||||
var on_ladder = (this.contact("Ladder"))?true:false;
|
||||
var up_key = (Crafty.keydown[Crafty.keys['W']] || Crafty.keydown[Crafty.keys['UP_ARROW']] || Crafty.keydown[Crafty.keys['SPACE']]);
|
||||
var left_key = (Crafty.keydown[Crafty.keys['A']] || Crafty.keydown[Crafty.keys['LEFT_ARROW']]);
|
||||
var right_key = (Crafty.keydown[Crafty.keys['D']] || Crafty.keydown[Crafty.keys['RIGHT_ARROW']]);
|
||||
|
||||
// Physics
|
||||
var vvel = 3.8;
|
||||
|
||||
// Ladder physics
|
||||
if (on_ladder) {
|
||||
this.body.ApplyForce(new b2Vec2(0, -(9.81 * this.body.GetMass())), this.body.GetPosition());
|
||||
this.body.SetLinearDamping(10);
|
||||
vvel = 10;
|
||||
if ((Crafty.keydown[Crafty.keys['S']] || Crafty.keydown[Crafty.keys['DOWN_ARROW']])){
|
||||
this.body.ApplyImpulse(new b2Vec2(0, 0.5), this.body.GetPosition());
|
||||
}
|
||||
if (up_key)
|
||||
this.body.ApplyImpulse(new b2Vec2(0, -0.7), this.body.GetPosition());
|
||||
} else {
|
||||
this.body.SetLinearDamping(0.5);
|
||||
|
||||
// Handle Jumping
|
||||
var on_ground = (this.contactWithFixture("Obstacle", this.foot)) ? true : false;
|
||||
if (up_key && on_ground)
|
||||
this.body.ApplyImpulse(new b2Vec2(0,-0.5), this.body.GetPosition());
|
||||
}
|
||||
|
||||
// Walk left
|
||||
if (left_key) {
|
||||
if (this.lock_turn == 0)
|
||||
this.facing = FACING_LEFT;
|
||||
this.body.ApplyForce(new b2Vec2(-vvel, 0), this.body.GetPosition());
|
||||
} else if (right_key) {
|
||||
if (this.lock_turn == 0)
|
||||
this.facing = FACING_RIGHT;
|
||||
this.body.ApplyForce(new b2Vec2(vvel, 0), this.body.GetPosition());
|
||||
}
|
||||
},
|
||||
physics: function() {
|
||||
this.box2d({
|
||||
bodyType: "dynamic",
|
||||
density: 1,
|
||||
shape: [[0,0],[27,0],[27,29],[0,29]]
|
||||
},true);
|
||||
this.foot = this.addSensor([[9,30],[20,30],[20,33],[9,33]]);
|
||||
this.left_hand = this.addSensor([[-5,10],[0,10],[0,20],[-5,20]]);
|
||||
var wid = 27; // width of character
|
||||
this.right_hand = this.addSensor([[wid,10],[wid+5,10],[wid+5,20],[wid,20]]);
|
||||
return this;
|
||||
},
|
||||
addSensor: function(loc) {
|
||||
this.addFixture({
|
||||
bodyType: 'static',
|
||||
shape: loc,
|
||||
isSensor: true
|
||||
});
|
||||
return this.fixtures[this.fixtures.length - 1];
|
||||
}
|
||||
});
|
||||
|
||||
Crafty.c("PickUp",{
|
||||
type: null,
|
||||
amount: null,
|
||||
count: 0,
|
||||
init: function(){
|
||||
},
|
||||
PickUp: function(type,amount){
|
||||
this.type = type;
|
||||
this.amount = amount;
|
||||
this.count = 0;
|
||||
this.bind("EnterFrame",this._enterframe);
|
||||
},
|
||||
_enterframe: function(){
|
||||
this.count += 1;
|
||||
if ( this.count > 2 ){
|
||||
this.count = 0;
|
||||
var now_pos = {x: game.player.x, y: game.player.y, w: 27, h: 29};
|
||||
if (!this.last_pos){
|
||||
this.last_pos = now_pos;
|
||||
return;
|
||||
}
|
||||
if ( map.raycast_player(this.last_pos, now_pos, {x: this.x+20, y: this.y+30, w: 30, h: 40}, 2) ){
|
||||
this.destroy();
|
||||
if ( game.inventory[this.type] )
|
||||
game.inventory[this.type]+=this.amount;
|
||||
else
|
||||
game.inventory[this.type]=this.amount;
|
||||
|
||||
console.log(this.amount+"x "+this.type+" added to the Inventory");
|
||||
Crafty.trigger("PickUp",{type:this.type,amount:this.amount});
|
||||
if (this.tile_data.onPickUp){
|
||||
this.tile_data.onPickUp(this);
|
||||
}
|
||||
}
|
||||
this.last_pos = now_pos;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Crafty.c("Flag",{
|
||||
type: null,
|
||||
amount: null,
|
||||
count: 0,
|
||||
init: function(){
|
||||
this.count = 0;
|
||||
this.triggered = false;
|
||||
this.bind("EnterFrame",this._enterframe);
|
||||
this.bind("reset_flags", function(){
|
||||
if (this.tile_data.onFlagReset)
|
||||
this.tile_data.onFlagReset(this);
|
||||
|
||||
this.triggered = false;
|
||||
});
|
||||
},
|
||||
_enterframe: function(){
|
||||
if (this.triggered)
|
||||
return;
|
||||
this.count += 1;
|
||||
if ( this.count > 2 ){
|
||||
this.count = 0;
|
||||
var now_pos = {x: game.player.x, y: game.player.y, w: 27, h: 29};
|
||||
if ( !this.last_pos ){
|
||||
this.last_pos = now_pos;
|
||||
return;
|
||||
}
|
||||
if ( map.raycast_player(this.last_pos, now_pos, {x: this.x+10, y: this.y+10, w: 62, h: 62}, 2) ){
|
||||
Crafty.trigger("reset_flags");
|
||||
|
||||
game.player.newSpawn({x: this.tile_p.x, y: this.tile_p.y});
|
||||
|
||||
if (this.tile_data.onFlag)
|
||||
this.tile_data.onFlag(this);
|
||||
|
||||
this.triggered = true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
/*
|
||||
* part of PUZZLE PLATFORMER
|
||||
* by rubenwardy (rubenwardy@gmail.com)
|
||||
* Licensed under GNU GPL 3.0 or later. See LICENSE.txt
|
||||
*/
|
||||
|
||||
var FACING_RIGHT = 0;
|
||||
var FACING_LEFT = 1;
|
||||
var FACING_FORWARD = 2;
|
||||
var PLAYER_Z = 700;
|
||||
|
||||
// Player component
|
||||
// Handles player related stuff
|
||||
Crafty.c("Player",{
|
||||
pbody: null,
|
||||
deadbody: null,
|
||||
lastSpawn: {x:1,y:1},
|
||||
pulling: null,
|
||||
head: null,
|
||||
pbody: null,
|
||||
foot: null,
|
||||
left_hand: null,
|
||||
right_hand: null,
|
||||
facing: FACING_RIGHT,
|
||||
lock_turn: 0,
|
||||
health: 10,
|
||||
freeze: false,
|
||||
data: {
|
||||
head: 'default',
|
||||
body: 'default'
|
||||
},
|
||||
hit: function(amt){
|
||||
if (this.health == 0 && this.dstart){
|
||||
return;
|
||||
}
|
||||
|
||||
this.health -= amt;
|
||||
|
||||
var f = $("#flash");
|
||||
f.show();
|
||||
f.fadeOut();
|
||||
|
||||
if (this.health <= 0){
|
||||
this.kill();
|
||||
}
|
||||
},
|
||||
kill: function(){
|
||||
if (this.health == 0 && this.dstart){
|
||||
return;
|
||||
}
|
||||
console.log("Player has died!");
|
||||
Crafty.trigger("PlayerDeath", null);
|
||||
this.head.visible = false;
|
||||
this.pbody.visible = false;
|
||||
this.deadbody.visible = true;
|
||||
$(".DeadPlayer").show();
|
||||
this.health = 0;
|
||||
this.freeze = true;
|
||||
this.dstart = new Date().getTime();
|
||||
this.body.SetAwake(false);
|
||||
},
|
||||
revive: function(){
|
||||
console.log("Reviving player");
|
||||
this.goto(this.lastSpawn);
|
||||
this.attr({x: this.body.GetPosition().x, y: this.body.GetPosition().y});
|
||||
this.head.visible = true;
|
||||
this.pbody.visible = true;
|
||||
this.deadbody.visible = false;
|
||||
$(".DeadPlayer").hide();
|
||||
setTimeout(function(){
|
||||
console.log("Unfrozen");
|
||||
game.player.health = 10;
|
||||
game.player.freeze = false;
|
||||
game.player.body.SetAwake(true);
|
||||
}, 10);
|
||||
},
|
||||
goto: function(pos){
|
||||
console.log("Going to tile ("+pos.x+","+pos.y+")");
|
||||
this.body.SetPosition({x: pos.x,y: pos.y});
|
||||
this.body.SetAwake(true);
|
||||
},
|
||||
newSpawn: function(pos){
|
||||
console.log("Last spawn position changed");
|
||||
this.lastSpawn = pos;
|
||||
},
|
||||
init: function(){
|
||||
this.requires("Box2D");
|
||||
return this;
|
||||
},
|
||||
player: function(){
|
||||
// Set up physics
|
||||
this.attr({w:20,h:46,z:PLAYER_Z});
|
||||
|
||||
// Create body parts
|
||||
this.head = Crafty.e("2D, drawmode, SpriteAnimation, PlayerHead")
|
||||
.attr({x:3,z: PLAYER_Z + 1});
|
||||
this.pbody = Crafty.e("2D, drawmode, SpriteAnimation, PlayerBody")
|
||||
.attr({y:8,z: PLAYER_Z});
|
||||
this.deadbody = Crafty.e("2D, drawmode, SpriteAnimation, DeadPlayer");
|
||||
this.deadbody.attr({y:8,x:-2,z: PLAYER_Z});
|
||||
|
||||
// Attach body parts
|
||||
this.attach(this.head);
|
||||
this.attach(this.pbody);
|
||||
this.attach(this.deadbody);
|
||||
this.deadbody.visible=false;
|
||||
$(".DeadPlayer").hide();
|
||||
|
||||
// Bind to events
|
||||
/*this.head.bind("NewDirection",function (direction) {
|
||||
if (direction.x < 0) {
|
||||
if (!this.isPlaying("walk"))
|
||||
this.stop().animate("walk", 10, -1);
|
||||
}
|
||||
if (direction.x > 0 ) {
|
||||
if (!this.isPlaying("walk"))
|
||||
this.stop().animate("walk", 10, -1);
|
||||
}
|
||||
if(!direction.x && !direction.y) {
|
||||
this.stop();
|
||||
}
|
||||
});*/
|
||||
this.bind("EnterFrame",this._enterframe);
|
||||
this.bind("KeyDown", function(e) {
|
||||
if (!this.body || this.freeze)
|
||||
return;
|
||||
|
||||
// Punch
|
||||
if (e.key == Crafty.keys.K) {
|
||||
if (this.facing == FACING_RIGHT) {
|
||||
var contact = this.contactWithFixture("crushable", this.right_hand);
|
||||
if (contact)
|
||||
contact[0].obj.crush();
|
||||
} else if (this.facing == FACING_LEFT) {
|
||||
var contact = this.contactWithFixture("crushable", this.left_hand);
|
||||
if (contact)
|
||||
contact[0].obj.crush();
|
||||
}
|
||||
}
|
||||
|
||||
// Use
|
||||
if (e.key == Crafty.keys.E) {
|
||||
if (this.facing == FACING_RIGHT) {
|
||||
var contact = this.contactWithFixture("usable", this.right_hand);
|
||||
if (contact) {
|
||||
Crafty.trigger("using", contact[0].obj);
|
||||
contact[0].obj.use();
|
||||
}
|
||||
} else if (this.facing == FACING_LEFT) {
|
||||
var contact = this.contactWithFixture("usable", this.left_hand);
|
||||
if (contact)
|
||||
contact[0].obj.use();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return this;
|
||||
},
|
||||
_enterframe: function() {
|
||||
// Progress to next level
|
||||
if (game.inventory.cake >= map.map_data.cakes && !game.switching){
|
||||
game.switching = true;
|
||||
setTimeout(function(){
|
||||
game.switching = false;
|
||||
game.next_map = define._map[map.map_data.id + 1];
|
||||
|
||||
if (game.next_map)
|
||||
Crafty.scene("play");
|
||||
else
|
||||
Crafty.scene("menu");
|
||||
}, 2000);
|
||||
return;
|
||||
}
|
||||
|
||||
// Die and revive
|
||||
if (this.health <= 0){
|
||||
if (!this.dstart)
|
||||
this.kill();
|
||||
|
||||
if (new Date().getTime() > this.dstart + 500)
|
||||
this.revive();
|
||||
return;
|
||||
}
|
||||
if (!this.body || this.freeze)
|
||||
return;
|
||||
|
||||
// Die if falling too far
|
||||
if (this.y > (map.map_data.height + 5)* 64){
|
||||
this.kill();
|
||||
return;
|
||||
}
|
||||
this.update_player();
|
||||
},
|
||||
update_player: function() {
|
||||
assert(this.lock_turn >= 0);
|
||||
|
||||
var on_ladder = (this.contact("Ladder"))?true:false;
|
||||
var up_key = (Crafty.keydown[Crafty.keys['W']] || Crafty.keydown[Crafty.keys['UP_ARROW']] || Crafty.keydown[Crafty.keys['SPACE']]);
|
||||
var left_key = (Crafty.keydown[Crafty.keys['A']] || Crafty.keydown[Crafty.keys['LEFT_ARROW']]);
|
||||
var right_key = (Crafty.keydown[Crafty.keys['D']] || Crafty.keydown[Crafty.keys['RIGHT_ARROW']]);
|
||||
|
||||
// Physics
|
||||
var vvel = 3.8;
|
||||
|
||||
// Ladder physics
|
||||
if (on_ladder) {
|
||||
this.body.ApplyForce(new b2Vec2(0, -(9.81 * this.body.GetMass())), this.body.GetPosition());
|
||||
this.body.SetLinearDamping(10);
|
||||
vvel = 10;
|
||||
if ((Crafty.keydown[Crafty.keys['S']] || Crafty.keydown[Crafty.keys['DOWN_ARROW']])){
|
||||
this.body.ApplyImpulse(new b2Vec2(0, 0.5), this.body.GetPosition());
|
||||
}
|
||||
if (up_key)
|
||||
this.body.ApplyImpulse(new b2Vec2(0, -0.7), this.body.GetPosition());
|
||||
} else {
|
||||
this.body.SetLinearDamping(0.5);
|
||||
|
||||
// Handle Jumping
|
||||
var on_ground = (this.contactWithFixture("Obstacle", this.foot)) ? true : false;
|
||||
if (up_key && on_ground)
|
||||
this.body.ApplyImpulse(new b2Vec2(0,-0.5), this.body.GetPosition());
|
||||
}
|
||||
|
||||
// Walk left
|
||||
if (left_key) {
|
||||
if (this.lock_turn == 0)
|
||||
this.facing = FACING_LEFT;
|
||||
this.body.ApplyForce(new b2Vec2(-vvel, 0), this.body.GetPosition());
|
||||
} else if (right_key) {
|
||||
if (this.lock_turn == 0)
|
||||
this.facing = FACING_RIGHT;
|
||||
this.body.ApplyForce(new b2Vec2(vvel, 0), this.body.GetPosition());
|
||||
}
|
||||
},
|
||||
physics: function() {
|
||||
this.box2d({
|
||||
bodyType: "dynamic",
|
||||
density: 1,
|
||||
shape: [[0,0],[27,0],[27,29],[0,29]]
|
||||
},true);
|
||||
this.foot = this.addSensor([[9,30],[20,30],[20,33],[9,33]]);
|
||||
this.left_hand = this.addSensor([[-5,10],[0,10],[0,20],[-5,20]]);
|
||||
var wid = 27; // width of character
|
||||
this.right_hand = this.addSensor([[wid,10],[wid+5,10],[wid+5,20],[wid,20]]);
|
||||
return this;
|
||||
},
|
||||
addSensor: function(loc) {
|
||||
this.addFixture({
|
||||
bodyType: 'static',
|
||||
shape: loc,
|
||||
isSensor: true
|
||||
});
|
||||
return this.fixtures[this.fixtures.length - 1];
|
||||
}
|
||||
});
|
||||
|
||||
Crafty.c("PickUp",{
|
||||
type: null,
|
||||
amount: null,
|
||||
count: 0,
|
||||
init: function(){
|
||||
},
|
||||
PickUp: function(type,amount){
|
||||
this.type = type;
|
||||
this.amount = amount;
|
||||
this.count = 0;
|
||||
this.bind("EnterFrame",this._enterframe);
|
||||
},
|
||||
_enterframe: function(){
|
||||
this.count += 1;
|
||||
if ( this.count > 2 ){
|
||||
this.count = 0;
|
||||
var now_pos = {x: game.player.x, y: game.player.y, w: 27, h: 29};
|
||||
if (!this.last_pos){
|
||||
this.last_pos = now_pos;
|
||||
return;
|
||||
}
|
||||
if ( map.raycast_player(this.last_pos, now_pos, {x: this.x+20, y: this.y+30, w: 30, h: 40}, 2) ){
|
||||
this.destroy();
|
||||
if ( game.inventory[this.type] )
|
||||
game.inventory[this.type]+=this.amount;
|
||||
else
|
||||
game.inventory[this.type]=this.amount;
|
||||
|
||||
console.log(this.amount+"x "+this.type+" added to the Inventory");
|
||||
Crafty.trigger("PickUp",{type:this.type,amount:this.amount});
|
||||
if (this.tile_data.onPickUp){
|
||||
this.tile_data.onPickUp(this);
|
||||
}
|
||||
}
|
||||
this.last_pos = now_pos;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Crafty.c("Flag",{
|
||||
type: null,
|
||||
amount: null,
|
||||
count: 0,
|
||||
init: function(){
|
||||
this.count = 0;
|
||||
this.triggered = false;
|
||||
this.bind("EnterFrame",this._enterframe);
|
||||
this.bind("reset_flags", function(){
|
||||
if (this.tile_data.onFlagReset)
|
||||
this.tile_data.onFlagReset(this);
|
||||
|
||||
this.triggered = false;
|
||||
});
|
||||
},
|
||||
_enterframe: function(){
|
||||
if (this.triggered)
|
||||
return;
|
||||
this.count += 1;
|
||||
if ( this.count > 2 ){
|
||||
this.count = 0;
|
||||
var now_pos = {x: game.player.x, y: game.player.y, w: 27, h: 29};
|
||||
if ( !this.last_pos ){
|
||||
this.last_pos = now_pos;
|
||||
return;
|
||||
}
|
||||
if ( map.raycast_player(this.last_pos, now_pos, {x: this.x+10, y: this.y+10, w: 62, h: 62}, 2) ){
|
||||
Crafty.trigger("reset_flags");
|
||||
|
||||
game.player.newSpawn({x: this.tile_p.x, y: this.tile_p.y});
|
||||
|
||||
if (this.tile_data.onFlag)
|
||||
this.tile_data.onFlag(this);
|
||||
|
||||
this.triggered = true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
319
assets/style.css
319
assets/style.css
|
@ -1,159 +1,160 @@
|
|||
/*
|
||||
* part of PUZZLE PLATFORMER
|
||||
* by rubenwardy (rubenwardy@gmail.com)
|
||||
* Licensed under GNU GPL 3.0 or later. See LICENSE.txt
|
||||
*/
|
||||
|
||||
body{
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
font-family: "Arial",sans-serif;
|
||||
}
|
||||
|
||||
a{
|
||||
color: blue;
|
||||
}
|
||||
|
||||
div{
|
||||
image-rendering: -moz-crisp-edges; /* Firefox */
|
||||
image-rendering: -o-crisp-edges; /* Opera */
|
||||
image-rendering: -webkit-optimize-contrast;/* Webkit (non-standard naming) */
|
||||
image-rendering: crisp-edges;
|
||||
-ms-interpolation-mode: nearest-neighbor; /* IE (non-standard property) */
|
||||
}
|
||||
|
||||
#panel {
|
||||
position: fixed;
|
||||
left: 0;
|
||||
top: 0;
|
||||
z-index: 10000;
|
||||
}
|
||||
#panel div{
|
||||
width: 128px;
|
||||
margin: 1em;
|
||||
border-radius: 5px;
|
||||
background: rgba(255,255,255,0.3);
|
||||
padding: 1em;
|
||||
z-index: 1101;
|
||||
}
|
||||
|
||||
#tools ul{
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
#tools ul li a{
|
||||
display: block;
|
||||
padding: 4px;
|
||||
color: black;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
#tools ul li a:hover{
|
||||
background: rgba(255,255,255,0.5);
|
||||
}
|
||||
|
||||
.selected{
|
||||
color: blue !important;
|
||||
padding: 4px 4px 4px 1.2em !important;
|
||||
}
|
||||
|
||||
#flash {
|
||||
position: fixed;
|
||||
display: none;
|
||||
left: 0;
|
||||
top: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
background: rgba(255,0,0,0.4);
|
||||
z-index: 1100;
|
||||
}
|
||||
|
||||
#menu {
|
||||
display: table;
|
||||
position: fixed;
|
||||
bottom: 35px;
|
||||
left: 30%;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
border-radius: 5px;
|
||||
z-index: 2000;
|
||||
list-style: none;
|
||||
}
|
||||
|
||||
#menu li {
|
||||
display: table-cell;
|
||||
width: 25%;
|
||||
text-align: center;
|
||||
padding: 0 10px 0 0;
|
||||
}
|
||||
|
||||
#menu li a {
|
||||
background: rgba(255, 255, 255, 0.6);
|
||||
display: block;
|
||||
padding: 5px 15px 5px 15px;
|
||||
text-decoration: none;
|
||||
width: auto;
|
||||
color: black;
|
||||
cursor: pointer;
|
||||
font-size: 150%;
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
#menu li a:hover {
|
||||
text-decoration: underline;
|
||||
background: rgba(255, 255, 255, 0.75);
|
||||
}
|
||||
|
||||
.bubble{
|
||||
background: #d7bc7b;
|
||||
border: 1px solid #ae965d;
|
||||
font-size: 12px !important;
|
||||
padding: 4px 7px 4px 7px;
|
||||
position: fixed;
|
||||
top: 50%;
|
||||
left: 60%;
|
||||
display: block;
|
||||
width: auto;
|
||||
height: auto !important;
|
||||
color: white;
|
||||
z-index: 10000;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
#help {
|
||||
position: fixed;
|
||||
top: 10px;
|
||||
left: 10px;
|
||||
z-index: 2000;
|
||||
background: rgba(255, 255, 255, 0.6);
|
||||
padding: 1em;
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
#level_select {
|
||||
background: rgba(255, 255, 255, 0.8);
|
||||
padding: 1em;
|
||||
border-radius: 5px;
|
||||
position: fixed;
|
||||
margin: auto;
|
||||
top: 100px;
|
||||
z-index: 10000;
|
||||
}
|
||||
|
||||
#level_select li {
|
||||
display: block;
|
||||
padding: 2px;
|
||||
}
|
||||
|
||||
#level_select li a {
|
||||
display: block;
|
||||
padding: 10px;
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
#level_select li a:hover {
|
||||
background: rgba(255, 255, 255, 0.6);
|
||||
}
|
||||
/*
|
||||
* part of PUZZLE PLATFORMER
|
||||
* by rubenwardy (rubenwardy@gmail.com)
|
||||
* Licensed under GNU GPL 3.0 or later. See LICENSE.txt
|
||||
*/
|
||||
|
||||
body{
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
font-family: "Arial",sans-serif;
|
||||
}
|
||||
|
||||
a{
|
||||
color: blue;
|
||||
}
|
||||
|
||||
div{
|
||||
image-rendering: -moz-crisp-edges; /* Firefox */
|
||||
image-rendering: -o-crisp-edges; /* Opera */
|
||||
image-rendering: -webkit-optimize-contrast;/* Webkit (non-standard naming) */
|
||||
image-rendering: crisp-edges;
|
||||
-ms-interpolation-mode: nearest-neighbor; /* IE (non-standard property) */
|
||||
}
|
||||
|
||||
#panel {
|
||||
position: fixed;
|
||||
left: 0;
|
||||
top: 0;
|
||||
z-index: 10000;
|
||||
}
|
||||
#panel div{
|
||||
width: 128px;
|
||||
margin: 1em;
|
||||
border-radius: 5px;
|
||||
background: rgba(255,255,255,0.3);
|
||||
padding: 1em;
|
||||
z-index: 1101;
|
||||
}
|
||||
|
||||
#tools ul{
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
#tools ul li a{
|
||||
display: block;
|
||||
padding: 4px;
|
||||
color: black;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
#tools ul li a:hover{
|
||||
background: rgba(255,255,255,0.5);
|
||||
}
|
||||
|
||||
.selected{
|
||||
color: blue !important;
|
||||
padding: 4px 4px 4px 1.2em !important;
|
||||
}
|
||||
|
||||
#flash {
|
||||
position: fixed;
|
||||
display: none;
|
||||
left: 0;
|
||||
top: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
background: rgba(255,0,0,0.4);
|
||||
z-index: 1100;
|
||||
}
|
||||
|
||||
#menu {
|
||||
display: table;
|
||||
position: fixed;
|
||||
bottom: 35px;
|
||||
left: 30%;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
border-radius: 5px;
|
||||
z-index: 2000;
|
||||
list-style: none;
|
||||
}
|
||||
|
||||
#menu li {
|
||||
display: table-cell;
|
||||
width: 25%;
|
||||
text-align: center;
|
||||
padding: 0 10px 0 0;
|
||||
}
|
||||
|
||||
#menu li a {
|
||||
background: rgba(255, 255, 255, 0.6);
|
||||
display: block;
|
||||
padding: 5px 15px 5px 15px;
|
||||
text-decoration: none;
|
||||
width: auto;
|
||||
color: black;
|
||||
cursor: pointer;
|
||||
font-size: 150%;
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
#menu li a:hover {
|
||||
text-decoration: underline;
|
||||
background: rgba(255, 255, 255, 0.75);
|
||||
}
|
||||
|
||||
.bubble{
|
||||
background: #d7bc7b;
|
||||
border: 1px solid #ae965d;
|
||||
font-size: 12px !important;
|
||||
padding: 4px 7px 4px 7px;
|
||||
position: fixed;
|
||||
top: 50%;
|
||||
left: 60%;
|
||||
display: block;
|
||||
width: auto;
|
||||
height: auto !important;
|
||||
color: white;
|
||||
z-index: 10000;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
#help {
|
||||
position: fixed;
|
||||
top: 10px;
|
||||
left: 10px;
|
||||
z-index: 2000;
|
||||
background: rgba(255, 255, 255, 0.6);
|
||||
padding: 1em;
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
#level_select {
|
||||
background: rgba(255, 255, 255, 0.8);
|
||||
padding: 1em;
|
||||
border-radius: 5px;
|
||||
position: fixed;
|
||||
margin: auto;
|
||||
top: 100px;
|
||||
z-index: 10000;
|
||||
}
|
||||
|
||||
#level_select li {
|
||||
display: block;
|
||||
padding: 2px;
|
||||
}
|
||||
|
||||
#level_select li a {
|
||||
display: block;
|
||||
padding: 10px;
|
||||
border-radius: 5px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
#level_select li a:hover {
|
||||
background: rgba(255, 255, 255, 0.6);
|
||||
}
|
||||
|
|
122
editor.html
122
editor.html
|
@ -1,61 +1,61 @@
|
|||
<!DOCTYPE html>
|
||||
<!--
|
||||
PUZZLE PLATFORMER
|
||||
by rubenwardy (rubenwardy@gmail.com)
|
||||
Licensed under GNU GPL 3.0 or later. See LICENSE.txt
|
||||
-->
|
||||
<head>
|
||||
<title>Puzzle Platform</title>
|
||||
<link rel="stylesheet" type="text/css" href="assets/style.css">
|
||||
|
||||
<!-- Libraries -->
|
||||
<script type="application/javascript" src="assets/libraries/jQuery.min.js"></script>
|
||||
<script type="application/javascript" src="assets/libraries/crafty.js"></script>
|
||||
|
||||
<script type="application/javascript" src="assets/map.js"></script>
|
||||
<script type="application/javascript" src="assets/effects.js"></script>
|
||||
<script type="application/javascript" src="assets/engine.js"></script>
|
||||
<script type="application/javascript" src="assets/editor.js"></script>
|
||||
|
||||
<!-- mods -->
|
||||
<script type="application/javascript" src="assets/content.js"></script>
|
||||
<style>
|
||||
#cr-stage{
|
||||
margin-left: 190px;
|
||||
}
|
||||
#load_dia{
|
||||
position:fixed;
|
||||
top:0;
|
||||
left: 190px;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: #f0f0f0;
|
||||
z-index: 9000;
|
||||
padding:1em;
|
||||
}
|
||||
#load_dia h2{
|
||||
margin:0;
|
||||
padding:0;
|
||||
}
|
||||
#load_code{
|
||||
min-width: 50%;
|
||||
min-height: 50%
|
||||
}
|
||||
#tools{
|
||||
overflow: auto;
|
||||
overflow-x: hidden;
|
||||
height: 460px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<script type="application/javascript">
|
||||
Crafty.init();
|
||||
Crafty.viewport.init();
|
||||
Crafty.scene("Load");
|
||||
</script>
|
||||
<div id="panel">
|
||||
<div id="fps">Loading Engine...</div>
|
||||
</div>
|
||||
<div id="flash"></div>
|
||||
</body>
|
||||
<!DOCTYPE html>
|
||||
<!--
|
||||
PUZZLE PLATFORMER
|
||||
by rubenwardy (rubenwardy@gmail.com)
|
||||
Licensed under GNU GPL 3.0 or later. See LICENSE.txt
|
||||
-->
|
||||
<head>
|
||||
<title>Puzzle Platform</title>
|
||||
<link rel="stylesheet" type="text/css" href="assets/style.css">
|
||||
|
||||
<!-- Libraries -->
|
||||
<script type="application/javascript" src="assets/libraries/jQuery.min.js"></script>
|
||||
<script type="application/javascript" src="assets/libraries/crafty.js"></script>
|
||||
|
||||
<script type="application/javascript" src="assets/map.js"></script>
|
||||
<script type="application/javascript" src="assets/effects.js"></script>
|
||||
<script type="application/javascript" src="assets/engine.js"></script>
|
||||
<script type="application/javascript" src="assets/editor.js"></script>
|
||||
|
||||
<!-- mods -->
|
||||
<script type="application/javascript" src="assets/content.js"></script>
|
||||
<style>
|
||||
#cr-stage{
|
||||
margin-left: 190px;
|
||||
}
|
||||
#load_dia{
|
||||
position:fixed;
|
||||
top:0;
|
||||
left: 190px;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: #f0f0f0;
|
||||
z-index: 9000;
|
||||
padding:1em;
|
||||
}
|
||||
#load_dia h2{
|
||||
margin:0;
|
||||
padding:0;
|
||||
}
|
||||
#load_code{
|
||||
min-width: 50%;
|
||||
min-height: 50%
|
||||
}
|
||||
#tools{
|
||||
overflow: auto;
|
||||
overflow-x: hidden;
|
||||
height: 460px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<script type="application/javascript">
|
||||
Crafty.init();
|
||||
Crafty.viewport.init();
|
||||
Crafty.scene("Load");
|
||||
</script>
|
||||
<div id="panel">
|
||||
<div id="fps">Loading Engine...</div>
|
||||
</div>
|
||||
<div id="flash"></div>
|
||||
</body>
|
||||
|
|
76
index.html
76
index.html
|
@ -1,38 +1,38 @@
|
|||
<!DOCTYPE html>
|
||||
<!--
|
||||
PUZZLE PLATFORMER
|
||||
by rubenwardy (rubenwardy@gmail.com)
|
||||
Licensed under GNU GPL 3.0 or later. See LICENSE.txt
|
||||
-->
|
||||
<head>
|
||||
<title>Puzzle Platform</title>
|
||||
<link rel="stylesheet" type="text/css" href="assets/style.css">
|
||||
|
||||
<!-- Libraries -->
|
||||
<script type="application/javascript" src="assets/libraries/jQuery.min.js"></script>
|
||||
<script type="application/javascript" src="assets/libraries/crafty.js"></script>
|
||||
<script type="application/javascript" src="assets/libraries/Box2d.js"></script>
|
||||
|
||||
<script type="application/javascript" src="assets/Box2d.js"></script>
|
||||
<script type="application/javascript" src="assets/map.js"></script>
|
||||
<script type="application/javascript" src="assets/effects.js"></script>
|
||||
<script type="application/javascript" src="assets/engine.js"></script>
|
||||
<script type="application/javascript" src="assets/game.js"></script>
|
||||
<script type="application/javascript" src="assets/player.js"></script>
|
||||
|
||||
<!-- mods -->
|
||||
<script type="application/javascript" src="assets/content.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<script type="application/javascript">
|
||||
Crafty.init();
|
||||
Crafty.viewport.init();
|
||||
Crafty.box2D.init(0,9.81,64,true);
|
||||
//Crafty.box2D.showDebugInfo();
|
||||
Crafty.scene("Load");
|
||||
</script>
|
||||
<div id="panel">
|
||||
<div id="fps">Loading Engine...</div>
|
||||
</div>
|
||||
<div id="flash"></div>
|
||||
</body>
|
||||
<!DOCTYPE html>
|
||||
<!--
|
||||
PUZZLE PLATFORMER
|
||||
by rubenwardy (rubenwardy@gmail.com)
|
||||
Licensed under GNU GPL 3.0 or later. See LICENSE.txt
|
||||
-->
|
||||
<head>
|
||||
<title>Puzzle Platform</title>
|
||||
<link rel="stylesheet" type="text/css" href="assets/style.css">
|
||||
|
||||
<!-- Libraries -->
|
||||
<script type="application/javascript" src="assets/libraries/jQuery.min.js"></script>
|
||||
<script type="application/javascript" src="assets/libraries/crafty.js"></script>
|
||||
<script type="application/javascript" src="assets/libraries/Box2d.js"></script>
|
||||
|
||||
<script type="application/javascript" src="assets/Box2d.js"></script>
|
||||
<script type="application/javascript" src="assets/map.js"></script>
|
||||
<script type="application/javascript" src="assets/effects.js"></script>
|
||||
<script type="application/javascript" src="assets/engine.js"></script>
|
||||
<script type="application/javascript" src="assets/game.js"></script>
|
||||
<script type="application/javascript" src="assets/player.js"></script>
|
||||
|
||||
<!-- mods -->
|
||||
<script type="application/javascript" src="assets/content.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<script type="application/javascript">
|
||||
Crafty.init();
|
||||
Crafty.viewport.init();
|
||||
Crafty.box2D.init(0,9.81,64,true);
|
||||
//Crafty.box2D.showDebugInfo();
|
||||
Crafty.scene("Load");
|
||||
</script>
|
||||
<div id="panel">
|
||||
<div id="fps">Loading Engine...</div>
|
||||
</div>
|
||||
<div id="flash"></div>
|
||||
</body>
|
||||
|
|
Loading…
Reference in New Issue