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
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
===================================================================
--- original.js
+++ change.js
@@ -4,15 +4,17 @@
self.x = x;
self.y = y;
;
var typeValue = Math.random();
- var type = typeValue <= SPAWN_TNT_CHANCE ? 'tnt' : 'basic';
+ var type = (typeValue -= SPAWN_GOLD_CHANCE) < 0 ? 'gold' : (typeValue -= SPAWN_TNT_CHANCE) < 0 ? 'tnt' : (typeValue -= POINTS_CHANCE) < 0 ? 'points' : 'basic';
+ var settings = BOX_SETTINGS[type];
+ var image = settings.images[Math.floor(Math.random() * settings.images.length)];
var speed = BOX_SPEED;
- var boxGraphics = self.createAsset(type + 'Box', 'Box graphics', .5, .5);
+ var boxGraphics = self.createAsset(image + 'Box', 'Box graphics', settings.x, settings.y);
var hitboxGraphics = self.createAsset('hitbox', 'Hitbox graphics', .5, .5);
- hitboxGraphics.alpha = 0.5;
- hitboxGraphics.width = BOX_SIZE;
- hitboxGraphics.height = BOX_SIZE;
+ hitboxGraphics.width = BOX_WIDTH;
+ hitboxGraphics.height = BOX_HEIGHT;
+ hitboxGraphics.alpha = 0;
;
self.active = true;
self.hitbox = hitboxGraphics;
self.update = update;
@@ -34,24 +36,24 @@
parent.addChild(self);
self.x = x;
self.y = y;
;
- var floorGraphics = self.createAsset('floor', 'Floor image', 0.5, 1);
- floorGraphics.width = STAGE_WIDTH;
+ var floorGraphics = self.createAsset('floor', 'Floor image', 0.5, 0.95);
+ floorGraphics.width = STAGE_WIDTH * 1.25;
});
var Player = Container.expand(function (parent, x, y) {
var self = Container.call(this);
parent.addChild(self);
self.x = x;
self.y = y;
;
+ var isJumping = false;
+ var verticalSpeed = 0;
+ var floorHeight = y;
var playerGraphics = self.createAsset('player', 'Player character', .5, .5);
+ playerGraphics.width = PLAYER_SIZE;
+ playerGraphics.height = PLAYER_SIZE;
;
- self.isJumping = false;
- self.jumpHeight = 150;
- self.jumpSpeed = -15;
- self.gravity = 0.5;
- self.verticalSpeed = 0;
self.move = move;
self.jump = jump;
self.update = update;
;
@@ -61,21 +63,21 @@
self.y = y;
}
}
function jump() {
- if (!self.isJumping) {
- self.isJumping = true;
- self.verticalSpeed = self.jumpSpeed;
+ if (!isJumping) {
+ isJumping = true;
+ verticalSpeed = PLAYER_JUMP_SPEED;
}
}
function update() {
if (self.isJumping) {
- self.verticalSpeed += self.gravity;
- self.y += self.verticalSpeed;
- if (self.y > FLOOR_OFFSET - self.height) {
- self.y = FLOOR_OFFSET - self.height;
- self.isJumping = false;
- self.verticalSpeed = 0;
+ verticalSpeed += PLAYER_GRAVITY;
+ self.y += verticalSpeed;
+ if (self.y >= floorHeight) {
+ self.y = floorHeight;
+ isJumping = false;
+ verticalSpeed = 0;
}
}
}
});
@@ -91,36 +93,68 @@
self.update = update;
;
function update(boxes) {
if (--countdown <= 0) {
- boxes.push(new Box(self, x, y + SPAWN_OFFSET, STAGE_HEIGHT - count++ * BOX_SIZE));
countdown = SPAWN_CONST + Math.floor(Math.random() * SPAWN_VARIANCE);
+ if (count < COLUMN_VOLUME) {
+ var targetHeight = STAGE_HEIGHT - (count + 0.5) * BOX_HEIGHT - FLOOR_OFFSET;
+ boxes.push(new Box(self, 0, SPAWN_OFFSET, targetHeight));
+ count++;
+ }
}
}
});
var STAGE_WIDTH = 2048;
var STAGE_HEIGHT = 2732;
-var NUM_COLUMNS = 15;
-var BOX_SIZE = STAGE_WIDTH / NUM_COLUMNS;
-var PLAYER_SIZE = 0.8 * BOX_SIZE;
+var NUM_COLUMNS = 9;
+var BOX_WIDTH = STAGE_WIDTH / NUM_COLUMNS;
+var BOX_HEIGHT = 0.75 * BOX_WIDTH;
+var PLAYER_SIZE = 0.8 * BOX_WIDTH;
+var PLAYER_GRAVITY = 0.5;
+var PLAYER_JUMP_SPEED = 15;
var SPAWN_OFFSET = -100;
var SPAWN_CONST = 30;
var SPAWN_VARIANCE = 10 * 60 - SPAWN_CONST;
-var SPAWN_TNT_CHANCE = 0.02;
+var SPAWN_TNT_CHANCE = 0.03;
+var SPAWN_GOLD_CHANCE = 0.01;
+var SPAWN_POINTS_CHANCE = 0.05;
var BOX_SPEED = 5;
var BOX_GRAVITY = 0.1;
var FLOOR_OFFSET = 100;
+var COLUMN_VOLUME = Math.floor((STAGE_HEIGHT - FLOOR_OFFSET) / BOX_HEIGHT);
+var BOX_SETTINGS = {
+ basic: {
+ x: .5,
+ y: .5,
+ images: ['basic1', 'basic2', 'basic3, stone']
+ },
+ tnt: {
+ x: .5,
+ y: .55,
+ images: ['tnt']
+ },
+ gold: {
+ x: .5,
+ y: .5,
+ images: ['gold']
+ },
+ points: {
+ x: .5,
+ y: .55,
+ images: ['points1', 'points2']
+ }
+};
var Game = Container.expand(function () {
var self = Container.call(this);
;
var lastTouchX = null;
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 * BOX_SIZE, 0));
+ columns.push(new Column(self, (i + 0.5) * BOX_WIDTH, 0));
}
+ var player = self.addChild(new Player(self, STAGE_WIDTH / 2, STAGE_HEIGHT - FLOOR_OFFSET - PLAYER_SIZE / 2));
var scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});
@@ -142,11 +176,11 @@
if (lastTouchX !== null) {
var event = obj.event;
var currentTouchX = event.global.x;
var deltaX = currentTouchX - lastTouchX;
- if (Math.abs(deltaX) > BOX_SIZE / 2) {
+ if (Math.abs(deltaX) > BOX_WIDTH / 2) {
var direction = deltaX > 0 ? 1 : -1;
- var targetX = Math.max(Math.min(player.x + direction * BOX_SIZE, 2048 - BOX_SIZE / 2), BOX_SIZE / 2);
+ var targetX = Math.max(Math.min(player.x + direction * BOX_WIDTH, 2048 - BOX_WIDTH / 2), BOX_WIDTH / 2);
player.targetX = targetX;
player.startX = player.x;
player.tweening = true;
player.tweenStart = LK.ticks;
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.