Code edit (13 edits merged)
Please save this source code
Code edit (8 edits merged)
Please save this source code
User prompt
landscape tiles should have a background asset
Code edit (1 edits merged)
Please save this source code
User prompt
after updating the player in the on tick function, call the update function of the interface, making sure to supply the player.distanceTravelled as the first parameter
Code edit (1 edits merged)
Please save this source code
===================================================================
--- original.js
+++ change.js
@@ -164,21 +164,20 @@
}
return distSqr <= collectDistSqr;
}
});
-var LandscapeTile = Container.expand(function (x, y, {lookup, xIndex, yIndex, width, height, density, pickups, monsters, player, key, landscapeTiles, rampList}) {
+var LandscapeTile = Container.expand(function (x, y, {lookup, xIndex, yIndex, density, pickups, monsters, player, key, landscapeTiles, layers, rampList}) {
var self = Container.call(this);
var obstructions = [];
var background = self.createAsset('landscapeBackground', 'Landscape background', 0.5, 0.5);
- background.width = width;
- background.height = height;
- background.alpha = 0.1;
+ background.width = TILE_SIZE;
+ background.height = TILE_SIZE;
+ background.alpha = 0.03;
+ background.x = yIndex % 2 === 0 ? TILE_BACKGROUND_OFFSET : 0;
;
self.x = x;
self.y = y;
self.activate = activate;
- self.width = width;
- self.height = height;
self.active = false;
self.key = key;
self.checkCollision = checkCollision;
;
@@ -186,9 +185,9 @@
if (!player.airborne) {
var reach = 200;
var dx = Math.abs(player.x - self.x);
var dy = Math.abs(player.y - self.y);
- if (dx < width / 2 + reach && dy < height / 2 + reach) {
+ if (dx < TILE_SIZE / 2 + reach && dy < TILE_SIZE / 2 + reach) {
for (var i = 0; i < obstructions.length; i++) {
var obstruction = obstructions[i];
if (obstruction.active && player.hitbox.intersects(obstruction.hitbox)) {
obstruction.deactivate();
@@ -207,22 +206,22 @@
var clearanceDist = 300;
var clearanceDistSqr = clearanceDist * clearanceDist;
var spawnBorder = 25;
var cellSize = 150;
- var cols = Math.ceil(width / cellSize);
- var rows = Math.ceil(height / cellSize);
- var cellWidth = width / cols;
- var cellHeight = height / rows;
+ var cols = Math.ceil(TILE_SIZE / cellSize);
+ var rows = Math.ceil(TILE_SIZE / cellSize);
+ var cellWidth = TILE_SIZE / cols;
+ var cellHeight = TILE_SIZE / rows;
var landmark;
if (Math.random() <= SPAWN_PICKUP_CHANCE) {
- var {pointX, pointY} = randomPointInRect(self.x, self.y, width, height, clearanceDist);
+ var {pointX, pointY} = randomPointInRect(self.x, self.y, TILE_SIZE, TILE_SIZE, clearanceDist);
pickups.push(landmark = self.parent.addChild(new Pickup(pointX, pointY)));
} else if (Math.random() <= SPAWN_RAMP_CHANCE) {
- var {pointX, pointY} = randomPointInRect(self.x, self.y, width, height, clearanceDist);
- rampList.push(landmark = self.parent.addChild(new Ramp(pointX, pointY)));
+ var {pointX, pointY} = randomPointInRect(self.x, self.y, TILE_SIZE, TILE_SIZE, clearanceDist);
+ rampList.push(landmark = layers[LAYER_BACKGROUND].addChild(new Ramp(pointX, pointY)));
}
if (player.distanceTravelled > MONSTER_SPAWN_DIST && Math.random() <= SPAWN_MONSTER_CHANCE) {
- var {pointX, pointY} = randomPointInRect(self.x, self.y, width, height, clearanceDist);
+ var {pointX, pointY} = randomPointInRect(self.x, self.y, TILE_SIZE, TILE_SIZE, clearanceDist);
monsters.push(self.parent.addChild(new Monster(self.x, self.y)));
}
for (i = 0; i < cols; i++) {
for (j = 0; j < rows; j++) {
@@ -249,52 +248,49 @@
var rightKey = xIndex + 1 + ':' + yIndex;
var downKey = xIndex + ':' + (yIndex + 1);
var newDensity = (1 + Math.pow(Math.log(player.distanceTravelled / DIFFICULTY_FACTOR_DIST + 2), 2)) / 100;
if (!lookup[leftKey]) {
- landscapeTiles.push(lookup[leftKey] = self.parent.addChild(new LandscapeTile(self.x - width, self.y, {
+ landscapeTiles.push(lookup[leftKey] = self.parent.addChild(new LandscapeTile(self.x - TILE_SIZE, self.y, {
key: leftKey,
density: newDensity,
xIndex: xIndex - 1,
yIndex,
landscapeTiles,
rampList,
- width,
- height,
lookup,
pickups,
monsters,
+ layers,
player
})));
}
if (!lookup[rightKey]) {
- landscapeTiles.push(lookup[rightKey] = self.parent.addChild(new LandscapeTile(self.x + width, self.y, {
+ landscapeTiles.push(lookup[rightKey] = self.parent.addChild(new LandscapeTile(self.x + TILE_SIZE, self.y, {
key: rightKey,
density: newDensity,
xIndex: xIndex + 1,
yIndex,
landscapeTiles,
rampList,
- width,
- height,
lookup,
pickups,
monsters,
+ layers,
player
})));
}
if (!lookup[downKey]) {
- landscapeTiles.push(lookup[downKey] = self.parent.addChild(new LandscapeTile(self.x, self.y + height, {
+ landscapeTiles.push(lookup[downKey] = self.parent.addChild(new LandscapeTile(self.x, self.y + TILE_SIZE, {
key: downKey,
density: newDensity,
yIndex: yIndex + 1,
xIndex,
landscapeTiles,
rampList,
- width,
- height,
lookup,
pickups,
monsters,
+ layers,
player
})));
}
function randomPointInRect(centerX, centerY, width, height, border = 0) {
@@ -551,38 +547,39 @@
var STAGE_HEIGHT = 2732;
var SCREEN_METERAGE = 1 / 150;
var MONSTER_SPAWN_DIST = 100 / SCREEN_METERAGE;
var DIFFICULTY_FACTOR_DIST = 150 / SCREEN_METERAGE;
+var TILE_SIZE = 512;
+var TILE_MARGIN = TILE_SIZE;
+var TILE_BACKGROUND_OFFSET = 100;
var SPAWN_PICKUP_CHANCE = 0.1;
var SPAWN_MONSTER_CHANCE = 0.01;
var SPAWN_RAMP_CHANCE = 0.025;
var RAMP_CRITICAL_SPEED = 15.0;
var RAMP_CRITICAL_REDUX = 10;
var RAMP_SPEED_BOOST = 1.25;
var RAMP_SPEED_DURATION = 3.0;
var RAMP_SPEED_HEIGHT = 20.0;
+var LAYER_BACKGROUND = 0;
+var LAYER_MIDGROUND = 1;
+var LAYER_FOREGROUND = 2;
;
var Game = Container.expand(function () {
var self = Container.call(this);
- var stageWidth = 2048;
- var stageHeight = 2732;
- var tileSize = 512;
- var playerPosX = Math.round(stageWidth / 2);
- var playerPosY = Math.round(stageWidth / 3);
- var tileMargin = tileSize;
+ var playerPosX = Math.round(STAGE_WIDTH / 2);
+ var playerPosY = Math.round(STAGE_WIDTH / 3);
var landscapeLookup = {};
var landscapeTiles = [];
var pickups = [];
var monsters = [];
var effects = [];
var rampList = [];
+ var layers = [self.addChild(new Container()), self.addChild(new Container()), self.addChild(new Container())];
var speed = 0;
var interface = LK.gui.topCenter.addChild(new Interface(0, 10));
- var trail = self.addChild(new Trail(playerPosX, playerPosY));
- var player = self.addChild(new Player(playerPosX, playerPosY));
- landscapeTiles.push(landscapeLookup['0:0'] = self.addChild(new LandscapeTile(player.x, player.y, {
- width: tileSize,
- height: tileSize,
+ var trail = layers[LAYER_BACKGROUND].addChild(new Trail(playerPosX, playerPosY));
+ var player = layers[LAYER_MIDGROUND].addChild(new Player(playerPosX, playerPosY));
+ landscapeTiles.push(landscapeLookup['0:0'] = layers[LAYER_FOREGROUND].addChild(new LandscapeTile(STAGE_WIDTH / 2, TILE_SIZE / 2, {
density: -1,
lookup: landscapeLookup,
xIndex: 0,
yIndex: 0,
@@ -590,8 +587,9 @@
landscapeTiles,
rampList,
monsters,
pickups,
+ layers,
player
})));
var isMouseDown = false;
var targetPosition = {
@@ -619,13 +617,13 @@
for (var i = landscapeTiles.length - 1; i >= 0; i--) {
var landscapeTile = landscapeTiles[i];
landscapeTile.x -= velocityX;
landscapeTile.y -= velocityY;
- if (landscapeTile.y < -(tileSize / 2 + tileMargin)) {
+ if (landscapeTile.y < -(TILE_SIZE / 2 + TILE_MARGIN)) {
landscapeTile.destroy();
landscapeTiles.splice(i, 1);
landscapeLookup[landscapeTile.key] = undefined;
- } else if (!landscapeTile.active && landscapeTile.x > -tileMargin && landscapeTile.x < stageWidth + tileMargin && landscapeTile.y < stageHeight + tileMargin) {
+ } else if (!landscapeTile.active && landscapeTile.x > -TILE_MARGIN && landscapeTile.x < STAGE_WIDTH + TILE_MARGIN && landscapeTile.y < STAGE_HEIGHT + TILE_MARGIN) {
landscapeTile.activate();
} else if (landscapeTile.checkCollision(player)) {
if (interface.changeScore(-1)) {
effects.push(new DropEffect(self, player.x, player.y));
@@ -641,9 +639,9 @@
if (pickup.update(velocityX, velocityY, player)) {
interface.changeScore(1);
pickup.destroy();
pickups.splice(i, 1);
- } else if (pickup.y < -(tileSize / 2 + tileMargin) || pickup.active && player.hitbox.intersects(pickup.hitbox)) {
+ } else if (pickup.y < -(TILE_SIZE / 2 + TILE_MARGIN) || pickup.active && player.hitbox.intersects(pickup.hitbox)) {
pickup.destroy();
pickups.splice(i, 1);
}
}
Pixel art of a Santa. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
pixel art of a tree stump covered in snow. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
pixel art of a dead tree covered in snow. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
pixel art of a christmas tree covered in snow. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
pixel art of a spruce tree covered in snow. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
pixel art of a rock covered in snow. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
pixel art of a christmas present counter. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
pixel art of a christmas present. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
pixel art of a blue christmas present. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Pixel art heart icon . Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
two vertical lines with a blank background.
pixel art of a large, snow covered rock . Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
pixel art of skiis . Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
pixel art of a floating grinch monster . Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
single green firework explosion . Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
pixel art of a wooden board covered in snow. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
pixel art of a wooden pole with snow at it's base. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
tileable white water texture pixel art.