User prompt
end the game if landscapeTile.checkCollision return true within the tick function
Code edit (22 edits merged)
Please save this source code
User prompt
in the checkCollision function, if the player is within reach of the landscapeTile, iterate through the obstructions and check if the player's hitbox intersects with the obstructions hitbox
Code edit (1 edits merged)
Please save this source code
Code edit (2 edits merged)
Please save this source code
User prompt
After moving obstructions, check if their hitbox intersect the player hitbox and show a game over
User prompt
The player also has a 1x1 hitbox centered on the bottom
User prompt
all obstructions have a hitbox graphic, centered on the bottom of the graphic. These hitboxes have a width of the graphics and a height of half the width
User prompt
add black text to the top-right of the screen showing the current velocity as "Speed:"
Code edit (3 edits merged)
Please save this source code
User prompt
spawn a new obstacle below the bottom of the screen, with a random x position, every 100 distance traveled in the y direction
Code edit (1 edits merged)
Please save this source code
User prompt
velocity should scale based on the angle, with vertical being 100%, and horizonal being 0%
User prompt
destroy obstructions whose y position is < -100
User prompt
obstructions should be stored in an obstructions array. Instead of iterating through the children in the tick function, use the obstructions array
User prompt
instead of setting the player position to the position variable, increase the positions of all obstructions by the velocity
User prompt
every tick adjust the position variable by the speed in the direction of angle
User prompt
when spawning obstructions, they should uniformally randomize their scale between 0.9 and 1.1, and have their x scale randomly flipped
Code edit (11 edits merged)
Please save this source code
User prompt
on game start, randomly spawn 10 obstructions within the screen space
User prompt
Add several obstruction classes; LargeTree, SmallTree, Rock, Stump, DeadTree and a function that would randomly spawn one of these obstructions at a given location
Code edit (2 edits merged)
Please save this source code
User prompt
when setting the targetPosition, flip the playerGraphics if the targetPos.x < player.x
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'TypeError: player is undefined' in this line: 'platform.y = player.y + playerGraphics.height / 2 + platformGraphics.height / 2;' Line Number: 47
===================================================================
--- original.js
+++ change.js
@@ -2,31 +2,101 @@
var self = Container.call(this);
parent.addChild(self);
self.x = x;
self.y = y;
- self.width = args.width;
- self.height = args.height;
+ var landscapeTiles = args.landscapeTiles;
+ var lookup = args.lookup;
+ var xIndex = args.xIndex;
+ var yIndex = args.yIndex;
+ var width = args.width;
+ var height = args.height;
+ var density = args.density;
+ var key = args.key;
+ self.checkCollision = checkCollision;
+ self.activate = activate;
+ self.width = width;
+ self.height = height;
+ self.active = false;
+ self.key = key;
var obstructions = [];
- var densityChance = Math.pow(1 + args.density, 3) / 100;
- var obstructionTypes = ['largeTree', 'smallTree', 'deadTree', 'rock', 'stump'];
- var spawnBorder = 10;
- var cellSize = 100;
- var cols = Math.ceil(args.width / cellSize);
- var rows = Math.ceil(args.height / cellSize);
- var cellWidth = args.width / cols;
- var cellHeight = args.height / rows;
- var cellInnerWidth = Math.max(0, cellWidth - 2 * spawnBorder);
- var cellInnerHeight = Math.max(0, cellHeight - 2 * spawnBorder);
- for (i = 0; i < cols; i++) {
- for (j = 0; j < rows; j++) {
- if (Math.random() <= densityChance) {
- var obsX = cellWidth * i + spawnBorder + Math.random() * cellInnerWidth;
- var obsY = cellHeight * j + spawnBorder + Math.random() * cellInnerHeight;
- var type = obstructionTypes[Math.floor(Math.random() * obstructionTypes.length)];
- obstructions.push(new Obstruction(self, obsX, obsY, type));
+ var visual = self.createAsset('hitbox', 'Landscape area', 0.5, 0.5);
+ visual.alpha = 0;
+ visual.width = width;
+ visual.height = height;
+ function checkCollision(player, x, y) {
+ var reach = 200;
+ var dx = Math.abs(x - self.x);
+ var dy = Math.abs(y - self.y);
+ if (dx < width / 2 + reach && dy < height / 2 + reach) {
+ for (var i = 0; i < obstructions.length; i++) {
+ if (player.hitbox.intersects(obstructions[i].hitbox)) {}
}
}
}
+ function activate() {
+ if (!self.active) {
+ self.active = true;
+ var densityChance = Math.pow(1 + density, 3) / 100;
+ var obstructionTypes = ['largeTree', 'smallTree', 'deadTree', 'rock', 'stump'];
+ var spawnBorder = 10;
+ var cellSize = 100;
+ var cols = Math.ceil(width / cellSize);
+ var rows = Math.ceil(height / cellSize);
+ var cellWidth = width / cols;
+ var cellHeight = height / rows;
+ var cellInnerWidth = Math.max(0, cellWidth - 2 * spawnBorder);
+ var cellInnerHeight = Math.max(0, cellHeight - 2 * spawnBorder);
+ for (i = 0; i < cols; i++) {
+ for (j = 0; j < rows; j++) {
+ if (Math.random() <= densityChance) {
+ var obsX = cellWidth * i + spawnBorder + Math.random() * cellInnerWidth - width / 2;
+ var obsY = cellHeight * j + spawnBorder + Math.random() * cellInnerHeight - height / 2;
+ var type = obstructionTypes[Math.floor(Math.random() * obstructionTypes.length)];
+ obstructions.push(new Obstruction(self, obsX, obsY, type));
+ }
+ }
+ }
+ }
+ var leftKey = xIndex - 1 + ':' + yIndex;
+ var rightKey = xIndex + 1 + ':' + yIndex;
+ var downKey = xIndex + ':' + (yIndex + 1);
+ if (!lookup[leftKey]) {
+ landscapeTiles.push(lookup[leftKey] = new LandscapeTile(parent, self.x - width, self.y, {
+ key: leftKey,
+ density: Math.random(),
+ xIndex: xIndex - 1,
+ yIndex,
+ landscapeTiles,
+ width,
+ height,
+ lookup
+ }));
+ }
+ if (!lookup[rightKey]) {
+ landscapeTiles.push(lookup[rightKey] = new LandscapeTile(parent, self.x + width, self.y, {
+ key: rightKey,
+ density: Math.random(),
+ xIndex: xIndex + 1,
+ yIndex,
+ landscapeTiles,
+ width,
+ height,
+ lookup
+ }));
+ }
+ if (!lookup[downKey]) {
+ landscapeTiles.push(lookup[downKey] = new LandscapeTile(parent, self.x, self.y + height, {
+ key: downKey,
+ density: Math.random(),
+ yIndex: yIndex + 1,
+ xIndex,
+ landscapeTiles,
+ width,
+ height,
+ lookup
+ }));
+ }
+ }
});
var Obstruction = Container.expand(function (parent, x, y, type) {
var self = Container.call(this);
parent.addChild(self);
@@ -55,20 +125,18 @@
var Game = Container.expand(function () {
var self = Container.call(this);
var stageWidth = 2048;
var stageHeight = 2732;
+ var tileSize = 512;
+ var tileMargin = tileSize / 2 + 100;
var background = self.createAsset('background', 'Fullscreen background', 0, 0);
+ var landscapeLookup = {};
var landscapeTiles = [];
- var position = {
- x: 0,
- y: 0
- };
var direction = {
x: 0,
y: 0
};
var speed = 0;
- var totalDistanceY = 0;
background.width = stageWidth;
background.height = stageHeight;
var targetPosition = {
x: 0,
@@ -85,8 +153,18 @@
});
speedText.anchor.set(1, 0);
speedText.x = stageWidth;
speedText.y = 0;
+ landscapeTiles.push(landscapeLookup['0:0'] = new LandscapeTile(self, player.x, player.y, {
+ width: tileSize,
+ height: tileSize,
+ density: -1,
+ lookup: landscapeLookup,
+ xIndex: 0,
+ yIndex: 0,
+ key: '0:0',
+ landscapeTiles
+ }));
LK.gui.topRight.addChild(speedText);
var isMouseDown = false;
stage.on('down', function (obj) {
isMouseDown = true;
@@ -108,18 +186,21 @@
speed = Math.max(0, speed * 0.95 + acceleration);
player.platformGraphics.rotation = angle + Math.PI / 2;
var velocityX = Math.cos(angle) * speed;
var velocityY = Math.sin(angle) * speed;
- for (var i = self.landscapeTiles.length - 1; i >= 0; i--) {
+ for (var i = landscapeTiles.length - 1; i >= 0; i--) {
var landscapeTile = landscapeTiles[i];
landscapeTile.x -= velocityX;
landscapeTile.y -= velocityY;
- if (landscapeTile.y < -100) {
+ if (landscapeTile.y < -(tileSize / 2 + tileMargin)) {
landscapeTile.destroy();
landscapeTiles.splice(i, 1);
+ landscapeLookup[landscapeTile.key] = undefined;
+ } else if (landscapeTile.x > -tileMargin && landscapeTile.x < stageWidth + tileMargin && landscapeTile.y < stageHeight + tileMargin) {
+ landscapeTile.activate();
}
+ speedText.setText('Speed: ' + speed);
}
- speedText.setText('Speed: ' + speed);
});
function angleClamp(angle) {
return angle >= 0 ? angle : angle < -Math.PI / 2 ? Math.PI : 0;
}
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.