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
User prompt
create a snowman subclass of enemy
Code edit (5 edits merged)
Please save this source code
User prompt
on tap anywhere, increase player velocity towards the clicked position
Code edit (1 edits merged)
Please save this source code
User prompt
hide playbutton when pressed
User prompt
create a playbutton and call playButonPressed when it's pressed
Code edit (2 edits merged)
Please save this source code
User prompt
don't start spawning before playbutton pressed
User prompt
Fix Bug: 'Timeout.tick error: stage.getMousePosition is not a function' in this line: 'var pos = stage.getMousePosition();' Line Number: 167
User prompt
log mouse or pointer position every 2 seconds
Code edit (6 edits merged)
Please save this source code
User prompt
if bullets leave game area, destroy them
var Snowflake = Container.expand(function () { var self = Container.call(this); var snowflakeGraphics = self.createAsset('snowflake', 'Snowflake', .5, .5); snowflakeGraphics.width = 10; snowflakeGraphics.height = 10; self.speed = Math.random() * 4 + 2; self.move = function () { self.y += self.speed; self.x += Math.sin(self.y / 100) * 5; if (self.y > 2800) { self.y = -10; } }; }); var FloorTile = Container.expand(function () { var self = Container.call(this); var floorTileGraphics = self.createAsset('floorTile', 'Floor Tile', .5, .5); floorTileGraphics.width = 200; floorTileGraphics.height = 200; }); var IceBlock = Container.expand(function () { var self = Container.call(this); var iceBlockGraphics = self.createAsset('iceBlock', 'Ice Block', .5, .5); }); var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.createAsset('player', 'Player character', .5, .5); self.velocity = { x: 0, y: 0 }; self.speed = 5; self.shoot = function () {}; 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 = function () { self.x += self.velocity.x; self.y += self.velocity.y; self.velocity.x *= 0.95; self.velocity.y *= 0.95; }; }); var Bullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.createAsset('bullet', 'Bullet', .5, .5); self.direction = { x: 0, y: 0 }; self.speed = 10; self.move = function () { self.x += self.direction.x * self.speed; self.y += self.direction.y * self.speed; }; }); var SnowManEnemy = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.createAsset('arrowUp', 'SnowManEnemy Character', .5, .5); self.width *= 2; self.height *= 2; self.speed = 2; self.move = 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 Game = Container.expand(function () { var self = Container.call(this); var iceBlocks = []; var blockSize = 200; var worldWidth = blockSize * 11; var worldHeight = blockSize * 15; console.log('Game world size:', worldWidth, 'x', worldHeight); console.log('LK.stageContainer.height:', LK.stageContainer.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; self.addChild(iceBlock); } else { var floorTile = new FloorTile(); floorTile.x = i * blockSize; floorTile.y = j * blockSize; self.addChild(floorTile); } } } var player = self.addChild(new Player()); var playButton = self.createAsset('playButton', 'Play Button', .5, .5); playButton.x = worldWidth / 2 - 100; playButton.y = worldHeight / 2; playButton.width = 400; playButton.height = 400; playButton.on('down', function () { playButton.visible = false; LK.emit('playButtonPressed'); }); var instructions = new Text2('Tap to move and throw\nsnowballs at the evil snowmen', { size: 80, fill: '#444488' }); instructions.x = worldWidth / 2; instructions.y = worldHeight / 2 + 200; instructions.anchor.set(0.5, 0.5); self.addChild(instructions); var bullets = []; var enemies = []; var enemySpawnInterval; var bulletInterval; LK.on('playButtonPressed', function () { enemySpawnInterval = LK.setInterval(function () { var snowManEnemy = new SnowManEnemy(); snowManEnemy.x = Math.random() * worldWidth; snowManEnemy.y = Math.random() * worldHeight; enemies.push(snowManEnemy); self.addChild(snowManEnemy); }, 2000); 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); self.addChild(bullet); }, 2000); }); var snowflakes = []; for (var i = 0; i < 10; i++) { var snowflake = new Snowflake(); snowflake.x = Math.random() * 1800; snowflake.y = Math.random() * LK.stageContainer.height; snowflakes.push(snowflake); self.addChild(snowflake); } player.x = 330; player.y = 300; LK.on('tick', function () { player.move(); for (var i = 0; i < bullets.length; i++) { bullets[i].move(); 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(); enemies.splice(j, 1); break; } } } for (var i = 0; i < enemies.length; i++) { enemies[i].move(player); if (player.intersects(enemies[i])) { LK.showGameOver(); } } for (var i = 0; i < snowflakes.length; i++) { snowflakes[i].move(); } }); var lastTapPos = { x: 0, y: 0 }; stage.on('down', function (obj) { var pos = obj.event.getLocalPosition(self); lastTapPos = pos; player.moveTowards(pos); }); });
===================================================================
--- original.js
+++ change.js
@@ -111,14 +111,15 @@
playButton.on('down', function () {
playButton.visible = false;
LK.emit('playButtonPressed');
});
- var instructions = new Text2('Tap to move and throw snowballs at the evil snowmen', {
- size: 100,
- fill: '#aaaaff'
+ var instructions = new Text2('Tap to move and throw\nsnowballs at the evil snowmen', {
+ size: 80,
+ fill: '#444488'
});
- instructions.x = worldWidth / 2 - self.width / 2;
+ instructions.x = worldWidth / 2;
instructions.y = worldHeight / 2 + 200;
+ instructions.anchor.set(0.5, 0.5);
self.addChild(instructions);
var bullets = [];
var enemies = [];
var enemySpawnInterval;
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.