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
User prompt
if bullet hits enemy, enemy destroyed
User prompt
instantiate an enemy at a random position every 2 seconds
Code edit (1 edits merged)
Please save this source code
User prompt
set anchor for arrow up to .5,.5
User prompt
set anchor for arrow up to 0, .5
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'length')' in this line: 'for (var i = 0; i < this.iceBlocks.length; i++) {' Line Number: 49
User prompt
Fix Bug: 'ReferenceError: iceBlocks is not defined' in this line: 'for (var i = 0; i < iceBlocks.length; i++) {' Line Number: 49
User prompt
Fix Bug: 'ReferenceError: iceBlocks is not defined' in this line: 'for (var i = 0; i < iceBlocks.length; i++) {' Line Number: 49
User prompt
make sure player can not moveinto or beyond iceblocks
User prompt
give Arrow Right an on down handler
User prompt
give Arrow Left an on down handler
User prompt
give Arrow Up an on down handler
User prompt
add slight player decelleration every frame
User prompt
call player.move in on tick
User prompt
rename player.update to player.move
User prompt
on arrow down tapped incease player y velocity
User prompt
rotate arrow down by PI/2 on spawn
User prompt
rotate arrow down by pi/2
User prompt
rotate arrow up by -PI72
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.shoot = function () {}; 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 Enemy = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.createAsset('enemy', 'Enemy character', .5, .5); self.move = function () {}; }); 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 arrowUp = self.createAsset('arrowUp', 'Arrow Up', .5, .5); arrowUp.rotation = -Math.PI / 2; arrowUp.on('down', function () { player.velocity.y -= 5; }); var arrowDown = self.createAsset('arrowDown', 'Arrow Down', .5, .5); arrowDown.rotation = Math.PI / 2; arrowDown.on('down', function () { player.velocity.y += 5; }); var arrowLeft = self.createAsset('arrowLeft', 'Arrow Left', .5, .5); arrowLeft.rotation = Math.PI; arrowLeft.on('down', function () { player.velocity.x -= 5; }); var arrowRight = self.createAsset('arrowRight', 'Arrow Right', .5, .5); arrowRight.on('down', function () { player.velocity.x += 5; }); var arrowKeysCenter = LK.stageContainer.width; arrowUp.x = arrowKeysCenter; arrowUp.y = LK.stageContainer.height + 50; arrowDown.x = arrowKeysCenter; arrowDown.y = LK.stageContainer.height + 200; arrowLeft.x = arrowKeysCenter - 100; arrowLeft.y = LK.stageContainer.height + 125; arrowRight.x = arrowKeysCenter + 100; arrowRight.y = LK.stageContainer.height + 125; LK.gui.addChild(arrowUp); LK.gui.addChild(arrowDown); LK.gui.addChild(arrowLeft); LK.gui.addChild(arrowRight); var bullets = []; var enemies = []; var enemySpawnInterval = LK.setInterval(function () { var enemy = new Enemy(); enemy.x = Math.random() * worldWidth; enemy.y = Math.random() * worldHeight; enemies.push(enemy); self.addChild(enemy); }, 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(); } for (var i = 0; i < snowflakes.length; i++) { snowflakes[i].move(); } }); stage.on('down', function (obj) { var bullet = new Bullet(); bullet.x = player.x; bullet.y = player.y; var pos = obj.event.getLocalPosition(self); 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); player.x -= bullet.direction.x * 10; player.y -= bullet.direction.y * 10; var recoilFrames = 10; LK.on('tick', function recoilTick() { if (recoilFrames-- <= 0) { return; } player.x += bullet.direction.x; player.y += bullet.direction.y; }); }); });
===================================================================
--- original.js
+++ change.js
@@ -133,8 +133,13 @@
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);
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.