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.
Code edit (1 edits merged)
Please save this source code
User prompt
make the player invulnerable for 3 seconds after landscapeTile.checkCollision returns true
Code edit (1 edits merged)
Please save this source code
Code edit (8 edits merged)
Please save this source code
User prompt
flash the screen red when losing a life instead of on game over
Code edit (6 edits merged)
Please save this source code
User prompt
Fix Bug: 'ReferenceError: scoreText is not defined' in this line: 'scoreText.setText(score);' Line Number: 328
User prompt
Move the displayed score, score icon and lives into its own Interface class. This class should have changeLives(amount) and changeScore(amount) functions which change the score and lives values by the amount
User prompt
Fix Bug: 'TypeError: self.gameInstance.lifeIcons is undefined' in this line: 'var lifeIcon = self.gameInstance.lifeIcons[self.gameInstance.lives];' Line Number: 191
User prompt
Fix Bug: 'TypeError: self.parent.lifeIcons is undefined' in this line: 'var lifeIcon = self.parent.lifeIcons[self.parent.lives];' Line Number: 190
User prompt
The player should have 3 lives, displayed as three icons under the score. The player should lose 1 life when colliding with an obstacle, and the obstacle should become inactive
User prompt
Fix Bug: 'ReferenceError: velocityX is not defined' in this line: 'playerGraphics.scale.x = velocityX < 0 ? -1 : 1;' Line Number: 193
Code edit (1 edits merged)
Please save this source code
User prompt
landscapeTiles should create the pickup before the obstructions, additionally, if a pickup is created, prevent spawning obstructions within 200 distance from the pickup
Code edit (1 edits merged)
Please save this source code
Code edit (3 edits merged)
Please save this source code
User prompt
when a pickup is within 200*200 distance squared from the player, the pickup becomes active, flying towards the player at a speed of 5
Code edit (4 edits merged)
Please save this source code
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 Trail = Container.expand(function (parent, x, y) { var self = Container.call(this); parent.addChild(self); self.x = x; self.y = y; var trailWidth = 20; var trailLength = 30; var trailAlpha = 0.6; var trailElements = []; self.update = update; function update(velocityX, velocityY) { var trailElement = null; if (velocityX !== 0 || velocityY !== 0) { trailElement = self.createAsset('blank', 'Trail element', 1, 0.5); var angle = Math.atan2(velocityY, velocityX) + Math.PI / 2; var speed = Math.sqrt(velocityX * velocityX + velocityY * velocityY); trailElement.rotation = angle; trailElement.scale.y = speed / 100; } trailElements.push(trailElement); if (trailElements.length > trailLength) { var removedElement = trailElements.shift(); if (removedElement) { removedElement.destroy(); } } for (var i = trailElements.length - 1; i >= 0; i--) { var element = trailElements[i]; if (element) { var alpha = trailAlpha * (i / trailLength); element.x -= velocityX; element.y -= velocityY; element.alpha = alpha; } } } }); 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 playerPosX = stageWidth / 2; var playerPosY = stageWidth / 5; 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 trail = new Trail(self, playerPosX, playerPosY); var player = new Player(self, playerPosX, playerPosY); 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); trail.update(velocityX, velocityY); 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; } });
===================================================================
--- original.js
+++ change.js
@@ -239,10 +239,9 @@
trailElement = self.createAsset('blank', 'Trail element', 1, 0.5);
var angle = Math.atan2(velocityY, velocityX) + Math.PI / 2;
var speed = Math.sqrt(velocityX * velocityX + velocityY * velocityY);
trailElement.rotation = angle;
- trailElement.scale.x = speed / 100;
- trailElement.scale.y = trailWidth / 100;
+ trailElement.scale.y = speed / 100;
}
trailElements.push(trailElement);
if (trailElements.length > trailLength) {
var removedElement = trailElements.shift();
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.