User prompt
Do not set waveText.x and waveText.y and attach element to LK.gui.center
Code edit (3 edits merged)
Please save this source code
User prompt
Show a wave indicator text at the center of the screen
User prompt
move left shotIndicator by 10px
User prompt
move down shotIndicator by 20px
User prompt
set scoreTxt weight:500 and add black dropshadow
User prompt
Add a score to top center of the screen
User prompt
call ShotIndicator with 5
Code edit (1 edits merged)
Please save this source code
User prompt
ShotIndicator is not showing?
User prompt
Add the delay variable to the HexagonElement constructor
User prompt
in HexagonElement accept a delay variable argument in the constructor. Then use that * 5 for the fadeInDelay
User prompt
in startNextLevel pass i to HexagonElement
User prompt
make 0-30
User prompt
Set a random tick delay for when to start fading in HexagonElement
User prompt
Set initial HexagonElement scale to 0
User prompt
also set scale when fading HexagonElement in
User prompt
in HexagonElement set alpha to zero when it's spawned, then use tick to fade it in
User prompt
make sure resetShots is called in startnextlevel
User prompt
when starting the next level, reward the user two new lives, with a max of 5
User prompt
when starting a new level, reward the user two new lives, with a max of 5
User prompt
Spawn 7 elements per level
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.
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 = Math.min(self.currentShots + 2, 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.speed += 0.1; self.x += Math.cos(self.rotation) * self.speed; self.y += Math.sin(self.rotation) * self.speed; }; }); var HexagonElement = Container.expand(function (delay) { 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); elementGraphics.alpha = 0; elementGraphics.scale.x = 0; elementGraphics.scale.y = 0; self.fadeInDelay = delay * 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 () { if (self.fadeInDelay > 0) { self.fadeInDelay--; } else if (elementGraphics.alpha < 1) { elementGraphics.alpha += 0.05; elementGraphics.scale.x += 0.05; elementGraphics.scale.y += 0.05; } 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 score = 0; var scoreTxt = new Text2(score.toString(), { size: 150, fill: "#ffffff", weight: 500, dropShadow: true, dropShadowColor: '#000000', dropShadowBlur: 4, dropShadowAngle: Math.PI / 6, dropShadowDistance: 6 }); scoreTxt.anchor.set(0.5, 0); LK.gui.topCenter.addChild(scoreTxt); self.updateScore = function (points) { score += points; scoreTxt.setText(score.toString()); }; self.updateScore(0); var bullets = []; var elements = []; var shotIndicator = new ShotIndicator(5); shotIndicator.x = 2048 - shotIndicator.width * shotIndicator.maxShots - 20 - 30 - 10; shotIndicator.y = 40 + 10 + 20; 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 = []; self.shotIndicator.resetShots(); for (var i = 0; i < 7; i++) { var hexagonElement = new HexagonElement(i); hexagonElement.x = Math.random() * 2048; hexagonElement.y = Math.random() * 2732; elements.push(hexagonElement); self.addChild(hexagonElement); } } self.startNextLevel = function () { var waveText = new Text2('Wave ' + (score / 7 + 1), { size: 200, fill: '#ffffff', align: 'center' }); waveText.x = 2048 / 2; waveText.y = 2732 / 2; LK.gui.addChild(waveText); LK.setTimeout(function () { waveText.destroy(); }, 2000); startNextLevel.call(this); }; self.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 (elements.length === 0 && bullets.length === 0) { self.startNextLevel(); } else if (self.shotIndicator.currentShots <= 0 && bullets.length === 0) { LK.showGameOver(); } }); });
===================================================================
--- original.js
+++ change.js
@@ -148,9 +148,8 @@
size: 200,
fill: '#ffffff',
align: 'center'
});
- waveText.anchor.set(0.5, 0.5);
waveText.x = 2048 / 2;
waveText.y = 2732 / 2;
LK.gui.addChild(waveText);
LK.setTimeout(function () {
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.