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);
zombiesEscaped = 0;
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;
}
// Track escaped zombies
if (typeof zombiesEscaped === "undefined") {
var zombiesEscaped = 0;
}
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);
zombiesEscaped++;
// Game over if 10 zombies escape
if (zombiesEscaped >= 10) {
LK.effects.flashScreen(0xff0000, 800);
LK.showGameOver();
gameStarted = false;
return;
}
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
@@ -108,8 +108,9 @@
}
bullets = [];
score = 0;
scoreText.setText(score);
+ zombiesEscaped = 0;
gameStarted = true;
lastZombieTick = LK.ticks;
lastBulletTick = 0;
// Create player
@@ -152,16 +153,27 @@
zombies.push(zombie);
game.addChild(zombie);
lastZombieTick = LK.ticks;
}
- // Update zombies
+ // Track escaped zombies
+ if (typeof zombiesEscaped === "undefined") {
+ var zombiesEscaped = 0;
+ }
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);
+ zombiesEscaped++;
+ // Game over if 10 zombies escape
+ if (zombiesEscaped >= 10) {
+ LK.effects.flashScreen(0xff0000, 800);
+ LK.showGameOver();
+ gameStarted = false;
+ return;
+ }
continue;
}
// Check collision with player
if (player.intersects(zombie)) {