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
User prompt
Columns have a shadow asset which has its y property set to: `STAGE_HEIGHT - FLOOR_OFFSET - BOX_HEIGHT * self.count` in the update function
Code edit (1 edits merged)
Please save this source code
Code edit (2 edits merged)
Please save this source code
User prompt
convert interface text2 to use BorderedText instead
Code edit (3 edits merged)
Please save this source code
User prompt
add a background class
User prompt
Add a fullscreen background before the floor
Code edit (4 edits merged)
Please save this source code
User prompt
Display the following text under the score "Swipe left or right to move" and "Swipe up or tap to jump" under that
User prompt
set initial invulnerability to 0
User prompt
player no longer starts invulnerable
Code edit (1 edits merged)
Please save this source code
User prompt
player starts with invulnerability equal to INVULNERABILITY_TIME
Code edit (1 edits merged)
Please save this source code
User prompt
flash the player black when invulnerability reaches 60 and 30
User prompt
tint the player gold while it is invulnerable
Code edit (1 edits merged)
Please save this source code
User prompt
decrement player invulnerability in it's update function if it's greater than 0
var Interface = Container.expand(function (parent) {
var self = Container.call(this);
parent.addChild(self);
;
var score = 0;
;
var scoreTxt = new Text2(score.toString(), {
size: 150,
fill: "#ffffff"
});
scoreTxt.anchor.set(.5, 0);
self.addChild(scoreTxt);
;
self.increment = increment;
self.gameOver = gameOver;
;
function increment(value) {
score += value;
scoreTxt.setText(score.toString());
LK.setScore(score);
}
;
function gameOver() {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
});
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.95);
floorGraphics.width = STAGE_WIDTH * 1.25;
});
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, .5);
hitboxGraphics.width = BOX_WIDTH;
hitboxGraphics.height = BOX_HEIGHT;
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;
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':
self.alive = false;
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;
}
}
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 = getCountdown();
;
self.count = 0;
self.boxes = boxes;
self.squash = squash;
self.remove = remove;
self.update = update;
;
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) {
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) {
if (self.invulnerability > 0) {
self.invulnerability--;
}
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.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_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 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 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);
}
}
});
});
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.