User prompt
when bonus reaches 1st target then it moves toward the player while decreasing width and height to 10
Code edit (1 edits merged)
Please save this source code
User prompt
Animate bonus : move to road x,y while increasing width and height to 1024
Code edit (7 edits merged)
Please save this source code
User prompt
in startBonusAnimation add a green screen flash
User prompt
play startButon audio when start button pressed
User prompt
replace this code ``` for (var i = 0; i < road.segments.length; i++) { var segment = road.segments[i]; for (var j = 0; j < segment.background.children.length; j++) { var child = segment.background.children[j]; log("child[".concat(i, "][").concat(j, "]"), child); if (child.taken) { log("IS TAKEN : ", child); child.children[0].alpha = 0; } } } ```` to search for taken property in game children because when taken objects are deteched from road to game
Code edit (2 edits merged)
Please save this source code
User prompt
fix : ``` for (var i = 0; i < roadContainer.children.length; i++) { var child = roadContainer.children[i]; if (child.taken) { child.alpha = 0; } } ``` becaus detritus are attached to background property of roadsegment that are in road.segments array
Code edit (1 edits merged)
Please save this source code
User prompt
in startBonusAnimation, set alpha of all taken detritus to 0
Code edit (4 edits merged)
Please save this source code
User prompt
in startBonusAnimation, play bonus start sound and create a bonus asset at the recycleBin position
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
in Starfield add a property 'direction' to star, then use it to make star alpha change from 0 to 1 and vice versa
User prompt
update this : self.update = function () { for (var i = 0; i < self.children.length; i++) { var star = self.children[i]; if (Math.random() < 0.01) { // 1% chance to animate each star per frame star.alpha = 0.5 + 0.5 * Math.sin(LK.ticks / 30 + i); // Animate alpha from 0.5 to 1.0 } } }; to use this algotithm: Every 3 sec, select 10 stars randomly, then for this selected stars animate alpha from 0 to 1 and vice versa
Code edit (10 edits merged)
Please save this source code
User prompt
in starfield, animate alpha of random stars
User prompt
animate star field by animating alpha of random stars
Code edit (1 edits merged)
Please save this source code
Code edit (5 edits merged)
Please save this source code
User prompt
add a new global function isActive() that returns isStarted && !isBonusStartAnim && !player.isDead
Code edit (2 edits merged)
Please save this source code
User prompt
Make detritus rotate on themselves when taken
===================================================================
--- original.js
+++ change.js
@@ -71,15 +71,15 @@
scaleY: scale
});
self.taken = false;
self.update = function () {
- console.log("player.sliding:", player.sliding);
+ log("player.sliding:", player.sliding);
if (!player.sliding && player.body.torso.intersects(self)) {
player.hitWall = true;
player.sliding = true; // Keep down
player.isDead = true;
tintPlayer(0x666666);
- console.log("Player hit a wall!");
+ log("Player hit a wall!");
// Flash screen red for 1 second (1000ms) to show we are dead.
LK.effects.flashScreen(0xff0000, 1000);
// Play lose sound
LK.getSound('lose').play();
@@ -184,9 +184,9 @@
object.rotation = (obj.rotation || 0) + 0;
parent.addChild(object);
}
function generateBackground() {
- console.log(self.distance);
+ log(self.distance);
background.removeChildren();
self.isRiver = false;
self.isWall = false;
self.segmentRiver.visible = false;
@@ -335,9 +335,9 @@
self.fadeout = false;
rescale();
}
function update() {
- if (!isStarted) {
+ if (!isActive()) {
return;
}
if (self.fadeout && self.alpha > 0) {
if ((self.alpha -= ROAD_SEGMENT_FADEOUT) < 0) {
@@ -421,8 +421,11 @@
self.getNode = getNode;
self.getNodeDist = getNodeDist;
;
function rotate(speed) {
+ if (!isActive()) {
+ return;
+ }
self.rotation -= speed;
var newDestroyIndex = getIndex(ROAD_SEGMENT_DESTROY);
var newRegenerateIndex = getIndex(20); // TEMP
if (newDestroyIndex >= 0 && newDestroyIndex !== destroyIndex && !segments[newDestroyIndex].fadeout) {
@@ -665,14 +668,11 @@
self.slideStart = slideStart;
self.slideEnd = slideEnd;
;
function update() {
- if (!isStarted) {
+ if (!isActive()) {
return;
}
- if (self.isDead) {
- return;
- }
var nextNode = road.getNode(1);
var currentNode = nextNode.previous;
// Update horizontal movement
var outputSpeed = PLAYER_SPEED_BASE * speedFactor;
@@ -708,11 +708,11 @@
}
// TOOD: Get new node if applicable
// Update vertical movement
if (jumping) {
- console.log("speedFactor", speedFactor, "outputSpeed", outputSpeed);
+ log("speedFactor", speedFactor, "outputSpeed", outputSpeed);
jumpStep += aerialSpeed * speedFactor;
- //console.log("jumpAction:", jumpAction, "jumpStep:", jumpStep, "PLAYER_JUMP_STEP_MIN:", PLAYER_JUMP_STEP_MIN, "PLAYER_JUMP_STEP_MAX:", PLAYER_JUMP_STEP_MAX);
+ //log("jumpAction:", jumpAction, "jumpStep:", jumpStep, "PLAYER_JUMP_STEP_MIN:", PLAYER_JUMP_STEP_MIN, "PLAYER_JUMP_STEP_MAX:", PLAYER_JUMP_STEP_MAX);
if (!jumpAction && jumpStep <= PLAYER_JUMP_STEP_MIN || jumpStep >= PLAYER_JUMP_STEP_MAX) {
falling = true;
jumping = false;
jumpAction = false;
@@ -724,9 +724,9 @@
falling = true;
body.pushAnimation(animationJump, PLAYER_POSE_TRANSITION);
}
step += aerialSpeed;
- //console.log("falling", falling, "step:", step, "currentNode.step:", currentNode.step);
+ //log("falling", falling, "step:", step, "currentNode.step:", currentNode.step);
if (falling && step <= currentNode.step) {
step = currentNode.step;
falling = false;
aerialSpeed = 0;
@@ -765,9 +765,9 @@
if (currentSegment.isRiver && !jumping && !falling && !jumpAction) {
self.isDead = true;
tintPlayer(0xff0000);
// Player is above a river segment
- console.log("Player fell in the river!");
+ log("Player fell in the river!");
// Flash screen red for 1 second (1000ms) to show we are dead.
LK.effects.flashScreen(0xff0000, 1000);
// Play lose sound
LK.getSound('lose').play();
@@ -800,9 +800,9 @@
// Flip the body horizontally to ensure correct orientation
body.scale.x *= -1;
// Play slide sound (if available)
// LK.getSound('slide').play();
- */
+ */
}
}
function slideEnd() {
if (self.sliding && !self.hitWall) {
@@ -855,9 +855,9 @@
scaleX: Math.random() < 0.5 ? -scale : scale,
scaleY: scale
});
self.update = function () {
- if (!isStarted) {
+ if (!isActive()) {
return;
}
if (self.taken) {
var targetX = recycleBin.x;
@@ -896,8 +896,16 @@
self.parent.removeChild(self);
game.addChildAt(self, game.getChildIndex(recycleBin));
self.position = game.toLocal(globalPosition);
LK.getSound('collectDetritus').play();
+ if (!isBonusActive) {
+ nbCollectedBeforeBonus++;
+ }
+ if (nbCollectedBeforeBonus > BONUS_COLLECT_THRESHOLD) {
+ log("Gained Bonus !!!");
+ nbCollectedBeforeBonus = 0;
+ isBonusActive = true;
+ }
} else {
self.rotation += 0.05 + (Math.random() - 0.25) * 0.1;
}
};
@@ -915,8 +923,11 @@
scaleY: scale
});
self.taken = false;
self.update = function () {
+ if (!isActive()) {
+ return;
+ }
if (self.taken) {
var targetX = recycleBin.x;
var targetY = recycleBin.y;
var startX = player.x;
@@ -1024,24 +1035,33 @@
;
buildTextAssets(text);
return self;
});
+var Star = Container.expand(function () {
+ var self = Container.call(this);
+ var starGraphics = self.attachAsset('circle', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.alphaSpeed = Math.random() * 0.02 + 0.01; // Random alpha speed between 0.01 and 0.03
+ self.alphaDirection = Math.random() < 0.5 ? 1 : -1; // Random initial direction
+ self.update = function () {
+ starGraphics.alpha += self.alphaSpeed * self.alphaDirection;
+ if (starGraphics.alpha <= 0 || starGraphics.alpha >= 1) {
+ self.alphaDirection *= -1; // Reverse direction at bounds
+ }
+ };
+ return self;
+});
var Starfield = Container.expand(function (config) {
var self = Container.call(this);
config = config || {};
var starCount = config.starCount || 100;
- var starColor = config.starColor || 0xFFFFFF;
- var starSize = config.starSize || 2;
for (var i = 0; i < starCount; i++) {
- var star = self.attachAsset('circle', {
- width: starSize,
- height: starSize,
- color: starColor,
- x: Math.random() * GAME_WIDTH,
- y: Math.random() * GAME_HEIGHT,
- anchorX: 0.5,
- anchorY: 0.5
- });
+ var star = new Star();
+ star.x = Math.random() * GAME_WIDTH;
+ star.y = Math.random() * GAME_HEIGHT;
+ self.addChild(star);
}
return self;
});
var StartButton = Container.expand(function () {
@@ -1096,11 +1116,10 @@
/****
* Game Code
****/
-function isActive() {
- return isStarted && !isBonusStartAnim && !player.isDead;
-}
+var isDebug = true;
+var _console = console;
var isStarted = false;
var isBonusStartAnim = false;
var isBonusActive = false;
//==============================================================================
@@ -1231,9 +1250,9 @@
y: road.y - TEXT_DEFAULT_SIZE,
anchorX: 0.5,
anchorY: 1
}));
-var scoreText = game.addChild(new BorderedText('0000.00', {
+var scoreText = game.addChild(new BorderedText('0.00kg', {
x: road.x,
y: road.y,
size: TEXT_DEFAULT_SIZE * 1.2,
anchorX: 0.5,
@@ -1282,13 +1301,13 @@
;
var startButton = game.addChild(new StartButton());
startButton.x = GAME_WIDTH / 2;
startButton.y = road.y;
-/*
-var boilingLava = game.addChild(new BoilingLava());
-boilingLava.x = 600;
-boilingLava.y = 600;
-*/
+game.update = function () {
+ for (var i = 0; i < starfield.children.length; i++) {
+ starfield.children[i].update();
+ }
+};
//==============================================================================
// Global events
//==============================================================================
;
@@ -1320,12 +1339,22 @@
// Global functions
//==============================================================================
;
// Helpers
+function log() {
+ if (isDebug) {
+ _console.log.apply(_console, arguments);
+ }
+}
+;
+function isActive() {
+ return isStarted && !isBonusStartAnim && !player.isDead;
+}
+;
function callGameOver(lost) {
gameOver = true;
winningTime = LK.ticks;
- LK.setScore(score);
+ LK.setScore(score + kgCollected * 100);
LK.stopMusic();
winningText.setText(lost ? 'Oh no!' : 'Congratulations!');
// Check if winningTime is set and show game over screen after 60 ticks
game.update = function () {
white
circle sliced into many pieces, flat image. 2d, white background, shadowless.
pixel art of a tall, tree. game asset, 2d, white background, shadowless.
pixel art cloud. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
dark space.
flying lava bubble. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a bonus crystal ball with the recycle symbol. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
top view A green round start button empty in the center like a ring.