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
/**** * Classes ****/ // Bullet class var Bullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.attachAsset('bullet', { anchorX: 0.5, anchorY: 0.5 }); self.speed = -10; self.update = function () { var dx = this.targetX - this.x; var dy = this.targetY - this.y; var angle = Math.atan2(dy, dx); this.x += Math.cos(angle) * this.speed; this.y += Math.sin(angle) * this.speed; }; }); // Piggy class var Piggy = Container.expand(function () { var self = Container.call(this); var piggyGraphics = self.attachAsset('piggy', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 2; self.update = function () { self.y += self.speed; }; }); // Assets will be automatically created and loaded by the LK engine // Player class var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.update = function () { // Player movement logic if (dragNode) { self.x = dragNode.x; self.y = dragNode.y; // Calculate the angle between the player and the dragNode var dx = dragNode.x - self.x; var dy = dragNode.y - self.y; var angle = Math.atan2(dy, dx); // Rotate the player to face the dragNode self.rotation = angle; } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 // Init game with black background }); /**** * Game Code ****/ var player = game.addChild(new Player()); player.x = 2048 / 2; player.y = 2732 - 100; var bullets = []; var piggies = []; var scoreTxt = new Text2('0', { size: 150, fill: "#ffffff" }); LK.gui.top.addChild(scoreTxt); game.update = function () { // Player movement logic if (dragNode) { dragNode.x = dragNode.x; dragNode.y = dragNode.y; } // Bullet logic for (var i = bullets.length - 1; i >= 0; i--) { var bullet = bullets[i]; if (bullet.y < 0) { bullet.destroy(); bullets.splice(i, 1); } else { for (var j = piggies.length - 1; j >= 0; j--) { var piggy = piggies[j]; if (bullet.intersects(piggy)) { bullet.destroy(); bullets.splice(i, 1); piggy.destroy(); piggies.splice(j, 1); LK.setScore(LK.getScore() + 1); scoreTxt.setText(LK.getScore()); break; } } } } // Piggy logic for (var i = piggies.length - 1; i >= 0; i--) { var piggy = piggies[i]; if (piggy.y > 2732) { piggy.destroy(); piggies.splice(i, 1); } else if (piggy.intersects(player)) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } } // Spawn piggies if (LK.ticks % 120 == 0) { var piggy = new Piggy(); piggy.x = Math.random() * 2048; piggy.y = 0; piggies.push(piggy); game.addChild(piggy); } }; var dragNode = null; game.down = function (x, y, obj) { dragNode = player; }; game.up = function (x, y, obj) { dragNode = null; var bullet = new Bullet(); bullet.x = player.x; bullet.y = player.y; bullet.targetX = x; bullet.targetY = y; bullets.push(bullet); game.addChild(bullet); };
===================================================================
--- original.js
+++ change.js
@@ -42,8 +42,14 @@
// Player movement logic
if (dragNode) {
self.x = dragNode.x;
self.y = dragNode.y;
+ // Calculate the angle between the player and the dragNode
+ var dx = dragNode.x - self.x;
+ var dy = dragNode.y - self.y;
+ var angle = Math.atan2(dy, dx);
+ // Rotate the player to face the dragNode
+ self.rotation = angle;
}
};
});