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
****/
// Coin class: collectible coin
var Coin = Container.expand(function () {
var self = Container.call(this);
// Attach a yellow ellipse as the coin
var coinAsset = self.attachAsset('centerCircle', {
anchorX: 0.5,
anchorY: 0.5
});
coinAsset.width = 100;
coinAsset.height = 100;
coinAsset.tint = 0xFFD700; // gold/yellow
// For collision and movement
self.lastX = self.x;
self.update = function () {
self.lastX = self.x;
self.x -= obstacleSpeed;
};
return self;
});
// Obstacle class: a single green box (top or bottom pipe)
var Obstacle = Container.expand(function () {
var self = Container.call(this);
// Attach green box asset, anchor top left
var obstacleAsset = self.attachAsset('centerCircle', {
anchorX: 0,
anchorY: 0
});
// Set width and height for the obstacle
obstacleAsset.width = 200;
obstacleAsset.height = 900;
// For collision
self.lastX = self.x;
// Update method (move left)
self.update = function () {
self.lastX = self.x;
self.x -= obstacleSpeed;
};
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)
self.update = function () {
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 () {
var self = Container.call(this);
// Attach red box asset, centered
var playerAsset = self.attachAsset('character', {
anchorX: 0.5,
anchorY: 0.5
});
// Physics properties
self.y = 1366; // Start vertically centered
self.x = 600; // Start horizontally at 600px
self.vy = 0; // Vertical velocity
self.gravity = 1.2; // Gravity per frame (slower fall)
self.jumpStrength = -28; // Upward velocity on jump (slower jump)
// For collision and scoring
self.lastY = self.y;
// Jump method
self.jump = function () {
self.vy = self.jumpStrength;
};
// Update method (called every frame)
self.update = function () {
self.lastY = self.y;
self.vy += self.gravity;
self.y += self.vy;
// Prevent player from rotating (keep upright)
playerAsset.rotation = 0;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000
});
/****
* Game Code
****/
// Game constants
// --- Flappy Box Main Game Logic ---
var obstacleSpeed = 8; // Speed at which obstacles move left (slower)
var obstacleInterval = 150; // Frames between obstacle pairs (slower spawn rate)
var gapSize = 500; // Vertical gap between obstacles
// Game state
var player;
var obstacles = [];
var coins = [];
var score = 0;
var coinScore = 0;
var scoreText;
var coinText;
var gameStarted = false;
var lastObstacleTick = 0;
// Add score text to GUI
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();
}
obstacles = [];
for (var i = 0; i < coins.length; i++) {
coins[i].destroy();
}
coins = [];
score = 0;
coinScore = 0;
scoreText.setText(score);
coinText.setText(coinScore);
gameStarted = true;
lastObstacleTick = 0;
// Create player
if (player) player.destroy();
player = new Player();
player.x = 600;
player.y = 1366;
game.addChild(player);
}
// Handle tap to jump
game.down = function (x, y, obj) {
if (!gameStarted) {
startGame();
}
if (player) {
player.jump();
}
};
// 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;
}
// 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);
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)) {
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;
}
}
// 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'); ===================================================================
--- original.js
+++ change.js
@@ -1,7 +1,26 @@
/****
* Classes
****/
+// Coin class: collectible coin
+var Coin = Container.expand(function () {
+ var self = Container.call(this);
+ // Attach a yellow ellipse as the coin
+ var coinAsset = self.attachAsset('centerCircle', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ coinAsset.width = 100;
+ coinAsset.height = 100;
+ coinAsset.tint = 0xFFD700; // gold/yellow
+ // For collision and movement
+ self.lastX = self.x;
+ self.update = function () {
+ self.lastX = self.x;
+ self.x -= obstacleSpeed;
+ };
+ return self;
+});
// Obstacle class: a single green box (top or bottom pipe)
var Obstacle = Container.expand(function () {
var self = Container.call(this);
// Attach green box asset, anchor top left
@@ -102,10 +121,13 @@
var gapSize = 500; // Vertical gap between obstacles
// Game state
var player;
var obstacles = [];
+var coins = [];
var score = 0;
+var coinScore = 0;
var scoreText;
+var coinText;
var gameStarted = false;
var lastObstacleTick = 0;
// Add score text to GUI
scoreText = new Text2('0', {
@@ -113,17 +135,32 @@
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();
}
obstacles = [];
+ for (var i = 0; i < coins.length; i++) {
+ coins[i].destroy();
+ }
+ coins = [];
score = 0;
+ coinScore = 0;
scoreText.setText(score);
+ coinText.setText(coinScore);
gameStarted = true;
lastObstacleTick = 0;
// Create player
if (player) player.destroy();
@@ -151,8 +188,18 @@
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;
}
// Update obstacles and check for passed/cleanup
for (var i = obstacles.length - 1; i >= 0; i--) {
@@ -169,8 +216,26 @@
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);
+ 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