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
****/
// Ground: long rectangle
// Barrier: tall rectangle
// Character: pixelated box
// 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 = 7;
var SCROLL_MAX_SPEED = 14;
var SCROLL_ACCEL = 0.008; // px per tick^2
// 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;
// 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
runner = new Runner();
runner.x = RUNNER_START_X;
runner.groundY = GROUND_Y;
runner.y = GROUND_Y;
game.addChild(runner);
// 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
var h = BARRIER_MIN_HEIGHT + Math.floor(Math.random() * (BARRIER_MAX_HEIGHT - BARRIER_MIN_HEIGHT + 1));
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 (isGameOver) return;
isTouching = true;
runner.jump();
};
// Release to cut jump short
game.up = function (x, y, obj) {
if (isGameOver) return;
isTouching = false;
runner.cancelJump();
};
// Main update loop
game.update = function () {
if (isGameOver) return;
// 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 () {
resetGame();
});
// Prevent elements in top left 100x100
// (All elements are placed away from this area by design) ===================================================================
--- original.js
+++ change.js
@@ -98,22 +98,22 @@
/****
* Game Code
****/
-// Game constants
-// Character: pixelated box
-// Barrier: tall rectangle
// Ground: long rectangle
+// Barrier: tall rectangle
+// Character: pixelated box
+// 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 = 12;
-var SCROLL_MAX_SPEED = 24;
-var SCROLL_ACCEL = 0.012; // px per tick^2
+var SCROLL_START_SPEED = 7;
+var SCROLL_MAX_SPEED = 14;
+var SCROLL_ACCEL = 0.008; // px per tick^2
// Game state
var runner = null;
var ground = null;
var barriers = [];