User prompt
make chracter repel the ball so its harder
User prompt
make chracter look twoards where it moves
User prompt
make it so obstacles cant spawn on the player so the game doesnt instantly fails and more obstacles and add some long and tall obstacles
User prompt
randomize obstacles in each sessions of game and make the ball faster 2x
User prompt
make ball bounce off of the obstacles
User prompt
add obstacles to the arena and when player touches them make them lose
User prompt
make the ball's avade circle triple the amount it was
User prompt
make ball a twice as fast
User prompt
the character is teleporting right now make it slowly chase the crosshair ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
add lag to player it should slowly come to the crosshair ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
make the ball faster and it should try to evade me
Code edit (1 edits merged)
Please save this source code
User prompt
Ball Chase
Initial prompt
i want a game that you chase a ball and if you catch the ball you win
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Ball = Container.expand(function () {
var self = Container.call(this);
var ballGraphics = self.attachAsset('ball', {
anchorX: 0.5,
anchorY: 0.5
});
// Ball movement properties
self.speedX = 10;
self.speedY = 10;
self.maxSpeed = 16;
self.minSpeed = 8;
// Evasion properties
self.evasionDistance = 300; // Distance at which ball starts evading
self.evasionStrength = 0.3; // How strongly the ball evades
// Direction change timer
self.directionChangeTimer = 0;
self.directionChangeInterval = 80; // Change direction more frequently
self.update = function () {
// Move the ball
self.x += self.speedX;
self.y += self.speedY;
// Bounce off screen edges
if (self.x <= 30 || self.x >= 2048 - 30) {
self.speedX = -self.speedX;
self.x = Math.max(30, Math.min(2048 - 30, self.x));
}
if (self.y <= 30 || self.y >= 2732 - 30) {
self.speedY = -self.speedY;
self.y = Math.max(30, Math.min(2732 - 30, self.y));
}
// Evasive behavior - move away from player
var distanceToPlayer = Math.sqrt(Math.pow(self.x - player.x, 2) + Math.pow(self.y - player.y, 2));
if (distanceToPlayer < self.evasionDistance) {
// Calculate direction away from player
var evadeAngle = Math.atan2(self.y - player.y, self.x - player.x);
// Apply evasion force
self.speedX += Math.cos(evadeAngle) * self.evasionStrength;
self.speedY += Math.sin(evadeAngle) * self.evasionStrength;
// Clamp speed to max values
var currentSpeed = Math.sqrt(self.speedX * self.speedX + self.speedY * self.speedY);
if (currentSpeed > self.maxSpeed) {
self.speedX = self.speedX / currentSpeed * self.maxSpeed;
self.speedY = self.speedY / currentSpeed * self.maxSpeed;
}
}
// Random direction changes (more frequent when being chased)
self.directionChangeTimer++;
var changeInterval = distanceToPlayer < self.evasionDistance ? self.directionChangeInterval / 2 : self.directionChangeInterval;
if (self.directionChangeTimer >= changeInterval) {
self.directionChangeTimer = 0;
self.directionChangeInterval = 40 + Math.random() * 120; // Faster random interval
// Random direction change
if (Math.random() < 0.7) {
// Higher chance of direction change
var angle = Math.random() * Math.PI * 2;
var speed = self.minSpeed + Math.random() * (self.maxSpeed - self.minSpeed);
self.speedX = Math.cos(angle) * speed;
self.speedY = Math.sin(angle) * speed;
}
}
};
return self;
});
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x2196F3
});
/****
* Game Code
****/
// Game variables
var player;
var ball;
var dragNode = null;
var gameWon = false;
// Initialize player
player = game.addChild(new Player());
player.x = 1024; // Center horizontally
player.y = 1800; // Near bottom of screen
// Initialize ball
ball = game.addChild(new Ball());
ball.x = 1024; // Center horizontally
ball.y = 400; // Upper portion of screen
// Set initial random direction for ball
var initialAngle = Math.random() * Math.PI * 2;
var initialSpeed = 10;
ball.speedX = Math.cos(initialAngle) * initialSpeed;
ball.speedY = Math.sin(initialAngle) * initialSpeed;
// Tracking intersection state
var lastIntersecting = false;
// Store target position for smooth chasing
var targetX = 0;
var targetY = 0;
function handleMove(x, y, obj) {
if (dragNode && !gameWon) {
// Calculate target position with bounds
targetX = Math.max(40, Math.min(2048 - 40, x));
targetY = Math.max(40, Math.min(2732 - 40, y));
}
}
// Game input handlers
game.move = handleMove;
game.down = function (x, y, obj) {
if (!gameWon) {
dragNode = player;
handleMove(x, y, obj);
}
};
game.up = function (x, y, obj) {
dragNode = null;
};
// Main game update loop
game.update = function () {
if (gameWon) return;
// Smooth player chasing movement
if (dragNode) {
var followSpeed = 0.08; // Adjust this value to control lag (0.1 = faster, 0.05 = slower)
var deltaX = targetX - dragNode.x;
var deltaY = targetY - dragNode.y;
dragNode.x += deltaX * followSpeed;
dragNode.y += deltaY * followSpeed;
}
// Check for collision between player and ball
var currentIntersecting = player.intersects(ball);
if (!lastIntersecting && currentIntersecting) {
// Player caught the ball!
gameWon = true;
// Play catch sound
LK.getSound('catch').play();
// Flash effect
LK.effects.flashScreen(0x4CAF50, 1000);
// Show victory after a short delay
LK.setTimeout(function () {
LK.showYouWin();
}, 500);
}
lastIntersecting = currentIntersecting;
}; ===================================================================
--- original.js
+++ change.js
@@ -12,12 +12,12 @@
anchorX: 0.5,
anchorY: 0.5
});
// Ball movement properties
- self.speedX = 5;
- self.speedY = 5;
- self.maxSpeed = 8;
- self.minSpeed = 4;
+ self.speedX = 10;
+ self.speedY = 10;
+ self.maxSpeed = 16;
+ self.minSpeed = 8;
// Evasion properties
self.evasionDistance = 300; // Distance at which ball starts evading
self.evasionStrength = 0.3; // How strongly the ball evades
// Direction change timer
@@ -102,9 +102,9 @@
ball.x = 1024; // Center horizontally
ball.y = 400; // Upper portion of screen
// Set initial random direction for ball
var initialAngle = Math.random() * Math.PI * 2;
-var initialSpeed = 5;
+var initialSpeed = 10;
ball.speedX = Math.cos(initialAngle) * initialSpeed;
ball.speedY = Math.sin(initialAngle) * initialSpeed;
// Tracking intersection state
var lastIntersecting = false;