Code edit (15 edits merged)
Please save this source code
User prompt
in road class , add a resertInnerLine function that take the innerLine and and boolean argument for left or right
Code edit (4 edits merged)
Please save this source code
User prompt
replace currentSpeed += 0.005; to handle a max
Code edit (1 edits merged)
Please save this source code
User prompt
add a max to player frame anim speed to avoid optical effects
User prompt
update how player animation is related to currentSpeed because currently the player anim isn't regular (it works only for certain values of speed). make it work all the time
Code edit (1 edits merged)
Please save this source code
Code edit (5 edits merged)
Please save this source code
User prompt
make currentSpeed increase over time
Code edit (4 edits merged)
Please save this source code
User prompt
make player frame animation depend on currentSpeed
Code edit (3 edits merged)
Please save this source code
User prompt
add a new global currentSpeed
User prompt
change move system from tap to swipe (swipe left => go left; swipe right> go right)
Code edit (4 edits merged)
Please save this source code
User prompt
in coin make w & h go from startSize to endSize following progress (like x)
Code edit (1 edits merged)
Please save this source code
Code edit (3 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: innerLeftLineEndX is not defined' in or related to this line: 'if (self.x != innerLeftLineEndX) {' Line Number: 37
Code edit (5 edits merged)
Please save this source code
User prompt
like in road, add a progress to Coin
Code edit (3 edits merged)
Please save this source code
User prompt
if coin is on left or right path, add leftStartOffsetX or rightStartOffsetX to ts x
Code edit (8 edits merged)
Please save this source code
/****
* 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', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
self.y += 5; // Move coin downwards
if (self.y > 2732) {
self.reset();
}
};
self.reset = function () {
self.y = -50;
self.x = playerPositions[Math.floor(Math.random() * playerPositions.length)];
};
});
// Player class
var Player = Container.expand(function () {
var self = Container.call(this);
var playerShadow = self.attachAsset('playerShadow', {
anchorX: 0.5,
anchorY: 0.5
});
playerShadow.alpha = 0.5; // Make the shadow semi-transparent
playerShadow.y = 270; // Offset the shadow slightly below the player
var playerGraphics1 = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
var playerGraphics2 = self.attachAsset('player2', {
anchorX: 0.5,
anchorY: 0.5
});
playerGraphics2.visible = false; // Initially hide player2 asset
var frame = 0;
self.update = function () {
frame++;
if (frame % 10 === 0) {
// Swap frames every 10 game ticks
var visible = playerGraphics1.visible;
playerGraphics1.visible = !visible;
playerGraphics2.visible = visible;
}
};
});
// Road class
var Road = Container.expand(function () {
var self = Container.call(this);
var roadGraphics = self.attachAsset('road', {
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;
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 = [];
for (var i = 0; i < 5; 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);
}
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.update = function () {
// Add any update logic for the road if needed
for (var i = 0; i < self.innerLeftLines.length; i++) {
innerLineLeft = self.innerLeftLines[i];
var newSpeed = speed + (10 - speed) * innerLineLeft.progress;
innerLineLeft.y += newSpeed;
if (innerLineLeft.y > roadGraphics.height / 2) {
innerLineLeft.y = -roadGraphics.height / 2;
innerLineLeft.x = innerLeftLineStartX;
innerLineLeft.rotation = innerLeftLineStartR;
innerLineLeft.width = innerLeftLineStartW;
innerLineLeft.height = innerLeftLineStartH;
innerLineLeft.progress = 0; // Reset progress property
} 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];
var newSpeed = speed + (10 - speed) * innerLineRight.progress;
innerLineRight.y += newSpeed;
if (innerLineRight.y > roadGraphics.height / 2) {
innerLineRight.y = -roadGraphics.height / 2;
innerLineRight.x = innerRightLineStartX;
innerLineRight.rotation = innerRightLineStartR;
innerLineRight.width = innerRightLineStartW;
innerLineRight.height = innerRightLineStartH;
innerLineRight.progress = 0; // Reset progress property
} 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;
}
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 // Init game with black background
});
/****
* Game Code
****/
// Initialize arrays and variables
var coins = [];
var road;
var score = 0;
var scoreTxt;
// 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) {
// If tap is on the left half of the screen, move player to the left
if (x < 2048 / 2) {
if (playerPositionIndex > 0) {
playerPositionIndex--;
}
} else {
// If tap is on the right half of the screen, move player to the right
if (playerPositionIndex < 2) {
playerPositionIndex++;
}
}
// 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 () {
// Update coins and check for collisions
for (var i = coins.length - 1; i >= 0; i--) {
if (player.intersects(coins[i])) {
score += 1;
scoreTxt.setText(score);
coins[i].reset();
}
}
};
// Initialize game
function gameInitialize() {
// Initialize arrays and variables
// Attach the background asset to the game
var background = game.attachAsset('background', {
anchorX: 0.0,
anchorY: 0.0
});
// 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 player
player = game.addChild(new Player());
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;
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