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
User prompt
boxes should get increasingly faster as if affected by gravity
User prompt
boxes have a 1% chance of being a tnt instead
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'ReferenceError: COLUMN_WIDTH is not defined' in this line: 'player.x = Math.floor(2048 / 2 / COLUMN_WIDTH) * COLUMN_WIDTH + COLUMN_WIDTH / 2;' Line Number: 97
User prompt
Create a columns array that holds a Column class instances.
User prompt
if quickly tapping on the screen, make the player jump
User prompt
the player can move a maximum of 1 column when swiping
User prompt
add a hitbox asset to the box class that, the player should check the hitbox instead of the box for intersections
User prompt
Add a floor image that is the full width of the game
User prompt
if the player collides with a box it's game over
User prompt
Fix Bug: 'TypeError: event.data is undefined' in this line: 'var currentTouchX = event.data.global.x;' Line Number: 27
User prompt
Fix Bug: 'TypeError: event.data is undefined' in this line: 'lastTouchX = event.data.global.x;' Line Number: 22
===================================================================
--- original.js
+++ change.js
@@ -1,39 +1,68 @@
+var STAGE_WIDTH = 2048;
+var STAGE_HEIGHT = 2732;
var NUM_COLUMNS = 16;
-var COLUMN_WIDTH = 2048 / NUM_COLUMNS;
-var TNTBox = Container.expand(function () {
+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 self = Container.call(this);
+ parent.addChild(self);
+ self.x = x;
+ self.y = y;
+ ;
+ 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;
+ ;
+ self.hitbox = hitboxGraphics;
+ self.update = update;
+ ;
+ function update() {
+ speed += BOX_GRAVITY;
+ self.y += speed;
+ }
+});
+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.gravity = 0.1;
- self.speed = 5;
- self.move = function () {
- self.speed += self.gravity;
- self.y += self.speed;
- };
+ self.update = update;
+ ;
+ function update() {
+ speed += BOX_GRAVITY;
+ self.y += speed;
+ }
});
-var Floor = Container.expand(function () {
+var Floor = Container.expand(function (parent, x, y) {
var self = Container.call(this);
- var floorGraphics = self.createAsset('floor', 'Floor image', 0, 1);
- floorGraphics.width = 2048;
- self.addChild(floorGraphics);
+ parent.addChild(self);
+ self.x = x;
+ self.y = y;
+ ;
+ var floorGraphics = self.createAsset('floor', 'Floor image', 0.5, 1);
+ floorGraphics.width = STAGE_WIDTH;
});
-var Box = Container.expand(function () {
+var Player = Container.expand(function (parent, x, y) {
var self = Container.call(this);
- var boxGraphics = self.createAsset('box', 'Falling box', .5, .5);
- var hitboxGraphics = self.createAsset('hitbox', 'Box hitbox', .5, .5);
- self.hitbox = hitboxGraphics;
- self.gravity = 0.1;
- self.speed = 5;
- self.move = function () {
- self.speed += self.gravity;
- self.y += self.speed;
- };
-});
-var Player = Container.expand(function (floorInstance) {
- var self = Container.call(this);
- self.floor = floorInstance;
+ parent.addChild(self);
+ self.x = x;
+ self.y = y;
+ ;
var playerGraphics = self.createAsset('player', 'Player character', .5, .5);
self.isJumping = false;
self.jumpHeight = 150;
self.jumpSpeed = -15;
@@ -54,55 +83,73 @@
self.update = function () {
if (self.isJumping) {
self.verticalSpeed += self.gravity;
self.y += self.verticalSpeed;
- if (self.y > self.floor.y - self.height) {
- self.y = self.floor.y - self.height;
+ if (self.y > FLOOR_OFFSET - self.height) {
+ self.y = FLOOR_OFFSET - self.height;
self.isJumping = false;
self.verticalSpeed = 0;
}
}
};
});
-var Column = Container.expand(function () {
+var Column = Container.expand(function (parent, x, y) {
var self = Container.call(this);
- self.countdown = Math.floor(Math.random() * 100) + 50;
- self.width = COLUMN_WIDTH;
- self.height = 2732;
- var columnGraphics = self.createAsset('column', 'Column graphics', 0.5, 1);
- columnGraphics.width = self.width;
- columnGraphics.height = self.height;
- self.addChild(columnGraphics);
- self.update = function (boxes, tickOffset) {
+ parent.addChild(self);
+ self.x = x;
+ self.y = y;
+ ;
+ var countdown = SPAWN_CONST + Math.floor(Math.random() * SPAWN_VARIANCE);
+ ;
+ self.update = update;
+ ;
+ function update(boxes) {
var newBox;
- self.countdown--;
- if (self.countdown <= 0) {
- if (Math.random() < 0.01) {
- newBox = new TNTBox();
+ countdown--;
+ if (countdown <= 0) {
+ if (Math.random() < SPAWN_TNT_CHANCE) {
+ newBox = new TntBox();
} else {
newBox = new Box();
}
- newBox.x = self.x + COLUMN_WIDTH / 2;
+ newBox.x = self.x;
newBox.y = 0;
boxes.push(newBox);
self.parent.addChild(newBox);
self.countdown = Math.floor(Math.random() * 100) + 50;
}
- };
+ }
});
var Game = Container.expand(function () {
var self = Container.call(this);
+ ;
var lastTouchX = null;
- stage.on('down', function (obj) {
+ var boxes = [];
+ var columns = [];
+ var floor = self.addChild(new Floor(self, STAGE_WIDTH / 2, STAGE_HEIGHT));
+ var player = self.addChild(new Player(self, STAGE_WIDTH / 2, STAGE_HEIGHT - FLOOR_OFFSET - PLAYER_SIZE / 2));
+ for (var i = 0; i < NUM_COLUMNS; i++) {
+ columns.push(new Column(self, (i + 0.5) * COLUMN_WIDTH, 0));
+ }
+ var scoreTxt = new Text2('0', {
+ size: 150,
+ fill: "#ffffff"
+ });
+ scoreTxt.anchor.set(.5, 0);
+ LK.gui.topCenter.addChild(scoreTxt);
+ var isGameOver = false;
+ var tickOffset = 0;
+ ;
+ LK.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;
});
- stage.on('move', function (obj) {
+ LK.on('move', function (obj) {
if (lastTouchX !== null) {
var event = obj.event;
var currentTouchX = event.global.x;
var deltaX = currentTouchX - lastTouchX;
@@ -119,47 +166,27 @@
lastTouchX = currentTouchX;
}
}
});
- stage.on('up', function (obj) {
+ LK.on('up', function (obj) {
lastTouchX = null;
});
- var boxes = [];
- var columns = [];
- for (var i = 0; i < NUM_COLUMNS; i++) {
- var column = new Column();
- column.x = i * column.width;
- columns.push(column);
- self.addChild(column);
- }
- var floor = self.addChild(new Floor());
- floor.y = 2732 - floor.height;
- var player = self.addChild(new Player(floor));
- player.x = Math.floor(2048 / 2 / COLUMN_WIDTH) * COLUMN_WIDTH + COLUMN_WIDTH / 2;
- player.y = floor.y - player.height;
- var scoreTxt = new Text2('0', {
- size: 150,
- fill: "#ffffff"
- });
- scoreTxt.anchor.set(.5, 0);
- LK.gui.topCenter.addChild(scoreTxt);
- var isGameOver = false;
- var tickOffset = 0;
LK.on('tick', function () {
if (isGameOver) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
+ player.update();
columns.forEach(function (column) {
column.update(boxes, tickOffset);
});
- player.update();
- for (var a = boxes.length - 1; a >= 0; a--) {
- boxes[a].move();
- if (boxes[a].y > 2732) {
- boxes[a].destroy();
- boxes.splice(a, 1);
- } else if (player.intersects(boxes[a].hitbox)) {
+ for (var i = boxes.length - 1; i >= 0; i--) {
+ var box = boxes[i];
+ box.update();
+ if (box.y > STAGE_HEIGHT) {
+ box.destroy();
+ boxes.splice(i, 1);
+ } else if (player.intersects(box.hitbox)) {
isGameOver = true;
}
}
});
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.