Code edit (2 edits merged)
Please save this source code
User prompt
add landcape1 to the game, horizontal center, top tier
User prompt
apply currentCoinType to CoinAnimation (add necessary asset2)
User prompt
when currentCoinType == 0 set coinGraphics.alpha to 1 and coinGraphics2.alpha to 0 when currentCoinType == 1 set coinGraphics.alpha to 0 and coinGraphics2.alpha to 1
User prompt
when coinsCollected >= nextCoinTypeThreshold, set currentCoinType = 1
User prompt
add a global nextCoinTypeThreshold = 5
User prompt
add a global currentCoinType = 0
Code edit (2 edits merged)
Please save this source code
User prompt
Retire le texte de Start du bouton Start.
Code edit (1 edits merged)
Please save this source code
User prompt
Dieu a fait le contraire. Dieu a activé les pièces et les obstacles au lieu d'activer la route et le joueur.
User prompt
Tu n'as pas modifié au bon endroit. On recommence. Je te rappelle qu'il faut que le joueur et la route soient mis à jour avant que le start soit appuyé.
Code edit (1 edits merged)
Please save this source code
User prompt
Finalement, tu peux laisser l'animation de la route et du joueur avant qu'on appuie sur start
User prompt
Apparemment tu as ignoré l'animation des coins plusieurs fois avant le start alors que les obstacles bougent toujours. Corrige cela.
User prompt
Rien ne doit être animé avant qu'on appuie sur Start.
Code edit (3 edits merged)
Please save this source code
User prompt
Ajoute un gros bouton au central qui s'appelle Start Button. Et lorsqu'on appuie sur l'écran, ce bouton disparaît et IsPlaying passe à tout.
User prompt
add a global isPlaying
Code edit (3 edits merged)
Please save this source code
User prompt
En utilisant une vérification globale, empêche les obstacles de toucher les pièces.
User prompt
Essayez également de rendre les déplacements latéraux fluides.
User prompt
Remplace l'utilisation de scaleX et scaleY par les changements de largeur et de hauteur pour l'animation de l'ombre pendant le saut.
User prompt
Essayez de rendre le seau plus fluide.
User prompt
Ignore les collisions pendant les sauts.
/****
* Classes
****/
// Assets will be automatically created and loaded during gameplay
// Coin class
var Coin = Container.expand(function () {
var self = Container.call(this);
var coinGraphics = self.attachAsset('coin', {
//'dollarsBundle'
anchorX: 0.5,
anchorY: 0.5,
width: startSize,
height: startSize
});
var speed = 5;
var leftStartX = 1024 - 350;
var leftEndX = 1024 - 700;
var rightStartX = 1024 + 350;
var rightEndX = 1024 + 700;
var innerLeftLineStartX = -150;
var innerLeftLineEndX = -390;
var startSize = coinGraphics.width;
var endSize = coinGraphics.width * 1.5;
coinGraphics.width = startSize;
coinGraphics.height = startSize;
self.pathIndex = 0;
self.update = function () {
self.progress = (self.y + 50) / (2732 + 50); // Update progress property
coinGraphics.width = startSize + (endSize - startSize) * self.progress;
coinGraphics.height = startSize + (endSize - startSize) * self.progress;
var newSpeed = currentSpeed; // + 10 * self.progress;
self.y += newSpeed;
// Move innerLineLeft x progressively to innerLeftLineEndX
if (self.pathIndex == 0 && self.x != leftEndX) {
self.x = leftStartX + (leftEndX - leftStartX) * self.progress;
}
if (self.pathIndex == 2 && self.x != rightEndX) {
self.x = rightStartX + (rightEndX - rightStartX) * self.progress;
}
if (self.y > 2732 + endSize / 2) {
self.reset();
}
};
self.reset = function () {
self.y = -50;
self.progress = 0; // Initialize progress property
coinGraphics.width = startSize;
coinGraphics.height = startSize;
self.pathIndex = Math.floor(Math.random() * 3);
if (self.pathIndex === 0) {
self.x = leftStartX;
} else if (self.pathIndex === 2) {
self.x = rightStartX;
} else {
self.x = 1024;
}
};
});
// CoinAnimation class
var CoinAnimation = Container.expand(function () {
var self = Container.call(this);
var coinGraphics = self.attachAsset('dollarsBundle', {
anchorX: 0.5,
anchorY: 0.5
});
// Initialize velocity and gravity
self.vx = (Math.random() < 0.5 ? -1 : 1) * 5; // Random horizontal velocity
self.vy = -15; // Initial vertical velocity
self.gravity = 0.5; // Gravity effect
self.update = function () {
self.vy += self.gravity; // Apply gravity to vertical velocity
self.x += self.vx; // Update horizontal position
self.y += self.vy; // Update vertical position
self.alpha -= 0.0035; // Fade out the coin
if (self.alpha <= 0) {
self.destroy(); // Remove the coin when it becomes invisible
}
};
});
// Obstacle class
var Obstacle = Container.expand(function () {
var self = Container.call(this);
var assets = ['obstacle1', 'obstacle2', 'obstacle3'];
self.assetIndex = Math.floor(Math.random() * assets.length);
var randomAsset = assets[self.assetIndex];
var obstacleGraphics = self.attachAsset(randomAsset, {
anchorX: 0.5,
anchorY: 0.5
});
var speed = 5;
var leftStartX = 1024 - 350;
var leftEndX = 1024 - 700;
var rightStartX = 1024 + 350;
var rightEndX = 1024 + 700;
var innerLeftLineStartX = -150;
var innerLeftLineEndX = -390;
var startSize, endSize;
if (self.assetIndex == 0) {
startSize = 300;
endSize = 500;
} else if (self.assetIndex == 1) {
startSize = 60;
endSize = 120;
} else if (self.assetIndex == 2) {
startSize = 150;
endSize = 200;
}
obstacleGraphics.width = startSize;
obstacleGraphics.height = startSize;
self.pathIndex = 0;
self.update = function () {
self.progress = (self.y + 50) / (2732 + 50); // Update progress property
obstacleGraphics.width = startSize + (endSize - startSize) * self.progress;
obstacleGraphics.height = startSize + (endSize - startSize) * self.progress;
var newSpeed = currentSpeed; // + 10 * self.progress;
self.y += newSpeed;
// Move innerLineLeft x progressively to innerLeftLineEndX
if (self.pathIndex == 0 && self.x != leftEndX) {
self.x = leftStartX + (leftEndX - leftStartX) * self.progress;
}
if (self.pathIndex == 2 && self.x != rightEndX) {
self.x = rightStartX + (rightEndX - rightStartX) * self.progress;
}
if (self.y > 2732 + endSize / 2) {
//self.y = -startSize; // Move obstacle back to the top
self.reset();
}
};
self.reset = function () {
self.y = -startSize;
self.progress = 0; // Initialize progress property
obstacleGraphics.width = startSize;
obstacleGraphics.height = startSize;
self.pathIndex = Math.floor(Math.random() * 3);
if (self.pathIndex === 0) {
self.x = leftStartX;
} else if (self.pathIndex === 2) {
self.x = rightStartX;
} else {
self.x = 1024;
}
};
});
// Player class
var Player = Container.expand(function () {
var self = Container.call(this);
self.shadow = self.attachAsset('playerShadow', {
anchorX: 0.5,
anchorY: 0.5
});
self.isJumping = false; // Initialize isJumping to false
self.shadow.alpha = 0.5; // Make the shadow semi-transparent
self.shadow.y = 270; // Offset the shadow slightly below the player
var playerGraphics1 = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5,
x: -5
});
var playerGraphics2 = self.attachAsset('player2', {
anchorX: 0.5,
anchorY: 0.5,
x: 5
});
playerGraphics2.visible = false; // Initially hide player2 asset
var frame = 0;
self.update = function () {
if (!self.isJumping) {
frame += Math.min(currentSpeed, 10); // Add a max limit to avoid optical effects
if (frame >= 100) {
frame = 0;
// Swap frames every 10 game ticks
var visible = playerGraphics1.visible;
playerGraphics1.visible = !visible;
playerGraphics2.visible = visible;
}
}
self.jump = function () {
if (!self.isJumping) {
self.isJumping = true;
var initialY = self.y;
var initialShadowY = self.shadow.y;
var jumpHeight = 300;
var jumpDuration = 30;
var jumpStep = jumpHeight / jumpDuration;
var fallStep = jumpHeight / jumpDuration;
var jumpInterval = LK.setInterval(function () {
if (self.y > initialY - jumpHeight) {
self.y -= jumpStep;
self.shadow.y += jumpStep; // Move shadow inversely
self.shadow.scaleX -= 0.01; // Reduce shadow size
self.shadow.scaleY -= 0.01; // Reduce shadow size
} else {
LK.clearInterval(jumpInterval);
var fallInterval = LK.setInterval(function () {
if (self.y < initialY) {
self.y += fallStep;
self.shadow.y -= fallStep; // Move shadow inversely
self.shadow.scaleX += 0.01; // Reset shadow size
self.shadow.scaleY += 0.01; // Reset shadow size
} else {
self.y = initialY;
self.shadow.y = initialShadowY; // Reset shadow position
self.isJumping = false;
LK.clearInterval(fallInterval);
}
}, 1000 / 60);
}
}, 1000 / 60);
}
};
};
});
// Road class
var Road = Container.expand(function () {
var self = Container.call(this);
var roadGraphics = self.attachAsset('road', {
tint: 0xffffff,
// Initialize tint to white
anchorX: 0.5,
anchorY: 0.5
});
var speed = 5;
var lineOffset = 250;
var innerLineStartOffset = 950;
var innerLineEndOffset = 650;
var innerLeftLineStartX = -150;
var innerLeftLineEndX = -390;
var innerLeftLineStartW = 30;
var innerLeftLineEndW = 60;
var innerLeftLineStartH = 200;
var innerLeftLineEndH = 400;
var innerLeftLineStartR = 0.075;
var innerLeftLineEndR = 0.075;
var innerRightLineStartX = 150;
var innerRightLineEndX = 390;
var innerRightLineStartW = 30;
var innerRightLineEndW = 60;
var innerRightLineStartH = 200;
var innerRightLineEndH = 400;
var innerRightLineStartR = -0.075;
var innerRightLineEndR = -0.075;
// Lamp posts
var leftLampStartX = -550;
var leftLampEndX = -1100;
var rightLampStartX = 550;
var rightLampEndX = 1100;
var leftLine = self.attachAsset('line', {
anchorX: 0.5,
anchorY: 0.5,
width: 60,
height: 2900,
rotation: 0.16
});
leftLine.x = -roadGraphics.width / 2 + lineOffset; // Position the left line on the left side of the road
leftLine.y = 0; // Center the left line vertically
var rightLine = self.attachAsset('line', {
anchorX: 0.5,
anchorY: 0.5,
width: 60,
height: 2900,
rotation: -0.16
});
rightLine.x = roadGraphics.width / 2 - lineOffset; // Position the right line on the right side of the road
rightLine.y = 0; // Center the right line vertically
self.innerLeftLines = [];
self.innerRightLines = [];
self.leftLampPosts = [];
self.rightLampPosts = [];
for (var i = 0; i < 6; i++) {
var innerLineLeft = self.attachAsset('line', {
anchorX: 0.5,
anchorY: 0.5,
width: innerLeftLineStartW,
height: innerLeftLineStartH,
rotation: innerLeftLineStartR
});
innerLineLeft.x = innerLeftLineStartX;
innerLineLeft.y = -roadGraphics.height / 2 + i * 600;
innerLineLeft.progress = 0; // Initialize progress property
self.innerLeftLines.push(innerLineLeft);
var innerLineRight = self.attachAsset('line', {
anchorX: 0.5,
anchorY: 0.5,
width: innerLeftLineStartW,
height: innerLeftLineStartH,
rotation: innerRightLineStartR
});
innerLineRight.x = innerRightLineStartX;
innerLineRight.y = -roadGraphics.height / 2 + i * 600;
innerLineRight.progress = 0; // Initialize progress property
self.innerRightLines.push(innerLineRight);
if (i % 3 < 2) {
continue;
}
var leftLampPost = self.attachAsset('lampPost', {
anchorX: 0.5,
anchorY: 0.5
});
leftLampPost.x = leftLampStartX;
leftLampPost.y = -roadGraphics.height / 2 + i * 600;
self.addChild(leftLampPost);
self.leftLampPosts.push(leftLampPost);
var rightLampPost = self.attachAsset('lampPost', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: -1
});
rightLampPost.x = roadGraphics.width / 2 - 100;
rightLampPost.y = -roadGraphics.height / 2 + i * 600;
self.addChild(rightLampPost);
self.rightLampPosts.push(rightLampPost);
}
var leftLine2 = self.attachAsset('line', {
anchorX: 0.5,
anchorY: 0.5,
width: 60,
height: 2900,
rotation: 0.075,
alpha: 0 //0.15
});
leftLine2.x = -267; // Position the left line on the left side of the road
leftLine2.y = 0; // Center the left line vertically
var leftLine3 = self.attachAsset('line', {
anchorX: 0.5,
anchorY: 0.5,
width: 60,
height: 2900,
rotation: -0.075,
alpha: 0 //0.15
});
leftLine3.x = 267; // Position the left line on the left side of the road
leftLine3.y = 0; // Center the left line vertically
//
self.resetInnerLine = function (innerLine, isLeft) {
if (isLeft) {
innerLine.x = innerLeftLineStartX;
innerLine.rotation = innerLeftLineStartR;
innerLine.width = innerLeftLineStartW;
innerLine.height = innerLeftLineStartH;
} else {
innerLine.x = innerRightLineStartX;
innerLine.rotation = innerRightLineStartR;
innerLine.width = innerRightLineStartW;
innerLine.height = innerRightLineStartH;
}
innerLine.progress = 0; // Reset progress property
};
self.update = function () {
var newTint = intensityHalf << 16 | intensityHalf << 8 | intensityHalf;
roadGraphics.tint = newTint; // Apply reduced tint to the road based on the intensity
leftLine.tint = newTint;
rightLine.tint = newTint;
// Add any update logic for the road if needed
for (var i = 0; i < self.innerLeftLines.length; i++) {
innerLineLeft = self.innerLeftLines[i];
innerLineLeft.tint = newTint;
var newSpeed = currentSpeed; // + 10 * innerLineLeft.progress;
innerLineLeft.y += newSpeed;
if (innerLineLeft.y > roadGraphics.height / 2) {
innerLineLeft.y = -roadGraphics.height / 2;
self.resetInnerLine(innerLineLeft, true);
} else {
innerLineLeft.progress = (innerLineLeft.y + roadGraphics.height / 2) / roadGraphics.height; // Update progress property
}
// Move innerLineLeft x progressively to innerLeftLineEndX
if (innerLineLeft.x != innerLeftLineEndX) {
innerLineLeft.x = innerLeftLineStartX + (innerLeftLineEndX - innerLeftLineStartX) * innerLineLeft.progress;
}
// Move innerLineLeft x progressively
if (innerLineLeft.rotation != innerLeftLineEndR) {
innerLineLeft.rotation = innerLeftLineStartR + (innerLeftLineEndR - innerLeftLineStartR) * innerLineLeft.progress;
}
// Move innerLineLeft x progressively
if (innerLineLeft.width != innerLeftLineEndW) {
//innerLineLeft.width = innerLeftLineStartW + (innerLeftLineEndW - innerLeftLineStartW) * innerLineLeft.progress;
}
// Move innerLineLeft x progressively
if (innerLineLeft.height != innerLeftLineEndH) {
//innerLineLeft.height = innerLeftLineStartH + (innerLeftLineEndH - innerLeftLineStartH) * innerLineLeft.progress;
}
}
for (var i = 0; i < self.innerRightLines.length; i++) {
innerLineRight = self.innerRightLines[i];
innerLineRight.tint = newTint;
var newSpeed = currentSpeed; //+ 10 * innerLineRight.progress;
innerLineRight.y += newSpeed;
if (innerLineRight.y > roadGraphics.height / 2) {
innerLineRight.y = -roadGraphics.height / 2;
self.resetInnerLine(innerLineRight, false);
} else {
innerLineRight.progress = (innerLineRight.y + roadGraphics.height / 2) / roadGraphics.height; // Update progress property
}
// Move innerLineRight x progressively to innerRightLineEndX
if (innerLineRight.x != innerRightLineEndX) {
innerLineRight.x = innerRightLineStartX + (innerRightLineEndX - innerRightLineStartX) * innerLineRight.progress;
}
// Move innerLineRight x progressively
if (innerLineRight.rotation != innerRightLineEndR) {
innerLineRight.rotation = innerRightLineStartR + (innerRightLineEndR - innerRightLineStartR) * innerLineRight.progress;
}
// Move innerLineRight x progressively
if (innerLineRight.width != innerRightLineEndW) {
//innerLineRight.width = innerRightLineStartW + (innerRightLineEndW - innerRightLineStartW) * innerLineRight.progress;
}
// Move innerLineRight x progressively
if (innerLineRight.height != innerRightLineEndH) {
//innerLineRight.height = innerRightLineStartH + (innerRightLineEndH - innerRightLineStartH) * innerLineRight.progress;
}
}
// Lamp posts
for (var i = 0; i < self.leftLampPosts.length; i++) {
var leftLampPost = self.leftLampPosts[i];
//leftLampPost.tint = newTint;
leftLampPost.y += currentSpeed;
if (leftLampPost.y > roadGraphics.height / 2) {
leftLampPost.y = -roadGraphics.height / 2;
}
leftLampPost.progress = (leftLampPost.y + roadGraphics.height / 2) / roadGraphics.height; // Update progress property
if (leftLampPost.x != leftLampEndX) {
leftLampPost.x = leftLampStartX + (leftLampEndX - leftLampStartX) * leftLampPost.progress;
}
}
for (var i = 0; i < self.rightLampPosts.length; i++) {
var rightLampPost = self.rightLampPosts[i];
//rightLampPost.tint = newTint;
rightLampPost.y += currentSpeed;
if (rightLampPost.y > roadGraphics.height / 2) {
rightLampPost.y = -roadGraphics.height / 2;
}
rightLampPost.progress = (rightLampPost.y + roadGraphics.height / 2) / roadGraphics.height; // Update progress property
if (rightLampPost.x != rightLampEndX) {
rightLampPost.x = rightLampStartX + (rightLampEndX - rightLampStartX) * rightLampPost.progress;
}
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 // Init game with black background
});
/****
* Game Code
****/
// Initialize arrays and variables
var isNight = false;
var background;
var coins = [];
var obstacles = [];
var road;
var score = 0;
var scoreTxt;
var startX = 0;
var startY = 0;
var endX = 0;
var endY = 0;
var maxSpeed = 50; // Define a maximum speed limit
var currentSpeed = 15; //20; // Initialize currentSpeed
var coinsCollected = 0; // Initialize coins collected counter
var isIntersectingObstacle = false; // Flag to track if the player is currently intersecting an obstacle
var playerPositionIndex = 1; // Initialize player position index
// Define the three fixed x positions for the player
var playerPositions = [2048 / 6, 2048 / 2, 5 * 2048 / 6];
// Create player
var player;
// Handle move events
game.down = function (x, y, obj) {
startX = x;
startY = y;
};
game.up = function (x, y, obj) {
endX = x;
endY = y;
var deltaX = endX - startX;
var deltaY = endY - startY;
if (Math.abs(deltaX) > Math.abs(deltaY)) {
if (deltaX > 0) {
// Swipe right
if (playerPositionIndex < 2) {
playerPositionIndex++;
}
} else {
// Swipe left
if (playerPositionIndex > 0) {
playerPositionIndex--;
}
}
} else {
if (deltaY < 0) {
// Swipe up
player.jump();
}
}
// Make the player move progressively to the next path
var targetX = playerPositions[playerPositionIndex];
var moveStep = (targetX - player.x) / 10;
var moveInterval = LK.setInterval(function () {
if (Math.abs(targetX - player.x) <= Math.abs(moveStep)) {
player.x = targetX;
LK.clearInterval(moveInterval);
} else {
player.x += moveStep;
}
}, 1000 / 60);
};
// Update game every tick
game.update = function () {
updateBackgroundColor();
// Update coins and check for collisions
for (var i = coins.length - 1; i >= 0; i--) {
if (player && player.shadow && player.shadow.intersects(coins[i]) && !player.isJumping) {
score += 1;
coinsCollected += 1; // Increment coins collected counter
scoreTxt.setText(score);
LK.effects.flashObject(player, 0xffd700, 500); // Flash gold for 0.5 seconds
coins[i].reset();
// Increase speed every 3 coins collected
if (coinsCollected % 3 === 0 && currentSpeed < maxSpeed) {
currentSpeed += 3; // Increase speed by 0.5
}
}
}
// Update obstacles and check for collisions
for (var i = obstacles.length - 1; i >= 0; i--) {
if (player && player.shadow && player.shadow.intersects(obstacles[i]) && !player.isJumping) {
if (!isIntersectingObstacle) {
// Make player flash red for 1 second
LK.effects.flashObject(player, 0xff0000, 1000);
// Add coin animation only if score is greater than 0
if (score > 0) {
var coinAnimation = new CoinAnimation();
coinAnimation.x = player.x;
coinAnimation.y = player.y;
game.addChild(coinAnimation);
}
// Reduce score by 1
score = Math.max(0, score - 1);
scoreTxt.setText(score);
isIntersectingObstacle = true; // Set the flag to true
}
} else {
isIntersectingObstacle = false; // Reset the flag when the intersection ends
}
}
// Removed continuous speed increase
};
// Initialize game
function gameInitialize() {
// Initialize arrays and variables
// Attach the background asset to the game
background = game.attachAsset('background', {
anchorX: 0.0,
anchorY: 0.0
});
game.addChild(background);
// Create and attach the road instance to the game
road = game.addChild(new Road());
road.x = 2048 / 2;
road.y = 2732 / 2;
score = 0;
scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
coins = [];
var newCoin = new Coin();
newCoin.reset();
coins.push(newCoin);
game.addChild(newCoin);
// Create a variable to store the current player position index
playerPositionIndex = 1;
// Create and attach the obstacle instance to the game
var newObstacle = new Obstacle();
newObstacle.reset();
obstacles.push(newObstacle);
game.addChild(newObstacle);
// Create player
player = game.addChild(new Player());
player.frame = 0;
player.x = playerPositions[playerPositionIndex]; // Start at the center position
player.y = 2732 - 300;
}
gameInitialize();
// Attach a debugMarker asset to the game at position (1000, 0)
var debugMarker = game.attachAsset('debugMarker', {
anchorX: 0.5,
anchorY: 0.5
});
debugMarker.x = 1024;
debugMarker.y = 10;
//debugMarker.x = 1024 - 370;
//debugMarker.y = 2732 - 10;
var intensity = 0;
var intensityHalf = 0;
function updateBackgroundColor() {
var time = new Date().getTime() * 0.0002;
intensity = Math.sin(time) * 127 + 128;
var color = intensity << 16 | intensity << 8 | intensity;
background.tint = color;
isNight = intensity < 128;
intensityHalf = 128 + Math.floor(intensity * 0.5);
}
var leftLampPosts = [];
var rightLampPosts = [];
Directly overhead, plumb view of a beggar heading top (we see his back).. Zenith view, directly overhead, plumb view. NOT PERSPECTIVE! Fantasy theme. Pixel art
a traffic cone. video game sprite
face view of a big start button in the shape of a dollar bill. video game style
a tree. video game style
a black garbage bag. video game style
Dollar bill. Perspective. video game sprite
perspective of a simple snake rolled up on itself.. video game sprite
Ball of dry desert bushes. video game sprite
tractor. high definition video game sprite
street ad billboard with 1 or 2 posts with "Get rich!" on it. high definition video game sprite
a dog sleeping on a street. video game sprite
desert bush. video game sprite
profile view of an empty motorcycle helmet. black with a white vertical central band and another thiner orange band on the center. NOT PERSPECTIVE!. Pixel art high definition
simple red and white magnet. video game style
gold sign with a "X" and a "2". video game style
bgMusic
Music
coin_1
Sound effect
hit_1
Sound effect
hit_2
Sound effect
hit_3
Sound effect
levelWin_1
Sound effect
car_1
Sound effect
police_1
Sound effect
ambulance_1
Sound effect
accident_1
Sound effect
killed_1
Sound effect
jump_1
Sound effect
rip_1
Sound effect
bonus_take
Sound effect
bonus_approaching
Sound effect