neingeist
/
cosmos
Archived
1
0
Fork 0
You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

165 lines
3.8 KiB
JavaScript

11 years ago
// heavily based/copied from/on the quintus platformer example.
11 years ago
// vim:tw=120:
window.addEventListener("load",function() {
var Q = window.Q = Quintus({ development: true })
.include("Sprites, Scenes, Input, 2D, Anim, Touch, UI")
.setup({ maximize: true })
.controls().touch()
Q.Sprite.extend("Player",{
init: function(p) {
this._super(p, {
11 years ago
sheet: "astronaut",
x: 320,
y: 90
});
this.add('2d, platformerControls');
this.on("hit.sprite",function(collision) {
11 years ago
if(collision.obj.isA("Rocket")) {
11 years ago
11 years ago
// the rocket flies away
var rocket = collision.obj;
11 years ago
rocket.add("tween");
rocket.animate({ x: 100, y: -500, angle: 360 });
11 years ago
// the player disappears
this.destroy();
11 years ago
// and the invite is displayed
11 years ago
$("#einladung").show("slow");
}
});
}
});
11 years ago
Q.Sprite.extend("Rocket", {
init: function(p) {
11 years ago
this._super(p, { sheet: 'rocket' });
}
});
Q.Sprite.extend("Neingeist",{
init: function(p) {
this._super(p, { sheet: 'neingeist', vx: 100 });
this.add('2d, aiBounce');
this.on("bump.left,bump.right,bump.bottom",function(collision) {
if(collision.obj.isA("Player")) {
Q.stageScene("endGame", 1);
collision.obj.destroy();
}
});
this.on("bump.top",function(collision) {
if(collision.obj.isA("Player")) {
this.destroy();
collision.obj.p.vy = -300;
}
});
}
});
// FIXME do not copy
Q.Sprite.extend("Starbug",{
init: function(p) {
this._super(p, { sheet: 'starbug', vx: 100 });
this.add('2d, aiBounce');
this.on("bump.left,bump.right,bump.bottom",function(collision) {
if(collision.obj.isA("Player")) {
Q.stageScene("endGame", 1);
collision.obj.destroy();
}
});
this.on("bump.top",function(collision) {
if(collision.obj.isA("Player")) {
this.destroy();
collision.obj.p.vy = -300;
}
});
}
});
// FIXME do not copy
Q.Sprite.extend("Martin",{
init: function(p) {
this._super(p, { sheet: 'martin', vx: 100 });
this.add('2d, aiBounce');
this.on("bump.left,bump.right,bump.bottom",function(collision) {
if(collision.obj.isA("Player")) {
Q.stageScene("endGame", 1);
collision.obj.destroy();
}
});
this.on("bump.top",function(collision) {
if(collision.obj.isA("Player")) {
this.destroy();
collision.obj.p.vy = -300;
}
});
}
});
11 years ago
Q.scene("level1", function(stage) {
stage.insert(new Q.Repeater({ asset: "background.png", speedX: 0.5, speedY: 0.5 }));
stage.collisionLayer(new Q.TileLayer({
11 years ago
tileW: 24,
tileH: 24,
dataAsset: 'level.json',
sheet: 'tiles' }));
11 years ago
// player
var player = stage.insert(new Q.Player());
11 years ago
// viewport
stage.add("viewport").follow(player);
11 years ago
stage.viewport.scale = 2;
11 years ago
// enemies
11 years ago
stage.insert(new Q.Starbug({ x: 600, y: 0 }));
stage.insert(new Q.Neingeist({ x: 650, y: 0 }));
stage.insert(new Q.Martin({ x: 550, y: 0 }));
11 years ago
stage.insert(new Q.Rocket({ x: 146, 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)"
}));
var button = container.insert(new Q.UI.Button({ x: 0, y: 0, fill: "#CCCCCC",
11 years ago
label: "NOCHMAL" }))
11 years ago
button.on("click",function() {
Q.clearStages();
Q.stageScene('level1');
});
11 years ago
container.fit(16);
});
Q.load("sprites.png, sprites.json, level.json, tiles.png, background.png", function() {
11 years ago
Q.sheet("tiles","tiles.png", { tilew: 24, tileh: 24 });
Q.compileSheets("sprites.png","sprites.json");
Q.stageScene("level1");
});
});