User prompt
Destroy the green entity that appears when I sprint and analyze the game to fix the bug. ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Acceleration is now a sprint ability that lasts for 0.9 seconds and then slows the character by 1.5x. There's a bar just below the health bar that shows how many seconds of sprint time we have left. ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
The monster does not follow the player during the dash, it simply runs in that direction.
User prompt
The monster dashes every 5 seconds and if it hits an obstacle while dashing, it will be stunned for 1 second. ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
We can make the character follow the cursor faster by pressing the left mouse button.
User prompt
When we hit obstacles, we lose 2 health, but every time we take damage, we jump a distance away from the creature we damaged. ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Add a monster that chases us and deals 3 damage when it catches us ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Add a health bar with 10 lives
Code edit (1 edits merged)
Please save this source code
User prompt
Bird's Eye Adventure
Initial prompt
Take the area as the ground and place a character in the middle so that we can look at this character from above with a bird's eye view.
/****
* Classes
****/
var Character = Container.expand(function () {
var self = Container.call(this);
var characterGraphics = self.attachAsset('character', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 8;
self.targetX = self.x;
self.targetY = self.y;
self.update = function () {
// Smooth movement towards target position
var dx = self.targetX - self.x;
var dy = self.targetY - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > 2) {
self.x += dx / distance * self.speed;
self.y += dy / distance * self.speed;
}
};
return self;
});
var Collectible = Container.expand(function () {
var self = Container.call(this);
var collectibleGraphics = self.attachAsset('collectible', {
anchorX: 0.5,
anchorY: 0.5
});
self.collected = false;
self.update = function () {
// Gentle floating animation
collectibleGraphics.y = Math.sin(LK.ticks * 0.1) * 5;
};
return self;
});
var Obstacle = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 0.5
});
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87ceeb
});
/****
* Game Code
****/
// Create the ground/play area
var ground = LK.getAsset('ground', {
anchorX: 0.5,
anchorY: 0.5
});
ground.x = 2048 / 2;
ground.y = 2732 / 2;
game.addChild(ground);
// Create character in center
var character = new Character();
character.x = 2048 / 2;
character.y = 2732 / 2;
character.targetX = character.x;
character.targetY = character.y;
game.addChild(character);
// Create obstacles around the play area
var obstacles = [];
for (var i = 0; i < 8; i++) {
var obstacle = new Obstacle();
var angle = i / 8 * Math.PI * 2;
var radius = 600;
obstacle.x = 2048 / 2 + Math.cos(angle) * radius;
obstacle.y = 2732 / 2 + Math.sin(angle) * radius;
obstacles.push(obstacle);
game.addChild(obstacle);
}
// Create collectibles
var collectibles = [];
for (var i = 0; i < 12; i++) {
var collectible = new Collectible();
var angle = Math.random() * Math.PI * 2;
var radius = 200 + Math.random() * 400;
collectible.x = 2048 / 2 + Math.cos(angle) * radius;
collectible.y = 2732 / 2 + Math.sin(angle) * radius;
collectibles.push(collectible);
game.addChild(collectible);
}
// Create score display
var scoreTxt = new Text2('Score: 0', {
size: 80,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Game bounds (keep character within ground area)
var groundBounds = {
left: 2048 / 2 - 850,
right: 2048 / 2 + 850,
top: 2732 / 2 - 850,
bottom: 2732 / 2 + 850
};
// Touch/mouse controls
game.down = function (x, y, obj) {
// Set character target to touch position, but keep within bounds
character.targetX = Math.max(groundBounds.left, Math.min(groundBounds.right, x));
character.targetY = Math.max(groundBounds.top, Math.min(groundBounds.bottom, y));
};
game.move = function (x, y, obj) {
// Continue moving to touch position while dragging
character.targetX = Math.max(groundBounds.left, Math.min(groundBounds.right, x));
character.targetY = Math.max(groundBounds.top, Math.min(groundBounds.bottom, y));
};
// Game update loop
game.update = function () {
// Check for collectible collection
for (var i = collectibles.length - 1; i >= 0; i--) {
var collectible = collectibles[i];
if (!collectible.collected && character.intersects(collectible)) {
collectible.collected = true;
LK.setScore(LK.getScore() + 10);
scoreTxt.setText('Score: ' + LK.getScore());
// Remove collectible
collectible.destroy();
collectibles.splice(i, 1);
// Check win condition
if (collectibles.length === 0) {
LK.showYouWin();
}
}
}
// Check collision with obstacles
for (var i = 0; i < obstacles.length; i++) {
var obstacle = obstacles[i];
if (character.intersects(obstacle)) {
// Push character away from obstacle
var dx = character.x - obstacle.x;
var dy = character.y - obstacle.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > 0) {
var pushDistance = 100;
character.targetX = obstacle.x + dx / distance * pushDistance;
character.targetY = obstacle.y + dy / distance * pushDistance;
// Keep within bounds
character.targetX = Math.max(groundBounds.left, Math.min(groundBounds.right, character.targetX));
character.targetY = Math.max(groundBounds.top, Math.min(groundBounds.bottom, character.targetY));
}
}
}
}; ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,155 @@
-/****
+/****
+* Classes
+****/
+var Character = Container.expand(function () {
+ var self = Container.call(this);
+ var characterGraphics = self.attachAsset('character', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 8;
+ self.targetX = self.x;
+ self.targetY = self.y;
+ self.update = function () {
+ // Smooth movement towards target position
+ var dx = self.targetX - self.x;
+ var dy = self.targetY - self.y;
+ var distance = Math.sqrt(dx * dx + dy * dy);
+ if (distance > 2) {
+ self.x += dx / distance * self.speed;
+ self.y += dy / distance * self.speed;
+ }
+ };
+ return self;
+});
+var Collectible = Container.expand(function () {
+ var self = Container.call(this);
+ var collectibleGraphics = self.attachAsset('collectible', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.collected = false;
+ self.update = function () {
+ // Gentle floating animation
+ collectibleGraphics.y = Math.sin(LK.ticks * 0.1) * 5;
+ };
+ return self;
+});
+var Obstacle = Container.expand(function () {
+ var self = Container.call(this);
+ var obstacleGraphics = self.attachAsset('obstacle', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x87ceeb
+});
+
+/****
+* Game Code
+****/
+// Create the ground/play area
+var ground = LK.getAsset('ground', {
+ anchorX: 0.5,
+ anchorY: 0.5
+});
+ground.x = 2048 / 2;
+ground.y = 2732 / 2;
+game.addChild(ground);
+// Create character in center
+var character = new Character();
+character.x = 2048 / 2;
+character.y = 2732 / 2;
+character.targetX = character.x;
+character.targetY = character.y;
+game.addChild(character);
+// Create obstacles around the play area
+var obstacles = [];
+for (var i = 0; i < 8; i++) {
+ var obstacle = new Obstacle();
+ var angle = i / 8 * Math.PI * 2;
+ var radius = 600;
+ obstacle.x = 2048 / 2 + Math.cos(angle) * radius;
+ obstacle.y = 2732 / 2 + Math.sin(angle) * radius;
+ obstacles.push(obstacle);
+ game.addChild(obstacle);
+}
+// Create collectibles
+var collectibles = [];
+for (var i = 0; i < 12; i++) {
+ var collectible = new Collectible();
+ var angle = Math.random() * Math.PI * 2;
+ var radius = 200 + Math.random() * 400;
+ collectible.x = 2048 / 2 + Math.cos(angle) * radius;
+ collectible.y = 2732 / 2 + Math.sin(angle) * radius;
+ collectibles.push(collectible);
+ game.addChild(collectible);
+}
+// Create score display
+var scoreTxt = new Text2('Score: 0', {
+ size: 80,
+ fill: 0xFFFFFF
+});
+scoreTxt.anchor.set(0.5, 0);
+LK.gui.top.addChild(scoreTxt);
+// Game bounds (keep character within ground area)
+var groundBounds = {
+ left: 2048 / 2 - 850,
+ right: 2048 / 2 + 850,
+ top: 2732 / 2 - 850,
+ bottom: 2732 / 2 + 850
+};
+// Touch/mouse controls
+game.down = function (x, y, obj) {
+ // Set character target to touch position, but keep within bounds
+ character.targetX = Math.max(groundBounds.left, Math.min(groundBounds.right, x));
+ character.targetY = Math.max(groundBounds.top, Math.min(groundBounds.bottom, y));
+};
+game.move = function (x, y, obj) {
+ // Continue moving to touch position while dragging
+ character.targetX = Math.max(groundBounds.left, Math.min(groundBounds.right, x));
+ character.targetY = Math.max(groundBounds.top, Math.min(groundBounds.bottom, y));
+};
+// Game update loop
+game.update = function () {
+ // Check for collectible collection
+ for (var i = collectibles.length - 1; i >= 0; i--) {
+ var collectible = collectibles[i];
+ if (!collectible.collected && character.intersects(collectible)) {
+ collectible.collected = true;
+ LK.setScore(LK.getScore() + 10);
+ scoreTxt.setText('Score: ' + LK.getScore());
+ // Remove collectible
+ collectible.destroy();
+ collectibles.splice(i, 1);
+ // Check win condition
+ if (collectibles.length === 0) {
+ LK.showYouWin();
+ }
+ }
+ }
+ // Check collision with obstacles
+ for (var i = 0; i < obstacles.length; i++) {
+ var obstacle = obstacles[i];
+ if (character.intersects(obstacle)) {
+ // Push character away from obstacle
+ var dx = character.x - obstacle.x;
+ var dy = character.y - obstacle.y;
+ var distance = Math.sqrt(dx * dx + dy * dy);
+ if (distance > 0) {
+ var pushDistance = 100;
+ character.targetX = obstacle.x + dx / distance * pushDistance;
+ character.targetY = obstacle.y + dy / distance * pushDistance;
+ // Keep within bounds
+ character.targetX = Math.max(groundBounds.left, Math.min(groundBounds.right, character.targetX));
+ character.targetY = Math.max(groundBounds.top, Math.min(groundBounds.bottom, character.targetY));
+ }
+ }
+ }
+};
\ No newline at end of file