User prompt
once 30 points are on the coin count,end game
User prompt
add point to coin count every time a coin is collected
User prompt
every time player collects a coin add point to coin count
User prompt
show how many coins out of 30 the player has gotten in the game
User prompt
remove wall
User prompt
when leprechaun gets caught leave 5 coins end game when player gets 30 gold
User prompt
when leprechaun gets caught add another
User prompt
give leprechaun 3 lives before the player wins
User prompt
make the leprechaun faster
User prompt
add blocks inside the map that the leprechaun can go through but the player can't.
User prompt
make many walls around the map that the leprechaun can go through but the player can't.
User prompt
make the player slower
User prompt
make the leprechaun faster
User prompt
increes speed of leprechaun
User prompt
make the leprechaun run away from the player
User prompt
make shure the leprechaun does not go into corners
User prompt
make the leprechaun run away from the player
User prompt
make the leprechan run away from player faster
User prompt
make the leprechaun go fast
User prompt
make the leprechaun move
Initial prompt
The leprechaun trap
/**** * Classes ****/ // Class for the leprechaun var Leprechaun = Container.expand(function () { var self = Container.call(this); var leprechaunGraphics = self.attachAsset('leprechaun', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 50; self.update = function () { // Leprechaun update logic // Calculate direction towards the player var dx = player.x - self.x; var dy = player.y - self.y; var distance = Math.sqrt(dx * dx + dy * dy); // Run away from the player self.direction = Math.atan2(dy, dx) + Math.PI; // Move in the current direction self.x += Math.cos(self.direction) * self.speed; self.y += Math.sin(self.direction) * self.speed; // Keep the leprechaun within the game bounds and away from corners if (self.x < 200) { self.x = 200; } if (self.y < 200) { self.y = 200; } if (self.x > 1848) { self.x = 1848; } if (self.y > 2532) { self.y = 2532; } // Make the leprechaun run away from the player if (distance < 500) { self.speed = 10; } else { self.speed = 5; } }; }); //<Assets used in the game will automatically appear here> //<Write imports for supported plugins here> // Class for the player character var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 3; self.update = function () { // Player update logic }; }); // Class for the wall var Wall = Container.expand(function () { var self = Container.call(this); var wallGraphics = self.attachAsset('wall', { anchorX: 0.5, anchorY: 0.5 }); }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ // Initialize player and leprechaun var player = game.addChild(new Player()); // Create walls around the map for (var i = 0; i < 20; i++) { for (var j = 0; j < 27; j++) { if (i == 0 || j == 0 || i == 19 || j == 26) { var wall = game.addChild(new Wall()); wall.x = i * 100; wall.y = j * 100; } } } player.x = 1024; // Center horizontally player.y = 1366; // Center vertically var leprechaun = game.addChild(new Leprechaun()); leprechaun.x = Math.random() * 2048; leprechaun.y = Math.random() * 2732; // Game update logic game.update = function () { // Update player and leprechaun positions player.update(); leprechaun.update(); // Check for intersection if (player.intersects(leprechaun)) { // Player has trapped the leprechaun LK.showYouWin(); } }; // Handle player movement game.move = function (x, y, obj) { // Check if the new position intersects with any wall var intersectsWall = false; for (var i = 0; i < game.children.length; i++) { if (game.children[i] instanceof Wall) { if (game.children[i].intersects({ x: x, y: y, width: player.width, height: player.height })) { intersectsWall = true; break; } } } // Only move the player if the new position does not intersect with any wall if (!intersectsWall) { player.x = x; player.y = y; } };
===================================================================
--- original.js
+++ change.js
@@ -54,8 +54,16 @@
self.update = function () {
// Player update logic
};
});
+// Class for the wall
+var Wall = Container.expand(function () {
+ var self = Container.call(this);
+ var wallGraphics = self.attachAsset('wall', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+});
/****
* Initialize Game
****/
@@ -67,8 +75,18 @@
* Game Code
****/
// Initialize player and leprechaun
var player = game.addChild(new Player());
+// Create walls around the map
+for (var i = 0; i < 20; i++) {
+ for (var j = 0; j < 27; j++) {
+ if (i == 0 || j == 0 || i == 19 || j == 26) {
+ var wall = game.addChild(new Wall());
+ wall.x = i * 100;
+ wall.y = j * 100;
+ }
+ }
+}
player.x = 1024; // Center horizontally
player.y = 1366; // Center vertically
var leprechaun = game.addChild(new Leprechaun());
leprechaun.x = Math.random() * 2048;
@@ -85,7 +103,25 @@
}
};
// Handle player movement
game.move = function (x, y, obj) {
- player.x = x;
- player.y = y;
+ // Check if the new position intersects with any wall
+ var intersectsWall = false;
+ for (var i = 0; i < game.children.length; i++) {
+ if (game.children[i] instanceof Wall) {
+ if (game.children[i].intersects({
+ x: x,
+ y: y,
+ width: player.width,
+ height: player.height
+ })) {
+ intersectsWall = true;
+ break;
+ }
+ }
+ }
+ // Only move the player if the new position does not intersect with any wall
+ if (!intersectsWall) {
+ player.x = x;
+ player.y = y;
+ }
};
\ No newline at end of file