Code edit (1 edits merged)
Please save this source code
User prompt
set the player hitbox alpha to 0
Code edit (1 edits merged)
Please save this source code
User prompt
when the player rotates, rotate the player graphics instead
User prompt
when checking box collision, use the player hitbox instead of the player itself
Code edit (13 edits merged)
Please save this source code
User prompt
add a hitbox to the player
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'TypeError: self is undefined' in this line: 'self.build('basic', .5, .5, 3);' Line Number: 195
Code edit (1 edits merged)
Please save this source code
Code edit (3 edits merged)
Please save this source code
User prompt
when a TNT box countdown expires, create an ExplosionEffect centered on the TNT as a child of the game variable, and add it to the effectsList
Code edit (1 edits merged)
Please save this source code
User prompt
create an effectList array in the game class, iterate through it in the on tick calling their update function; if it returns truthy, remove and delete the effect
Code edit (9 edits merged)
Please save this source code
User prompt
create an explosion effect class
User prompt
while counting down, the tnt type box should flash red every 30 ticks (self.countdown % 30)
Code edit (1 edits merged)
Please save this source code
Code edit (2 edits merged)
Please save this source code
User prompt
Move the column shadow to the box class
Code edit (2 edits merged)
Please save this source code
User prompt
column shadow is only visible if the boxes array size is greater than the count
Code edit (1 edits merged)
Please save this source code
User prompt
Columns should have a sub-container called boxContainer that holds Boxes
Code edit (7 edits merged)
Please save this source code
var BorderedText = Container.expand(function (string, settings) {
var self = Container.call(this);
var textList = [];
var defaultFill = '#ffffff';
var defaultBorder = '#000000';
var defaultFont = 'Arial';
var defaultSize = 80;
var defaultWeight = 3;
var offsets = [[-1, -1], [-1, 1], [1, 1], [1, -1], [0, 0]];
var borderSettings = {
fill: settings.border || defaultBorder,
font: settings.font || defaultFont,
size: settings.size || defaultSize
};
var textSettings = {
fill: settings.fill || defaultFill,
font: settings.font || defaultFont,
size: settings.size || defaultSize
};
self.x = settings.x;
self.y = settings.y;
for (var i = 0; i < offsets.length; i++) {
var localSettings = i === offsets.length - 1 ? textSettings : borderSettings;
var text = new Text2(string, localSettings);
text.x += offsets[i][0] * defaultWeight;
text.y += offsets[i][1] * defaultWeight;
if (settings.anchor) {
text.anchor.set(settings.anchor.x || 0, settings.anchor.y || 0);
}
textList.push(text);
self.addChild(text);
}
self.setText = function (string) {
for (var i = 0; i < textList.length; i++) {
textList[i].setText(string);
}
};
self.setFill = function (newFill) {
textList[textList.length - 1].fill = newFill;
};
});
var Background = Container.expand(function (parent) {
var self = Container.call(this);
parent.addChild(self);
var backgroundGraphics = self.createAsset('background', 'Background image', 0.5, 0.5);
backgroundGraphics.width = STAGE_WIDTH;
backgroundGraphics.height = STAGE_HEIGHT;
self.x = STAGE_WIDTH / 2;
self.y = STAGE_HEIGHT / 2;
});
var Floor = Container.expand(function (parent, x, y) {
var self = Container.call(this);
parent.addChild(self);
self.x = x;
self.y = y;
;
var floorGraphics = self.createAsset('floor', 'Floor image', 0.5, 0.5);
});
var Interface = Container.expand(function (parent) {
var self = Container.call(this);
parent.addChild(self);
;
var score = 0;
var scoreTxt = new BorderedText(score.toString(), {
size: 150,
anchor: {
x: .5
}
});
var moveInstructions = new BorderedText('Swipe left or right to move', {
y: scoreTxt.height + 20,
anchor: {
x: .5
}
});
var jumpInstructions = new BorderedText('Swipe up or tap to jump', {
y: moveInstructions.y + moveInstructions.height + 10,
anchor: {
x: .5
}
});
;
self.addChild(scoreTxt);
self.addChild(moveInstructions);
self.addChild(jumpInstructions);
self.increment = increment;
self.gameOver = gameOver;
self.hideInstructions = hideInstructions;
;
function increment(value) {
score += value;
scoreTxt.setText(score.toString());
LK.setScore(score);
}
function gameOver() {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
function hideInstructions() {
moveInstructions.destroy();
jumpInstructions.destroy();
}
});
var Box = Container.expand(function (parent, x, y, index) {
var self = Container.call(this);
parent.addChild(self);
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 -= 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);
var hitboxGraphics = self.createAsset('hitbox', 'Hitbox graphics', .5, .25);
hitboxGraphics.width = BOX_WIDTH * 0.9;
hitboxGraphics.height = BOX_HEIGHT * 0.6;
hitboxGraphics.alpha = 0;
;
self.alive = true;
self.active = false;
self.falling = true;
self.type = type;
self.index = index;
self.hitbox = hitboxGraphics;
self.update = update;
self.squash = squash;
;
function update(args) {
var {interface, player} = args;
var destroyNextTick = false;
if (self.falling) {
speed += BOX_GRAVITY;
self.y += speed;
var targetHeight = STAGE_HEIGHT - (self.index + 0.5) * BOX_HEIGHT - FLOOR_OFFSET;
if (self.y >= targetHeight) {
self.falling = false;
self.y = targetHeight;
speed = 0;
parent.count++;
parent.squash(self, self.index - 1);
} else if (player.intersects(self.hitbox)) {
switch (type) {
case 'gold':
case 'points':
destroyNextTick = true;
self.active = true;
break;
case 'tnt':
self.active = true;
default:
if (!player.invulnerability) {
interface.gameOver();
}
break;
}
}
}
if (self.active) {
switch (type) {
case 'gold':
player.invulnerability += INVULNERABILITY_TIME;
break;
case 'points':
interface.increment(POINTS_GAIN_PICKUP);
break;
case 'tnt':
break;
}
}
if (!self.alive) {
parent.remove(self);
return true;
}
if (destroyNextTick) {
self.alive = false;
}
}
function squash(target) {
if (target instanceof Player) {
switch (type) {
case 'gold':
case 'points':
self.alive = false;
case 'tnt':
self.active = true;
break;
}
} else if (target.type === 'stone') {
switch (type) {
case 'gold':
case 'points':
self.alive = false;
break;
case 'tnt':
self.active = true;
break;
}
}
}
});
var Column = Container.expand(function (parent, x, y) {
var self = Container.call(this);
parent.addChild(self);
self.x = x;
self.y = y;
;
var boxes = [];
var countdown = SPAWN_INITIAL + getCountdown();
var shadow = self.createAsset('shadow', 'Shadow image', 0.5, 0.5);
shadow.alpha = 0.5;
;
self.count = 0;
self.boxes = boxes;
self.squash = squash;
self.remove = remove;
self.update = update;
self.addChild(shadow);
;
function getCountdown() {
return SPAWN_CONST + Math.floor(Math.random() * (SPAWN_VARIANCE + SPAWN_COUNT_VARIANCE * boxes.length));
}
function squash(target, index) {
var box = self.boxes[index];
if (box) {
box.squash(target);
}
}
function remove(box) {
var index = box.index;
boxes.splice(index, 1);
if (!box.falling) {
self.count--;
}
for (var i = index; i < boxes.length; i++) {
var box = boxes[i];
box.index--;
if (!box.falling) {
self.count--;
box.falling = true;
}
}
}
function update(args) {
shadow.y = STAGE_HEIGHT - FLOOR_OFFSET - BOX_HEIGHT * self.count;
if (--countdown <= 0) {
countdown = getCountdown();
if (self.count < COLUMN_VOLUME) {
var {boxList} = args;
var box = new Box(self, 0, SPAWN_OFFSET, boxes.length);
boxList.push(box);
boxes.push(box);
}
}
}
});
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 targetColumn = Math.floor(x / BOX_WIDTH);
var playerGraphics = self.createAsset('player', 'Player character', .5, .5);
playerGraphics.width = PLAYER_SIZE;
playerGraphics.height = PLAYER_SIZE;
;
self.heightClimbed = 0;
self.invulnerability = 0;
self.airborne = false;
self.move = move;
self.jump = jump;
self.update = update;
;
function getColIndex() {
return Math.floor(self.x / BOX_WIDTH);
}
function getRowIndex() {
return Math.floor((STAGE_HEIGHT - self.y - FLOOR_OFFSET) / BOX_HEIGHT);
}
function move(direction) {
var colIndex = getColIndex();
if (targetColumn === colIndex) {
targetColumn = Math.max(0, Math.min(NUM_COLUMNS - 1, targetColumn + direction));
}
}
function jump() {
if (!self.airborne) {
self.airborne = true;
verticalSpeed = PLAYER_JUMP_SPEED;
}
}
function update(args) {
var {interface, columnList} = args;
var colIndex = getColIndex();
var rowIndex = getRowIndex();
var targetX = (targetColumn + 0.5) * BOX_WIDTH;
var targetY = floorHeight - columnList[colIndex].count * BOX_HEIGHT;
if (self.invulnerability > 0) {
self.invulnerability--;
if (self.invulnerability === 60 || self.invulnerability === 30) {
LK.effects.flashObject(playerGraphics, 0x000000, 1000);
}
playerGraphics.tint = 0xFFD700;
} else {
playerGraphics.tint = 0xFFFFFF;
}
if (self.x !== targetX) {
var moveSpeed = Math.min(Math.abs(targetX - self.x), PLAYER_MOVE_SPEED);
self.x += Math.sign(targetX - self.x) * moveSpeed;
self.rotation = Math.PI * (self.x - STAGE_WIDTH / 2) / (BOX_WIDTH * 2);
}
if (self.airborne) {
verticalSpeed -= PLAYER_GRAVITY;
self.y -= verticalSpeed;
if (self.y >= targetY) {
self.y = targetY;
self.airborne = false;
verticalSpeed = 0;
}
} else {
if (self.y < targetY) {
self.airborne = true;
} else {
self.y = targetY;
}
}
if (!self.airborne) {
colIndex = getColIndex();
rowIndex = getRowIndex();
columnList[colIndex].squash(self, rowIndex - 1);
if (rowIndex > self.heightClimbed) {
interface.increment((rowIndex - self.heightClimbed) * POINTS_GAIN_CLIMBING);
self.heightClimbed = rowIndex;
}
}
}
});
;
var STAGE_WIDTH = 2048;
var STAGE_HEIGHT = 2732;
var STAGE_TICKS = 60;
var CONTROL_SWIPE_DIST = 100;
var CONTROL_TAP_TICKS = STAGE_TICKS / 3;
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 = 20;
var PLAYER_MOVE_SPEED = 15;
var SPAWN_OFFSET = -100;
var SPAWN_INITIAL = 5 * STAGE_TICKS;
var SPAWN_CONST = STAGE_TICKS / 2;
var SPAWN_VARIANCE = 10 * STAGE_TICKS - SPAWN_CONST;
var SPAWN_COUNT_VARIANCE = STAGE_TICKS / 4;
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 POINTS_GAIN_CLIMBING = 1;
var POINTS_GAIN_PICKUP = 5;
var INVULNERABILITY_TIME = 5 * STAGE_TICKS;
var INSTRUCTION_DURATION = 5 * STAGE_TICKS;
var BOX_SPEED = 5;
var BOX_GRAVITY = 0.2;
var FLOOR_OFFSET = 100;
var COLUMN_VOLUME = Math.floor((STAGE_HEIGHT - FLOOR_OFFSET) / BOX_HEIGHT) + 1;
var BOX_SETTINGS = {
basic: {
x: .5,
y: .5,
images: ['basic1', 'basic2', 'basic3']
},
tnt: {
x: .5,
y: .55,
images: ['tnt']
},
gold: {
x: .5,
y: .5,
images: ['gold']
},
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 background = self.addChild(new Background(self));
;
var lastTouchX = null;
var lastTouchY = null;
var touchTime = null;
var boxList = [];
var columnList = [];
;
var floor = self.addChild(new Floor(self, STAGE_WIDTH / 2, STAGE_HEIGHT));
for (var i = 0; i < NUM_COLUMNS; i++) {
columnList.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 interface = new Interface(LK.gui.topCenter);
;
stage.on('down', function (obj) {
var event = obj.event;
lastTouchX = event.global.x;
lastTouchY = event.global.y;
touchTime = LK.ticks;
});
stage.on('up', function (obj) {
if (touchTime !== null && LK.ticks - touchTime < CONTROL_TAP_TICKS) {
player.jump();
}
lastTouchX = null;
lastTouchY = null;
touchTime = null;
});
stage.on('move', function (obj) {
if (touchTime !== null) {
var reset = false;
var event = obj.event;
var deltaX = lastTouchX - event.global.x;
var deltaY = lastTouchY - event.global.y;
if (Math.abs(deltaX) > CONTROL_SWIPE_DIST) {
var direction = deltaX > 0 ? -1 : 1;
player.move(direction);
reset = true;
} else if (deltaY > CONTROL_SWIPE_DIST) {
player.jump();
reset = true;
}
if (reset) {
touchTime = null;
lastTouchX = null;
lastTouchY = null;
}
}
});
LK.on('tick', function () {
var playerArgs = {
interface,
columnList
};
player.update(playerArgs);
;
var columnArgs = {
boxList
};
for (var i = columnList.length - 1; i >= 0; i--) {
columnList[i].update(columnArgs);
}
;
var boxArgs = {
interface,
player
};
for (var i = boxList.length - 1; i >= 0; i--) {
var box = boxList[i];
if (box.update(boxArgs)) {
box.destroy();
boxList.splice(i, 1);
}
}
;
if (LK.ticks === INSTRUCTION_DURATION) {
interface.hideInstructions();
}
});
});
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.