Code edit (1 edits merged)
Please save this source code
User prompt
Add an effects array to the game class, and add a BloodsplatterEffect class, which lasts for 1s, growing larger and more transparent, and is also affected by the player velocity. When a monster is destroyed after taking a player life, create a BloodsplatterEffect
Code edit (1 edits merged)
Please save this source code
Code edit (10 edits merged)
Please save this source code
User prompt
Add a hitbox to the monster. After updating a monster, check if its hitbox intersects the player's hitbox, causing the player to lose a life
User prompt
The changeScore function should additionally call the LK.setScore function after adjusting the score
User prompt
ensure the score cannot go below zero
User prompt
instead of losing a life when colliding with an obstacle, reduce the score by 1, but keep the invulnerability system
User prompt
instead of losing a life when colliding with an obstacle, reduce the score by 1
Code edit (8 edits merged)
Please save this source code
User prompt
pickups should also have a shadow
Code edit (1 edits merged)
Please save this source code
Code edit (2 edits merged)
Please save this source code
User prompt
the monsters have shadow assets underneath them
Code edit (5 edits merged)
Please save this source code
User prompt
after traveling 10000 distance, spawn a new Monster class at the bottom of the screen that heads towards the player, but is also affected by the VelocityX and VelocityY in it's update function
User prompt
add a monsters array variable to the game class
Code edit (1 edits merged)
Please save this source code
Code edit (4 edits merged)
Please save this source code
User prompt
Fix Bug: 'TypeError: removedElement is null' in this line: 'removedElement.destroy();' Line Number: 249
Code edit (8 edits merged)
Please save this source code
User prompt
the new trailelement should be scaled and rotated to match the velocity
User prompt
Add an update function that takes in a velocityX and velocityY to the Trail class. The update function creates a `blank` asset and adds it to a list, if the list has more than 60 elements the first element is removed. All elements have their x and y adjusted by the velocityX and velocityY
User prompt
Create a Trail class that takes a `parent`, `x`, and `y` parameters
User prompt
Create a Trail class that takes a `parent`, `x`, `y`, and `args` parameters.
var Trail = Container.expand(function (parent, x, y, args) {
var self = Container.call(this);
parent.addChild(self);
self.x = x;
self.y = y;
self.trailLength = args.trailLength || 10;
self.update = function () {};
});
var Pickup = Container.expand(function (parent, x, y) {
var self = Container.call(this);
parent.addChild(self);
self.x = x;
self.y = y;
self.update = update;
var activeDist = 300;
var activeDistSqr = activeDist * activeDist;
var collectDist = 50;
var collectDistSqr = collectDist * collectDist;
var collectSpeed = 25;
var collectOffset = -50;
var active = false;
var variant = Math.floor(Math.random() * 3);
var graphics = self.createAsset('pickup' + variant, 'Pickup graphics', 0.5, 0.5);
function update(player, velocityX, velocityY) {
var dx = player.x - self.x;
var dy = player.y + collectOffset - self.y;
var distSqr = dx * dx + dy * dy;
if (self.active) {
var dist = Math.sqrt(distSqr);
self.x += dx / dist * collectSpeed;
self.y += dy / dist * collectSpeed;
} else if (distSqr <= activeDistSqr) {
self.active = true;
} else {
self.x -= velocityX;
self.y -= velocityY;
}
return distSqr <= collectDistSqr;
}
});
var LandscapeTile = Container.expand(function (parent, x, y, args) {
var self = Container.call(this);
parent.addChild(self);
self.x = x;
self.y = y;
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 pickups = args.pickups;
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 visual = self.createAsset('hitbox', 'Landscape area', 0.5, 0.5);
visual.alpha = 0;
visual.width = width;
visual.height = height;
function checkCollision(player) {
var reach = 100;
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) {
for (var i = 0; i < obstructions.length; i++) {
var obstruction = obstructions[i];
if (obstruction.active && player.hitbox.intersects(obstruction.hitbox)) {
obstruction.deactivate();
return true;
}
}
}
return false;
}
function activate() {
if (!self.active) {
self.active = true;
var densityChance = Math.pow(1 + density, 3) / 100;
var obstructionTypes = ['largeTree', 'smallTree', 'deadTree', 'rock', 'stump'];
var clearanceDist = 150;
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 cellInnerWidth = Math.max(0, cellWidth - 2 * spawnBorder);
var cellInnerHeight = Math.max(0, cellHeight - 2 * spawnBorder);
var pickup;
if (Math.random() <= 0.1) {
var pickupX = self.x - width / 2 + spawnBorder + Math.random() * (width - spawnBorder * 2);
var pickupY = self.y - height / 2 + spawnBorder + Math.random() * (height - spawnBorder * 2);
pickups.push(pickup = new Pickup(parent, pickupX, pickupY));
}
for (i = 0; i < cols; i++) {
for (j = 0; j < rows; j++) {
if (Math.random() <= densityChance) {
var canPlace = true;
var obsX = cellWidth * i + spawnBorder + Math.random() * cellInnerWidth - width / 2;
var obsY = cellHeight * j + spawnBorder + Math.random() * cellInnerHeight - height / 2;
if (pickup) {
var dx = pickup.x - obsX;
var dy = pickup.y - obsY;
var distSqr = dx * dx + dy * dy;
if (distSqr <= clearanceDistSqr) {
canPlace = false;
}
}
if (canPlace) {
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,
pickups
}));
}
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,
pickups
}));
}
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,
pickups
}));
}
}
});
var Obstruction = Container.expand(function (parent, x, y, type) {
var self = Container.call(this);
parent.addChild(self);
self.x = x;
self.y = y;
self.active = true;
var graphics = self.createAsset(type, 'Obstruction graphics', 0.5, 1);
var hitbox = self.createAsset('hitbox', 'Obstruction hitbox', 0.5, 0.5);
var randomScale = 0.9 + Math.random() * 0.2;
hitbox.y = -25;
hitbox.alpha = 0;
hitbox.width = graphics.width * 0.8;
hitbox.height = graphics.width * 0.45;
self.scale.set(randomScale, randomScale);
self.hitbox = hitbox;
self.deactivate = deactivate;
function deactivate() {
self.active = false;
graphics.alpha = 0.5;
}
});
var Player = Container.expand(function (parent, x, y) {
var self = Container.call(this);
parent.addChild(self);
self.x = x;
self.y = y;
self.update = update;
var speed = 0;
self.invulnerable = false;
self.invulnerableTime = 3 * 60;
self.invulnerableTimer = 0;
var invulnerableReduction = 0.75;
var platformGraphics = self.createAsset('platform', 'Platform image', 0.5, 0.5);
var playerGraphics = self.createAsset('player', 'Player character', 0.575, 1);
var hitbox = self.createAsset('hitbox', 'Player Hitbox', 0.5, 0.5);
hitbox.width = 25;
hitbox.height = 25;
hitbox.alpha = 0;
self.hitbox = hitbox;
function update(targetPosition) {
if (self.invulnerable) {
self.invulnerableTimer--;
if (self.invulnerableTimer <= 0) {
self.invulnerable = false;
}
self.alpha = self.invulnerableTimer % 60 < 30 ? 1 : 0.5;
}
var dx = targetPosition.x - self.x;
var dy = targetPosition.y - self.y;
var angle = angleClamp(Math.atan2(dy, dx));
var acceleration = (Math.sin(angle) - 0.1) * 2.0;
speed = Math.max(0, speed * 0.95 + acceleration);
var reduction = self.invulnerable ? 1 - self.invulnerableTimer / self.invulnerableTime : 1;
var velocityX = Math.cos(angle) * speed * reduction;
var velocityY = Math.sin(angle) * speed * reduction;
platformGraphics.rotation = angle + Math.PI / 2;
playerGraphics.scale.x = velocityX < 0 ? -1 : 1;
return {
velocityX,
velocityY
};
}
function angleClamp(angle) {
return angle >= 0 ? angle : angle < -Math.PI / 2 ? Math.PI : 0;
}
});
var Interface = Container.expand(function (parent, x, y) {
var self = Container.call(this);
parent.addChild(self);
self.x = x;
self.y = y;
var score = 0;
var lives = 3;
var lifeIcons = [];
var scoreIcon = self.createAsset('scoreIcon', 'Score icon', 0.5, 0);
var scoreText = new Text2('| ' + score, {
size: 70,
fill: "#000000",
align: 'left'
});
self.addChild(scoreText);
for (var i = 0; i < lives; i++) {
var lifeIcon = self.createAsset('lifeIcon', 'Life icon', 1, 0);
lifeIcon.x = -10 - i * 60;
lifeIcon.y = scoreIcon.height + 20;
lifeIcons.push(lifeIcon);
}
scoreText.x = -5;
scoreText.y = scoreIcon.height;
scoreText.anchor.set(0, 0);
self.changeScore = changeScore;
self.changeLives = changeLives;
function changeLives(amount) {
lives += amount;
for (var i = 0; i < lifeIcons.length; i++) {
lifeIcons[i].alpha = i < lives ? 1 : 0.5;
}
if (amount < 0) {
LK.effects.flashScreen(0xaa0000, 300);
if (lives <= 0) {
LK.showGameOver();
}
}
}
function changeScore(amount) {
score += amount;
scoreText.setText('| ' + score);
}
});
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 pickups = [];
var speed = 0;
background.width = stageWidth;
background.height = stageHeight;
var interface = new Interface(self, 0, 20);
LK.gui.topCenter.addChild(interface);
var player = new Player(self, stageWidth / 2, stageHeight / 5);
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,
pickups
}));
var isMouseDown = false;
var targetPosition = {
x: player.x,
y: player.y
};
stage.on('down', function (obj) {
isMouseDown = true;
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);
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)) {
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) {
landscapeTile.activate();
} else if (landscapeTile.checkCollision(player) && !player.invulnerable) {
player.invulnerable = true;
player.invulnerableTimer = player.invulnerableTime;
interface.changeLives(-1);
}
}
for (var i = pickups.length - 1; i >= 0; i--) {
var pickup = pickups[i];
if (pickup.update(player, velocityX, velocityY)) {
interface.changeScore(1);
pickup.destroy();
pickups.splice(i, 1);
} else if (pickup.y < -(tileSize / 2 + tileMargin) || pickup.active && player.hitbox.intersects(pickup.hitbox)) {
pickup.destroy();
pickups.splice(i, 1);
}
}
});
function updatePosition(event) {
var pos = event.getLocalPosition(self);
targetPosition.x = pos.x;
targetPosition.y = pos.y;
}
});
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.