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,9 +4,9 @@
self.x = x;
self.y = y;
;
var typeValue = Math.random();
- var type = (typeValue -= SPAWN_GOLD_CHANCE) < 0 ? 'gold' : (typeValue -= SPAWN_TNT_CHANCE) < 0 ? 'tnt' : (typeValue -= POINTS_CHANCE) < 0 ? 'points' : 'basic';
+ var type = (typeValue -= SPAWN_GOLD_CHANCE) < 0 ? 'gold' : (typeValue -= SPAWN_TNT_CHANCE) < 0 ? 'tnt' : (typeValue -= SPAWN_POINTS_CHANCE) < 0 ? 'points' : (typeValue -= SPAWN_STONE_CHANCE) < 0 ? 'stone' : '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(image + 'Box', 'Box graphics', settings.x, settings.y);
@@ -48,30 +48,28 @@
;
var isJumping = false;
var verticalSpeed = 0;
var floorHeight = y;
+ var targetColumn = Math.floor(x / BOX_WIDTH);
var playerGraphics = self.createAsset('player', 'Player character', .5, .5);
playerGraphics.width = PLAYER_SIZE;
playerGraphics.height = PLAYER_SIZE;
;
self.move = move;
self.jump = jump;
self.update = update;
;
- function move(x, y) {
- self.x = x;
- if (!self.isJumping) {
- self.y = y;
- }
+ function move(direction) {
+ targetColumn += direction;
}
function jump() {
if (!isJumping) {
isJumping = true;
verticalSpeed = PLAYER_JUMP_SPEED;
}
}
function update() {
- if (self.isJumping) {
+ if (isJumping) {
verticalSpeed += PLAYER_GRAVITY;
self.y += verticalSpeed;
if (self.y >= floorHeight) {
self.y = floorHeight;
@@ -104,8 +102,10 @@
}
});
var STAGE_WIDTH = 2048;
var STAGE_HEIGHT = 2732;
+var CONTROL_SWIPE_DIST = 100;
+var CONTROL_TAP_TICKS = 20;
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;
@@ -116,17 +116,18 @@
var SPAWN_VARIANCE = 10 * 60 - SPAWN_CONST;
var SPAWN_TNT_CHANCE = 0.03;
var SPAWN_GOLD_CHANCE = 0.01;
var SPAWN_POINTS_CHANCE = 0.05;
+var SPAWN_STONE_CHANCE = 0.1;
var BOX_SPEED = 5;
-var BOX_GRAVITY = 0.1;
+var BOX_GRAVITY = 0.2;
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']
+ images: ['basic1', 'basic2', 'basic3']
},
tnt: {
x: .5,
y: .55,
@@ -140,14 +141,21 @@
points: {
x: .5,
y: .55,
images: ['points1', 'points2']
+ },
+ stone: {
+ x: .5,
+ y: .5,
+ images: ['stone']
}
};
var Game = Container.expand(function () {
var self = Container.call(this);
;
var lastTouchX = null;
+ var lastTouchY = null;
+ var touchTime = null;
var boxes = [];
var columns = [];
var floor = self.addChild(new Floor(self, STAGE_WIDTH / 2, STAGE_HEIGHT));
for (var i = 0; i < NUM_COLUMNS; i++) {
@@ -165,36 +173,40 @@
;
stage.on('down', function (obj) {
var event = obj.event;
lastTouchX = event.global.x;
- var currentTime = Date.now();
- if (self.lastTapTime && currentTime - self.lastTapTime < 200) {
+ lastTouchY = event.global.y;
+ touchTime = LK.ticks;
+ });
+ stage.on('up', function (obj) {
+ if (touchTime !== null && LK.ticks - touchTime < CONTROL_TAP_TICKS) {
player.jump();
}
- self.lastTapTime = currentTime;
+ lastTouchX = null;
+ lastTouchY = null;
+ touchTime = null;
});
stage.on('move', function (obj) {
- if (lastTouchX !== null) {
+ if (touchTime !== null) {
var event = obj.event;
var currentTouchX = event.global.x;
+ var currentTouchY = event.global.y;
var deltaX = currentTouchX - lastTouchX;
- if (Math.abs(deltaX) > BOX_WIDTH / 2) {
+ var deltaY = currentTouchY - lastTouchY;
+ if (Math.abs(deltaX) > CONTROL_SWIPE_DIST) {
var direction = deltaX > 0 ? 1 : -1;
- 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;
- player.tweenDuration = 200;
- player.startRotation = player.rotation;
- player.endRotation = player.rotation + Math.PI / 2;
- lastTouchX = currentTouchX;
+ player.move(direction);
+ touchTime = null;
+ lastTouchX = null;
+ lastTouchY = null;
+ } else if (deltaY > CONTROL_SWIPE_DIST) {
+ player.jump();
+ touchTime = null;
+ lastTouchX = null;
+ lastTouchY = null;
}
}
});
- stage.on('up', function (obj) {
- lastTouchX = null;
- });
LK.on('tick', function () {
if (isGameOver) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
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.