User prompt
make the player move up down left or right when i press arrow keys or wasd
User prompt
make the tick function check a boolean for player movement set based on captured keyboard events for arrow keys or WASD keys
User prompt
remove the player.move call in the tick function
User prompt
explain why players doesn't move on keypress
User prompt
make the player object a singleton
User prompt
explain when the tick functino is called
User prompt
Fix Bug: 'Uncaught TypeError: window.addEventListener is not a function' in this line: 'window.addEventListener('keydown', function (event) {' Line Number: 42
User prompt
make penguin move up, down, left and right on keyboard events with arrow keys and WASD
User prompt
don't place iceblocks everywhere, only along the game world edges
User prompt
remove maze generating code
User prompt
update the iceblocks placement to account for their width and height of 200 pixels
User prompt
rewrite maze generating function to produce a maze where walls and blank, walkable tiles each make up around 50% of the available area, and where walkable areas are all connected
User prompt
use a star algorithm to place iceblocks only in a maze pattern, with walkable paths and areas between them
User prompt
add a tilemap layer showing a maze of destructible ice blocks
User prompt
add a comment about the LK object
User prompt
explain what LK is?
Initial prompt
My 1st test game
var Player = (function () { var instance; function createInstance() {} return { getInstance: function () { if (!instance) { instance = createInstance(); } return instance; } }; })(); var IceBlock = Container.expand(function () { var self = Container.call(this); var iceBlockGraphics = self.createAsset('iceBlock', 'Ice Block', .5, .5); self.destroyBlock = function () { self.destroy(); }; }); var self = Container.expand(function () { self = Container.call(this); var playerGraphics = self.createAsset('player', 'Player character', .5, .5); self.move = function (direction) { switch (direction) { case 'up': self.y -= 10; break; case 'down': self.y += 10; break; case 'left': self.x -= 10; break; case 'right': self.x += 10; break; } }; self.shoot = function () {}; return self; }); var Bullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.createAsset('bullet', 'Bullet', .5, .5); self.move = function () {}; }); 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 player = self.addChild(Player.getInstance()); LK.on('keydown', function (event) { switch (event.key) { case 'ArrowUp': case 'w': player.move('up'); break; case 'ArrowDown': case 's': player.move('down'); break; case 'ArrowLeft': case 'a': player.move('left'); break; case 'ArrowRight': case 'd': player.move('right'); break; } }); var bullets = []; var enemies = []; player.x = 2048 / 2; player.y = 2732 / 2; var iceBlocks = []; for (var i = 0; i < 20; i++) { var topIceBlock = new IceBlock(); topIceBlock.x = i * 200; topIceBlock.y = 0; iceBlocks.push(topIceBlock); self.addChild(topIceBlock); var bottomIceBlock = new IceBlock(); bottomIceBlock.x = i * 200; bottomIceBlock.y = 2732 - bottomIceBlock.height; iceBlocks.push(bottomIceBlock); self.addChild(bottomIceBlock); } for (var j = 1; j < 13; j++) { var leftIceBlock = new IceBlock(); leftIceBlock.x = 0; leftIceBlock.y = j * 200; iceBlocks.push(leftIceBlock); self.addChild(leftIceBlock); var rightIceBlock = new IceBlock(); rightIceBlock.x = 2048 - rightIceBlock.width; rightIceBlock.y = j * 200; iceBlocks.push(rightIceBlock); self.addChild(rightIceBlock); } LK.on('tick', function () { player.move(); for (var i = 0; i < bullets.length; i++) { bullets[i].move(); } for (var i = 0; i < enemies.length; i++) { enemies[i].move(); } for (var i = 0; i < bullets.length; i++) { for (var j = 0; j < iceBlocks.length; j++) { if (bullets[i].intersects(iceBlocks[j])) { iceBlocks[j].destroyBlock(); iceBlocks.splice(j, 1); bullets[i].destroy(); bullets.splice(i, 1); break; } } } }); player.on('down', function (obj) { var bullet = new Bullet(); bullet.x = player.x; bullet.y = player.y; bullets.push(bullet); self.addChild(bullet); }); var dragNode = null; stage.on('down', function (obj) { dragNode = player; }); stage.on('move', function (obj) { var event = obj.event; var pos = event.getLocalPosition(self); if (dragNode) { dragNode.x = pos.x; dragNode.y = pos.y; } }); stage.on('up', function (obj) { dragNode = null; }); });
===================================================================
--- original.js
+++ change.js
@@ -1,13 +1,25 @@
+var Player = (function () {
+ var instance;
+ function createInstance() {}
+ return {
+ getInstance: function () {
+ if (!instance) {
+ instance = createInstance();
+ }
+ return instance;
+ }
+ };
+})();
var IceBlock = Container.expand(function () {
var self = Container.call(this);
var iceBlockGraphics = self.createAsset('iceBlock', 'Ice Block', .5, .5);
self.destroyBlock = function () {
self.destroy();
};
});
-var Player = Container.expand(function () {
- var self = Container.call(this);
+var self = Container.expand(function () {
+ self = Container.call(this);
var playerGraphics = self.createAsset('player', 'Player character', .5, .5);
self.move = function (direction) {
switch (direction) {
case 'up':
@@ -24,8 +36,9 @@
break;
}
};
self.shoot = function () {};
+ return self;
});
var Bullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.createAsset('bullet', 'Bullet', .5, .5);
@@ -37,9 +50,9 @@
self.move = function () {};
});
var Game = Container.expand(function () {
var self = Container.call(this);
- var player = self.addChild(new Player());
+ var player = self.addChild(Player.getInstance());
LK.on('keydown', function (event) {
switch (event.key) {
case 'ArrowUp':
case 'w':
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.