User prompt
Character moving by holding and obstacles are smaller
User prompt
Add a lot of obstacle
User prompt
Add more coins and do them collectiable
User prompt
Add coins somewheres in the game
Code edit (1 edits merged)
Please save this source code
User prompt
Third Person Adventure Runner
User prompt
Make the game third person camera
Initial prompt
Make me GTA 7
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Character = Container.expand(function () {
var self = Container.call(this);
var characterGraphics = self.attachAsset('character', {
anchorX: 0.5,
anchorY: 1.0
});
// Character properties
self.baseY = 2400; // Ground level
self.targetX = 1024; // Center of screen
self.moveSpeed = 8;
self.update = function () {
// Smooth movement toward target X position
var deltaX = self.targetX - self.x;
if (Math.abs(deltaX) > 2) {
self.x += deltaX * 0.15;
}
// Keep character within screen bounds
self.x = Math.max(200, Math.min(1848, self.x));
};
return self;
});
var Coin = Container.expand(function () {
var self = Container.call(this);
var coinGraphics = self.attachAsset('coin', {
anchorX: 0.5,
anchorY: 0.5
});
// Scale coin to simulate 3D perspective
self.baseScale = 0.4;
self.scale.set(self.baseScale);
// Add floating animation
self.floatOffset = Math.random() * Math.PI * 2;
self.baseY = 0;
self.update = function () {
// Move toward camera
self.y += gameSpeed;
// Simulate 3D perspective
var distanceFromCamera = (2732 - self.y) / 2732;
var perspectiveScale = self.baseScale + (1 - self.baseScale) * (1 - distanceFromCamera);
self.scale.set(perspectiveScale);
// Floating animation
self.y = self.baseY + Math.sin(LK.ticks * 0.1 + self.floatOffset) * 10;
// Coin spinning animation for classic coin effect
coinGraphics.rotation += 0.08;
// Scale pulsing to make coin more noticeable
var pulseScale = 1 + Math.sin(LK.ticks * 0.15) * 0.1;
coinGraphics.scaleX = pulseScale;
// Adjust hit area
self.hitWidth = 80 * perspectiveScale;
self.hitHeight = 80 * perspectiveScale;
};
return self;
});
var Obstacle = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 1.0
});
// Scale obstacle to simulate 3D perspective
self.baseScale = 0.3;
self.scale.set(self.baseScale);
self.update = function () {
// Move toward camera (increase Y and scale)
self.y += gameSpeed;
// Simulate 3D perspective by scaling based on distance
var distanceFromCamera = (2732 - self.y) / 2732;
var perspectiveScale = self.baseScale + (1 - self.baseScale) * (1 - distanceFromCamera);
self.scale.set(perspectiveScale);
// Adjust apparent width based on perspective
self.hitWidth = 150 * perspectiveScale;
self.hitHeight = 200 * perspectiveScale;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
// Game variables
var character;
var obstacles = [];
var coins = [];
var gameSpeed = 6;
var spawnTimer = 0;
var coinTimer = 0;
var cameraY = 0;
var gameRunning = true;
// UI elements
var scoreTxt = new Text2('Score: 0', {
size: 80,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
var speedTxt = new Text2('Speed: 1.0x', {
size: 60,
fill: 0xFFFFFF
});
speedTxt.anchor.set(1, 0);
LK.gui.topRight.addChild(speedTxt);
// Create ground strips for perspective effect
var groundStrips = [];
for (var i = 0; i < 8; i++) {
var ground = game.addChild(LK.getAsset('ground', {
anchorX: 0.5,
anchorY: 0.5
}));
ground.x = 1024;
ground.y = 2400 + i * 300;
ground.baseY = ground.y;
ground.alpha = 0.3;
groundStrips.push(ground);
}
// Create character
character = game.addChild(new Character());
character.x = 1024;
character.y = character.baseY;
// Touch controls
game.down = function (x, y, obj) {
if (!gameRunning) return;
if (x < 1024) {
// Left side - move left
character.targetX = Math.max(200, character.targetX - 300);
} else {
// Right side - move right
character.targetX = Math.min(1848, character.targetX + 300);
}
};
// Spawn obstacles
function spawnObstacle() {
var obstacle = new Obstacle();
obstacle.x = 200 + Math.random() * 1648; // Random X position
obstacle.y = -200; // Start above screen
obstacle.baseY = obstacle.y;
obstacles.push(obstacle);
game.addChild(obstacle);
}
// Spawn coins
function spawnCoin() {
var coin = new Coin();
coin.x = 300 + Math.random() * 1448; // Random X position
coin.y = -100; // Start above screen
coin.baseY = coin.y;
coins.push(coin);
game.addChild(coin);
}
// Collision detection function
function checkCollision(obj1, obj2) {
var dx = obj1.x - obj2.x;
var dy = obj1.y - obj2.y;
var distance = Math.sqrt(dx * dx + dy * dy);
var minDistance = (obj1.hitWidth || 120) / 2 + (obj2.hitWidth || 150) / 2;
return distance < minDistance;
}
// Game update loop
game.update = function () {
if (!gameRunning) return;
// Increase speed over time
gameSpeed += 0.002;
speedTxt.setText('Speed: ' + (gameSpeed / 6).toFixed(1) + 'x');
// Update ground for scrolling effect
for (var i = 0; i < groundStrips.length; i++) {
var ground = groundStrips[i];
ground.y += gameSpeed;
if (ground.y > 2932) {
ground.y = -200;
}
// Perspective scaling for ground
var distanceFromCamera = (2732 - ground.y) / 2732;
var perspectiveScale = 0.5 + 0.5 * (1 - distanceFromCamera);
ground.scaleY = perspectiveScale;
}
// Spawn obstacles
spawnTimer++;
if (spawnTimer > 60 - gameSpeed * 2) {
spawnObstacle();
spawnTimer = 0;
}
// Spawn coins
coinTimer++;
if (coinTimer > 90) {
spawnCoin();
coinTimer = 0;
}
// Update and check obstacles
for (var i = obstacles.length - 1; i >= 0; i--) {
var obstacle = obstacles[i];
// Remove obstacles that are off screen
if (obstacle.y > 2832) {
obstacle.destroy();
obstacles.splice(i, 1);
continue;
}
// Check collision with character
if (obstacle.y > 2000 && obstacle.y < 2600) {
if (checkCollision(character, obstacle)) {
// Game over
gameRunning = false;
LK.getSound('hit').play();
LK.effects.flashScreen(0xFF0000, 500);
LK.setTimeout(function () {
LK.showGameOver();
}, 500);
break;
}
}
}
// Update and check coins
for (var j = coins.length - 1; j >= 0; j--) {
var coin = coins[j];
// Remove coins that are off screen
if (coin.y > 2832) {
coin.destroy();
coins.splice(j, 1);
continue;
}
// Check coin collection
if (coin.y > 2000 && coin.y < 2600) {
if (checkCollision(character, coin)) {
// Coin collected
LK.setScore(LK.getScore() + 10);
scoreTxt.setText('Score: ' + LK.getScore());
LK.getSound('collect').play();
// Coin collection visual effect
tween(coin, {
alpha: 0,
scaleX: 2,
scaleY: 2
}, {
duration: 200,
onFinish: function onFinish() {
coin.destroy();
}
});
coins.splice(j, 1);
}
}
}
}; ===================================================================
--- original.js
+++ change.js
@@ -26,15 +26,15 @@
self.x = Math.max(200, Math.min(1848, self.x));
};
return self;
});
-var Collectible = Container.expand(function () {
+var Coin = Container.expand(function () {
var self = Container.call(this);
- var collectibleGraphics = self.attachAsset('collectible', {
+ var coinGraphics = self.attachAsset('coin', {
anchorX: 0.5,
anchorY: 0.5
});
- // Scale collectible to simulate 3D perspective
+ // Scale coin to simulate 3D perspective
self.baseScale = 0.4;
self.scale.set(self.baseScale);
// Add floating animation
self.floatOffset = Math.random() * Math.PI * 2;
@@ -47,10 +47,13 @@
var perspectiveScale = self.baseScale + (1 - self.baseScale) * (1 - distanceFromCamera);
self.scale.set(perspectiveScale);
// Floating animation
self.y = self.baseY + Math.sin(LK.ticks * 0.1 + self.floatOffset) * 10;
- // Rotation for visual appeal
- collectibleGraphics.rotation += 0.05;
+ // Coin spinning animation for classic coin effect
+ coinGraphics.rotation += 0.08;
+ // Scale pulsing to make coin more noticeable
+ var pulseScale = 1 + Math.sin(LK.ticks * 0.15) * 0.1;
+ coinGraphics.scaleX = pulseScale;
// Adjust hit area
self.hitWidth = 80 * perspectiveScale;
self.hitHeight = 80 * perspectiveScale;
};
@@ -91,12 +94,12 @@
****/
// Game variables
var character;
var obstacles = [];
-var collectibles = [];
+var coins = [];
var gameSpeed = 6;
var spawnTimer = 0;
-var collectibleTimer = 0;
+var coinTimer = 0;
var cameraY = 0;
var gameRunning = true;
// UI elements
var scoreTxt = new Text2('Score: 0', {
@@ -147,16 +150,16 @@
obstacle.baseY = obstacle.y;
obstacles.push(obstacle);
game.addChild(obstacle);
}
-// Spawn collectibles
-function spawnCollectible() {
- var collectible = new Collectible();
- collectible.x = 300 + Math.random() * 1448; // Random X position
- collectible.y = -100; // Start above screen
- collectible.baseY = collectible.y;
- collectibles.push(collectible);
- game.addChild(collectible);
+// Spawn coins
+function spawnCoin() {
+ var coin = new Coin();
+ coin.x = 300 + Math.random() * 1448; // Random X position
+ coin.y = -100; // Start above screen
+ coin.baseY = coin.y;
+ coins.push(coin);
+ game.addChild(coin);
}
// Collision detection function
function checkCollision(obj1, obj2) {
var dx = obj1.x - obj2.x;
@@ -188,13 +191,13 @@
if (spawnTimer > 60 - gameSpeed * 2) {
spawnObstacle();
spawnTimer = 0;
}
- // Spawn collectibles
- collectibleTimer++;
- if (collectibleTimer > 90) {
- spawnCollectible();
- collectibleTimer = 0;
+ // Spawn coins
+ coinTimer++;
+ if (coinTimer > 90) {
+ spawnCoin();
+ coinTimer = 0;
}
// Update and check obstacles
for (var i = obstacles.length - 1; i >= 0; i--) {
var obstacle = obstacles[i];
@@ -217,36 +220,36 @@
break;
}
}
}
- // Update and check collectibles
- for (var j = collectibles.length - 1; j >= 0; j--) {
- var collectible = collectibles[j];
- // Remove collectibles that are off screen
- if (collectible.y > 2832) {
- collectible.destroy();
- collectibles.splice(j, 1);
+ // Update and check coins
+ for (var j = coins.length - 1; j >= 0; j--) {
+ var coin = coins[j];
+ // Remove coins that are off screen
+ if (coin.y > 2832) {
+ coin.destroy();
+ coins.splice(j, 1);
continue;
}
- // Check collection
- if (collectible.y > 2000 && collectible.y < 2600) {
- if (checkCollision(character, collectible)) {
- // Collected
+ // Check coin collection
+ if (coin.y > 2000 && coin.y < 2600) {
+ if (checkCollision(character, coin)) {
+ // Coin collected
LK.setScore(LK.getScore() + 10);
scoreTxt.setText('Score: ' + LK.getScore());
LK.getSound('collect').play();
- // Visual effect
- tween(collectible, {
+ // Coin collection visual effect
+ tween(coin, {
alpha: 0,
scaleX: 2,
scaleY: 2
}, {
duration: 200,
onFinish: function onFinish() {
- collectible.destroy();
+ coin.destroy();
}
});
- collectibles.splice(j, 1);
+ coins.splice(j, 1);
}
}
}
};
\ No newline at end of file