Code edit (3 edits merged)
Please save this source code
User prompt
Migrate to the latest version of LK
Code edit (6 edits merged)
Please save this source code
User prompt
after three seconds make powerups blink for three seconds and then be destroyed
Code edit (6 edits merged)
Please save this source code
User prompt
write a function that spawn 16 bullets in a circle around player, each moving away from him
Code edit (1 edits merged)
Please save this source code
Code edit (5 edits merged)
Please save this source code
User prompt
Fix Bug: 'Uncaught ReferenceError: truee is not defined' in this line: 'if (truee) {' Line Number: 98
Code edit (3 edits merged)
Please save this source code
User prompt
Fix Bug: 'Uncaught TypeError: floorTile.anchor is not a function' in this line: 'floorTile.anchor(0, 0);' Line Number: 109
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
Code edit (6 edits merged)
Please save this source code
User prompt
center align instructions text
Code edit (1 edits merged)
Please save this source code
User prompt
add game instructions text: "Tap to move and throw snowballs at the evil snowmen"
User prompt
if player collides with snowmanenemy game over
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'ReferenceError: player is not defined' in this line: 'var dx = player.x - self.x;' Line Number: 75
Code edit (6 edits merged)
Please save this source code
User prompt
Fix Bug: 'ReferenceError: player is not defined' in this line: 'var dx = player.x - self.x;' Line Number: 75
User prompt
Fix Bug: 'ReferenceError: player is not defined' in this line: 'var dx = player.x - self.x;' Line Number: 75
Code edit (4 edits merged)
Please save this source code
User prompt
rename enemy class to SnowManEnemy
/**** * Classes ****/ var Bullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.attachAsset('bullet', { anchorX: 0.5, anchorY: 0.5 }); self.direction = { x: 0, y: 0 }; self.speed = 10; self.width *= 0.5; self.height *= 0.5; self._move_migrated = function () { self.x += self.direction.x * self.speed; self.y += self.direction.y * self.speed; }; }); var FloorTile = Container.expand(function () { var self = Container.call(this); var floorTileGraphics = self.attachAsset('floorTile', { anchorX: 0.5, anchorY: 0.5 }); }); var IceBlock = Container.expand(function () { var self = Container.call(this); var iceBlockGraphics = self.attachAsset('iceBlock', { anchorX: 0.5, anchorY: 0.5 }); }); var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5 }); self.velocity = { x: 0, y: 0 }; self.speed = 15; self.shoot = function () { for (var i = 0; i < 16; i++) { var bullet = new Bullet(); bullet.x = self.x; bullet.y = self.y; var angle = Math.PI * 2 / 16 * i; bullet.direction.x = Math.cos(angle); bullet.direction.y = Math.sin(angle); bullets.push(bullet); self.addChild(bullet); } }; self.moveTowards = function (pos) { var dx = pos.x - self.x; var dy = pos.y - self.y; var magnitude = Math.sqrt(dx * dx + dy * dy); self.velocity.x += dx * self.speed / magnitude; self.velocity.y += dy * self.speed / magnitude; }; self.moveAwayFrom = function (pos) { var dx = pos.x - self.x; var dy = pos.y - self.y; var magnitude = Math.sqrt(dx * dx + dy * dy); self.velocity.x -= dx * self.speed / magnitude; self.velocity.y -= dy * self.speed / magnitude; }; self._move_migrated = function () { self.x += self.velocity.x; self.y += self.velocity.y; self.velocity.x *= 0.95; self.velocity.y *= 0.95; }; }); var Powerup = Container.expand(function () { var self = Container.call(this); var powerupGraphics = self.attachAsset('arrowDown', { anchorX: 0.5, anchorY: 0.5 }); self.width *= 2; self.height *= 2; self.timer = 0; self.blinking = false; self._update_migrated = function () { self.timer += 1; if (self.timer > 240) { self.blinking = true; } if (self.blinking) { powerupGraphics.alpha = 0.5 + 0.5 * Math.sin(self.timer / 10); } }; }); var SnowManEnemy = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.attachAsset('arrowUp', { anchorX: 0.5, anchorY: 0.5 }); self.width *= 2; self.height *= 2; self.speed = 2 + Math.random() * 0.5; self._move_migrated = function (player) { var dx = player.x - self.x; var dy = player.y - self.y; var magnitude = Math.sqrt(dx * dx + dy * dy); self.x += dx * self.speed / magnitude; self.y += dy * self.speed / magnitude; }; }); var Snowflake = Container.expand(function () { var self = Container.call(this); var snowflakeGraphics = self.attachAsset('snowflake', { anchorX: 0.5, anchorY: 0.5 }); snowflakeGraphics.width = 10; snowflakeGraphics.height = 10; self.speed = Math.random() * 4 + 2; self._move_migrated = function () { self.y += self.speed; self.x += Math.sin(self.y / 100) * 5; if (self.y > 2800) { self.y = -10; } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ var iceBlocks = []; var blockSize = 200; var worldWidth = blockSize * 11; var worldHeight = blockSize * 15; console.log('Game world size:', worldWidth, 'x', worldHeight); console.log('game.height:', game.height); for (var i = 0; i < worldWidth / blockSize; i++) { for (var j = 0; j < worldHeight / blockSize; j++) { if (i === 0 || i === worldWidth / blockSize - 1 || j === 0 || j === worldHeight / blockSize - 1) { var iceBlock = new IceBlock(); iceBlock.x = i * blockSize; iceBlock.y = j * blockSize; game.addChild(iceBlock); } else { if (true) { var floorTile = new FloorTile(); floorTile.x = i * blockSize; floorTile.y = j * blockSize; game.addChild(floorTile); } } } } var player = game.addChild(new Player()); var scoreLabel = new Text2('Score: 0', { size: 60, fill: '#113355', align: 'left' }); scoreLabel.x = worldWidth - 560; scoreLabel.y = 160; scoreLabel.anchor.set(0.5, 0.5); game.addChild(scoreLabel); var playerScore = 0; var instructions = new Text2('Tap to move and throw\nsnowballs at the evil snowmen', { size: 100, fill: '#446688', align: 'center', dropShadow: true }); instructions.x = worldWidth / 2 - 100; instructions.y = worldHeight / 2 + 340; instructions.anchor.set(0.5, 0.5); game.addChild(instructions); var playButton = game.attachAsset('playButton', { anchorX: 0.5, anchorY: 0.5 }); playButton.x = worldWidth / 2 - 100; playButton.y = worldHeight / 2; playButton.width = 400; playButton.height = 400; playButton.on('down', function () { instructions.visible = false; playButton.visible = false; LK.emit('playButtonPressed'); }); var bullets = []; var enemies = []; var powerups = []; var enemySpawnInterval; var bulletInterval; var updateSpawnSpeedInterval; var initialSpawnSpeed = 2000; var spawnSpeedNow = initialSpawnSpeed; var powerupSpawnInterval; spawnPowerup = function spawnPowerup() { var powerup = new Powerup(); do { var xx = Math.random() * worldWidth; var yy = Math.random() * worldHeight; var dx = xx - player.x; var dy = yy - player.y; var magnitude = Math.sqrt(dx * dx + dy * dy); } while (magnitude < 800); powerup.x = xx; powerup.y = yy; powerups.push(powerup); game.addChild(powerup); }; spawnEnemy = function spawnEnemy() { var snowManEnemy = new SnowManEnemy(); do { var xx = Math.random() * worldWidth; var yy = Math.random() * worldHeight; var dx = xx - player.x; var dy = yy - player.y; var magnitude = Math.sqrt(dx * dx + dy * dy); } while (magnitude < 500); snowManEnemy.x = xx; snowManEnemy.y = yy; enemies.push(snowManEnemy); game.addChild(snowManEnemy); }; triggerBomb = function triggerBomb() { for (var i = 0; i < 16; i++) { var bullet = new Bullet(); bullet.x = player.x; bullet.y = player.y; var angle = Math.PI * 2 / 16 * i; bullet.direction.x = Math.cos(angle); bullet.direction.y = Math.sin(angle); bullets.push(bullet); game.addChild(bullet); } }; var gameStarted = false; LK.on('playButtonPressed', function () { gameStarted = true; updateSpawnSpeedInterval = LK.setInterval(function () { if (spawnSpeedNow > 200) { spawnSpeedNow -= 100; LK.clearInterval(enemySpawnInterval); enemySpawnInterval = LK.setInterval(function () { spawnEnemy(); }, spawnSpeedNow); } }, 10000); enemySpawnInterval = LK.setInterval(function () { spawnEnemy(); }, initialSpawnSpeed); bulletInterval = LK.setInterval(function () { var bullet = new Bullet(); bullet.x = player.x; bullet.y = player.y; var pos = { x: 0, y: 0 }; pos = lastTapPos; var dx = pos.x - player.x; var dy = pos.y - player.y; var magnitude = Math.sqrt(dx * dx + dy * dy); bullet.direction.x = dx / magnitude; bullet.direction.y = dy / magnitude; bullets.push(bullet); game.addChild(bullet); }, 2000); powerupSpawnInterval = LK.setInterval(function () { spawnPowerup(); }, 12000); }); var snowflakes = []; for (var i = 0; i < 30; i++) { var snowflake = new Snowflake(); snowflake.x = Math.random() * 1800; snowflake.y = Math.random() * game.height; snowflakes.push(snowflake); game.addChild(snowflake); } player.x = 330; player.y = 300; LK.on('tick', function () { player._move_migrated(); for (var i = 0; i < bullets.length; i++) { bullets[i]._move_migrated(); if (bullets[i].x < 0 || bullets[i].x > worldWidth || bullets[i].y < 0 || bullets[i].y > worldHeight) { bullets[i].destroy(); bullets.splice(i, 1); continue; } for (var j = 0; j < enemies.length; j++) { if (bullets[i].intersects(enemies[j])) { enemies[j].destroy(); playerScore += 100; scoreLabel.setText("Score: " + playerScore); enemies.splice(j, 1); break; } } } for (var i = 0; i < enemies.length; i++) { enemies[i]._move_migrated(player); if (player.intersects(enemies[i])) { LK.setScore(playerScore); LK.showGameOver(); } } for (var i = 0; i < snowflakes.length; i++) { snowflakes[i]._move_migrated(); } for (var i = 0; i < powerups.length; i++) { powerups[i]._update_migrated(); if (powerups[i].timer > 480) { powerups[i].destroy(); powerups.splice(i, 1); } else { if (player.intersects(powerups[i])) { triggerBomb(); powerups[i].destroy(); powerups.splice(i, 1); } } } }); var lastTapPos = { x: 0, y: 0 }; game.on('down', function (x, y, obj) { if (gameStarted) { var pos = game.toLocal(obj.global); lastTapPos = pos; player.moveTowards(pos); } });
===================================================================
--- original.js
+++ change.js
@@ -315,8 +315,9 @@
}
for (var i = 0; i < enemies.length; i++) {
enemies[i]._move_migrated(player);
if (player.intersects(enemies[i])) {
+ LK.setScore(playerScore);
LK.showGameOver();
}
}
for (var i = 0; i < snowflakes.length; i++) {
a penguin engineer Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
rectangular ice wall section, top down view Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
ice floor texture tile top down view Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
one cartoony snowball. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
white dot. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
button with arrow key pointing left. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a large round playbutton Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
cartoony evil snowman character Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
icy treasure chest Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A snowcovered christmas tree decorated with snowballs.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.