// heavily based/copied from/on the quintus platformer example. // 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, { sheet: "astronaut", x: 320, y: 90 }); this.add('2d, platformerControls'); this.on("hit.sprite",function(collision) { if(collision.obj.isA("Rocket")) { // the rocket flies away var rocket = collision.obj; rocket.add("tween"); rocket.animate({ x: 100, y: -500, angle: 360 }); // the player disappears this.destroy(); // and the invite is displayed $("#einladung").show("slow"); } }); } }); Q.Sprite.extend("Rocket", { init: function(p) { this._super(p, { sheet: 'rocket' }); } }); Q.Sprite.extend("Enemy", { init: function(p, q) { this._super(p, q); 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; } }); } }); Q.Enemy.extend("Neingeist",{ init: function(p) { this._super(p, { sheet: 'neingeist', vx: 100 }); } }); Q.Enemy.extend("Starbug",{ init: function(p) { this._super(p, { sheet: 'starbug', vx: 90 }); } }); Q.Enemy.extend("Martin",{ init: function(p) { this._super(p, { sheet: 'martin', vx: 80 }); } }); Q.scene("level1", function(stage) { stage.insert(new Q.Repeater({ asset: "background.png", speedX: 0.5, speedY: 0.5 })); stage.collisionLayer(new Q.TileLayer({ tileW: 24, tileH: 24, dataAsset: 'level.json', sheet: 'tiles' })); // player var player = stage.insert(new Q.Player()); // viewport stage.add("viewport").follow(player); stage.viewport.scale = 2; // enemies 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 })); 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", label: "NOCHMAL" })) button.on("click",function() { Q.clearStages(); Q.stageScene('level1'); }); container.fit(16); }); Q.load("sprites.png, sprites.json, level.json, tiles.png, background.png", function() { Q.sheet("tiles","tiles.png", { tilew: 24, tileh: 24 }); Q.compileSheets("sprites.png","sprites.json"); Q.stageScene("level1"); }); });