Archived
1
0
Fork 0
This repository has been archived on 2020-02-13. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
cosmos/platformer.js

141 lines
3.1 KiB
JavaScript
Raw Normal View History

2013-11-25 12:44:39 +01:00
// heavily based/copied from/on the quintus platformer example.
2013-11-25 01:35:42 +01:00
// vim:tw=120:
window.addEventListener("load",function() {
2013-11-25 19:06:08 +01:00
var Q = window.Q = Quintus({ development: false })
.include("Sprites, Scenes, Input, 2D, Anim, Touch, UI")
.setup({ maximize: true })
.controls().touch()
Q.Sprite.extend("Player",{
init: function(p) {
this._super(p, {
2013-11-25 12:44:39 +01:00
sheet: "astronaut",
x: 320,
y: 90
});
this.add('2d, platformerControls');
this.on("hit.sprite",function(collision) {
2013-11-25 01:35:22 +01:00
if(collision.obj.isA("Rocket")) {
2013-11-25 01:47:45 +01:00
2013-11-25 12:44:39 +01:00
// the rocket flies away
var rocket = collision.obj;
2013-11-25 01:47:45 +01:00
rocket.add("tween");
rocket.animate({ x: 100, y: -500, angle: 360 });
2013-11-25 13:11:44 +01:00
// FIXME following the rocket does not work
Q.stage().unfollow();
Q.stage().viewport.follow(rocket);
2013-11-25 12:44:39 +01:00
// the player disappears
this.destroy();
2013-11-25 12:44:39 +01:00
// and the invite is displayed
2013-11-25 02:26:38 +01:00
$("#einladung").show("slow");
}
});
}
});
2013-11-25 01:35:22 +01:00
Q.Sprite.extend("Rocket", {
init: function(p) {
2013-11-25 01:35:22 +01:00
this._super(p, { sheet: 'rocket' });
}
});
2013-11-25 12:51:20 +01:00
Q.Sprite.extend("Enemy", {
init: function(p, q) {
this._super(p, q);
2013-11-24 21:04:46 +01:00
this.add('2d, aiBounce');
this.on("bump.left,bump.right,bump.bottom",function(collision) {
2013-11-25 00:55:32 +01:00
if(collision.obj.isA("Player")) {
2013-11-25 12:37:55 +01:00
Q.stageScene("endGame", 1);
2013-11-24 21:04:46 +01:00
collision.obj.destroy();
}
});
this.on("bump.top",function(collision) {
2013-11-25 00:55:32 +01:00
if(collision.obj.isA("Player")) {
2013-11-24 21:04:46 +01:00
this.destroy();
collision.obj.p.vy = -300;
}
});
}
});
2013-11-25 12:51:20 +01:00
Q.Enemy.extend("Neingeist",{
2013-11-24 21:04:46 +01:00
init: function(p) {
2013-11-25 12:51:20 +01:00
this._super(p, { sheet: 'neingeist', vx: 100 });
}
});
2013-11-25 12:51:20 +01:00
Q.Enemy.extend("Starbug",{
2013-11-25 12:32:47 +01:00
init: function(p) {
2013-11-25 12:51:20 +01:00
this._super(p, { sheet: 'starbug', vx: 90 });
}
});
2013-11-25 12:32:47 +01:00
2013-11-25 12:51:20 +01:00
Q.Enemy.extend("Martin",{
init: function(p) {
this._super(p, { sheet: 'martin', vx: 80 });
2013-11-25 12:32:47 +01:00
}
});
2013-11-25 12:44:39 +01:00
Q.scene("level1", function(stage) {
2013-11-24 21:38:03 +01:00
stage.insert(new Q.Repeater({ asset: "background.png", speedX: 0.5, speedY: 0.5 }));
stage.collisionLayer(new Q.TileLayer({
2013-11-24 23:38:23 +01:00
tileW: 24,
tileH: 24,
dataAsset: 'level.json',
sheet: 'tiles' }));
2013-11-25 12:44:39 +01:00
// player
var player = stage.insert(new Q.Player());
2013-11-25 12:44:39 +01:00
// viewport
stage.add("viewport").follow(player);
2013-11-24 22:28:34 +01:00
stage.viewport.scale = 2;
2013-11-25 12:44:39 +01:00
// enemies
2013-11-25 17:00:15 +01:00
stage.insert(new Q.Starbug({ x: 584, y: 0 }));
stage.insert(new Q.Neingeist({ x: 620, y: 0 }));
stage.insert(new Q.Martin({ x: 530, y: 0 }));
2013-11-25 17:00:15 +01:00
stage.insert(new Q.Rocket({ x: 122, y: 32 }));
});
Q.scene('endGame',function(stage) {
var container = stage.insert(new Q.UI.Container({
x: Q.width/2, y: Q.height/2, fill: "rgba(0,0,0,0.5)"
}));
2013-11-25 16:37:10 +01:00
var button = container.insert(new Q.UI.Button({ x: 0, y: 0, asset: "nochmal.png" }))
2013-11-25 12:44:39 +01:00
button.on("click",function() {
Q.clearStages();
Q.stageScene('level1');
});
2013-11-24 23:38:23 +01:00
container.fit(16);
});
2013-11-25 16:37:10 +01:00
Q.load("sprites.png, sprites.json, level.json, tiles.png, background.png, nochmal.png", function() {
2013-11-24 23:38:23 +01:00
Q.sheet("tiles","tiles.png", { tilew: 24, tileh: 24 });
Q.compileSheets("sprites.png","sprites.json");
Q.stageScene("level1");
});
});