Code edit (1 edits merged)
Please save this source code
User prompt
make enemies shoot at enemyShootInterval rate
Code edit (2 edits merged)
Please save this source code
User prompt
make the enemies alway shoot but at a high interval, add a variable to adjust that interval
User prompt
ensure no gaps between background images, and no overlaps
User prompt
remake the background spawning logic
Code edit (1 edits merged)
Please save this source code
User prompt
spawn instantly a new image where the current one ends
User prompt
remake the logic of spawning background, it should only spawn a new one at the end of the image before, ensure no gaps between images and there should be no overlap between the images
User prompt
make the game start move slower and take longer to speed up ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
add an background music
User prompt
remake the logic of spawning background, it should only spawn a new one at the end of the image before, ensure no gaps between images and there should be no overlap between the images
User prompt
adjust the the spawn of the backround tiles, it should have no spacing between them
User prompt
add swipe controllers to the game, swipe left to move left and swipe right to move right
User prompt
write the source code for the game
User prompt
Bullet Rush
Initial prompt
Game Title: Bullet Rush Concept: In this 2D top down infinite runner, you play as a mercenary escaping an enemy warzone. Your character is constantly shooting, has to jump over, move to one of 3 lanes to avoid bullets and obstacles, destroy obstacles and kill enemies Core Mechanics: Auto-Shooting – Your weapon fires continuously, cutting through enemies. Enemy Waves – Different enemy types appear, forcing strategic movement. Destructible Objects – Some sections may have barriers that need to be shot before passing through, these barriers must occupy al 3 playable lanes. Power-Ups – Pick up boosts like that gives you different type of bullets(shoots 2 bullets simultaneously side by side, 3 bullets one goes forward the others go diagonally, etc). Level Features: Dynamic Warzone Setting – The battlefield scrolls endlessly, featuring crumbling buildings Increasing Difficulty – Enemy spawn rates and environmental hazards intensify the longer you survive.
/****
* Classes
****/
// Background elements that scrolls to create movement illusion
var BackgroundTile = Container.expand(function () {
var self = Container.call(this);
var tileGraphics = self.attachAsset('backgroundTile', {
anchorX: 0.5,
anchorY: 0
});
self.speed = 5;
self.update = function () {
self.y += self.speed;
// Reset position when it goes out of view
if (self.y >= 2732) {
self.y = -tileGraphics.height; // Place exactly at the top edge
}
};
return self;
});
// Game variables
// Barrier obstacle
var Barrier = Container.expand(function () {
var self = Container.call(this);
var barrierGraphics = self.attachAsset('barrier', {
anchorX: 0.5,
anchorY: 0.5
});
// Barrier properties
self.health = 5;
self.speed = 5;
// Last position tracking for collision detection
self.lastX = 0;
self.lastY = 0;
self.lastWasIntersecting = false;
// Take damage
self.takeDamage = function () {
self.health--;
if (self.health <= 0) {
LK.getSound('explosion').play();
LK.setScore(LK.getScore() + 2);
return true; // Barrier destroyed
}
return false; // Barrier still intact
};
// Update called every frame
self.update = function () {
self.lastX = self.x;
self.lastY = self.y;
// Move downward
self.y += self.speed;
};
return self;
});
// Enemy class
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5
});
// Enemy properties
self.health = 1;
self.speed = 5;
self.shootChance = 0.01; // 1% chance per frame
self.lane = 0;
self.type = 'basic'; // basic, shooter, tank
// Last position tracking for collision detection
self.lastX = 0;
self.lastY = 0;
self.lastWasIntersecting = false;
// Initialize enemy with type
self.init = function (type, lane) {
self.type = type;
self.lane = lane;
if (type === 'basic') {
self.health = 1;
self.speed = 5;
self.shootChance = 0;
} else if (type === 'shooter') {
self.health = 1;
self.speed = 4;
self.shootChance = 0.02;
} else if (type === 'tank') {
self.health = 3;
self.speed = 3;
self.shootChance = 0.01;
enemyGraphics.scaleX = 1.3;
enemyGraphics.scaleY = 1.3;
}
};
// Shoot method for enemies
self.tryShoot = function () {
if (Math.random() < self.shootChance) {
var bullet = new EnemyBullet();
bullet.x = self.x;
bullet.y = self.y + 60;
game.addChild(bullet);
enemyBullets.push(bullet);
}
};
// Take damage
self.takeDamage = function () {
self.health--;
if (self.health <= 0) {
LK.getSound('explosion').play();
LK.setScore(LK.getScore() + 1);
return true; // Enemy destroyed
}
return false; // Enemy still alive
};
// Update called every frame
self.update = function () {
self.lastX = self.x;
self.lastY = self.y;
// Move downward
self.y += self.speed;
// Try to shoot if we're a shooting type
if (self.type === 'shooter' || self.type === 'tank') {
self.tryShoot();
}
};
return self;
});
// Enemy bullet
var EnemyBullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('enemyBullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 10;
// Last position tracking for collision detection
self.lastX = 0;
self.lastY = 0;
self.lastWasIntersecting = false;
self.update = function () {
self.lastX = self.x;
self.lastY = self.y;
// Move bullet downward
self.y += self.speed;
};
return self;
});
// Lane definitions for positioning
var Lane = Container.expand(function () {
var self = Container.call(this);
var laneGraphics = self.attachAsset('lane', {
anchorX: 0.5,
anchorY: 0
});
return self;
});
// Player class
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
// Player properties
self.currentLane = 1; // 0=left, 1=center, 2=right
self.shootCooldown = 0;
self.bulletType = 'normal'; // normal, double, triple
self.powerUpTimer = 0;
self.isAlive = true;
// Last position tracking for collision detection
self.lastX = 0;
self.lastY = 0;
self.lastWasIntersecting = false;
// Movement handling
self.moveTo = function (laneIndex) {
if (laneIndex >= 0 && laneIndex <= 2) {
self.currentLane = laneIndex;
}
};
// Shoot method
self.shoot = function () {
if (self.shootCooldown <= 0) {
LK.getSound('shoot').play();
if (self.bulletType === 'normal') {
// Create a single bullet
var bullet = new PlayerBullet();
bullet.x = self.x;
bullet.y = self.y - 60;
game.addChild(bullet);
playerBullets.push(bullet);
} else if (self.bulletType === 'double') {
// Create two side-by-side bullets
var bullet1 = new PlayerBullet();
bullet1.x = self.x - 30;
bullet1.y = self.y - 60;
game.addChild(bullet1);
playerBullets.push(bullet1);
var bullet2 = new PlayerBullet();
bullet2.x = self.x + 30;
bullet2.y = self.y - 60;
game.addChild(bullet2);
playerBullets.push(bullet2);
} else if (self.bulletType === 'triple') {
// Create three bullets - one forward and two diagonal
var bulletCenter = new PlayerBullet();
bulletCenter.x = self.x;
bulletCenter.y = self.y - 60;
game.addChild(bulletCenter);
playerBullets.push(bulletCenter);
var bulletLeft = new PlayerBullet();
bulletLeft.x = self.x - 30;
bulletLeft.y = self.y - 60;
bulletLeft.angle = -15; // Diagonal left
game.addChild(bulletLeft);
playerBullets.push(bulletLeft);
var bulletRight = new PlayerBullet();
bulletRight.x = self.x + 30;
bulletRight.y = self.y - 60;
bulletRight.angle = 15; // Diagonal right
game.addChild(bulletRight);
playerBullets.push(bulletRight);
}
self.shootCooldown = 10; // Cooldown in frames
}
};
// Power-up activation
self.activatePowerUp = function (type) {
LK.getSound('powerUp').play();
self.bulletType = type;
self.powerUpTimer = 300; // 5 seconds at 60fps
};
// Update called every frame
self.update = function () {
self.lastX = self.x;
self.lastY = self.y;
// Handle cooldowns
if (self.shootCooldown > 0) {
self.shootCooldown--;
}
// Power-up timer
if (self.powerUpTimer > 0) {
self.powerUpTimer--;
if (self.powerUpTimer <= 0) {
self.bulletType = 'normal';
}
}
// Auto-shoot
self.shoot();
};
return self;
});
// Player bullet
var PlayerBullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('playerBullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 20;
self.angle = 0; // 0 = straight, positive/negative for diagonal
// Last position tracking for collision detection
self.lastX = 0;
self.lastY = 0;
self.lastWasIntersecting = false;
self.update = function () {
self.lastX = self.x;
self.lastY = self.y;
// Move bullet based on angle
var radians = self.angle * (Math.PI / 180);
self.x += Math.sin(radians) * self.speed;
self.y -= Math.cos(radians) * self.speed;
};
return self;
});
// Power-up class
var PowerUp = Container.expand(function () {
var self = Container.call(this);
var powerUpGraphics = self.attachAsset('powerUp', {
anchorX: 0.5,
anchorY: 0.5
});
// Power-up properties
self.type = 'double'; // double, triple
self.speed = 5;
// Last position tracking for collision detection
self.lastX = 0;
self.lastY = 0;
self.lastWasIntersecting = false;
// Initialize power-up with type
self.init = function (type) {
self.type = type;
if (type === 'double') {
powerUpGraphics.tint = 0x2ecc71; // Green
} else if (type === 'triple') {
powerUpGraphics.tint = 0x9b59b6; // Purple
}
};
// Update called every frame
self.update = function () {
self.lastX = self.x;
self.lastY = self.y;
// Move downward
self.y += self.speed;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000
});
/****
* Game Code
****/
// Background
// Sounds
// Power-ups
// Environment and obstacles
// Player, enemies and bullets
// Game variables
var player;
var lanes = [];
var lanePositions = [512, 1024, 1536]; // The three lanes X positions
var playerBullets = [];
var enemies = [];
var enemyBullets = [];
var barriers = [];
var powerUps = [];
var backgroundTiles = [];
var gameSpeed = 5;
var difficulty = 1;
var spawnTimer = 0;
var barrierTimer = 0;
var powerUpTimer = 0;
// Touch tracking for swipe detection
var touchStartX = null;
var touchStartY = null;
// Initialize the game elements
function initGame() {
// Set up background
var bgTileHeight = LK.getAsset('backgroundTile', {}).height;
var numTilesNeeded = Math.ceil(2732 / bgTileHeight) + 1; // One extra for seamless scrolling
for (var i = 0; i < numTilesNeeded; i++) {
var bgTile = new BackgroundTile();
bgTile.x = 1024; // Center of screen
bgTile.y = i * bgTileHeight; // Position tiles exactly adjacent to each other
backgroundTiles.push(bgTile);
game.addChild(bgTile);
}
// Create the lane markers
for (var i = 0; i < 2; i++) {
var lane = new Lane();
lane.x = lanePositions[i] + (lanePositions[1] - lanePositions[0]) / 2; // Position between lanes
lane.y = 0;
lane.alpha = 0.3;
lanes.push(lane);
game.addChild(lane);
}
// Create the player
player = new Player();
player.x = lanePositions[1]; // Start in center lane
player.y = 2732 - 300; // Near bottom of screen
game.addChild(player);
// Initialize score display
var scoreBackground = game.addChild(LK.getAsset('scoreBackground', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 80,
alpha: 0.7
}));
var scoreTxt = new Text2('0', {
size: 60,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0.5);
scoreTxt.x = 1024;
scoreTxt.y = 80;
game.addChild(scoreTxt);
// Update score display every second
LK.setInterval(function () {
scoreTxt.setText("SCORE: " + LK.getScore());
}, 1000);
}
// Spawn a new enemy
function spawnEnemy() {
var laneIndex = Math.floor(Math.random() * 3);
var enemyType = 'basic';
// Determine enemy type based on difficulty
var typeRoll = Math.random();
if (difficulty >= 2) {
if (typeRoll < 0.3) {
enemyType = 'shooter';
} else if (typeRoll < 0.4 && difficulty >= 3) {
enemyType = 'tank';
}
}
var enemy = new Enemy();
enemy.init(enemyType, laneIndex);
enemy.x = lanePositions[laneIndex];
enemy.y = -100;
game.addChild(enemy);
enemies.push(enemy);
}
// Spawn a barrier across all lanes
function spawnBarrier() {
var barrier = new Barrier();
barrier.x = 1024; // Center of screen
barrier.y = -100;
game.addChild(barrier);
barriers.push(barrier);
}
// Spawn a power-up
function spawnPowerUp() {
var laneIndex = Math.floor(Math.random() * 3);
var powerUpType = Math.random() < 0.5 ? 'double' : 'triple';
var powerUp = new PowerUp();
powerUp.init(powerUpType);
powerUp.x = lanePositions[laneIndex];
powerUp.y = -100;
game.addChild(powerUp);
powerUps.push(powerUp);
}
// Increase difficulty over time
function updateDifficulty() {
difficulty = 1 + Math.floor(LK.getScore() / 10);
gameSpeed = 5 + Math.min(difficulty, 5);
// Update game elements with new speed
for (var i = 0; i < backgroundTiles.length; i++) {
backgroundTiles[i].speed = gameSpeed;
}
for (var i = 0; i < enemies.length; i++) {
enemies[i].speed = gameSpeed + (enemies[i].type === 'basic' ? 1 : 0);
}
for (var i = 0; i < barriers.length; i++) {
barriers[i].speed = gameSpeed;
}
for (var i = 0; i < powerUps.length; i++) {
powerUps[i].speed = gameSpeed;
}
}
// Handle touch input for lane changing
game.down = function (x, y, obj) {
// Store touch start position for swipe detection
game.touchStartX = x;
game.touchStartY = y;
};
// Handle touch move events for swipe detection
game.move = function (x, y, obj) {
// Skip if no touch start position is recorded
if (!game.touchStartX) return;
};
// Handle touch up events for swipe detection
game.up = function (x, y, obj) {
// Skip if no touch start position is recorded
if (!game.touchStartX) return;
// Calculate horizontal distance moved
var deltaX = x - game.touchStartX;
var deltaY = y - game.touchStartY;
// Only process horizontal swipes (ignore vertical)
if (Math.abs(deltaX) > Math.abs(deltaY) && Math.abs(deltaX) > 50) {
if (deltaX < 0 && player.currentLane > 0) {
// Swipe left - move to left lane
player.moveTo(player.currentLane - 1);
} else if (deltaX > 0 && player.currentLane < 2) {
// Swipe right - move to right lane
player.moveTo(player.currentLane + 1);
}
}
// Reset touch start position
game.touchStartX = null;
game.touchStartY = null;
};
// Main update function
game.update = function () {
// Initialize game on first update
if (!player) {
initGame();
return;
}
// Update player position based on current lane
var targetX = lanePositions[player.currentLane];
player.x += (targetX - player.x) * 0.2; // Smooth movement
// Update all game elements
player.update();
// Update background tiles
for (var i = 0; i < backgroundTiles.length; i++) {
backgroundTiles[i].update();
}
// Update and check player bullets
for (var i = playerBullets.length - 1; i >= 0; i--) {
var bullet = playerBullets[i];
bullet.update();
// Remove bullets that go off screen
if (bullet.y < -50) {
bullet.destroy();
playerBullets.splice(i, 1);
continue;
}
// Check for collisions with enemies
var hitEnemy = false;
for (var j = enemies.length - 1; j >= 0; j--) {
var enemy = enemies[j];
if (!bullet.lastWasIntersecting && bullet.intersects(enemy)) {
bullet.lastWasIntersecting = true;
if (enemy.takeDamage()) {
enemy.destroy();
enemies.splice(j, 1);
}
hitEnemy = true;
break;
}
}
// Check for collisions with barriers
if (!hitEnemy) {
for (var j = barriers.length - 1; j >= 0; j--) {
var barrier = barriers[j];
if (!bullet.lastWasIntersecting && bullet.intersects(barrier)) {
bullet.lastWasIntersecting = true;
if (barrier.takeDamage()) {
barrier.destroy();
barriers.splice(j, 1);
}
hitEnemy = true;
break;
}
}
}
// Remove bullet if it hit something
if (hitEnemy) {
bullet.destroy();
playerBullets.splice(i, 1);
}
}
// Update and check enemy bullets
for (var i = enemyBullets.length - 1; i >= 0; i--) {
var bullet = enemyBullets[i];
bullet.update();
// Remove bullets that go off screen
if (bullet.y > 2732 + 50) {
bullet.destroy();
enemyBullets.splice(i, 1);
continue;
}
// Check for collision with player
if (!bullet.lastWasIntersecting && bullet.intersects(player) && player.isAlive) {
bullet.lastWasIntersecting = true;
// Player hit by enemy bullet - game over
player.isAlive = false;
LK.effects.flashScreen(0xff0000, 1000);
LK.setTimeout(function () {
LK.showGameOver();
}, 1000);
break;
}
}
// Update and check enemies
for (var i = enemies.length - 1; i >= 0; i--) {
var enemy = enemies[i];
enemy.update();
// Remove enemies that go off screen
if (enemy.y > 2732 + 100) {
enemy.destroy();
enemies.splice(i, 1);
continue;
}
// Check for collision with player
if (!enemy.lastWasIntersecting && enemy.intersects(player) && player.isAlive) {
enemy.lastWasIntersecting = true;
// Player hit by enemy - game over
player.isAlive = false;
LK.effects.flashScreen(0xff0000, 1000);
LK.setTimeout(function () {
LK.showGameOver();
}, 1000);
break;
}
}
// Update and check barriers
for (var i = barriers.length - 1; i >= 0; i--) {
var barrier = barriers[i];
barrier.update();
// Remove barriers that go off screen
if (barrier.y > 2732 + 100) {
barrier.destroy();
barriers.splice(i, 1);
continue;
}
// Check for collision with player
if (!barrier.lastWasIntersecting && barrier.intersects(player) && player.isAlive) {
barrier.lastWasIntersecting = true;
// Player hit by barrier - game over
player.isAlive = false;
LK.effects.flashScreen(0xff0000, 1000);
LK.setTimeout(function () {
LK.showGameOver();
}, 1000);
break;
}
}
// Update and check power-ups
for (var i = powerUps.length - 1; i >= 0; i--) {
var powerUp = powerUps[i];
powerUp.update();
// Remove power-ups that go off screen
if (powerUp.y > 2732 + 100) {
powerUp.destroy();
powerUps.splice(i, 1);
continue;
}
// Check for collision with player
if (!powerUp.lastWasIntersecting && powerUp.intersects(player)) {
powerUp.lastWasIntersecting = true;
// Player got power-up
player.activatePowerUp(powerUp.type);
powerUp.destroy();
powerUps.splice(i, 1);
}
}
// Spawn timers
spawnTimer--;
barrierTimer--;
powerUpTimer--;
// Spawn enemies
if (spawnTimer <= 0) {
spawnEnemy();
spawnTimer = Math.max(30, 90 - difficulty * 10); // Faster spawns as difficulty increases
}
// Spawn barriers occasionally
if (barrierTimer <= 0 && difficulty >= 2) {
spawnBarrier();
barrierTimer = 300; // Every 5 seconds
}
// Spawn power-ups occasionally
if (powerUpTimer <= 0) {
spawnPowerUp();
powerUpTimer = 600; // Every 10 seconds
}
// Update difficulty based on score
updateDifficulty();
}; ===================================================================
--- original.js
+++ change.js
@@ -11,10 +11,10 @@
self.speed = 5;
self.update = function () {
self.y += self.speed;
// Reset position when it goes out of view
- if (self.y > 2732) {
- self.y = -tileGraphics.height + (self.y - 2732); // Maintain seamless transition
+ if (self.y >= 2732) {
+ self.y = -tileGraphics.height; // Place exactly at the top edge
}
};
return self;
});
@@ -337,12 +337,14 @@
var touchStartY = null;
// Initialize the game elements
function initGame() {
// Set up background
- for (var i = 0; i < 10; i++) {
+ var bgTileHeight = LK.getAsset('backgroundTile', {}).height;
+ var numTilesNeeded = Math.ceil(2732 / bgTileHeight) + 1; // One extra for seamless scrolling
+ for (var i = 0; i < numTilesNeeded; i++) {
var bgTile = new BackgroundTile();
bgTile.x = 1024; // Center of screen
- bgTile.y = i * 300; // Position tiles adjacent to each other
+ bgTile.y = i * bgTileHeight; // Position tiles exactly adjacent to each other
backgroundTiles.push(bgTile);
game.addChild(bgTile);
}
// Create the lane markers
an 16bit 20x40 yellow bullet. In-Game asset. 2d. High contrast. No shadows
a tank from a top down view in realistic 16bit 90s retro game style. the tank should have its bazooka point straight forward, it should be seen from above so no wheels should be seen. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
make it redish like a ruby
make it so there are 2 bullets side by side
make it so that there are 3 bullets, the one on the left inclined diagonally to the left, the one in the middle forward and the one on the right inclined diagonally to the right
make it so that there are two bullets one above the other like this 2 dots, :
an 16bit 20x40 red heart. In-Game asset. 2d. High contrast. No shadows
make it just an round hole with spikes in it seen from above
create an simple retangular play button image writen "play" in it, make it in a 16bit style. In-Game asset. 2d. High contrast. No shadows
Create an title image written "Bullet Rush" in it, add some elements of war like bulets and make it in a semirealistic 16bit style. In-Game asset. 2d. High contrast. No shadows
make soldier laying in with belly up dead