User prompt
give the bird and control by mouse
User prompt
give the shape and animations also ↪💡 Consider importing and using the following plugins: @upit/tween.v1
Code edit (1 edits merged)
Please save this source code
User prompt
Flap or Flop
User prompt
make the game of flap or flop
User prompt
Please continue polishing my design document.
Initial prompt
make the game flap or flop
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Bird = Container.expand(function () {
var self = Container.call(this);
var birdGraphics = self.attachAsset('bird', {
anchorX: 0.5,
anchorY: 0.5
});
self.targetY = 2732 / 2;
self.currentPath = 'center';
self.update = function () {
// Smooth movement towards target position
var diff = self.targetY - self.y;
self.y += diff * 0.1;
// Slight bobbing animation
birdGraphics.rotation = Math.sin(LK.ticks * 0.1) * 0.1;
};
self.setPath = function (path) {
self.currentPath = path;
if (path === 'left') {
self.targetY = 2732 * 0.3;
} else if (path === 'right') {
self.targetY = 2732 * 0.7;
} else {
self.targetY = 2732 / 2;
}
};
return self;
});
var Obstacle = Container.expand(function (gapSide) {
var self = Container.call(this);
self.gapSide = gapSide || 'both';
self.speed = -gameSpeed;
self.passed = false;
var gapSize = 350;
// Create obstacles based on gap configuration
if (self.gapSide === 'left' || self.gapSide === 'both') {
// Top obstacle for left gap
var topLeft = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 1,
x: 0,
y: 2732 * 0.3 - gapSize / 2
});
// Bottom obstacle for left gap
var bottomLeft = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 0,
x: 0,
y: 2732 * 0.3 + gapSize / 2
});
}
if (self.gapSide === 'right' || self.gapSide === 'both') {
// Top obstacle for right gap
var topRight = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 1,
x: 0,
y: 2732 * 0.7 - gapSize / 2
});
// Bottom obstacle for right gap
var bottomRight = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 0,
x: 0,
y: 2732 * 0.7 + gapSize / 2
});
}
// Add middle obstacle if only one gap
if (self.gapSide === 'left') {
var rightBlock = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: 2732 * 0.7,
height: 800
});
}
if (self.gapSide === 'right') {
var leftBlock = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: 2732 * 0.3,
height: 800
});
}
self.update = function () {
self.x += self.speed;
};
return self;
});
var PathIndicator = Container.expand(function (side) {
var self = Container.call(this);
var indicator = self.attachAsset('pathIndicator', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.3
});
self.side = side;
if (side === 'left') {
self.y = 2732 * 0.3;
} else {
self.y = 2732 * 0.7;
}
self.update = function () {
self.x += -gameSpeed;
// Fade out as it moves
indicator.alpha = Math.max(0, indicator.alpha - 0.01);
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
// Game variables
var bird;
var obstacles = [];
var pathIndicators = [];
var gameSpeed = 8;
var obstacleSpawnTimer = 0;
var obstacleSpawnDelay = 180; // 3 seconds at 60fps
var nextObstacleGap = 'both';
// UI Elements
var scoreTxt = new Text2('0', {
size: 120,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Create bird
bird = game.addChild(new Bird());
bird.x = 300;
bird.y = 2732 / 2;
// Touch controls
game.down = function (x, y, obj) {
if (x < 2048 / 2) {
// Left side tapped
bird.setPath('left');
LK.getSound('flap').play();
} else {
// Right side tapped
bird.setPath('right');
LK.getSound('flap').play();
}
};
// Generate random gap configuration
function getRandomGapConfig() {
var configs = ['left', 'right', 'both'];
return configs[Math.floor(Math.random() * configs.length)];
}
// Check collision between bird and obstacles
function checkCollisions() {
for (var i = 0; i < obstacles.length; i++) {
var obstacle = obstacles[i];
if (bird.intersects(obstacle)) {
// Game over
LK.getSound('collision').play();
LK.effects.flashScreen(0xff0000, 500);
LK.showGameOver();
return true;
}
// Check if bird passed obstacle for scoring
if (!obstacle.passed && obstacle.x < bird.x - 100) {
obstacle.passed = true;
LK.setScore(LK.getScore() + 1);
scoreTxt.setText(LK.getScore());
LK.getSound('score').play();
// Increase speed every 5 points
if (LK.getScore() % 5 === 0) {
gameSpeed += 0.5;
obstacleSpawnDelay = Math.max(120, obstacleSpawnDelay - 5);
}
}
}
return false;
}
// Spawn new obstacle
function spawnObstacle() {
var gapConfig = getRandomGapConfig();
var newObstacle = new Obstacle(gapConfig);
newObstacle.x = 2048 + 200;
obstacles.push(newObstacle);
game.addChild(newObstacle);
// Add path indicators
if (gapConfig === 'left' || gapConfig === 'both') {
var leftIndicator = new PathIndicator('left');
leftIndicator.x = 2048 + 100;
pathIndicators.push(leftIndicator);
game.addChild(leftIndicator);
}
if (gapConfig === 'right' || gapConfig === 'both') {
var rightIndicator = new PathIndicator('right');
rightIndicator.x = 2048 + 100;
pathIndicators.push(rightIndicator);
game.addChild(rightIndicator);
}
}
// Main game loop
game.update = function () {
// Spawn obstacles
obstacleSpawnTimer++;
if (obstacleSpawnTimer >= obstacleSpawnDelay) {
spawnObstacle();
obstacleSpawnTimer = 0;
}
// Update and clean up obstacles
for (var i = obstacles.length - 1; i >= 0; i--) {
var obstacle = obstacles[i];
if (obstacle.x < -300) {
obstacle.destroy();
obstacles.splice(i, 1);
}
}
// Update and clean up path indicators
for (var j = pathIndicators.length - 1; j >= 0; j--) {
var indicator = pathIndicators[j];
if (indicator.x < -200 || indicator.children[0].alpha <= 0) {
indicator.destroy();
pathIndicators.splice(j, 1);
}
}
// Check for collisions
checkCollisions();
// Keep bird in bounds
if (bird.y < 50) bird.y = 50;
if (bird.y > 2732 - 50) bird.y = 2732 - 50;
}; ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,242 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+var Bird = Container.expand(function () {
+ var self = Container.call(this);
+ var birdGraphics = self.attachAsset('bird', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.targetY = 2732 / 2;
+ self.currentPath = 'center';
+ self.update = function () {
+ // Smooth movement towards target position
+ var diff = self.targetY - self.y;
+ self.y += diff * 0.1;
+ // Slight bobbing animation
+ birdGraphics.rotation = Math.sin(LK.ticks * 0.1) * 0.1;
+ };
+ self.setPath = function (path) {
+ self.currentPath = path;
+ if (path === 'left') {
+ self.targetY = 2732 * 0.3;
+ } else if (path === 'right') {
+ self.targetY = 2732 * 0.7;
+ } else {
+ self.targetY = 2732 / 2;
+ }
+ };
+ return self;
+});
+var Obstacle = Container.expand(function (gapSide) {
+ var self = Container.call(this);
+ self.gapSide = gapSide || 'both';
+ self.speed = -gameSpeed;
+ self.passed = false;
+ var gapSize = 350;
+ // Create obstacles based on gap configuration
+ if (self.gapSide === 'left' || self.gapSide === 'both') {
+ // Top obstacle for left gap
+ var topLeft = self.attachAsset('obstacle', {
+ anchorX: 0.5,
+ anchorY: 1,
+ x: 0,
+ y: 2732 * 0.3 - gapSize / 2
+ });
+ // Bottom obstacle for left gap
+ var bottomLeft = self.attachAsset('obstacle', {
+ anchorX: 0.5,
+ anchorY: 0,
+ x: 0,
+ y: 2732 * 0.3 + gapSize / 2
+ });
+ }
+ if (self.gapSide === 'right' || self.gapSide === 'both') {
+ // Top obstacle for right gap
+ var topRight = self.attachAsset('obstacle', {
+ anchorX: 0.5,
+ anchorY: 1,
+ x: 0,
+ y: 2732 * 0.7 - gapSize / 2
+ });
+ // Bottom obstacle for right gap
+ var bottomRight = self.attachAsset('obstacle', {
+ anchorX: 0.5,
+ anchorY: 0,
+ x: 0,
+ y: 2732 * 0.7 + gapSize / 2
+ });
+ }
+ // Add middle obstacle if only one gap
+ if (self.gapSide === 'left') {
+ var rightBlock = self.attachAsset('obstacle', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: 0,
+ y: 2732 * 0.7,
+ height: 800
+ });
+ }
+ if (self.gapSide === 'right') {
+ var leftBlock = self.attachAsset('obstacle', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: 0,
+ y: 2732 * 0.3,
+ height: 800
+ });
+ }
+ self.update = function () {
+ self.x += self.speed;
+ };
+ return self;
+});
+var PathIndicator = Container.expand(function (side) {
+ var self = Container.call(this);
+ var indicator = self.attachAsset('pathIndicator', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ alpha: 0.3
+ });
+ self.side = side;
+ if (side === 'left') {
+ self.y = 2732 * 0.3;
+ } else {
+ self.y = 2732 * 0.7;
+ }
+ self.update = function () {
+ self.x += -gameSpeed;
+ // Fade out as it moves
+ indicator.alpha = Math.max(0, indicator.alpha - 0.01);
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x87CEEB
+});
+
+/****
+* Game Code
+****/
+// Game variables
+var bird;
+var obstacles = [];
+var pathIndicators = [];
+var gameSpeed = 8;
+var obstacleSpawnTimer = 0;
+var obstacleSpawnDelay = 180; // 3 seconds at 60fps
+var nextObstacleGap = 'both';
+// UI Elements
+var scoreTxt = new Text2('0', {
+ size: 120,
+ fill: 0xFFFFFF
+});
+scoreTxt.anchor.set(0.5, 0);
+LK.gui.top.addChild(scoreTxt);
+// Create bird
+bird = game.addChild(new Bird());
+bird.x = 300;
+bird.y = 2732 / 2;
+// Touch controls
+game.down = function (x, y, obj) {
+ if (x < 2048 / 2) {
+ // Left side tapped
+ bird.setPath('left');
+ LK.getSound('flap').play();
+ } else {
+ // Right side tapped
+ bird.setPath('right');
+ LK.getSound('flap').play();
+ }
+};
+// Generate random gap configuration
+function getRandomGapConfig() {
+ var configs = ['left', 'right', 'both'];
+ return configs[Math.floor(Math.random() * configs.length)];
+}
+// Check collision between bird and obstacles
+function checkCollisions() {
+ for (var i = 0; i < obstacles.length; i++) {
+ var obstacle = obstacles[i];
+ if (bird.intersects(obstacle)) {
+ // Game over
+ LK.getSound('collision').play();
+ LK.effects.flashScreen(0xff0000, 500);
+ LK.showGameOver();
+ return true;
+ }
+ // Check if bird passed obstacle for scoring
+ if (!obstacle.passed && obstacle.x < bird.x - 100) {
+ obstacle.passed = true;
+ LK.setScore(LK.getScore() + 1);
+ scoreTxt.setText(LK.getScore());
+ LK.getSound('score').play();
+ // Increase speed every 5 points
+ if (LK.getScore() % 5 === 0) {
+ gameSpeed += 0.5;
+ obstacleSpawnDelay = Math.max(120, obstacleSpawnDelay - 5);
+ }
+ }
+ }
+ return false;
+}
+// Spawn new obstacle
+function spawnObstacle() {
+ var gapConfig = getRandomGapConfig();
+ var newObstacle = new Obstacle(gapConfig);
+ newObstacle.x = 2048 + 200;
+ obstacles.push(newObstacle);
+ game.addChild(newObstacle);
+ // Add path indicators
+ if (gapConfig === 'left' || gapConfig === 'both') {
+ var leftIndicator = new PathIndicator('left');
+ leftIndicator.x = 2048 + 100;
+ pathIndicators.push(leftIndicator);
+ game.addChild(leftIndicator);
+ }
+ if (gapConfig === 'right' || gapConfig === 'both') {
+ var rightIndicator = new PathIndicator('right');
+ rightIndicator.x = 2048 + 100;
+ pathIndicators.push(rightIndicator);
+ game.addChild(rightIndicator);
+ }
+}
+// Main game loop
+game.update = function () {
+ // Spawn obstacles
+ obstacleSpawnTimer++;
+ if (obstacleSpawnTimer >= obstacleSpawnDelay) {
+ spawnObstacle();
+ obstacleSpawnTimer = 0;
+ }
+ // Update and clean up obstacles
+ for (var i = obstacles.length - 1; i >= 0; i--) {
+ var obstacle = obstacles[i];
+ if (obstacle.x < -300) {
+ obstacle.destroy();
+ obstacles.splice(i, 1);
+ }
+ }
+ // Update and clean up path indicators
+ for (var j = pathIndicators.length - 1; j >= 0; j--) {
+ var indicator = pathIndicators[j];
+ if (indicator.x < -200 || indicator.children[0].alpha <= 0) {
+ indicator.destroy();
+ pathIndicators.splice(j, 1);
+ }
+ }
+ // Check for collisions
+ checkCollisions();
+ // Keep bird in bounds
+ if (bird.y < 50) bird.y = 50;
+ if (bird.y > 2732 - 50) bird.y = 2732 - 50;
+};
\ No newline at end of file