Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: obstacleManager is not defined' in or related to this line: 'obstacleManager.setPathOccupied(self.pathIndex, false); // Mark the path as unoccupied' Line Number: 481
User prompt
now create a ObstacleManager class that will be responsible of handling Obstacles path and active state globally
User prompt
add a propery active to Obstacle class
User prompt
obstacles spawn configuration is always the same, randomize it in order to have sometimes 1 obstacle, sometimes 2 spawned at same time (not same path)
User prompt
obstacles configuration is always the same, randomize it
User prompt
using index property of obstacles and reset() function, invent a way to avoid having 2 obstacles spwaned on the same path at the same time
User prompt
use baseNbObstacles to loop on obstacles spawn
User prompt
add a global baseNbObstacles = 5
User prompt
add a global baseNbCoins and use it instead of 5
User prompt
store the index in a property of Obstacle class
User prompt
also pass and index to Obstacle constructor
Code edit (3 edits merged)
Please save this source code
User prompt
pass an index to Coin constructor
User prompt
coin value is in $; in level 1 coinValue is 0.10$; adapt increaseScore to display score in ¢ when <1$ then round then in $ and ¢ when <10$ then rounded in $
Code edit (1 edits merged)
Please save this source code
User prompt
also move coinsCollected +=1 inside increase score
User prompt
now use increaseScore function instead of mannual increase
User prompt
add new global function increaseScore(); it add coinValue of currentLevel to the score
Code edit (1 edits merged)
Please save this source code
Code edit (23 edits merged)
Please save this source code
User prompt
add a global array levelConfigs that contains an object for each level. each object is the config of a level and have the following properties : name, coinValue, baseSpeed
Code edit (1 edits merged)
Please save this source code
Code edit (2 edits merged)
Please save this source code
User prompt
in decoration reset log // Add left & right startX & endX here
===================================================================
--- original.js
+++ change.js
@@ -44,10 +44,10 @@
var tempSpeed = currentSpeed * 0.05 + currentSpeed * (self.progress * 3);
newSpeed = tempSpeed;
self.y += newSpeed;
// Move innerLineLeft x progressively to innerLeftLineEndX
- if (self.pathIndex == 0 && self.x != self.leftEndX) {
- self.x = self.leftStartX + (self.leftEndX - self.leftStartX) * self.progress;
+ 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;
}
@@ -148,10 +148,10 @@
var rand = Math.random();
self.leftStartX = baseLeftStartX; // - rand * xOffset;
self.leftEndX = self.leftStartX - xOffset * (1.5 + rand);
var baseRightStartX = 1280;
- var rightStartX = baseRightStartX; // + rand * xOffset / 2;
- var rightEndX = rightStartX + xOffset * (1.5 + rand);
+ self.rightStartX = baseRightStartX; // + rand * xOffset / 2;
+ self.rightEndX = self.rightStartX + xOffset * (1.5 + rand);
self.assetWidthRatios = [100 / 300, 1];
self.endSizes = [600, 600];
var startSize = 1;
self.assetIndex = Math.floor(Math.random() * self.assets.length);
@@ -172,21 +172,22 @@
self.progress = Math.max(0, self.y - startY) / (endY - startY); // Update progress property
// Move innerLineLeft x progressively to innerLeftLineEndX
if (self.index == 7) {
//console.log("Decoration " + self.index + " update - p=", self.progress, "x:", Math.round(self.x), "y:", Math.round(self.y));
+ //console.log(self.progress);
}
if (self.pathIndex == 0 && self.x > self.leftEndX) {
- self.x = self.leftStartX + (self.leftEndX - self.leftStartX) * self.progress;
+ self.x = self.leftStartX + (self.leftEndX - self.leftStartX) * self.progress * 3;
}
- if (self.pathIndex == 1 && self.x < rightEndX) {
- self.x = rightStartX + (rightEndX - rightStartX) * self.progress;
+ if (self.pathIndex == 1 && self.x < self.rightEndX) {
+ self.x = self.rightStartX + (self.rightEndX - self.rightStartX) * self.progress * 3;
}
if (self.y > endY + self.endSizes[self.assetIndex] / 2) {
//self.y = -startSize; // Move obstacle back to the top
self.reset();
}
//mainGraphics = self.assets[self.assetIndex];
- mainGraphics.height = startSize + (self.endSizes[self.assetIndex] - startSize) * self.progress;
+ mainGraphics.height = startSize + (self.endSizes[self.assetIndex] - startSize) * self.progress * 2;
mainGraphics.width = mainGraphics.height * self.assetWidthRatios[self.assetIndex];
if (self.index == 8 && mainGraphics.width > 200) {
//console.log("Decoration " + self.index + " update - assetIndex:", self.assetIndex, "width:", mainGraphics.width, "x:", Math.round(self.x), "y:", Math.round(self.y));
}
@@ -219,21 +220,21 @@
if (self.index == 1 && mainGraphics.width > 200) {
//console.log("=== Decoration " + self.index + " reset - assetIndex:", self.assetIndex, "width:", mainGraphics.width, "y:", self.y, " ===");
}
self.leftStartX = baseLeftStartX; // - rand * xOffset;
- self.leftEndX = self.leftStartX - xOffset * (0.5 + rand);
- rightStartX = baseRightStartX; // + rand * xOffset;
- rightEndX = rightStartX + xOffset * (0.5 + rand);
+ self.leftEndX = self.leftStartX - xOffset * (1 + rand);
+ self.rightStartX = baseRightStartX; // + rand * xOffset;
+ self.rightEndX = self.rightStartX + xOffset * (1 + rand);
if (self.index == 1) {
console.log("=== Decoration " + self.index);
console.log("Left StartX:", self.leftStartX, "Left EndX:", self.leftEndX);
- console.log("Right StartX:", rightStartX, "Right EndX:", rightEndX);
+ console.log("Right StartX:", self.rightStartX, "Right EndX:", self.rightEndX);
}
self.pathIndex = Math.floor(rand * 2);
if (self.pathIndex === 0) {
self.x = self.leftStartX;
} else {
- self.x = rightStartX;
+ self.x = self.rightStartX;
}
self.ready = true;
};
});
@@ -246,9 +247,9 @@
anchorX: 0.5,
anchorY: 0.5
});
var speed = 5;
- var startY = roadTop - 1;
+ var startY = roadTop - 20;
var endY = startY + roadHeight;
var leftStartX = 1024 - 100;
var leftEndX = 1024 - 650;
var rightStartX = 1024 + 100;
@@ -287,10 +288,10 @@
self.progress = Math.max(0, self.y - startY) / (endY - startY);
killerGraphics.width = startSize + (endSize - startSize) * self.progress;
debugTxt.setText(self.progress.toFixed(2));
killerGraphics.height = assetHeightRatio * killerGraphics.width;
- var tempSpeed = currentSpeed * 0.5 + currentSpeed * (self.progress * 5);
- var newSpeed = currentSpeed * 5;
+ var tempSpeed = currentSpeed * 0.5 + currentSpeed * (self.progress * 3);
+ var newSpeed = currentSpeed * 3;
newSpeed = tempSpeed * 1;
self.y += newSpeed;
if (self.pathIndex == 0 && self.x != leftEndX) {
self.x = leftStartX + (leftEndX - leftStartX) * self.progress;
@@ -857,40 +858,21 @@
/****
* Game Code
****/
-function _toConsumableArray(r) {
- return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
-}
-function _nonIterableSpread() {
- throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
-}
-function _unsupportedIterableToArray(r, a) {
- if (r) {
- if ("string" == typeof r) {
- return _arrayLikeToArray(r, a);
- }
- var t = {}.toString.call(r).slice(8, -1);
- return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
- }
-}
-function _iterableToArray(r) {
- if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) {
- return Array.from(r);
- }
-}
-function _arrayWithoutHoles(r) {
- if (Array.isArray(r)) {
- return _arrayLikeToArray(r);
- }
-}
-function _arrayLikeToArray(r, a) {
- (null == a || a > r.length) && (a = r.length);
- for (var e = 0, n = Array(a); e < a; e++) {
- n[e] = r[e];
- }
- return n;
-}
+var levelConfigs = [{
+ name: "Level 1",
+ coinValue: 1,
+ baseSpeed: 10
+}, {
+ name: "Level 2",
+ coinValue: 5,
+ baseSpeed: 15
+}, {
+ name: "Level 3",
+ coinValue: 10,
+ baseSpeed: 20
+}];
var stripes = [];
var nbDecorations = 10;
var decorations = [];
// Initialize arrays and variables
@@ -940,9 +922,9 @@
function easeInOutQuad(t) {
return t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t;
}
function updateBackgroundColor() {
- var time = new Date().getTime() * 0.0002;
+ var time = 1000 + new Date().getTime() * 0.0002;
intensity = Math.sin(time) * 127 + 128;
var color = Math.max(32, intensity) << 16 | Math.max(32, intensity) << 8 | Math.max(32, intensity);
background.tint = color;
isNight = intensity < 128;
@@ -1042,10 +1024,8 @@
// Create and attach the road instance to the game
road = game.addChild(new Road());
road.x = 2048 / 2;
road.y = 0;
- // Create and attach the landscape instance to the game
- var landscape = game.addChild(new Landscape());
score = 0;
scoreTxt = new Text2(currentLevel == 1 ? '0¢' : '$0', {
size: 150,
fill: "#ffffff",
@@ -1081,8 +1061,16 @@
player = game.addChild(new Player());
player.frame = 0;
player.x = playerPositions[playerPositionIndex]; // Start at the center position
player.y = playerBaseY;
+ // Create and attach the landscape instance to the game
+ var landscape = game.addChild(new Landscape());
+ var startButton = game.addChild(new StartButton());
+ startButton.x = 2048 / 2;
+ startButton.y = 2732 / 4;
+ // TEMP DEBUG !!!
+ startButton.width = 100;
+ startButton.height = 100;
// Attach a debugMarker asset to the game at position (1000, 0)
debugMarker = game.attachAsset('debugMarker', {
anchorX: 0.5,
anchorY: 0.5
@@ -1094,14 +1082,8 @@
fill: "#ff0000"
});
debugTxt.anchor.set(1, 1); // Set anchor to the bottom right corner
LK.gui.bottomRight.addChild(debugTxt);
- var startButton = game.addChild(new StartButton());
- startButton.x = 2048 / 2;
- startButton.y = 2732 / 4;
- // TEMP DEBUG !!!
- startButton.width = 100;
- startButton.height = 100;
isPlaying = false;
}
gameInitialize();
for (var i = 0; i < stripes.length; i++) {
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