===================================================================
--- original.js
+++ change.js
@@ -1,4 +1,7 @@
+/****
+* Classes
+****/
var DropEffect = Container.expand(function (x, y, player) {
var self = Container.call(this);
var angle = player.angle + Math.random() * DROP_ANGLE_VARIANCE;
var speed = 10 + Math.random() * 5;
@@ -140,9 +143,9 @@
self.y = y;
self.update = update;
;
function update(velocityX, velocityY, args) {
- var {player} = args;
+ var player = args.player;
self.x -= velocityX;
self.y -= velocityY;
var dx = player.x - self.x;
var dy = player.y - self.y;
@@ -170,9 +173,11 @@
}
return Math.floor(value);
}
function activate(args) {
- var {pickupProjectileList, player, layers} = args;
+ var pickupProjectileList = args.pickupProjectileList,
+ player = args.player,
+ layers = args.layers;
var projectileX = self.x + decor.x + decor.width / 2;
var projectileY = self.y + decor.y;
pickupProjectileList.push(layers[LAYER_FOREGROUND].addChild(new PickupProjectile(projectileX, projectileY, player)));
decor.destroy();
@@ -198,10 +203,21 @@
self.y += velocityY;
return distance <= PICKUP_COLLIDE_DIST;
}
});
-var LandscapeTile = Container.expand(function (x, y, {lookup, xIndex, yIndex, density, pickups, monsters, player, key, landscapeTiles, layers, rampList}) {
+var LandscapeTile = Container.expand(function (x, y, _ref) {
var self = Container.call(this);
+ var lookup = _ref.lookup,
+ xIndex = _ref.xIndex,
+ yIndex = _ref.yIndex,
+ density = _ref.density,
+ pickups = _ref.pickups,
+ monsters = _ref.monsters,
+ player = _ref.player,
+ key = _ref.key,
+ landscapeTiles = _ref.landscapeTiles,
+ layers = _ref.layers,
+ rampList = _ref.rampList;
var obstructions = [];
var background = self.createAsset('landscapeBackground', 'Landscape background', 0.5, 0.5);
background.width = TILE_SIZE;
background.height = TILE_SIZE;
@@ -246,23 +262,31 @@
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, TILE_SIZE, TILE_SIZE, clearanceDist);
+ var _randomPointInRect = randomPointInRect(self.x, self.y, TILE_SIZE, TILE_SIZE, clearanceDist),
+ pointX = _randomPointInRect.pointX,
+ pointY = _randomPointInRect.pointY;
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, TILE_SIZE, TILE_SIZE, clearanceDist);
+ var _randomPointInRect2 = randomPointInRect(self.x, self.y, TILE_SIZE, TILE_SIZE, clearanceDist),
+ pointX = _randomPointInRect2.pointX,
+ pointY = _randomPointInRect2.pointY;
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, TILE_SIZE, TILE_SIZE, clearanceDist);
+ var _randomPointInRect3 = randomPointInRect(self.x, self.y, TILE_SIZE, TILE_SIZE, clearanceDist),
+ pointX = _randomPointInRect3.pointX,
+ pointY = _randomPointInRect3.pointY;
monsters.push(self.parent.addChild(new Monster(self.x, self.y)));
}
for (i = 0; i < cols; i++) {
for (j = 0; j < rows; j++) {
if (Math.random() <= densityChance) {
var canPlace = true;
- var {pointX, pointY} = randomPointInRect(cellWidth * i, cellHeight * j, cellWidth, cellHeight, spawnBorder);
+ var _randomPointInRect4 = randomPointInRect(cellWidth * i, cellHeight * j, cellWidth, cellHeight, spawnBorder),
+ pointX = _randomPointInRect4.pointX,
+ pointY = _randomPointInRect4.pointY;
if (landmark) {
var dx = landmark.x - pointX;
var dy = landmark.y - pointY;
var distSqr = dx * dx + dy * dy;
@@ -286,58 +310,59 @@
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,
- lookup,
- pickups,
- monsters,
- layers,
- player
+ yIndex: yIndex,
+ landscapeTiles: landscapeTiles,
+ rampList: rampList,
+ lookup: lookup,
+ pickups: pickups,
+ monsters: monsters,
+ layers: layers,
+ player: player
})));
}
if (!lookup[rightKey]) {
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,
- lookup,
- pickups,
- monsters,
- layers,
- player
+ yIndex: yIndex,
+ landscapeTiles: landscapeTiles,
+ rampList: rampList,
+ lookup: lookup,
+ pickups: pickups,
+ monsters: monsters,
+ layers: layers,
+ player: player
})));
}
if (!lookup[downKey]) {
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,
- lookup,
- pickups,
- monsters,
- layers,
- player
+ xIndex: xIndex,
+ landscapeTiles: landscapeTiles,
+ rampList: rampList,
+ lookup: lookup,
+ pickups: pickups,
+ monsters: monsters,
+ layers: layers,
+ player: player
})));
}
- function randomPointInRect(centerX, centerY, width, height, border = 0) {
+ function randomPointInRect(centerX, centerY, width, height) {
+ var border = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
var startX = centerX - width / 2 + border;
var startY = centerY - height / 2 + border;
var innerWidth = width - border * 2;
var innerHeight = height - border * 2;
var pointX = startX + Math.random() * innerWidth;
var pointY = startY + Math.random() * innerHeight;
return {
- pointX,
- pointY
+ pointX: pointX,
+ pointY: pointY
};
}
}
});
@@ -473,10 +498,10 @@
playerFront.alpha = imageAlpha;
playerSide.alpha = 1 - imageAlpha;
}
return {
- velocityX,
- velocityY
+ velocityX: velocityX,
+ velocityY: velocityY
};
}
function angleClamp(angle) {
return angle >= 0 ? angle : angle < -MATH_PI_BY_2 ? Math.PI : 0;
@@ -529,15 +554,14 @@
}
});
var Interface = Container.expand(function (x, y) {
var self = Container.call(this);
- var score = 0;
var lives = 3;
var lifeIcons = [];
var banner = self.createAsset('banner', 'Interface banner', 0.5, 0.5);
var scoreIcon = self.createAsset('scoreIcon', 'Score icon', 1, 0.5);
var dividor = self.createAsset('scoreDividor', 'Score dividor', 0.5, 0.5);
- var scoreText = self.addChild(new Text2(score, {
+ var scoreText = self.addChild(new Text2(LK.getScore(), {
size: 70,
fill: "#000000",
align: 'left'
}));
@@ -594,26 +618,66 @@
}
return false;
}
function changeScore(amount) {
- var returnValue = amount < 0 && score > 0;
- score = Math.max(0, score + amount);
- LK.setScore(score);
- scoreText.setText(score);
+ var returnValue = amount < 0 && LK.getScore() > 0;
+ LK.setScore(Math.max(0, LK.getScore() + amount));
+ scoreText.setText(LK.getScore());
return returnValue;
}
});
-var Instructions = Container.expand(function () {
+var Instructions = Container.expand(function (x, y) {
var self = Container.call(this);
- var instructionsText = self.addChild(new Text2('Tap, click or drag to change direction', {
- size: 50,
+ var instructionsText = 'Tap, click or drag to change direction';
+ var warningText = 'Warning: Monsters ahead';
+ var Distance;
+ var fadeDistance = 1000;
+ var fullDistance = 3000;
+ var distanceRemaining = fullDistance;
+ var instructionsShown = false;
+ var warningShown = false;
+ var warningOffset = 2000;
+ var distanceY = 0;
+ var displayText = self.addChild(new Text2('', {
+ size: 70,
fill: "#000000",
align: 'center'
}));
- instructionsText.anchor.set(0.5, 1);
- instructionsText.x = 0;
- instructionsText.y = 800;
+ displayText.anchor.set(0.5, 0.5);
+ ;
+ self.x = x;
+ self.y = y;
+ self.update = update;
+ ;
+ function update(velocityX, velocityY) {
+ distanceY += velocityY;
+ if (instructionsShown === false || warningShown === false && distanceY >= MONSTER_SPAWN_DIST - warningOffset) {
+ if (instructionsShown === false) {
+ instructionsShown = true;
+ displayText.setText(instructionsText);
+ } else {
+ warningShown = true;
+ displayText.setText(warningText);
+ }
+ distanceRemaining = fullDistance;
+ }
+ if (fadeDistance > 0) {
+ distanceRemaining -= velocityY * INTERFACE_SIZE_FACTOR;
+ displayText.alpha = Math.min(1, distanceRemaining / fadeDistance);
+ }
+ }
});
+
+/****
+* Initialize Game
+****/
+var game = new LK.Game({
+ backgroundColor: 0x000000
+});
+
+/****
+* Game Code
+****/
;
var MATH_PI_BY_2 = Math.PI / 2;
var MATH_PI_BY_180 = Math.PI / 180;
var STAGE_WIDTH = 2048;
@@ -656,137 +720,138 @@
var SHADOW_CRITICAL_HEIGHT = 1000;
var INTERFACE_HEIGHT_OFFSET = 40;
var INTERFACE_DIVIDOR_BORDER = -80;
var INTERFACE_SPACING = 10;
+var INTERFACE_SIZE_FACTOR = 0.6;
var LAYER_BACKGROUND = 0;
var LAYER_MIDGROUND = 1;
var LAYER_FOREGROUND = 2;
;
-var Game = Container.expand(function () {
- var self = Container.call(this);
- var playerPosX = Math.round(STAGE_WIDTH / 2);
- var playerPosY = Math.round(STAGE_WIDTH / 3);
- var landscapeLookup = {};
- var landscapeTiles = [];
- var pickups = [];
- var pickupProjectileList = [];
- var monsters = [];
- var effects = [];
- var rampList = [];
- ;
- var layers = [self.addChild(new Container()), self.addChild(new Container()), self.addChild(new Container())];
- var interface = LK.gui.topCenter.addChild(new Interface(0, INTERFACE_HEIGHT_OFFSET));
- var instructions = LK.gui.center.addChild(new Instructions());
- 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,
- key: '0:0',
- landscapeTiles,
- rampList,
- monsters,
- pickups,
- layers,
- player
- })));
- var isMouseDown = false;
- var targetPosition = {
- x: playerPosX,
- y: playerPosY
- };
- LK.stageContainer.setBackgroundColor(0xFFFFFF);
- ;
- stage.on('down', function (obj) {
- isMouseDown = true;
+var playerPosX = Math.round(STAGE_WIDTH / 2);
+var playerPosY = Math.round(STAGE_WIDTH / 3);
+var isMouseDown = false;
+var targetPosition = {
+ x: playerPosX,
+ y: playerPosY
+};
+var landscapeLookup = {};
+var landscapeTiles = [];
+var pickups = [];
+var pickupProjectileList = [];
+var monsters = [];
+var effects = [];
+var rampList = [];
+;
+var layers = [game.addChild(new Container()), game.addChild(new Container()), game.addChild(new Container())];
+var uiContainer = LK.gui.topCenter.addChild(new Interface(0, INTERFACE_HEIGHT_OFFSET));
+var instructions = LK.gui.bottom.addChild(new Instructions(0, -2 * INTERFACE_HEIGHT_OFFSET));
+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,
+ key: '0:0',
+ landscapeTiles: landscapeTiles,
+ rampList: rampList,
+ monsters: monsters,
+ pickups: pickups,
+ layers: layers,
+ player: player
+})));
+game.setBackgroundColor(0xFFFFFF);
+;
+game.on('down', function (obj) {
+ isMouseDown = true;
+ updatePosition(obj.event);
+});
+game.on('up', function (obj) {
+ isMouseDown = false;
+});
+game.on('move', function (obj) {
+ if (isMouseDown) {
updatePosition(obj.event);
- });
- stage.on('up', function (obj) {
- isMouseDown = false;
- });
- stage.on('move', function (obj) {
- if (isMouseDown) {
- updatePosition(obj.event);
- }
- });
- LK.on('tick', function () {
- var {velocityX, velocityY} = player.update(targetPosition);
- trail.update(velocityX, velocityY, !player.airborne);
- interface.update(player.distanceTravelled, player.netSpeed);
- for (var i = landscapeTiles.length - 1; i >= 0; i--) {
- var landscapeTile = landscapeTiles[i];
- landscapeTile.x -= velocityX;
- landscapeTile.y -= velocityY;
- if (landscapeTile.y < -(TILE_SIZE / 2 + TILE_MARGIN)) {
- landscapeTile.destroy();
- landscapeTiles.splice(i, 1);
- landscapeLookup[landscapeTile.key] = undefined;
- } 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(layers[LAYER_FOREGROUND].addChild(new DropEffect(player.x, player.y + PLAYER_COLLECTION_HEIGHT, player)));
- }
- if (!player.invulnerable) {
- player.invulnerable = true;
- player.invulnerableTimer = player.invulnerableTime;
- }
+ }
+});
+LK.on('tick', function () {
+ var _player$update = player.update(targetPosition),
+ velocityX = _player$update.velocityX,
+ velocityY = _player$update.velocityY;
+ trail.update(velocityX, velocityY, !player.airborne);
+ instructions.update(velocityX, velocityY);
+ uiContainer.update(player.distanceTravelled, player.netSpeed);
+ for (var i = landscapeTiles.length - 1; i >= 0; i--) {
+ var landscapeTile = landscapeTiles[i];
+ landscapeTile.x -= velocityX;
+ landscapeTile.y -= velocityY;
+ if (landscapeTile.y < -(TILE_SIZE / 2 + TILE_MARGIN)) {
+ landscapeTile.destroy();
+ landscapeTiles.splice(i, 1);
+ landscapeLookup[landscapeTile.key] = undefined;
+ } 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 (uiContainer.changeScore(-1)) {
+ effects.push(layers[LAYER_FOREGROUND].addChild(new DropEffect(player.x, player.y + PLAYER_COLLECTION_HEIGHT, player)));
}
- }
- ;
- var pickupArgs = {
- pickupProjectileList,
- layers,
- player
- };
- for (var i = pickups.length - 1; i >= 0; i--) {
- var pickup = pickups[i];
- if (pickup.update(velocityX, velocityY, pickupArgs)) {
- pickup.destroy();
- pickups.splice(i, 1);
+ if (!player.invulnerable) {
+ player.invulnerable = true;
+ player.invulnerableTimer = player.invulnerableTime;
}
}
- for (var i = effects.length - 1; i >= 0; i--) {
- var effect = effects[i];
- if (effect.update(velocityX, velocityY)) {
- effect.destroy();
- effects.splice(i, 1);
- }
+ }
+ ;
+ var pickupArgs = {
+ pickupProjectileList: pickupProjectileList,
+ layers: layers,
+ player: player
+ };
+ for (var i = pickups.length - 1; i >= 0; i--) {
+ var pickup = pickups[i];
+ if (pickup.update(velocityX, velocityY, pickupArgs)) {
+ pickup.destroy();
+ pickups.splice(i, 1);
}
- for (var i = rampList.length - 1; i >= 0; i--) {
- var ramp = rampList[i];
- if (ramp.update(velocityX, velocityY, player)) {
- rampList.splice(i, 1);
- }
+ }
+ for (var i = effects.length - 1; i >= 0; i--) {
+ var effect = effects[i];
+ if (effect.update(velocityX, velocityY)) {
+ effect.destroy();
+ effects.splice(i, 1);
}
- for (var i = monsters.length - 1; i >= 0; i--) {
- var monster = monsters[i];
- if (monster.update(velocityX, velocityY, player)) {
- monster.destroy();
- monsters.splice(i, 1);
- } else if (!monster.jumping && !player.airborne && monster.hitbox.intersects(player.hitbox)) {
- effects.push(layers[LAYER_FOREGROUND].addChild(new BloodsplatterEffect(monster.x, monster.y)));
- monster.destroy();
- monsters.splice(i, 1);
- if (interface.changeLives(-1)) {
- LK.showGameOver();
- }
- }
+ }
+ for (var i = rampList.length - 1; i >= 0; i--) {
+ var ramp = rampList[i];
+ if (ramp.update(velocityX, velocityY, player)) {
+ rampList.splice(i, 1);
}
- for (var i = pickupProjectileList.length - 1; i >= 0; i--) {
- var pickupProjectile = pickupProjectileList[i];
- if (pickupProjectile.update()) {
- pickupProjectile.destroy();
- pickupProjectileList.splice(i, 1);
- interface.changeScore(1);
+ }
+ for (var i = monsters.length - 1; i >= 0; i--) {
+ var monster = monsters[i];
+ if (monster.update(velocityX, velocityY, player)) {
+ monster.destroy();
+ monsters.splice(i, 1);
+ } else if (!monster.jumping && !player.airborne && monster.hitbox.intersects(player.hitbox)) {
+ effects.push(layers[LAYER_FOREGROUND].addChild(new BloodsplatterEffect(monster.x, monster.y)));
+ monster.destroy();
+ monsters.splice(i, 1);
+ if (uiContainer.changeLives(-1)) {
+ LK.showGameOver();
}
}
- });
- ;
- function updatePosition(event) {
- var pos = event.getLocalPosition(self);
- targetPosition.x = pos.x;
- targetPosition.y = pos.y;
}
+ for (var i = pickupProjectileList.length - 1; i >= 0; i--) {
+ var pickupProjectile = pickupProjectileList[i];
+ if (pickupProjectile.update()) {
+ pickupProjectile.destroy();
+ pickupProjectileList.splice(i, 1);
+ uiContainer.changeScore(1);
+ }
+ }
});
+;
+function updatePosition(event) {
+ var pos = event.getLocalPosition(game);
+ targetPosition.x = pos.x;
+ targetPosition.y = pos.y;
+}
\ No newline at end of file
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 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 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.
pixel art of a red flag. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
pixel art of a red orb. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
white
white
pixel art shape of a red arrow pointing downwards. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
pixel art banner of a pair of skis crossed. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
white