User prompt
Put cube_collapse in some columns instead of cube
User prompt
Fix Bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'attachAsset')' in or related to this line: 'var collapseGraphics = self.attachAsset('cube_collapse', {' Line Number: 23
User prompt
Put cube_collapse in some columns
User prompt
Fix Bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'update')' in or related to this line: 'var originalUpdate = self.update;' Line Number: 23
User prompt
Fix Bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'attachAsset')' in or related to this line: 'self.attachAsset('cube_collapse', {' Line Number: 23
User prompt
Put cube_collapse in some columns
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'attachAsset')' in or related to this line: 'self.attachAsset('cube_collapse', {' Line Number: 89
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'attachAsset')' in or related to this line: 'self.attachAsset('cube_collapse', {' Line Number: 89
User prompt
Put cube_collapse in some columns, cube_collapse must appear once every 30 seconds of the game.
User prompt
cube_collapse must necessarily appear once every 30 seconds of the game
User prompt
cube_collapse should appear once every 30 seconds of the game.
User prompt
cube_collapse should appear once every 30 seconds of the game.
User prompt
cube_collapse should appear once every 30 seconds of the game.
User prompt
cube_collapse should never occur in neighboring columns
User prompt
cube_collapse should never occur in neighboring columns
User prompt
modulus condition 13
User prompt
the appearance of cube_collapse should be more regular
User prompt
make the appearance of cube_collapse more rare but regular.
User prompt
Fix Bug: 'Uncaught ReferenceError: i is not defined' in or related to this line: 'game.lastCollapsiblePoleIndex = i;' Line Number: 44
User prompt
cube_collapse should never occur in neighboring columns
User prompt
Fix Bug: 'Uncaught ReferenceError: i is not defined' in or related to this line: 'game.lastCollapsiblePoleIndex = i;' Line Number: 44
User prompt
cube_collapse should never occur in neighboring columns
User prompt
Fix Bug: 'Uncaught ReferenceError: lastCollapsiblePoleIndex is not defined' in or related to this line: 'if (lastCollapsiblePoleIndex === -1 || lastCollapsiblePoleIndex !== poles.length - 1) {' Line Number: 41
User prompt
cube_collapse should never occur in neighboring columns
User prompt
cube_collapse must not occur in neighboring columns
/****
* Classes
****/
// Class for individual cubes that can fall
var Cube = Container.expand(function () {
var self = Container.call(this);
self.attachAsset('cube', {
anchorX: 0.5,
anchorY: 0.5
});
self.isFalling = false;
self.velocityY = 0; // Initial vertical velocity for falling cubes
self.update = function () {
if (self.isFalling) {
self.velocityY += 0.75; // Acceleration due to gravity increased by 50%
self.y += self.velocityY; // Fall speed with acceleration
}
};
});
// Class for the poles consisting of cubes
var Pole = Container.expand(function () {
var self = Container.call(this);
self.cubes = [];
self.addCube = function () {
var cube = new Cube();
cube.y = -(self.cubes.length * 100) - (self.cubes.length - 1) * 2;
self.addChild(cube);
self.cubes.push(cube);
};
self.makeCubesFall = function () {
for (var i = self.cubes.length - 1; i >= 0; i--) {
(function (index) {
LK.setTimeout(function () {
self.cubes[index].isFalling = true;
}, index * 250); // Delay between each cube falling
})(i);
}
};
self.isSliding = false;
self.slideDownUp = function () {
if (!self.isSliding) {
self.isSliding = true;
var initialY = self.y;
var step = 1;
var distance = 10;
var duration = 200;
var steps = duration / (1000 / 60);
var stepSize = distance / steps;
var currentStep = 0;
var slideInterval = LK.setInterval(function () {
if (currentStep < steps) {
self.y += stepSize;
currentStep++;
} else {
LK.clearInterval(slideInterval);
self.y = initialY;
self.isSliding = false;
}
}, 1000 / 60);
}
};
self.getHeight = function () {
return self.cubes.length * 100 + (self.cubes.length - 1) * 2;
};
});
// Class for the player's hero
var Hero = Container.expand(function () {
var self = Container.call(this);
var heroGraphics = self.attachAsset('hero', {
anchorX: 0.5,
anchorY: 0.5
});
self.isOnGround = false;
self.velocityY = 0;
self.jump = function () {
if (self.isOnGround) {
self.velocityY = -15;
self.isOnGround = false;
}
};
self.update = function () {
self.y += self.velocityY;
self.velocityY += 0.5; // Gravity effect
};
});
// Class for individual collapsing cubes
var CollapsingCube = Cube.expand(function () {
var self = Cube.call(this);
self.attachAsset('cube_collapse', {
anchorX: 0.5,
anchorY: 0.5
});
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 // Init game with black background
});
/****
* Game Code
****/
// Initialize important asset arrays
// Initialize assets used in the game.
var poles = [];
var hero;
// Time tracking for cube_collapse
var lastCollapseTime = 0;
// Create the hero
hero = game.addChild(new Hero());
hero.x = 2048 / 2;
hero.y = 2732 - 150; // Start above the bottom of the screen
// Create initial poles
function createInitialPoles() {
var poleSpacing = 2;
var poleWidth = 100 + poleSpacing;
var numPoles = Math.ceil(2048 / poleWidth);
for (var i = 0; i < numPoles; i++) {
var pole = game.addChild(new Pole());
pole.x = i * poleWidth;
pole.y = 2732 - 50; // Align base of pole with bottom of the screen and raise by 50 pixels
for (var j = 0; j < 10; j++) {
// Add 10 cubes to each pole to make them higher
pole.addCube();
}
poles.push(pole);
}
}
createInitialPoles();
// Event listener for jump action
game.on('down', function (obj) {
hero.jump();
});
// Game tick update
LK.on('tick', function () {
// Check if 30 seconds have passed to add a collapsing cube
if (LK.ticks - lastCollapseTime >= 1800) {
// 30 seconds at 60FPS
var randomPoleIndex = Math.floor(Math.random() * poles.length);
var randomPole = poles[randomPoleIndex];
var collapsingCube = new CollapsingCube();
collapsingCube.y = -(randomPole.cubes.length * 100) - (randomPole.cubes.length - 1) * 2;
randomPole.addChild(collapsingCube);
randomPole.cubes.push(collapsingCube);
lastCollapseTime = LK.ticks;
}
hero.update();
// Collision detection with poles
for (var i = 0; i < poles.length; i++) {
var pole = poles[i];
if (hero.intersects(pole) && hero.velocityY > 0 && hero.y + hero.height / 2 < pole.y) {
hero.y = pole.y - pole.getHeight() - hero.height / 2;
hero.isOnGround = true;
hero.velocityY = 0;
pole.slideDownUp();
}
}
// Remove off-screen poles and create new ones
var poleSpacing = 2;
var poleWidth = 100 + poleSpacing;
if (poles.length > 0 && poles[0].x + poleWidth / 2 < 0) {
poles[0].destroy();
poles.shift();
var newPole = game.addChild(new Pole());
newPole.x = poles[poles.length - 1].x + poleWidth;
newPole.y = 2732 - 50;
var prevPoleHeight = poles[poles.length - 1].cubes.length;
var minCubes = Math.max(6, prevPoleHeight - 1);
var maxCubes = Math.min(14, prevPoleHeight + 1);
var cubesCount = Math.floor(Math.random() * (maxCubes - minCubes + 1)) + minCubes;
for (var j = 0; j < cubesCount; j++) {
newPole.addCube();
}
poles.push(newPole);
}
// Move poles to the left to simulate hero running and make cubes fall after passing the middle
for (var i = 0; i < poles.length; i++) {
poles[i].x -= 5;
if (poles[i].x < 2048 / 2 && !poles[i].hasMadeCubesFall) {
poles[i].makeCubesFall();
poles[i].hasMadeCubesFall = true;
}
// Update each cube in the pole
for (var j = 0; j < poles[i].cubes.length; j++) {
poles[i].cubes[j].update();
}
}
}); ===================================================================
--- original.js
+++ change.js
@@ -1,22 +1,7 @@
/****
* Classes
****/
-var CollapsibleCube = Container.expand(function () {
- var self = Container.call(this);
- self.attachAsset('cube_collapse', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.isFalling = false;
- self.velocityY = 0; // Initial vertical velocity for falling cubes
- self.update = function () {
- if (self.isFalling) {
- self.velocityY += 0.75; // Acceleration due to gravity
- self.y += self.velocityY; // Fall speed with acceleration
- }
- };
-});
// Class for individual cubes that can fall
var Cube = Container.expand(function () {
var self = Container.call(this);
self.attachAsset('cube', {
@@ -32,29 +17,13 @@
}
};
});
// Class for the poles consisting of cubes
-var Pole = Container.expand(function (index) {
+var Pole = Container.expand(function () {
var self = Container.call(this);
- self.index = index;
self.cubes = [];
self.addCube = function () {
- var cube;
- if (game.lastCollapsiblePoleIndices === undefined) {
- game.lastCollapsiblePoleIndices = [];
- }
- var canBeCollapsible = game.lastCollapsiblePoleIndices.length < 2 || self.index > game.lastCollapsiblePoleIndices[game.lastCollapsiblePoleIndices.length - 1] + 1 && self.index > game.lastCollapsiblePoleIndices[game.lastCollapsiblePoleIndices.length - 2] + 1;
- var timeSinceLastCollapse = game.elapsedTime - game.lastCollapseTime;
- if (canBeCollapsible && timeSinceLastCollapse >= 30) {
- cube = new CollapsibleCube();
- game.lastCollapsiblePoleIndices.push(self.index);
- game.lastCollapseTime = game.elapsedTime; // Update the last collapse time
- if (game.lastCollapsiblePoleIndices.length > 2) {
- game.lastCollapsiblePoleIndices.shift();
- }
- } else {
- cube = new Cube();
- }
+ var cube = new Cube();
cube.y = -(self.cubes.length * 100) - (self.cubes.length - 1) * 2;
self.addChild(cube);
self.cubes.push(cube);
};
@@ -113,27 +82,33 @@
self.y += self.velocityY;
self.velocityY += 0.5; // Gravity effect
};
});
+// Class for individual collapsing cubes
+var CollapsingCube = Cube.expand(function () {
+ var self = Cube.call(this);
+ self.attachAsset('cube_collapse', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+});
/****
* Initialize Game
****/
var game = new LK.Game({
- backgroundColor: 0x000000,
- // Init game with black background
- elapsedTime: 0,
- // Track elapsed time in the game
- lastCollapseTime: 0 // Track the last time a 'cube_collapse' was added
+ backgroundColor: 0x000000 // Init game with black background
});
/****
* Game Code
****/
-// Initialize assets used in the game.
// Initialize important asset arrays
+// Initialize assets used in the game.
var poles = [];
var hero;
+// Time tracking for cube_collapse
+var lastCollapseTime = 0;
// Create the hero
hero = game.addChild(new Hero());
hero.x = 2048 / 2;
hero.y = 2732 - 150; // Start above the bottom of the screen
@@ -142,9 +117,9 @@
var poleSpacing = 2;
var poleWidth = 100 + poleSpacing;
var numPoles = Math.ceil(2048 / poleWidth);
for (var i = 0; i < numPoles; i++) {
- var pole = game.addChild(new Pole(i));
+ var pole = game.addChild(new Pole());
pole.x = i * poleWidth;
pole.y = 2732 - 50; // Align base of pole with bottom of the screen and raise by 50 pixels
for (var j = 0; j < 10; j++) {
// Add 10 cubes to each pole to make them higher
@@ -159,10 +134,19 @@
hero.jump();
});
// Game tick update
LK.on('tick', function () {
- // Increment the elapsed time by the time since the last tick (1/60th of a second)
- game.elapsedTime += 1 / 60;
+ // Check if 30 seconds have passed to add a collapsing cube
+ if (LK.ticks - lastCollapseTime >= 1800) {
+ // 30 seconds at 60FPS
+ var randomPoleIndex = Math.floor(Math.random() * poles.length);
+ var randomPole = poles[randomPoleIndex];
+ var collapsingCube = new CollapsingCube();
+ collapsingCube.y = -(randomPole.cubes.length * 100) - (randomPole.cubes.length - 1) * 2;
+ randomPole.addChild(collapsingCube);
+ randomPole.cubes.push(collapsingCube);
+ lastCollapseTime = LK.ticks;
+ }
hero.update();
// Collision detection with poles
for (var i = 0; i < poles.length; i++) {
var pole = poles[i];
girl sitting on Wrecking Ball, cartoon style.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
construction cranes on the sides of the frame, depth of field blur, cartoon style, black and white. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
"ALARM" text bubble, comic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
the surface is gray, concrete with a black square in the center. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Wrecking Ball with eyes, cartoon style.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
the surface is red, concrete with a black square in the center.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
"ALARM" text bubble yellow, comic book style.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
the surface is yellow, concrete with a black square in the center. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.