User prompt
Add dash button
User prompt
Background shouldn't be black
User prompt
Make background a pixel starry night
User prompt
Make game faster
User prompt
Extend barriers to lengthen and make game faster
User prompt
Extend barriers and make game faster
User prompt
Replace the background with gorgeous pixel art cubes,rectangles and electronic theme
User prompt
Replace the background with gorgeous pixel art cubes,rectangles and electronic theme
User prompt
Change the costume button with color button
User prompt
Add menu the game. In the menu, there should be play button and coştu me button. In costume button select the characters desin
User prompt
Make this game a bit slow
User prompt
Add main menu the game
User prompt
Make game a bit slowly
User prompt
Should be printeble blocks sometimes
User prompt
On the top side should be barriers
User prompt
Make character fall slowly
Code edit (1 edits merged)
Please save this source code
User prompt
Pixel Runner: Barrier Dash
Initial prompt
Make Me a pixel side view run game with barriers
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
// Barrier (obstacle)
var Barrier = Container.expand(function () {
var self = Container.call(this);
var barrierSprite = self.attachAsset('barrier', {
anchorX: 0.5,
anchorY: 1
});
self.width = barrierSprite.width;
self.height = barrierSprite.height;
self.speed = 0; // Will be set by game
// Called every tick
self.update = function () {
self.x -= self.speed;
};
return self;
});
// PrintableBlock (special printable barrier)
var PrintableBlock = Container.expand(function () {
var self = Container.call(this);
var blockSprite = self.attachAsset('barrier', {
anchorX: 0.5,
anchorY: 1
});
self.width = blockSprite.width;
self.height = blockSprite.height;
self.speed = 0; // Will be set by game
// Optionally, visually distinguish printable blocks (e.g. by color)
blockSprite.color = 0x27ae60; // greenish, but engine may ignore this
// Called every tick
self.update = function () {
self.x -= self.speed;
};
return self;
});
// Runner (player character)
var Runner = Container.expand(function () {
var self = Container.call(this);
var runnerSprite = self.attachAsset('runner', {
anchorX: 0.5,
anchorY: 1
});
self.width = runnerSprite.width;
self.height = runnerSprite.height;
self.groundY = 0; // Will be set after ground is created
self.isJumping = false;
self.jumpStartY = 0;
self.jumpStartTime = 0;
self.jumpDuration = 0;
self.jumpHeight = 0;
self.velocityY = 0;
// Physics
self.gravity = 1.2; // px per tick^2 (reduced for slower fall)
self.jumpVelocity = -52; // px per tick (negative is up)
// Called every tick
self.update = function () {
// If jumping, apply velocity
if (self.isJumping) {
self.y += self.velocityY;
self.velocityY += self.gravity;
// Landed
if (self.y >= self.groundY) {
self.y = self.groundY;
self.isJumping = false;
self.velocityY = 0;
}
}
};
// Start jump
self.jump = function () {
if (!self.isJumping) {
self.isJumping = true;
self.velocityY = self.jumpVelocity;
}
};
// Cancel jump (for variable jump height)
self.cancelJump = function () {
if (self.isJumping && self.velocityY < -18) {
self.velocityY = -18;
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000
});
/****
* Game Code
****/
// Gorgeous pixel art electronic cubes/rectangles background
var backgroundCubes = [];
var BG_SCROLL_SPEED = 1.2; // slower than game scroll
var BG_ROWS = 7;
var BG_COLS = 12;
var BG_CUBE_SIZE = 180;
var BG_COLORS = [0x1abc9c, 0x16a085, 0x2ecc71, 0x27ae60, 0x3498db, 0x2980b9, 0x9b59b6, 0x8e44ad, 0xf1c40f, 0xf39c12, 0xe67e22, 0xe74c3c, 0xecf0f1, 0x95a5a6, 0x34495e, 0x2c3e50];
// Create cubes in a grid, with random color and "electronic" pixel art look
function createBackgroundCubes() {
for (var row = 0; row < BG_ROWS; row++) {
for (var col = 0; col < BG_COLS; col++) {
var color = BG_COLORS[Math.floor(Math.random() * BG_COLORS.length)];
var cube = LK.getAsset('ground', {
anchorX: 0,
anchorY: 0,
width: BG_CUBE_SIZE - 10 + Math.floor(Math.random() * 12),
// pixel art offset
height: BG_CUBE_SIZE - 10 + Math.floor(Math.random() * 12),
x: col * BG_CUBE_SIZE + Math.floor(Math.random() * 8),
y: row * BG_CUBE_SIZE + Math.floor(Math.random() * 8)
});
cube.tint = color;
cube.alpha = 0.22 + Math.random() * 0.18;
// Add some "electronic" lines or dots
if (Math.random() < 0.4) {
var dot = LK.getAsset('ground', {
anchorX: 0,
anchorY: 0,
width: 18 + Math.floor(Math.random() * 10),
height: 18 + Math.floor(Math.random() * 10),
x: cube.x + 30 + Math.floor(Math.random() * 60),
y: cube.y + 30 + Math.floor(Math.random() * 60)
});
dot.tint = 0xffffff;
dot.alpha = 0.12 + Math.random() * 0.12;
backgroundCubes.push(dot);
game.addChild(dot);
}
backgroundCubes.push(cube);
game.addChild(cube);
}
}
}
createBackgroundCubes();
// Animate background cubes for parallax effect
function updateBackgroundCubes() {
for (var i = 0; i < backgroundCubes.length; i++) {
var cube = backgroundCubes[i];
cube.x -= BG_SCROLL_SPEED;
// Wrap around to right if off screen
if (cube.x < -BG_CUBE_SIZE) {
cube.x += BG_COLS * BG_CUBE_SIZE + BG_CUBE_SIZE;
// Optionally randomize color for more variety
if (cube.width > 40 && cube.height > 40) {
cube.tint = BG_COLORS[Math.floor(Math.random() * BG_COLORS.length)];
}
}
}
}
// Game constants
var GROUND_Y = 2200; // y position of ground top
var RUNNER_START_X = 400;
var BARRIER_MIN_GAP = 600;
var BARRIER_MAX_GAP = 950;
var BARRIER_MIN_HEIGHT = 180;
var BARRIER_MAX_HEIGHT = 320;
var BARRIER_WIDTH = 80;
var SCROLL_START_SPEED = 11;
var SCROLL_MAX_SPEED = 22;
var SCROLL_ACCEL = 0.018; // px per tick^2
// Character (costume) options
var CHARACTER_OPTIONS = [{
id: 'runner',
color: 0x2d9cdb
},
// blue
{
id: 'runner',
color: 0xe67e22
},
// orange
{
id: 'runner',
color: 0x27ae60
},
// green
{
id: 'runner',
color: 0x8e44ad
} // purple
];
var selectedCharacterIndex = 0;
// Game state
var runner = null;
var ground = null;
var barriers = [];
var score = 0;
var scrollSpeed = SCROLL_START_SPEED;
var lastBarrierX = 0;
var isGameOver = false;
var isTouching = false;
// Menu state
var isMenuOpen = true;
var menuContainer = null;
var costumeContainer = null;
// Score display
var scoreTxt = new Text2('0', {
size: 140,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Create ground
ground = LK.getAsset('ground', {
anchorX: 0,
anchorY: 0,
x: 0,
y: GROUND_Y
});
game.addChild(ground);
// Create runner (with selected costume)
function createRunnerWithCostume() {
var costume = CHARACTER_OPTIONS[selectedCharacterIndex];
var r = new Runner();
// Set color if possible
if (r.children && r.children[0]) {
r.children[0].tint = costume.color;
}
r.x = RUNNER_START_X;
r.groundY = GROUND_Y;
r.y = GROUND_Y;
return r;
}
runner = createRunnerWithCostume();
game.addChild(runner);
// Menu UI
function showMenu() {
isMenuOpen = true;
if (menuContainer) {
menuContainer.visible = true;
return;
}
menuContainer = new Container();
// Background overlay
var overlay = LK.getAsset('ground', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0,
width: 2048,
height: 2732
});
overlay.alpha = 0.85;
menuContainer.addChild(overlay);
// Title
var title = new Text2('Endless Runner', {
size: 180,
fill: 0xffffff
});
title.anchor.set(0.5, 0);
title.x = 2048 / 2;
title.y = 400;
menuContainer.addChild(title);
// Play button
var playBtn = LK.getAsset('barrier', {
anchorX: 0.5,
anchorY: 0.5,
width: 500,
height: 180,
x: 2048 / 2,
y: 900
});
playBtn.tint = 0x27ae60;
menuContainer.addChild(playBtn);
var playTxt = new Text2('PLAY', {
size: 120,
fill: 0xffffff
});
playTxt.anchor.set(0.5, 0.5);
playTxt.x = playBtn.x;
playTxt.y = playBtn.y;
menuContainer.addChild(playTxt);
// Color button
var colorBtn = LK.getAsset('barrier', {
anchorX: 0.5,
anchorY: 0.5,
width: 500,
height: 180,
x: 2048 / 2,
y: 1200
});
colorBtn.tint = 0x2980b9;
menuContainer.addChild(colorBtn);
var colorTxt = new Text2('COLOR', {
size: 100,
fill: 0xffffff
});
colorTxt.anchor.set(0.5, 0.5);
colorTxt.x = colorBtn.x;
colorTxt.y = colorBtn.y;
menuContainer.addChild(colorTxt);
// Play button event
playBtn.down = function (x, y, obj) {
hideMenu();
startGame();
};
playTxt.down = playBtn.down;
// Color button event
colorBtn.down = function (x, y, obj) {
showCostumeMenu();
};
colorTxt.down = colorBtn.down;
game.addChild(menuContainer);
}
function hideMenu() {
isMenuOpen = false;
if (menuContainer) menuContainer.visible = false;
if (costumeContainer) costumeContainer.visible = false;
}
function showCostumeMenu() {
if (!costumeContainer) {
costumeContainer = new Container();
// Overlay
var overlay = LK.getAsset('ground', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0,
width: 2048,
height: 2732
});
overlay.alpha = 0.85;
costumeContainer.addChild(overlay);
// Title
var title = new Text2('Select Costume', {
size: 150,
fill: 0xffffff
});
title.anchor.set(0.5, 0);
title.x = 2048 / 2;
title.y = 400;
costumeContainer.addChild(title);
// Costume preview
var preview = LK.getAsset('runner', {
anchorX: 0.5,
anchorY: 1,
x: 2048 / 2,
y: 1200,
width: 300,
height: 300
});
preview.tint = CHARACTER_OPTIONS[selectedCharacterIndex].color;
costumeContainer.addChild(preview);
// Left arrow
var leftBtn = LK.getAsset('barrier', {
anchorX: 0.5,
anchorY: 0.5,
width: 120,
height: 120,
x: 2048 / 2 - 250,
y: 1200
});
leftBtn.tint = 0x888888;
costumeContainer.addChild(leftBtn);
var leftTxt = new Text2('<', {
size: 120,
fill: 0xffffff
});
leftTxt.anchor.set(0.5, 0.5);
leftTxt.x = leftBtn.x;
leftTxt.y = leftBtn.y;
costumeContainer.addChild(leftTxt);
// Right arrow
var rightBtn = LK.getAsset('barrier', {
anchorX: 0.5,
anchorY: 0.5,
width: 120,
height: 120,
x: 2048 / 2 + 250,
y: 1200
});
rightBtn.tint = 0x888888;
costumeContainer.addChild(rightBtn);
var rightTxt = new Text2('>', {
size: 120,
fill: 0xffffff
});
rightTxt.anchor.set(0.5, 0.5);
rightTxt.x = rightBtn.x;
rightTxt.y = rightBtn.y;
costumeContainer.addChild(rightTxt);
// Select button
var selectBtn = LK.getAsset('barrier', {
anchorX: 0.5,
anchorY: 0.5,
width: 400,
height: 140,
x: 2048 / 2,
y: 1700
});
selectBtn.tint = 0x27ae60;
costumeContainer.addChild(selectBtn);
var selectTxt = new Text2('SELECT', {
size: 90,
fill: 0xffffff
});
selectTxt.anchor.set(0.5, 0.5);
selectTxt.x = selectBtn.x;
selectTxt.y = selectBtn.y;
costumeContainer.addChild(selectTxt);
// Arrow events
leftBtn.down = function (x, y, obj) {
selectedCharacterIndex = (selectedCharacterIndex + CHARACTER_OPTIONS.length - 1) % CHARACTER_OPTIONS.length;
preview.tint = CHARACTER_OPTIONS[selectedCharacterIndex].color;
};
leftTxt.down = leftBtn.down;
rightBtn.down = function (x, y, obj) {
selectedCharacterIndex = (selectedCharacterIndex + 1) % CHARACTER_OPTIONS.length;
preview.tint = CHARACTER_OPTIONS[selectedCharacterIndex].color;
};
rightTxt.down = rightBtn.down;
// Select event
selectBtn.down = function (x, y, obj) {
if (runner) {
runner.destroy();
}
runner = createRunnerWithCostume();
game.addChild(runner);
costumeContainer.visible = false;
menuContainer.visible = true;
};
selectTxt.down = selectBtn.down;
game.addChild(costumeContainer);
} else {
// Update preview
var preview = costumeContainer.children[2];
preview.tint = CHARACTER_OPTIONS[selectedCharacterIndex].color;
costumeContainer.visible = true;
}
if (menuContainer) menuContainer.visible = false;
}
// Start game from menu
function startGame() {
hideMenu();
resetGame();
}
// Show menu on load
showMenu();
// Helper: spawn a barrier at x
function spawnBarrier(x) {
// 25% chance to spawn a PrintableBlock instead of a Barrier
var isPrintable = Math.random() < 0.25;
var barrier;
if (isPrintable) {
barrier = new PrintableBlock();
} else {
barrier = new Barrier();
}
barrier.x = x;
// Randomize height and extend width for longer barriers
var h = BARRIER_MIN_HEIGHT + Math.floor(Math.random() * (BARRIER_MAX_HEIGHT - BARRIER_MIN_HEIGHT + 1));
// Make some barriers extra long (30% chance)
var isLong = Math.random() < 0.3;
if (isLong) {
barrier.width = BARRIER_WIDTH * 2.2;
barrier.children[0].width = BARRIER_WIDTH * 2.2;
} else {
barrier.width = BARRIER_WIDTH;
barrier.children[0].width = BARRIER_WIDTH;
}
barrier.height = h;
barrier.children[0].height = h;
barrier.y = GROUND_Y;
barrier.speed = scrollSpeed;
barriers.push(barrier);
game.addChild(barrier);
}
// Helper: reset game state
function resetGame() {
// Remove barriers
for (var i = 0; i < barriers.length; i++) {
barriers[i].destroy();
}
barriers = [];
score = 0;
scrollSpeed = SCROLL_START_SPEED;
lastBarrierX = 1400;
isGameOver = false;
runner.x = RUNNER_START_X;
runner.y = GROUND_Y;
runner.isJumping = false;
runner.velocityY = 0;
scoreTxt.setText('0');
// Spawn initial barriers
for (var i = 0; i < 3; i++) {
var gap = BARRIER_MIN_GAP + Math.floor(Math.random() * (BARRIER_MAX_GAP - BARRIER_MIN_GAP + 1));
lastBarrierX += gap;
spawnBarrier(lastBarrierX);
}
}
// Start game
resetGame();
// Touch/press to jump
game.down = function (x, y, obj) {
if (isMenuOpen || isGameOver) return;
isTouching = true;
runner.jump();
};
// Release to cut jump short
game.up = function (x, y, obj) {
if (isMenuOpen || isGameOver) return;
isTouching = false;
runner.cancelJump();
};
// Main update loop
game.update = function () {
if (isMenuOpen || isGameOver) return;
updateBackgroundCubes();
// Accelerate scroll speed
if (scrollSpeed < SCROLL_MAX_SPEED) {
scrollSpeed += SCROLL_ACCEL;
if (scrollSpeed > SCROLL_MAX_SPEED) scrollSpeed = SCROLL_MAX_SPEED;
}
// Update runner
runner.update();
// Update barriers
for (var i = barriers.length - 1; i >= 0; i--) {
var barrier = barriers[i];
barrier.speed = scrollSpeed;
barrier.update();
// Passed barrier
if (!barrier.passed && barrier.x + BARRIER_WIDTH / 2 < runner.x - runner.width / 2) {
barrier.passed = true;
score += 1;
scoreTxt.setText(score + '');
LK.setScore(score);
}
// Remove off-screen barriers
if (barrier.x < -BARRIER_WIDTH) {
barrier.destroy();
barriers.splice(i, 1);
}
}
// Spawn new barriers
if (barriers.length === 0 || barriers[barriers.length - 1].x < 2048 - BARRIER_MAX_GAP) {
var gap = BARRIER_MIN_GAP + Math.floor(Math.random() * (BARRIER_MAX_GAP - BARRIER_MIN_GAP + 1));
var newX = 2048 + gap;
spawnBarrier(newX);
}
// Collision detection
for (var i = 0; i < barriers.length; i++) {
var barrier = barriers[i];
if (runner.intersects(barrier)) {
// Game over
isGameOver = true;
LK.effects.flashScreen(0xff0000, 800);
LK.showGameOver();
return;
}
}
};
// On game over, reset state for next run
LK.on('gameover', function () {
showMenu();
});
// Prevent elements in top left 100x100
// (All elements are placed away from this area by design) ===================================================================
--- original.js
+++ change.js
@@ -165,11 +165,11 @@
var BARRIER_MAX_GAP = 950;
var BARRIER_MIN_HEIGHT = 180;
var BARRIER_MAX_HEIGHT = 320;
var BARRIER_WIDTH = 80;
-var SCROLL_START_SPEED = 7;
-var SCROLL_MAX_SPEED = 14;
-var SCROLL_ACCEL = 0.008; // px per tick^2
+var SCROLL_START_SPEED = 11;
+var SCROLL_MAX_SPEED = 22;
+var SCROLL_ACCEL = 0.018; // px per tick^2
// Character (costume) options
var CHARACTER_OPTIONS = [{
id: 'runner',
color: 0x2d9cdb
@@ -457,10 +457,19 @@
} else {
barrier = new Barrier();
}
barrier.x = x;
- // Randomize height
+ // Randomize height and extend width for longer barriers
var h = BARRIER_MIN_HEIGHT + Math.floor(Math.random() * (BARRIER_MAX_HEIGHT - BARRIER_MIN_HEIGHT + 1));
+ // Make some barriers extra long (30% chance)
+ var isLong = Math.random() < 0.3;
+ if (isLong) {
+ barrier.width = BARRIER_WIDTH * 2.2;
+ barrier.children[0].width = BARRIER_WIDTH * 2.2;
+ } else {
+ barrier.width = BARRIER_WIDTH;
+ barrier.children[0].width = BARRIER_WIDTH;
+ }
barrier.height = h;
barrier.children[0].height = h;
barrier.y = GROUND_Y;
barrier.speed = scrollSpeed;