31
0
1mo
/**** * Classes ****/ // Class for bombs dropped by Viggen var Bomb = Container.expand(function () { var self = Container.call(this); var bombGraphics = self.attachAsset('bomb', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 15; self.update = function () { self.y += self.speed; if (self.y > 2732) { self.destroy(); } }; }); // Class for enemy defenses var Defense = Container.expand(function () { var self = Container.call(this); var defenseGraphics = self.attachAsset('defense', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.update = function () { self.y += self.speed; if (self.y > 2732) { self.y = -100; } }; }); //<Assets used in the game will automatically appear here> //<Write imports for supported plugins here> // Class for the player's aircraft var Viggen = Container.expand(function () { var self = Container.call(this); var viggenGraphics = self.attachAsset('viggen', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 10; self.update = function () { // Update logic for Viggen }; self.move = function (x, y, obj) { self.x = x; self.y = y; }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ // Initialize player Viggen var viggen = game.addChild(new Viggen()); viggen.x = 1024; viggen.y = 2400; // Initialize defenses var defenses = []; for (var i = 0; i < 5; i++) { var defense = new Defense(); defense.x = Math.random() * 2048; defense.y = Math.random() * -1000; defenses.push(defense); game.addChild(defense); } // Initialize bombs var bombs = []; // Handle game move events game.move = function (x, y, obj) { viggen.move(x, y, obj); }; // Handle game update events game.update = function () { // Update defenses defenses.forEach(function (defense) { defense.update(); if (viggen.intersects(defense)) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } }); // Spawn new defenses every 2 seconds if (LK.ticks % 120 === 0) { var defense = new Defense(); defense.x = Math.random() * 2048; defense.y = Math.random() * -1000; defenses.push(defense); game.addChild(defense); } // Update bombs bombs.forEach(function (bomb, index) { bomb.update(); defenses.forEach(function (defense) { if (bomb.intersects(defense)) { defense.destroy(); bomb.destroy(); defenses.splice(defenses.indexOf(defense), 1); bombs.splice(index, 1); } }); }); // Drop bombs if (LK.ticks % 60 === 0) { var bomb = new Bomb(); bomb.x = viggen.x; bomb.y = viggen.y; bombs.push(bomb); game.addChild(bomb); } };
===================================================================
--- original.js
+++ change.js
@@ -1,112 +1,120 @@
-/****
+/****
* Classes
-****/
+****/
// Class for bombs dropped by Viggen
var Bomb = Container.expand(function () {
- var self = Container.call(this);
- var bombGraphics = self.attachAsset('bomb', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.speed = 15;
- self.update = function () {
- self.y += self.speed;
- if (self.y > 2732) {
- self.destroy();
- }
- };
+ var self = Container.call(this);
+ var bombGraphics = self.attachAsset('bomb', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 15;
+ self.update = function () {
+ self.y += self.speed;
+ if (self.y > 2732) {
+ self.destroy();
+ }
+ };
});
// Class for enemy defenses
var Defense = Container.expand(function () {
- var self = Container.call(this);
- var defenseGraphics = self.attachAsset('defense', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.speed = 5;
- self.update = function () {
- self.y += self.speed;
- if (self.y > 2732) {
- self.y = -100;
- }
- };
+ var self = Container.call(this);
+ var defenseGraphics = self.attachAsset('defense', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 5;
+ self.update = function () {
+ self.y += self.speed;
+ if (self.y > 2732) {
+ self.y = -100;
+ }
+ };
});
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Class for the player's aircraft
var Viggen = Container.expand(function () {
- var self = Container.call(this);
- var viggenGraphics = self.attachAsset('viggen', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.speed = 10;
- self.update = function () {
- // Update logic for Viggen
- };
- self.move = function (x, y, obj) {
- self.x = x;
- self.y = y;
- };
+ var self = Container.call(this);
+ var viggenGraphics = self.attachAsset('viggen', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 10;
+ self.update = function () {
+ // Update logic for Viggen
+ };
+ self.move = function (x, y, obj) {
+ self.x = x;
+ self.y = y;
+ };
});
-/****
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000 //Init game with black background
+ backgroundColor: 0x000000 //Init game with black background
});
-/****
+/****
* Game Code
-****/
+****/
// Initialize player Viggen
var viggen = game.addChild(new Viggen());
viggen.x = 1024;
viggen.y = 2400;
// Initialize defenses
var defenses = [];
for (var i = 0; i < 5; i++) {
- var defense = new Defense();
- defense.x = Math.random() * 2048;
- defense.y = Math.random() * -1000;
- defenses.push(defense);
- game.addChild(defense);
+ var defense = new Defense();
+ defense.x = Math.random() * 2048;
+ defense.y = Math.random() * -1000;
+ defenses.push(defense);
+ game.addChild(defense);
}
// Initialize bombs
var bombs = [];
// Handle game move events
game.move = function (x, y, obj) {
- viggen.move(x, y, obj);
+ viggen.move(x, y, obj);
};
// Handle game update events
game.update = function () {
- // Update defenses
- defenses.forEach(function (defense) {
- defense.update();
- if (viggen.intersects(defense)) {
- LK.effects.flashScreen(0xff0000, 1000);
- LK.showGameOver();
- }
- });
- // Update bombs
- bombs.forEach(function (bomb, index) {
- bomb.update();
- defenses.forEach(function (defense) {
- if (bomb.intersects(defense)) {
- defense.destroy();
- bomb.destroy();
- defenses.splice(defenses.indexOf(defense), 1);
- bombs.splice(index, 1);
- }
- });
- });
- // Drop bombs
- if (LK.ticks % 60 === 0) {
- var bomb = new Bomb();
- bomb.x = viggen.x;
- bomb.y = viggen.y;
- bombs.push(bomb);
- game.addChild(bomb);
- }
+ // Update defenses
+ defenses.forEach(function (defense) {
+ defense.update();
+ if (viggen.intersects(defense)) {
+ LK.effects.flashScreen(0xff0000, 1000);
+ LK.showGameOver();
+ }
+ });
+ // Spawn new defenses every 2 seconds
+ if (LK.ticks % 120 === 0) {
+ var defense = new Defense();
+ defense.x = Math.random() * 2048;
+ defense.y = Math.random() * -1000;
+ defenses.push(defense);
+ game.addChild(defense);
+ }
+ // Update bombs
+ bombs.forEach(function (bomb, index) {
+ bomb.update();
+ defenses.forEach(function (defense) {
+ if (bomb.intersects(defense)) {
+ defense.destroy();
+ bomb.destroy();
+ defenses.splice(defenses.indexOf(defense), 1);
+ bombs.splice(index, 1);
+ }
+ });
+ });
+ // Drop bombs
+ if (LK.ticks % 60 === 0) {
+ var bomb = new Bomb();
+ bomb.x = viggen.x;
+ bomb.y = viggen.y;
+ bombs.push(bomb);
+ game.addChild(bomb);
+ }
};
\ No newline at end of file
Pixel art of a Saab Viggen, the Swedish fighter jet.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
A anti-air missile. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
A Soviet fighter jet, facing down. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
supply crate. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows