User prompt
make that the pig need to be touched more than 1 time randomly
User prompt
make the ship more realistic
User prompt
turn the ship
User prompt
Make the bullet go where i clic
User prompt
Please fix the bug: 'ReferenceError: x is not defined' in or related to this line: 'dragNode.x = x;' Line Number: 76
User prompt
Please fix the bug: 'ReferenceError: x is not defined' in or related to this line: 'dragNode.x = x;' Line Number: 73
User prompt
Please fix the bug: 'ReferenceError: dragNode is not defined' in or related to this line: 'if (dragNode) {' Line Number: 71
User prompt
make it move with the arrows
User prompt
make the spaceship move
User prompt
Please fix the bug: 'ReferenceError: dragNode is not defined' in or related to this line: 'if (dragNode) {' Line Number: 71
Initial prompt
Shooter
===================================================================
--- original.js
+++ change.js
@@ -109,16 +109,61 @@
piggies.push(piggy);
game.addChild(piggy);
}
};
-var dragNode = null;
-game.down = function (x, y, obj) {
- dragNode = player;
+// Define the direction of the player
+var direction = {
+ up: false,
+ down: false,
+ left: false,
+ right: false
};
-game.up = function (x, y, obj) {
- dragNode = null;
- var bullet = new Bullet();
- bullet.x = player.x;
- bullet.y = player.y;
- bullets.push(bullet);
- game.addChild(bullet);
+// Listen to keydown event
+window.addEventListener('keydown', function (event) {
+ switch (event.key) {
+ case 'ArrowUp':
+ direction.up = true;
+ break;
+ case 'ArrowDown':
+ direction.down = true;
+ break;
+ case 'ArrowLeft':
+ direction.left = true;
+ break;
+ case 'ArrowRight':
+ direction.right = true;
+ break;
+ }
+});
+// Listen to keyup event
+window.addEventListener('keyup', function (event) {
+ switch (event.key) {
+ case 'ArrowUp':
+ direction.up = false;
+ break;
+ case 'ArrowDown':
+ direction.down = false;
+ break;
+ case 'ArrowLeft':
+ direction.left = false;
+ break;
+ case 'ArrowRight':
+ direction.right = false;
+ break;
+ }
+});
+game.update = function () {
+ // Player movement logic
+ if (direction.up) {
+ player.y -= player.speed;
+ }
+ if (direction.down) {
+ player.y += player.speed;
+ }
+ if (direction.left) {
+ player.x -= player.speed;
+ }
+ if (direction.right) {
+ player.x += player.speed;
+ }
+ // Rest of the game logic...
};
\ No newline at end of file