User prompt
Speed up bullets as they fly
User prompt
call game over if elements is not greater than zerp
User prompt
In tick, if you don't have any shots left and bullets.length is zero and elements length is greater than zero. call gameover.
Code edit (4 edits merged)
Please save this source code
User prompt
call startNextLevel when the game starts
User prompt
move the elements tick code and game over check outside the bullets array loop in tick
User prompt
don't test for elements.length in game over check
User prompt
In tick, if you don't have any shots left and bullets.length is zero, call gameover
User prompt
set fixedIntersectionDistance to half the width of element
User prompt
set fixedIntersectionDistance to the width of element
User prompt
Use a fixed intersection distance rather than trying to calculate one
User prompt
use circle to circle intersection to determine if an element and bullet is intersecting
User prompt
Spawn 5 elements per level
User prompt
In tick, if both elements array and bullets array are empty. start the next level
User prompt
move shots indicator 80px to the left
User prompt
remove the spacing between shot indicator graphics
User prompt
move down shotIndicator by 10px, also move it to the right by 50px
User prompt
Move down shotIndicator by 20px
User prompt
You make two shotIndicator delete the first one
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
Alpha does not seem to change inShotIndicator when I fire a bullet
User prompt
On test for currentShots and decrease shots when I tap the screen, not when any bullets are fired
User prompt
The shots indicator does not seem to show in the top right corner
User prompt
Fix Bug: 'TypeError: undefined is not an object (evaluating 'self.shotIndicator.resetShots')' in this line: 'self.shotIndicator.resetShots();' Line Number: 92
var ShotIndicator = Container.expand(function (maxShots) { var self = Container.call(this); self.maxShots = maxShots; self.currentShots = maxShots; self.indicators = []; for (var i = 0; i < self.maxShots; i++) { var indicator = self.createAsset('shotIndicator', 'Shot Indicator', 0, 0.5); indicator.x = i * indicator.width; self.indicators.push(indicator); self.addChild(indicator); } self.updateIndicators = function () { for (var i = 0; i < self.indicators.length; i++) { self.indicators[i].alpha = i < self.currentShots ? 1 : 0.3; } }; self.useShot = function () { if (self.currentShots > 0) { self.currentShots--; self.updateIndicators(); } }; self.resetShots = function () { self.currentShots = self.maxShots; self.updateIndicators(); }; self.updateIndicators(); return self; }); var Bullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.createAsset('bullet', 'Bullet Graphics', .5, .5); self.speed = 10; self.tick = function () { if (!self.initialized) { self.rotationSpeed = -Math.PI / 60; self.rotationTicks = 30; self.initialized = true; } if (self.rotationTicks > 0) { bulletGraphics.rotation += self.rotationSpeed; self.rotationTicks--; } self.x += Math.cos(self.rotation) * self.speed; self.y += Math.sin(self.rotation) * self.speed; }; }); var HexagonElement = Container.expand(function () { var self = Container.call(this); self.fadeOut = function () { var fadeOutInterval = LK.setInterval(function () { elementGraphics.alpha -= 0.05; elementGraphics.scale.x += 0.05; elementGraphics.scale.y += 0.05; if (elementGraphics.alpha <= 0) { LK.clearInterval(fadeOutInterval); self.destroy(); } }, 10); }; var elementGraphics = self.createAsset('element', 'Element Graphics', .5, .5); var directions = [{ x: 1, y: 0 }, { x: -1, y: 0 }, { x: 0.5, y: Math.sqrt(3) / 2 }, { x: -0.5, y: Math.sqrt(3) / 2 }, { x: 0.5, y: -Math.sqrt(3) / 2 }, { x: -0.5, y: -Math.sqrt(3) / 2 }]; var chosenDirection = directions[Math.floor(Math.random() * directions.length)]; self.speed = 2; self.tick = function () { self.x = (self.x + chosenDirection.x * self.speed + 2048) % 2048; self.y = (self.y + chosenDirection.y * self.speed + 2732) % 2732; }; }); var Game = Container.expand(function () { var self = Container.call(this); var bullets = []; var elements = []; var shotIndicator = new ShotIndicator(5); shotIndicator.x = 2048 - shotIndicator.width * shotIndicator.maxShots - 20 - 30; shotIndicator.y = 40 + 10; LK.gui.topRight.addChild(shotIndicator); self.shotIndicator = shotIndicator; self.shotIndicator.resetShots(); function startNextLevel() { bullets.forEach(function (bullet) { bullet.destroy(); }); bullets = []; elements.forEach(function (element) { element.destroy(); }); elements = []; for (var i = 0; i < 5; i++) { var hexagonElement = new HexagonElement(); hexagonElement.x = Math.random() * 2048; hexagonElement.y = Math.random() * 2732; elements.push(hexagonElement); self.addChild(hexagonElement); } } self.startNextLevel = startNextLevel; startNextLevel(); self.fireBulletsHexagon = function (position) { var directions = [{ x: 1, y: 0 }, { x: -1, y: 0 }, { x: 0.5, y: Math.sqrt(3) / 2 }, { x: -0.5, y: Math.sqrt(3) / 2 }, { x: 0.5, y: -Math.sqrt(3) / 2 }, { x: -0.5, y: -Math.sqrt(3) / 2 }]; directions.forEach(function (direction, index) { var bullet = new Bullet(); bullet.x = position.x; bullet.y = position.y; bullet.rotation = Math.atan2(direction.y, direction.x); bullets.push(bullet); self.addChild(bullet); }); }; stage.on('down', function (obj) { if (self.shotIndicator.currentShots <= 0) return; self.shotIndicator.useShot(); var event = obj.event; var pos = event.getLocalPosition(self); self.fireBulletsHexagon(pos); }); LK.on('tick', function () { for (var i = bullets.length - 1; i >= 0; i--) { bullets[i].tick(); for (var j = elements.length - 1; j >= 0; j--) { var dx = bullets[i].x - elements[j].x; var dy = bullets[i].y - elements[j].y; var fixedIntersectionDistance = elements[j].width / 2; if (Math.abs(dx) < fixedIntersectionDistance && Math.abs(dy) < fixedIntersectionDistance) { var pos = { x: elements[j].x, y: elements[j].y }; elements[j].fadeOut(); elements.splice(j, 1); self.fireBulletsHexagon(pos); break; } } if (bullets[i].x < 0 || bullets[i].x > 2048 || bullets[i].y < 0 || bullets[i].y > 2732) { bullets[i].destroy(); bullets.splice(i, 1); } } for (var j = 0; j < elements.length; j++) { elements[j].tick(); } if (bullets.length === 0) { if (self.shotIndicator.currentShots <= 0) { LK.showGameOver(); } else { self.startNextLevel(); } } }); });
===================================================================
--- original.js
+++ change.js
@@ -175,9 +175,9 @@
}
for (var j = 0; j < elements.length; j++) {
elements[j].tick();
}
- if (elements.length === 0 && bullets.length === 0) {
+ if (bullets.length === 0) {
if (self.shotIndicator.currentShots <= 0) {
LK.showGameOver();
} else {
self.startNextLevel();
Hexagon target Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Single White Hexagon, soft edges, simple, vector. Round corners. All white. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Amazing bright hexagon space background.
Triangle plasma bullet. Glowing. Pointing down. Dark outline. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
White triangle Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Single Bright light particle, white. Simple, vector. Triangle. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.