User prompt
Fix Bug: 'Uncaught TypeError: window.addEventListener is not a function' in this line: 'window.addEventListener('keydown', handleKeyDown);' Line Number: 108
User prompt
The player isn't moving with the WASD keys
User prompt
Fix Bug: 'Uncaught TypeError: window.addEventListener is not a function' in this line: 'window.addEventListener('keydown', handleKeyDown);' Line Number: 108
User prompt
Add a player object that can be moved with WASD, arrow keys or touch enabled virtual joystick
Initial prompt
Minion Control
===================================================================
--- original.js
+++ change.js
@@ -1,4 +1,25 @@
+var Player = Container.expand(function () {
+ var self = Container.call(this);
+ var playerGraphics = self.createAsset('player', 'Player Graphics', .5, .5);
+ self.speed = 5;
+ self.move = function (direction) {
+ switch (direction) {
+ case 'left':
+ self.x -= self.speed;
+ break;
+ case 'right':
+ self.x += self.speed;
+ break;
+ case 'up':
+ self.y -= self.speed;
+ break;
+ case 'down':
+ self.y += self.speed;
+ break;
+ }
+ };
+});
var Minion = Container.expand(function () {
var self = Container.call(this);
var minionGraphics = self.createAsset('minion', 'Minion Graphics', .5, .5);
self.speed = 5;
@@ -25,8 +46,68 @@
self.move = function () {};
});
var Game = Container.expand(function () {
var self = Container.call(this);
+ var player = self.addChild(new Player());
+ player.x = 2048 / 2;
+ player.y = 2732 - 200;
+ var keys = {
+ left: false,
+ right: false,
+ up: false,
+ down: false
+ };
+ function updatePlayerMovement() {
+ if (keys.left) player.move('left');
+ if (keys.right) player.move('right');
+ if (keys.up) player.move('up');
+ if (keys.down) player.move('down');
+ }
+ LK.on('tick', function () {
+ updatePlayerMovement();
+ });
+ function handleKeyDown(event) {
+ switch (event.key) {
+ case 'ArrowLeft':
+ case 'a':
+ keys.left = true;
+ break;
+ case 'ArrowRight':
+ case 'd':
+ keys.right = true;
+ break;
+ case 'ArrowUp':
+ case 'w':
+ keys.up = true;
+ break;
+ case 'ArrowDown':
+ case 's':
+ keys.down = true;
+ break;
+ }
+ }
+ function handleKeyUp(event) {
+ switch (event.key) {
+ case 'ArrowLeft':
+ case 'a':
+ keys.left = false;
+ break;
+ case 'ArrowRight':
+ case 'd':
+ keys.right = false;
+ break;
+ case 'ArrowUp':
+ case 'w':
+ keys.up = false;
+ break;
+ case 'ArrowDown':
+ case 's':
+ keys.down = false;
+ break;
+ }
+ }
+ window.addEventListener('keydown', handleKeyDown);
+ window.addEventListener('keyup', handleKeyUp);
var minions = [];
var enemies = [];
var heroBullets = [];
var enemyBullets = [];
A pixel art sprite in a Super Nintendo, Super Castlevania style where it looks a little gothic/vampire hunter like Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A pixel art large background in a Super Nintendo, Super Castlevania style with an open world like cemetery, 3/4 viewpoint Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows. A pixel art sprite in a Super Nintendo, Super Castlevania style that looks like a small pile of bones
Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows. A pixel art sprite in a Super Nintendo, Super Castlevania style that looks like a skeleton zombie that is haunched over
Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows. Pixel art in a SNES style that looks like something from castlevania. A ground explosion effect like something is coming out of the ground
Pixel art in SNES Castlevania style. Red goblin Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows. Pixel art in SNES Castlevania style. Red goblin