Code edit (2 edits merged)
Please save this source code
User prompt
Create an interface class that handles the score. It should contain the scoreTxt variable, and should have an increment function that takes in a value
Code edit (1 edits merged)
Please save this source code
User prompt
check if the squash target is a player
Code edit (9 edits merged)
Please save this source code
User prompt
boxes have an empty squash function that takes in a bool
User prompt
boxes have an activate function which takes in a bool
Code edit (1 edits merged)
Please save this source code
User prompt
clamp the new targetColumn value in the player's move function between 0 and NUM_COLUMNS
Code edit (10 edits merged)
Please save this source code
User prompt
remove the debug console.logs in the player
Code edit (1 edits merged)
Please save this source code
Code edit (3 edits merged)
Please save this source code
User prompt
Fix Bug: 'ReferenceError: COLUMN_WIDTH is not defined' in this line: 'columns.push(new Column(self, i * COLUMN_WIDTH, 0));' Line Number: 121
User prompt
Replace any and all occurances of `COLUMN_WIDTH` with `BOX_SIZE`
Code edit (1 edits merged)
Please save this source code
Code edit (9 edits merged)
Please save this source code
User prompt
columns have a `count` variable which increases by one every time a box is spawned. Additionally, created boxes take in a 4th parameter which is a `targetHeight` calculated as the STAGE_HEIGHT - count * COLUMN_WIDTH, which prevents it falling further
Code edit (2 edits merged)
Please save this source code
User prompt
instead of using tick offset for box spawning, columns should have a countdown variable that is randomly set after creation and after spawning a box
User prompt
The columns should be updated in the tick callback, not on creation silly
User prompt
columns should handle the spawning of boxes in an update function instead
User prompt
Fix Bug: 'ReferenceError: floor is not defined' in this line: 'if (self.y > floor.y - self.height) {' Line Number: 57
User prompt
Fix Bug: 'TypeError: LK.tween is not a function' in this line: 'LK.tween(player, {' Line Number: 94
User prompt
it should take the player 0.2s to move from it's old position, and should also rotate 90 degrees during the move
===================================================================
--- original.js
+++ change.js
@@ -1,53 +1,29 @@
-var STAGE_WIDTH = 2048;
-var STAGE_HEIGHT = 2732;
-var NUM_COLUMNS = 16;
-var COLUMN_WIDTH = STAGE_WIDTH / NUM_COLUMNS;
-var PLAYER_SIZE = 0.8 * COLUMN_WIDTH;
-var SPAWN_CONST = 30;
-var SPAWN_VARIANCE = 250;
-var SPAWN_TNT_CHANCE = 0.1;
-var BOX_SPEED = 5;
-var BOX_GRAVITY = 0.1;
-var FLOOR_OFFSET = 100;
-var Box = Container.expand(function (parent, x, y) {
+var Box = Container.expand(function (parent, x, y, targetHeight) {
var self = Container.call(this);
parent.addChild(self);
self.x = x;
self.y = y;
;
+ var typeValue = Math.random();
+ var type = typeValue <= SPAWN_TNT_CHANCE ? 'tnt' : 'basic';
var speed = BOX_SPEED;
- var boxGraphics = self.createAsset('box', 'Falling box', .5, .5);
- var hitboxGraphics = self.createAsset('hitbox', 'Box hitbox', .5, .5);
- hitboxGraphics.alpha = 0.1;
+ var boxGraphics = self.createAsset(type + 'Box', 'Box graphics', .5, .5);
+ var hitboxGraphics = self.createAsset('hitbox', 'Hitbox graphics', .5, .5);
+ hitboxGraphics.alpha = 0.5;
;
self.hitbox = hitboxGraphics;
self.update = update;
;
function update() {
speed += BOX_GRAVITY;
self.y += speed;
+ if (self.y > targetHeight) {
+ self.y = targetHeight;
+ speed = 0;
+ }
}
});
-var TntBox = Container.expand(function (parent, x, y) {
- var self = Container.call(this);
- parent.addChild(self);
- self.x = x;
- self.y = y;
- ;
- var speed = BOX_SPEED;
- var tntGraphics = self.createAsset('tnt', 'TNT box', .5, .5);
- var hitboxGraphics = self.createAsset('hitbox', 'TNT hitbox', .5, .5);
- hitboxGraphics.alpha = 0.1;
- ;
- self.hitbox = hitboxGraphics;
- self.update = update;
- ;
- function update() {
- speed += BOX_GRAVITY;
- self.y += speed;
- }
-});
var Floor = Container.expand(function (parent, x, y) {
var self = Container.call(this);
parent.addChild(self);
self.x = x;
@@ -98,28 +74,32 @@
self.x = x;
self.y = y;
;
var countdown = SPAWN_CONST + Math.floor(Math.random() * SPAWN_VARIANCE);
+ var count = 0;
;
self.update = update;
;
function update(boxes) {
- var newBox;
- countdown--;
- if (countdown <= 0) {
- if (Math.random() < SPAWN_TNT_CHANCE) {
- newBox = new TntBox();
- } else {
- newBox = new Box();
- }
- newBox.x = self.x;
- newBox.y = 0;
- boxes.push(newBox);
- self.parent.addChild(newBox);
- self.countdown = Math.floor(Math.random() * 100) + 50;
+ if (--countdown <= 0) {
+ count++;
+ boxes.push(new Box(self, x, y + SPAWN_OFFSET, STAGE_HEIGHT - count * COLUMN_WIDTH));
+ countdown = SPAWN_CONST + Math.floor(Math.random() * SPAWN_VARIANCE);
}
}
});
+var STAGE_WIDTH = 2048;
+var STAGE_HEIGHT = 2732;
+var NUM_COLUMNS = 15;
+var COLUMN_WIDTH = STAGE_WIDTH / NUM_COLUMNS;
+var PLAYER_SIZE = 0.8 * COLUMN_WIDTH;
+var SPAWN_OFFSET = -100;
+var SPAWN_CONST = 30;
+var SPAWN_VARIANCE = 10 * 60 - SPAWN_CONST;
+var SPAWN_TNT_CHANCE = 0.02;
+var BOX_SPEED = 5;
+var BOX_GRAVITY = 0.1;
+var FLOOR_OFFSET = 100;
var Game = Container.expand(function () {
var self = Container.call(this);
;
var lastTouchX = null;
@@ -138,18 +118,18 @@
LK.gui.topCenter.addChild(scoreTxt);
var isGameOver = false;
var tickOffset = 0;
;
- LK.on('down', function (obj) {
+ stage.on('down', function (obj) {
var event = obj.event;
lastTouchX = event.global.x;
var currentTime = Date.now();
if (self.lastTapTime && currentTime - self.lastTapTime < 200) {
player.jump();
}
self.lastTapTime = currentTime;
});
- LK.on('move', function (obj) {
+ stage.on('move', function (obj) {
if (lastTouchX !== null) {
var event = obj.event;
var currentTouchX = event.global.x;
var deltaX = currentTouchX - lastTouchX;
@@ -166,9 +146,9 @@
lastTouchX = currentTouchX;
}
}
});
- LK.on('up', function (obj) {
+ stage.on('up', function (obj) {
lastTouchX = null;
});
LK.on('tick', function () {
if (isGameOver) {
@@ -185,9 +165,9 @@
if (box.y > STAGE_HEIGHT) {
box.destroy();
boxes.splice(i, 1);
} else if (player.intersects(box.hitbox)) {
- isGameOver = true;
+ isGameOver = false;
}
}
});
});
Pixel art, side view of a concrete factory floor . Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Pixel art, square with cute eyes . Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Pixel art, square with the texture of a tnt . Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
pixel art of a crate, side view . Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
pixel art of a crate, flat side view . Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
pixel art of a crate, flat side view . Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Pixel art of a golden christmas present. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Pixel art of a green christmas present with red ribbons. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Pixel art of an elaborate green christmas present with red ribbons. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
pixel art of a metal background.
pixel art of a crate made of stone with a label of coal on the side, flat side view. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
pixel art of a square tnt explosion. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.