User prompt
show a start button
User prompt
show a start button when player clicks it start the game
User prompt
made a start screen
User prompt
delete medal thing
User prompt
Please fix the bug: 'TypeError: LK.showMedal is not a function' in or related to this line: 'LK.showMedal();' Line Number: 220
User prompt
give a medal when player reachs 20
User prompt
player can move only upwards and downwards
User prompt
make screen red when a zombie reachs left edge
User prompt
game end when ten zombie reachs left edge
User prompt
if ten zombie reach the end game over
User prompt
make me a 2d based zombie killing game
User prompt
make game slower
User prompt
make coins circle
User prompt
add some coins
User prompt
make game slower
User prompt
Generate the first version of the source code of my game: Flappy Box.
User prompt
Flappy Box
Initial prompt
hello buddy make me a game like flappy bird but same textures same character
/****
* Classes
****/
// Bullet class: fired by player, moves right, destroys zombies
var Bullet = Container.expand(function () {
var self = Container.call(this);
var bulletAsset = self.attachAsset('centerCircle', {
anchorX: 0.5,
anchorY: 0.5,
shape: 'ellipse'
});
bulletAsset.width = 60;
bulletAsset.height = 60;
bulletAsset.tint = 0xffe066; // yellow
self.speed = 32;
self.lastX = self.x;
self.update = function () {
self.lastX = self.x;
self.x += self.speed;
};
return self;
});
// Player class: the hero that can move and shoot
var Player = Container.expand(function () {
var self = Container.call(this);
// Attach player asset, centered
var playerAsset = self.attachAsset('character', {
anchorX: 0.5,
anchorY: 0.5
});
self.x = 400;
self.y = 1366;
self.speed = 18;
self.lastY = self.y;
self.lastX = self.x;
// Move up/down/left/right
self.moveTo = function (x, y) {
self.x = x;
self.y = y;
};
// Update method (not much needed for player)
self.update = function () {
self.lastY = self.y;
self.lastX = self.x;
};
return self;
});
// Zombie class: moves left, dies on bullet hit
var Zombie = Container.expand(function () {
var self = Container.call(this);
var zombieAsset = self.attachAsset('centerCircle', {
anchorX: 0.5,
anchorY: 0.5,
shape: 'box'
});
zombieAsset.width = 120;
zombieAsset.height = 120;
zombieAsset.tint = 0x4caf50; // green
self.speed = 6 + Math.random() * 4;
self.lastX = self.x;
self.lastY = self.y;
self.update = function () {
self.lastX = self.x;
self.lastY = self.y;
self.x -= self.speed;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000
});
/****
* Game Code
****/
// Game constants
var zombieSpawnInterval = 60; // frames between zombies
var bulletCooldown = 12; // frames between shots
var playerMoveRadius = 1000; // how far player can move from left
// Game state
var player;
var zombies = [];
var bullets = [];
var score = 0;
var gameStarted = false;
var lastZombieTick = 0;
var lastBulletTick = 0;
// Add score text to GUI
var scoreText = new Text2('0', {
size: 150,
fill: 0xFFFFFF
});
scoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreText);
// Start the game
function startGame() {
// Reset state
for (var i = 0; i < zombies.length; i++) {
zombies[i].destroy();
}
zombies = [];
for (var i = 0; i < bullets.length; i++) {
bullets[i].destroy();
}
bullets = [];
score = 0;
scoreText.setText(score);
gameStarted = true;
lastZombieTick = LK.ticks;
lastBulletTick = 0;
// Create player
if (player) player.destroy();
player = new Player();
player.x = 400;
player.y = 1366;
game.addChild(player);
}
// Handle tap: move player to tap and shoot
game.down = function (x, y, obj) {
if (!gameStarted) {
startGame();
return;
}
// Move player to tap position (clamped to left half of screen)
var px = Math.max(100, Math.min(x, playerMoveRadius));
var py = Math.max(120, Math.min(y, 2732 - 120));
player.moveTo(px, py);
// Shoot bullet if cooldown allows
if (LK.ticks - lastBulletTick > bulletCooldown) {
var bullet = new Bullet();
bullet.x = player.x + 80;
bullet.y = player.y;
bullets.push(bullet);
game.addChild(bullet);
lastBulletTick = LK.ticks;
}
};
// Main update loop
game.update = function () {
if (!gameStarted) return;
// Update player
if (player) player.update();
// Spawn zombies
if (LK.ticks - lastZombieTick > zombieSpawnInterval) {
var zombie = new Zombie();
zombie.x = 2048 + 80;
zombie.y = 200 + Math.random() * (2732 - 400);
zombies.push(zombie);
game.addChild(zombie);
lastZombieTick = LK.ticks;
}
// Update zombies
for (var i = zombies.length - 1; i >= 0; i--) {
var zombie = zombies[i];
zombie.update();
// Remove if off screen
if (zombie.x < -120) {
zombie.destroy();
zombies.splice(i, 1);
continue;
}
// Check collision with player
if (player.intersects(zombie)) {
LK.effects.flashScreen(0xff0000, 800);
LK.showGameOver();
gameStarted = false;
return;
}
}
// Update bullets
for (var i = bullets.length - 1; i >= 0; i--) {
var bullet = bullets[i];
bullet.update();
// Remove if off screen
if (bullet.x > 2048 + 120) {
bullet.destroy();
bullets.splice(i, 1);
continue;
}
// Check collision with zombies
for (var j = zombies.length - 1; j >= 0; j--) {
var zombie = zombies[j];
if (bullet.intersects(zombie)) {
// Kill zombie and bullet
zombie.destroy();
zombies.splice(j, 1);
bullet.destroy();
bullets.splice(i, 1);
// Score
score += 1;
scoreText.setText(score);
break;
}
}
}
};
// Start in idle state
gameStarted = false;
scoreText.setText('0'); ===================================================================
--- original.js
+++ change.js
@@ -1,107 +1,69 @@
/****
* Classes
****/
-// Coin class: collectible coin
-var Coin = Container.expand(function () {
+// Bullet class: fired by player, moves right, destroys zombies
+var Bullet = Container.expand(function () {
var self = Container.call(this);
- // Attach a yellow ellipse as the coin (use ellipse shape for circle)
- var coinAsset = self.attachAsset('centerCircle', {
+ var bulletAsset = self.attachAsset('centerCircle', {
anchorX: 0.5,
anchorY: 0.5,
shape: 'ellipse'
});
- coinAsset.width = 100;
- coinAsset.height = 100;
- coinAsset.tint = 0xFFD700; // gold/yellow
- // For collision and movement
+ bulletAsset.width = 60;
+ bulletAsset.height = 60;
+ bulletAsset.tint = 0xffe066; // yellow
+ self.speed = 32;
self.lastX = self.x;
self.update = function () {
self.lastX = self.x;
- self.x -= obstacleSpeed;
+ self.x += self.speed;
};
return self;
});
-// Obstacle class: a single green box (top or bottom pipe)
-var Obstacle = Container.expand(function () {
+// Player class: the hero that can move and shoot
+var Player = Container.expand(function () {
var self = Container.call(this);
- // Attach green box asset, anchor top left
- var obstacleAsset = self.attachAsset('centerCircle', {
- anchorX: 0,
- anchorY: 0
+ // Attach player asset, centered
+ var playerAsset = self.attachAsset('character', {
+ anchorX: 0.5,
+ anchorY: 0.5
});
- // Set width and height for the obstacle
- obstacleAsset.width = 200;
- obstacleAsset.height = 900;
- // For collision
+ self.x = 400;
+ self.y = 1366;
+ self.speed = 18;
+ self.lastY = self.y;
self.lastX = self.x;
- // Update method (move left)
- self.update = function () {
- self.lastX = self.x;
- self.x -= obstacleSpeed;
+ // Move up/down/left/right
+ self.moveTo = function (x, y) {
+ self.x = x;
+ self.y = y;
};
- return self;
-});
-// ObstaclePair class: a pair of obstacles with a gap
-var ObstaclePair = Container.expand(function () {
- var self = Container.call(this);
- // Gap size and vertical position
- var gapSize = 500;
- var minY = 400;
- var maxY = 2732 - 400 - gapSize;
- var gapY = minY + Math.floor(Math.random() * (maxY - minY));
- // Top obstacle
- self.top = new Obstacle();
- self.top.y = 0;
- self.top.x = 0;
- self.top.height = gapY;
- // Bottom obstacle
- self.bottom = new Obstacle();
- self.bottom.y = gapY + gapSize;
- self.bottom.x = 0;
- self.bottom.height = 2732 - (gapY + gapSize);
- // Add to pair
- self.addChild(self.top);
- self.addChild(self.bottom);
- // For scoring
- self.passed = false;
- self.lastX = self.x;
- // Update method (move left, update children)
+ // Update method (not much needed for player)
self.update = function () {
+ self.lastY = self.y;
self.lastX = self.x;
- self.x -= obstacleSpeed;
};
return self;
});
-// --- Flappy Box Main Game Logic ---
-// Game constants
-// Player class: the red box that jumps and falls with gravity
-var Player = Container.expand(function () {
+// Zombie class: moves left, dies on bullet hit
+var Zombie = Container.expand(function () {
var self = Container.call(this);
- // Attach red box asset, centered
- var playerAsset = self.attachAsset('character', {
+ var zombieAsset = self.attachAsset('centerCircle', {
anchorX: 0.5,
- anchorY: 0.5
+ anchorY: 0.5,
+ shape: 'box'
});
- // Physics properties
- self.y = 1366; // Start vertically centered
- self.x = 600; // Start horizontally at 600px
- self.vy = 0; // Vertical velocity
- self.gravity = 0.7; // Gravity per frame (even slower fall)
- self.jumpStrength = -18; // Upward velocity on jump (even slower jump)
- // For collision and scoring
+ zombieAsset.width = 120;
+ zombieAsset.height = 120;
+ zombieAsset.tint = 0x4caf50; // green
+ self.speed = 6 + Math.random() * 4;
+ self.lastX = self.x;
self.lastY = self.y;
- // Jump method
- self.jump = function () {
- self.vy = self.jumpStrength;
- };
- // Update method (called every frame)
self.update = function () {
+ self.lastX = self.x;
self.lastY = self.y;
- self.vy += self.gravity;
- self.y += self.vy;
- // Prevent player from rotating (keep upright)
- playerAsset.rotation = 0;
+ self.x -= self.speed;
};
return self;
});
@@ -114,154 +76,128 @@
/****
* Game Code
****/
-// --- Flappy Box Main Game Logic ---
// Game constants
-var obstacleSpeed = 4; // Speed at which obstacles move left (even slower)
-var obstacleInterval = 220; // Frames between obstacle pairs (even slower spawn rate)
-var gapSize = 500; // Vertical gap between obstacles
+var zombieSpawnInterval = 60; // frames between zombies
+var bulletCooldown = 12; // frames between shots
+var playerMoveRadius = 1000; // how far player can move from left
// Game state
var player;
-var obstacles = [];
-var coins = [];
+var zombies = [];
+var bullets = [];
var score = 0;
-var coinScore = 0;
-var scoreText;
-var coinText;
var gameStarted = false;
-var lastObstacleTick = 0;
+var lastZombieTick = 0;
+var lastBulletTick = 0;
// Add score text to GUI
-scoreText = new Text2('0', {
+var scoreText = new Text2('0', {
size: 150,
fill: 0xFFFFFF
});
scoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreText);
-// Add coin score text to GUI (smaller, right of score)
-coinText = new Text2('0', {
- size: 90,
- fill: 0xFFD700
-});
-coinText.anchor.set(0, 0);
-coinText.x = 200; // right of score
-coinText.y = 30;
-LK.gui.top.addChild(coinText);
// Start the game
function startGame() {
// Reset state
- for (var i = 0; i < obstacles.length; i++) {
- obstacles[i].destroy();
+ for (var i = 0; i < zombies.length; i++) {
+ zombies[i].destroy();
}
- obstacles = [];
- for (var i = 0; i < coins.length; i++) {
- coins[i].destroy();
+ zombies = [];
+ for (var i = 0; i < bullets.length; i++) {
+ bullets[i].destroy();
}
- coins = [];
+ bullets = [];
score = 0;
- coinScore = 0;
scoreText.setText(score);
- coinText.setText(coinScore);
gameStarted = true;
- lastObstacleTick = 0;
+ lastZombieTick = LK.ticks;
+ lastBulletTick = 0;
// Create player
if (player) player.destroy();
player = new Player();
- player.x = 600;
+ player.x = 400;
player.y = 1366;
game.addChild(player);
}
-// Handle tap to jump
+// Handle tap: move player to tap and shoot
game.down = function (x, y, obj) {
if (!gameStarted) {
startGame();
+ return;
}
- if (player) {
- player.jump();
+ // Move player to tap position (clamped to left half of screen)
+ var px = Math.max(100, Math.min(x, playerMoveRadius));
+ var py = Math.max(120, Math.min(y, 2732 - 120));
+ player.moveTo(px, py);
+ // Shoot bullet if cooldown allows
+ if (LK.ticks - lastBulletTick > bulletCooldown) {
+ var bullet = new Bullet();
+ bullet.x = player.x + 80;
+ bullet.y = player.y;
+ bullets.push(bullet);
+ game.addChild(bullet);
+ lastBulletTick = LK.ticks;
}
};
// Main update loop
game.update = function () {
if (!gameStarted) return;
// Update player
if (player) player.update();
- // Add new obstacles
- if (LK.ticks - lastObstacleTick > obstacleInterval) {
- var pair = new ObstaclePair();
- pair.x = 2048;
- game.addChild(pair);
- obstacles.push(pair);
- // Spawn a coin in the gap with some chance (e.g. 70%)
- if (Math.random() < 0.7) {
- var coin = new Coin();
- coin.x = pair.x + 400; // place coin after obstacle
- // Place coin in the vertical center of the gap
- var gapY = pair.top.height;
- coin.y = gapY + gapSize / 2;
- game.addChild(coin);
- coins.push(coin);
- }
- lastObstacleTick = LK.ticks;
+ // Spawn zombies
+ if (LK.ticks - lastZombieTick > zombieSpawnInterval) {
+ var zombie = new Zombie();
+ zombie.x = 2048 + 80;
+ zombie.y = 200 + Math.random() * (2732 - 400);
+ zombies.push(zombie);
+ game.addChild(zombie);
+ lastZombieTick = LK.ticks;
}
- // Update obstacles and check for passed/cleanup
- for (var i = obstacles.length - 1; i >= 0; i--) {
- var pair = obstacles[i];
- pair.update();
- // Check for scoring (player passes obstacle)
- if (!pair.passed && player.x > pair.x + 200) {
- pair.passed = true;
- score += 1;
- scoreText.setText(score);
- }
- // Remove obstacles off screen
- if (pair.x < -300) {
- pair.destroy();
- obstacles.splice(i, 1);
- }
- }
- // Update coins, check for collection and cleanup
- for (var i = coins.length - 1; i >= 0; i--) {
- var coin = coins[i];
- coin.update();
- // Check for collection
- if (player.intersects(coin)) {
- coinScore += 1;
- coinText.setText(coinScore);
- coin.destroy();
- coins.splice(i, 1);
+ // Update zombies
+ for (var i = zombies.length - 1; i >= 0; i--) {
+ var zombie = zombies[i];
+ zombie.update();
+ // Remove if off screen
+ if (zombie.x < -120) {
+ zombie.destroy();
+ zombies.splice(i, 1);
continue;
}
- // Remove coins off screen
- if (coin.x < -200) {
- coin.destroy();
- coins.splice(i, 1);
- }
- }
- // Collision detection
- for (var i = 0; i < obstacles.length; i++) {
- var pair = obstacles[i];
- // Check collision with top
- if (player.intersects(pair.top)) {
+ // Check collision with player
+ if (player.intersects(zombie)) {
LK.effects.flashScreen(0xff0000, 800);
LK.showGameOver();
gameStarted = false;
return;
}
- // Check collision with bottom
- if (player.intersects(pair.bottom)) {
- LK.effects.flashScreen(0xff0000, 800);
- LK.showGameOver();
- gameStarted = false;
- return;
+ }
+ // Update bullets
+ for (var i = bullets.length - 1; i >= 0; i--) {
+ var bullet = bullets[i];
+ bullet.update();
+ // Remove if off screen
+ if (bullet.x > 2048 + 120) {
+ bullet.destroy();
+ bullets.splice(i, 1);
+ continue;
}
+ // Check collision with zombies
+ for (var j = zombies.length - 1; j >= 0; j--) {
+ var zombie = zombies[j];
+ if (bullet.intersects(zombie)) {
+ // Kill zombie and bullet
+ zombie.destroy();
+ zombies.splice(j, 1);
+ bullet.destroy();
+ bullets.splice(i, 1);
+ // Score
+ score += 1;
+ scoreText.setText(score);
+ break;
+ }
+ }
}
- // Check collision with top/bottom of screen
- if (player.y < 0 || player.y > 2732) {
- LK.effects.flashScreen(0xff0000, 800);
- LK.showGameOver();
- gameStarted = false;
- return;
- }
};
// Start in idle state
gameStarted = false;
scoreText.setText('0');
\ No newline at end of file