User prompt
Only move player when dragging it, not if another part of the screen is touched
User prompt
But also allow to drag the player normally
User prompt
When user touches antoher part of the screen, player should not just appear there, but show player moevment
User prompt
Remove all code just leave character in the center of the screen
User prompt
Start game from scratch. Only leave player on the center of the screen
User prompt
Incline spears to aim at center of acreen
User prompt
Spearsh should alway have ditection of rhe center of thebscreen
User prompt
Spears should spawn from any border of thebscreen
User prompt
Add spears. Spears will spawn from any part on the on thoe border of the screen, shake for a second and then move stright to the opoait eise of the screen
Initial prompt
Dungeon Dodge
/**** * Classes ****/ // Assets will be automatically created and loaded by the LK engine based on their usage in the code. // Hero class representing the player character var Hero = Container.expand(function () { var self = Container.call(this); var heroGraphics = self.attachAsset('hero', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 10; self.update = function () { // Update logic for hero, if needed }; }); // Spear class representing deadly spears in the dungeon var Spear = Container.expand(function () { var self = Container.call(this); var spearGraphics = self.attachAsset('spear', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { // Update logic for spears, if needed self.x += self.speedX; self.y += self.speedY; }; }); // Trap class representing deadly traps in the dungeon var Trap = Container.expand(function () { var self = Container.call(this); var trapGraphics = self.attachAsset('trap', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { // Update logic for traps, if needed }; }); // Treasure class representing collectible treasures var Treasure = Container.expand(function () { var self = Container.call(this); var treasureGraphics = self.attachAsset('treasure', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { // Update logic for treasures, if needed }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 // Init game with black background }); /**** * Game Code ****/ // Initialize game variables var hero; var traps = []; var treasures = []; var spears = []; var score = 0; var scoreTxt; // Function to initialize game elements function initGame() { // Create and position the hero hero = game.addChild(new Hero()); hero.x = 2048 / 2; hero.y = 2732 - 200; // Create traps for (var i = 0; i < 5; i++) { var trap = new Trap(); trap.x = Math.random() * 2048; trap.y = Math.random() * (2732 - 400); traps.push(trap); game.addChild(trap); } // Create treasures for (var j = 0; j < 3; j++) { var treasure = new Treasure(); treasure.x = Math.random() * 2048; treasure.y = Math.random() * (2732 - 400); treasures.push(treasure); game.addChild(treasure); } // Function to spawn spears from any border of the screen function spawnSpear() { var spear = new Spear(); var border = Math.floor(Math.random() * 4); // Randomly select a border (0: top, 1: right, 2: bottom, 3: left) // Calculate the direction vector towards the center of the screen var directionX = 1024 - spear.x; var directionY = 1366 - spear.y; var length = Math.sqrt(directionX * directionX + directionY * directionY); // Normalize the direction vector directionX /= length; directionY /= length; // Set the spear's speed in the direction of the center of the screen spear.speedX = directionX * 5; spear.speedY = directionY * 5; spears.push(spear); game.addChild(spear); } // Spawn spears for (var k = 0; k < 5; k++) { spawnSpear(); } // Initialize score text scoreTxt = new Text2('Score: 0', { size: 100, fill: "#ffffff" }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); } // Function to handle hero movement function handleMove(x, y, obj) { hero.x = x; hero.y = y; } // Function to update game state game.update = function () { // Check for collisions between hero and traps for (var i = traps.length - 1; i >= 0; i--) { if (hero.intersects(traps[i])) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); return; } } // Check for collisions between hero and spears for (var k = spears.length - 1; k >= 0; k--) { if (hero.intersects(spears[k])) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); return; } // Remove spears that have moved off screen if (spears[k].y > 2732) { spears[k].destroy(); spears.splice(k, 1); } } // Check for collisions between hero and treasures for (var j = treasures.length - 1; j >= 0; j--) { if (hero.intersects(treasures[j])) { score += 10; scoreTxt.setText('Score: ' + score); treasures[j].destroy(); treasures.splice(j, 1); } } }; // Initialize game elements initGame(); // Set up event listeners for touch/mouse interactions game.down = function (x, y, obj) { handleMove(x, y, obj); }; game.move = function (x, y, obj) { handleMove(x, y, obj); }; game.up = function (x, y, obj) { // No specific action needed on release };
===================================================================
--- original.js
+++ change.js
@@ -22,9 +22,10 @@
anchorY: 0.5
});
self.update = function () {
// Update logic for spears, if needed
- self.y += self.speed;
+ self.x += self.speedX;
+ self.y += self.speedY;
};
});
// Trap class representing deadly traps in the dungeon
var Trap = Container.expand(function () {
@@ -91,34 +92,18 @@
// Function to spawn spears from any border of the screen
function spawnSpear() {
var spear = new Spear();
var border = Math.floor(Math.random() * 4); // Randomly select a border (0: top, 1: right, 2: bottom, 3: left)
- switch (border) {
- case 0:
- // Top
- spear.x = Math.random() * 2048;
- spear.y = 0;
- spear.speed = 5;
- break;
- case 1:
- // Right
- spear.x = 2048;
- spear.y = Math.random() * 2732;
- spear.speed = -5;
- break;
- case 2:
- // Bottom
- spear.x = Math.random() * 2048;
- spear.y = 2732;
- spear.speed = -5;
- break;
- case 3:
- // Left
- spear.x = 0;
- spear.y = Math.random() * 2732;
- spear.speed = 5;
- break;
- }
+ // Calculate the direction vector towards the center of the screen
+ var directionX = 1024 - spear.x;
+ var directionY = 1366 - spear.y;
+ var length = Math.sqrt(directionX * directionX + directionY * directionY);
+ // Normalize the direction vector
+ directionX /= length;
+ directionY /= length;
+ // Set the spear's speed in the direction of the center of the screen
+ spear.speedX = directionX * 5;
+ spear.speedY = directionY * 5;
spears.push(spear);
game.addChild(spear);
}
// Spawn spears
pixealrt spear. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
fireskull button. pixelart.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
spearbutton. pixelart.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Pixelart button that says "Start". Dungeon vibes.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
2000 by 2800 high quality banner. Pixelart. title reads: "Die Knight, Die!". Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Pixealrt. Dungeon. Reads: The Knight is DEAD. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.