User prompt
If the rocks go thorough you you lose health and you die
User prompt
Make a health bar on the top
User prompt
If the rocks is at your home base you lose health and if you die your score restarts
User prompt
When you touch the rocks you donβt die but you get score
User prompt
Make it so the spaceship can shoot the rocks and get score
User prompt
When the ship spawns make a home base
User prompt
Make some arrow kets
Code edit (1 edits merged)
Please save this source code
User prompt
Asteroid Mining Magnate
User prompt
Please continue polishing my design document.
Initial prompt
Shooting game
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1"); /**** * Classes ****/ var ArrowKey = Container.expand(function () { var self = Container.call(this); var arrowGraphics = self.attachAsset('arrowUp', { anchorX: 0.5, anchorY: 0.5 }); self.direction = 'up'; // Default direction self.setDirection = function (direction) { self.direction = direction; switch (direction) { case 'up': arrowGraphics = self.attachAsset('arrowUp', { anchorX: 0.5, anchorY: 0.5 }); break; case 'down': arrowGraphics = self.attachAsset('arrowDown', { anchorX: 0.5, anchorY: 0.5 }); break; case 'left': arrowGraphics = self.attachAsset('arrowLeft', { anchorX: 0.5, anchorY: 0.5 }); break; case 'right': arrowGraphics = self.attachAsset('arrowRight', { anchorX: 0.5, anchorY: 0.5 }); break; } }; return self; }); var Asteroid = Container.expand(function () { var self = Container.call(this); var asteroidGraphics = self.attachAsset('asteroid', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 3; self.update = function () { self.y += self.speed; }; return self; }); var HomeBase = Container.expand(function () { var self = Container.call(this); var baseGraphics = self.attachAsset('homeBase', { anchorX: 0.5, anchorY: 0.5 }); return self; }); var Mineral = Container.expand(function () { var self = Container.call(this); var mineralGraphics = self.attachAsset('mineral', { anchorX: 0.5, anchorY: 0.5 }); return self; }); var Spaceship = Container.expand(function () { var self = Container.call(this); var spaceshipGraphics = self.attachAsset('spaceship', { anchorX: 0.5, anchorY: 0.5 }); self.energy = 100; self.update = function () { // Update logic for spaceship }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ // Initialize assets used in this game. Scale them according to what is needed for the game. game.setBackgroundColor(0x000000); var homeBase = game.addChild(new HomeBase()); homeBase.x = 2048 / 2; homeBase.y = 2732 - 300; var spaceship = game.addChild(new Spaceship()); spaceship.x = 2048 / 2; spaceship.y = 2732 - 150; var asteroids = []; var minerals = []; var score = 0; var energy = 100; var arrowUp = game.addChild(new ArrowKey()); arrowUp.setDirection('up'); arrowUp.x = 2048 / 2; arrowUp.y = 2732 - 300; var arrowDown = game.addChild(new ArrowKey()); arrowDown.setDirection('down'); arrowDown.x = 2048 / 2; arrowDown.y = 2732 - 50; var arrowLeft = game.addChild(new ArrowKey()); arrowLeft.setDirection('left'); arrowLeft.x = 2048 / 2 - 150; arrowLeft.y = 2732 - 150; var arrowRight = game.addChild(new ArrowKey()); arrowRight.setDirection('right'); arrowRight.x = 2048 / 2 + 150; arrowRight.y = 2732 - 150; var scoreTxt = new Text2('Score: 0', { size: 100, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); var energyTxt = new Text2('Energy: 100', { size: 100, fill: 0xFFFFFF }); energyTxt.anchor.set(0.5, 0); LK.gui.topRight.addChild(energyTxt); function handleMove(x, y, obj) { if (dragNode) { dragNode.x = x; dragNode.y = y; } } game.move = handleMove; game.down = function (x, y, obj) { dragNode = spaceship; handleMove(x, y, obj); }; game.up = function (x, y, obj) { dragNode = null; }; game.update = function () { if (LK.ticks % 60 == 0) { var newAsteroid = new Asteroid(); newAsteroid.x = Math.random() * 2048; newAsteroid.y = -50; asteroids.push(newAsteroid); game.addChild(newAsteroid); } for (var i = asteroids.length - 1; i >= 0; i--) { var asteroid = asteroids[i]; if (asteroid.y > 2732) { asteroid.destroy(); asteroids.splice(i, 1); continue; } if (spaceship.intersects(asteroid)) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } } if (LK.ticks % 120 == 0) { var newMineral = new Mineral(); newMineral.x = Math.random() * 2048; newMineral.y = -50; minerals.push(newMineral); game.addChild(newMineral); } for (var j = minerals.length - 1; j >= 0; j--) { var mineral = minerals[j]; if (mineral.y > 2732) { mineral.destroy(); minerals.splice(j, 1); continue; } if (spaceship.intersects(mineral)) { score += 10; scoreTxt.setText('Score: ' + score); mineral.destroy(); minerals.splice(j, 1); } } }; LK.playMusic('bgMusic');
===================================================================
--- original.js
+++ change.js
@@ -56,8 +56,16 @@
self.y += self.speed;
};
return self;
});
+var HomeBase = Container.expand(function () {
+ var self = Container.call(this);
+ var baseGraphics = self.attachAsset('homeBase', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ return self;
+});
var Mineral = Container.expand(function () {
var self = Container.call(this);
var mineralGraphics = self.attachAsset('mineral', {
anchorX: 0.5,
@@ -89,8 +97,11 @@
* Game Code
****/
// Initialize assets used in this game. Scale them according to what is needed for the game.
game.setBackgroundColor(0x000000);
+var homeBase = game.addChild(new HomeBase());
+homeBase.x = 2048 / 2;
+homeBase.y = 2732 - 300;
var spaceship = game.addChild(new Spaceship());
spaceship.x = 2048 / 2;
spaceship.y = 2732 - 150;
var asteroids = [];