User prompt
move the score box to the front
User prompt
move the score background to the top of the screen, centered on the x axis
User prompt
add a background box for the score
User prompt
center the score text
User prompt
move the score to the top center of the screen
User prompt
flip the hero graphic on the x axis
User prompt
make the particles bigger and 50% opacity
User prompt
Add a little bit of randomness to each enemy's starting speed
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'move')' in this line: 'punch.move();' Line Number: 195
User prompt
When the star gets hit clear all punche and particles
User prompt
When a punch is destroyed make sure to destroy its particles
User prompt
Fix Bug: 'ReferenceError: particles is not defined' in this line: 'particles.push(particle);' Line Number: 253
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'filter')' in this line: 'self.particles = self.particles.filter(function (particle) {' Line Number: 255
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'push')' in this line: 'self.particles.push(particle);' Line Number: 252
User prompt
The game is slowing down a lot, make sure the particle graphics are destroyed when they are and make sure they are removed from any arrays
User prompt
Make the particles last twice as long
User prompt
Move the particles below the punches
User prompt
remove the limitation on the number of particle
User prompt
make the particles destroy themselves at the end of their lifespan
User prompt
The maximum particles on screen at once should be 10
User prompt
Make the lifespan of the particles 0.1
User prompt
Make the lifespan of the particles 10
User prompt
The punch should be rotated in the direction of travel
User prompt
The particles stay on screen forever
User prompt
the particles should have a lifespan of 0.5 seconds and fade out. They should go from red to black and have a bit of randomness
var globalSpeed = 5; var particleCounter = 0; var Particle = Container.expand(function () { var self = Container.call(this); var particleGraphics = self.createAsset('particle', 'Particle Graphics', .5, .5); particleGraphics.scale.set(0.5); self.lifetime = 0.2; self.move = function () { var randomX = (Math.random() - 0.5) * 2; var randomY = (Math.random() - 0.5) * 2; self.x += randomX; self.y += randomY; }; LK.setTimeout(function () { self.destroy(); }, self.lifetime * 1000); }); var TKOGraphic = Container.expand(function () { var self = Container.call(this); var tkoGraphic = self.createAsset('tko', 'TKO Graphic', .5, .5); tkoGraphic.scale.set(10); tkoGraphic.alpha = 1; var fadeOutInterval = LK.setInterval(function () { tkoGraphic.alpha -= 0.0167; if (tkoGraphic.alpha <= 0) { LK.clearInterval(fadeOutInterval); self.destroy(); particleCounter--; } }, 16.67); LK.setTimeout(function () { self.destroy(); }, 1000); }); var FlungOpponent = Container.expand(function () { var self = Container.call(this); var opponentGraphics = self.createAsset('opponent', 'Opponent Graphics', .5, .5); opponentGraphics.scale.set(-3, 3); self.speed = 20; self.move = function () { self.x += self.speed; }; self.flung = function () { var flungInterval = LK.setInterval(function () { self.move(); self.rotation += 0.5; if (self.x > LK.stage.width) { LK.clearInterval(flungInterval); self.destroy(); } }, 16.67); }; }); var HitGraphic = Container.expand(function () { var self = Container.call(this); var hitGraphic = self.createAsset('hit', 'Hit Graphic', .5, .5); hitGraphic.scale.set(3); hitGraphic.alpha = 1; var fadeOutInterval = LK.setInterval(function () { hitGraphic.alpha -= 0.0167; if (hitGraphic.alpha <= 0) { LK.clearInterval(fadeOutInterval); self.destroy(); } }, 16.67); LK.setTimeout(function () { self.destroy(); }, 1000); }); var Star = Container.expand(function () { var self = Container.call(this); var starGraphics = self.createAsset('star', 'Star Graphics', .5, .5); starGraphics.scale.set(2); self.lifetime = 3000; self.spawnTime = LK.ticks; }); var Opponent = Container.expand(function () { var self = Container.call(this); var opponentGraphics = self.createAsset('opponent', 'Opponent Graphics', .5, .5); opponentGraphics.scale.set(-3, 3); self.speed = globalSpeed; self.hitPoints = 3; self.move = function (heroX, heroY) { var dx = heroX - self.x; var dy = heroY - self.y; var distance = Math.sqrt(dx * dx + dy * dy); self.x += self.speed * (dx / distance); self.y += self.speed * (dy / distance); }; self.hit = function (punchX, punchY) { self.hitPoints--; var dx = self.x - punchX; var dy = self.y - punchY; var distance = Math.sqrt(dx * dx + dy * dy); var knockBackMultiplier = 1.2; self.x += 100 * knockBackMultiplier * (dx / distance); self.y += 100 * knockBackMultiplier * (dy / distance); if (self.hitPoints <= 0) { globalSpeed += 1; Punch.prototype.speed += 1; var hitGraphic = new HitGraphic(); hitGraphic.x = self.x; hitGraphic.y = self.y; self.parent.addChild(hitGraphic); if (self.parent && self.parent.opponents) { var index = self.parent.opponents.indexOf(self); if (index > -1) { self.parent.opponents.splice(index, 1); } } self.destroy(); } }; }); var Hero = Container.expand(function () { var self = Container.call(this); var heroGraphics = self.createAsset('hero', 'Hero character', .5, .5); heroGraphics.scale.set(6); self.speed = 5; self.move = function () {}; self.punch = function () {}; }); var Punch = Container.expand(function () { var self = Container.call(this); self.velocity = { x: 0, y: 0 }; self.setVelocity = function (targetX, targetY) { var dx = targetX - self.x; var dy = targetY - self.y; var distance = Math.sqrt(dx * dx + dy * dy); self.velocity.x = self.speed * (dx / distance); self.velocity.y = self.speed * (dy / distance); var angle = Math.atan2(dy, dx); self.rotation = angle; }; self.move = function () { self.x += self.velocity.x; self.y += self.velocity.y; }; var punchGraphics = self.createAsset('punch', 'Punch Graphics', .5, .5); punchGraphics.scale.set(2); punchGraphics.rotation = Math.PI / 2; self.speed = globalSpeed * 3; }); var Game = Container.expand(function () { var self = Container.call(this); var background = self.createAsset('boxingRing', 'Boxing Ring Background', 0, 0); background.scale.set(LK.stage.width / background.width, LK.stage.height / background.height); self.addChildAt(background, 0); var hero = self.addChild(new Hero()); var enemies = []; var punches = []; var opponents = []; var opponentSpawnRate = 120; var opponentSpawnCounter = 0; var lastStarSpawnTime = 0; var star = null; var scoreTxt = new Text2('0', { size: 150, fill: "#ffffff" }); LK.gui.topCenter.addChild(scoreTxt); var isGameOver = false; var tickOffset = 0; var glovesKillsCount = 0; var speedIncreaseTimer = 0; var speedIncreaseInterval = 300; var speedMultiplier = 1; hero.x = hero.width / 2; hero.y = 2732 / 2; var punchCooldown = 500; var lastPunchTime = 0; LK.stage.on('down', function (obj) { var currentTime = Date.now(); if (currentTime - lastPunchTime >= punchCooldown) { var event = obj.event; var tapPosition = event.getLocalPosition(self); var punch = new Punch(); punch.particles = []; punch.x = hero.x; punch.y = hero.y; punch.setVelocity(tapPosition.x, tapPosition.y); punches.push(punch); self.addChild(punch); LK.effects.flashObject(hero, 0xffcc00, 100); lastPunchTime = currentTime; } }); LK.on('tick', function () { hero.move(); for (var i = punches.length - 1; i >= 0; i--) { var punch = punches[i]; punch.move(); var starHit = false; for (var j = opponents.length - 1; j >= 0; j--) { var opponent = opponents[j]; if (star && punch.intersects(star)) { starHit = true; star.destroy(); LK.effects.flashScreen(0xffcc00, 100); var tkoGraphic = new TKOGraphic(); tkoGraphic.x = star.x; tkoGraphic.y = star.y; self.addChild(tkoGraphic); glovesKillsCount += 10; scoreTxt.setText(glovesKillsCount.toString()); star = null; punches.forEach(function (p) { p.destroy(); }); punches = []; self.children.forEach(function (child) { if (child instanceof Particle) { child.destroy(); } }); } else if (punch.intersects(opponent)) { opponent.hit(punch.x, punch.y); if (opponent.hitPoints <= 0) { glovesKillsCount++; scoreTxt.setText(glovesKillsCount.toString()); opponents.splice(j, 1); } else { var hitGraphic = new HitGraphic(); hitGraphic.x = (opponent.x + punch.x) / 2; hitGraphic.y = (opponent.y + punch.y) / 2; self.addChild(hitGraphic); LK.effects.flashObject(hitGraphic, 0xffffff, 1000); } starHit = false; punch.particles.forEach(function (particle) { particle.destroy(); }); punch.destroy(); punches.splice(i, 1); break; } } if (starHit) { opponents.forEach(function (opponent) { opponent.destroy(); var flungOpponent = new FlungOpponent(); flungOpponent.x = opponent.x; flungOpponent.y = opponent.y; self.addChild(flungOpponent); flungOpponent.flung(); }); opponents = []; globalSpeed = 5; Punch.prototype.speed = globalSpeed * 2; } punches.forEach(function (punch) { var particle = new Particle(); particle.x = punch.x; particle.y = punch.y; punch.particles.push(particle); self.addChildAt(particle, self.getChildIndex(punch)); }); } if (star && LK.ticks - star.spawnTime >= star.lifetime) { star.destroy(); star = null; } if (!star && LK.ticks - lastStarSpawnTime >= 5 * 60 + 120) { star = new Star(); star.x = LK.stage.width / 3 + Math.random() * (LK.stage.width * 2 / 3); star.y = LK.stage.height * 0.1 + Math.random() * (LK.stage.height * 0.8); self.addChild(star); lastStarSpawnTime = LK.ticks; } speedIncreaseTimer++; if (speedIncreaseTimer >= speedIncreaseInterval) { if (LK.ticks % (5 * 60) === 0) { speedMultiplier += 0.2; } globalSpeed *= speedMultiplier; speedIncreaseTimer = 0; } if (opponentSpawnCounter++ >= opponentSpawnRate) { var opponent = new Opponent(); opponent.speed += 0.5; opponent.x = LK.stage.width; opponent.y = Math.random() * (LK.stage.height - opponent.height) + opponent.height / 2; opponents.push(opponent); self.addChild(opponent); opponentSpawnCounter = 0; } for (var j = opponents.length - 1; j >= 0; j--) { var opponent = opponents[j]; opponent.move(hero.x, hero.y); if (opponent.intersects(hero)) { isGameOver = true; } if (opponent.x + opponent.width / 2 < 0) { opponent.destroy(); opponents.splice(j, 1); } } if (isGameOver) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } }); });
===================================================================
--- original.js
+++ change.js
@@ -206,8 +206,17 @@
self.addChild(tkoGraphic);
glovesKillsCount += 10;
scoreTxt.setText(glovesKillsCount.toString());
star = null;
+ punches.forEach(function (p) {
+ p.destroy();
+ });
+ punches = [];
+ self.children.forEach(function (child) {
+ if (child instanceof Particle) {
+ child.destroy();
+ }
+ });
} else if (punch.intersects(opponent)) {
opponent.hit(punch.x, punch.y);
if (opponent.hitPoints <= 0) {
glovesKillsCount++;
Boxing glove, pixel art Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A golden glowing star, pixel art Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
pixel art "bap!" explosion Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
pixel art explosion that says "TKO" Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
ball of fire sprite art Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a cute anthropomorphic cat wearing boxing shorts and boxing gloves, pixel art Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
pixel art view from inside boxing ring, floor near middle of image Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
anthropomorphic dog wearing boxing shorts and boxing gloves, boxer, pixel art Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.