/****
* 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.velocity = 0;
self.gravity = 0.5;
self.flapStrength = -12;
self.isDead = false;
self.flap = function () {
if (!self.isDead) {
self.velocity = self.flapStrength;
LK.getSound('flap').play();
// Rotate bird up when flapping
tween(self, {
rotation: -0.5
}, {
duration: 100,
easing: tween.linear
});
}
};
self.update = function () {
if (self.isDead) {
return;
}
// Apply gravity and update position
self.velocity += self.gravity;
self.y += self.velocity;
// Rotate bird based on velocity
if (self.velocity > 0) {
var targetRotation = Math.min(self.velocity * 0.05, 1.2);
tween(self, {
rotation: targetRotation
}, {
duration: 100,
easing: tween.linear
});
}
};
self.die = function () {
if (!self.isDead) {
self.isDead = true;
LK.getSound('hit').play();
}
};
return self;
});
var Pipe = Container.expand(function () {
var self = Container.call(this);
var topPipe = self.attachAsset('pipeTop', {
anchorX: 0.5,
anchorY: 1.0
});
var bottomPipe = self.attachAsset('pipeBottom', {
anchorX: 0.5,
anchorY: 0
});
self.gapHeight = 400;
self.gapPosition = 0;
self.speed = 5;
self.scored = false;
self.setGapPosition = function (position) {
self.gapPosition = position;
// Position pipes to create gap
topPipe.y = position - self.gapHeight / 2;
bottomPipe.y = position + self.gapHeight / 2;
};
self.update = function () {
self.x -= self.speed;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
// Game variables
var bird;
var pipes = [];
var ground;
var background;
var isGameStarted = false;
var pipeSpawnTimer = 0;
var pipeSpawnInterval = 120; // frames (2 seconds at 60fps)
var lastPipeX = 0;
var gameover = false;
// GUI
var scoreTxt = new Text2('0', {
size: 120,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Add tap to start text initially
var startTxt = new Text2('Tap to Start', {
size: 80,
fill: 0xFFFFFF
});
startTxt.anchor.set(0.5, 0.5);
LK.gui.center.addChild(startTxt);
// Create background
background = LK.getAsset('background', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0
});
game.addChild(background);
// Create ground
ground = LK.getAsset('ground', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 2732 - 100
});
game.addChild(ground);
// Create bird
bird = new Bird();
bird.x = 400;
bird.y = 2732 / 2;
game.addChild(bird);
// Start music
LK.playMusic('gameMusic', {
fade: {
start: 0,
end: 0.4,
duration: 1000
}
});
// Game functions
function spawnPipe() {
var pipe = new Pipe();
pipe.x = 2048 + 150; // Start just off-screen
// Random gap position between 500 and 2732-500 (avoiding too close to top/bottom)
var minY = 500;
var maxY = 2732 - 500;
var gapY = minY + Math.random() * (maxY - minY);
pipe.setGapPosition(gapY);
pipes.push(pipe);
game.addChild(pipe);
// Place pipe behind bird but in front of background
game.setChildIndex(pipe, 1);
lastPipeX = pipe.x;
}
function startGame() {
if (!isGameStarted) {
isGameStarted = true;
gameover = false;
LK.setScore(0);
scoreTxt.setText(0);
// Remove start text
if (startTxt.parent) {
startTxt.parent.removeChild(startTxt);
}
// Initial bird flap
bird.flap();
}
}
function checkCollisions() {
// Check if bird hits ground
if (bird.y + 40 > ground.y) {
bird.y = ground.y - 40; // Prevent bird from going through ground
gameOver();
return true;
}
// Check if bird hits ceiling
if (bird.y - 40 < 0) {
bird.y = 40; // Prevent bird from going through ceiling
bird.velocity = 0;
}
// Check collision with pipes
for (var i = 0; i < pipes.length; i++) {
var pipe = pipes[i];
// Get pipe children (top and bottom pipes)
var topPipe = pipe.children[0];
var bottomPipe = pipe.children[1];
// Calculate collision areas
var birdLeft = bird.x - 40;
var birdRight = bird.x + 40;
var birdTop = bird.y - 40;
var birdBottom = bird.y + 40;
var pipeLeft = pipe.x - 75;
var pipeRight = pipe.x + 75;
var topPipeBottom = pipe.gapPosition - pipe.gapHeight / 2;
var bottomPipeTop = pipe.gapPosition + pipe.gapHeight / 2;
// Check for collision
if (birdRight > pipeLeft && birdLeft < pipeRight) {
if (birdTop < topPipeBottom || birdBottom > bottomPipeTop) {
gameOver();
return true;
}
}
// Check for score
if (!pipe.scored && birdLeft > pipe.x) {
pipe.scored = true;
LK.setScore(LK.getScore() + 1);
scoreTxt.setText(LK.getScore());
LK.getSound('score').play();
}
}
return false;
}
function gameOver() {
if (!gameover) {
gameover = true;
bird.die();
// Flash screen and show game over
LK.effects.flashScreen(0xFF0000, 500);
// Wait a moment before showing game over
LK.setTimeout(function () {
LK.showGameOver();
}, 1000);
}
}
function resetGame() {
// Remove all pipes
for (var i = pipes.length - 1; i >= 0; i--) {
game.removeChild(pipes[i]);
pipes[i].destroy();
}
pipes = [];
// Reset bird
bird.velocity = 0;
bird.rotation = 0;
bird.y = 2732 / 2;
bird.isDead = false;
// Reset game state
isGameStarted = false;
gameover = false;
pipeSpawnTimer = 0;
LK.setScore(0);
scoreTxt.setText("0");
// Show start text
LK.gui.center.addChild(startTxt);
}
// Input handlers
game.down = function (x, y, obj) {
if (!isGameStarted) {
startGame();
} else if (!gameover) {
bird.flap();
}
};
// Game update loop
game.update = function () {
if (!isGameStarted) {
// Bird gently floats up and down before game starts
bird.y = 2732 / 2 + Math.sin(LK.ticks / 30) * 20;
return;
}
if (!gameover) {
// Update bird
bird.update();
// Spawn pipes
pipeSpawnTimer++;
if (pipeSpawnTimer >= pipeSpawnInterval) {
spawnPipe();
pipeSpawnTimer = 0;
}
// Update and clean up pipes
for (var i = pipes.length - 1; i >= 0; i--) {
pipes[i].update();
// Remove pipes that are off-screen
if (pipes[i].x < -200) {
game.removeChild(pipes[i]);
pipes[i].destroy();
pipes.splice(i, 1);
}
}
// Check collisions
checkCollisions();
}
}; ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,290 @@
-/****
+/****
+* 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.velocity = 0;
+ self.gravity = 0.5;
+ self.flapStrength = -12;
+ self.isDead = false;
+ self.flap = function () {
+ if (!self.isDead) {
+ self.velocity = self.flapStrength;
+ LK.getSound('flap').play();
+ // Rotate bird up when flapping
+ tween(self, {
+ rotation: -0.5
+ }, {
+ duration: 100,
+ easing: tween.linear
+ });
+ }
+ };
+ self.update = function () {
+ if (self.isDead) {
+ return;
+ }
+ // Apply gravity and update position
+ self.velocity += self.gravity;
+ self.y += self.velocity;
+ // Rotate bird based on velocity
+ if (self.velocity > 0) {
+ var targetRotation = Math.min(self.velocity * 0.05, 1.2);
+ tween(self, {
+ rotation: targetRotation
+ }, {
+ duration: 100,
+ easing: tween.linear
+ });
+ }
+ };
+ self.die = function () {
+ if (!self.isDead) {
+ self.isDead = true;
+ LK.getSound('hit').play();
+ }
+ };
+ return self;
+});
+var Pipe = Container.expand(function () {
+ var self = Container.call(this);
+ var topPipe = self.attachAsset('pipeTop', {
+ anchorX: 0.5,
+ anchorY: 1.0
+ });
+ var bottomPipe = self.attachAsset('pipeBottom', {
+ anchorX: 0.5,
+ anchorY: 0
+ });
+ self.gapHeight = 400;
+ self.gapPosition = 0;
+ self.speed = 5;
+ self.scored = false;
+ self.setGapPosition = function (position) {
+ self.gapPosition = position;
+ // Position pipes to create gap
+ topPipe.y = position - self.gapHeight / 2;
+ bottomPipe.y = position + self.gapHeight / 2;
+ };
+ self.update = function () {
+ self.x -= self.speed;
+ };
+ 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 pipes = [];
+var ground;
+var background;
+var isGameStarted = false;
+var pipeSpawnTimer = 0;
+var pipeSpawnInterval = 120; // frames (2 seconds at 60fps)
+var lastPipeX = 0;
+var gameover = false;
+// GUI
+var scoreTxt = new Text2('0', {
+ size: 120,
+ fill: 0xFFFFFF
+});
+scoreTxt.anchor.set(0.5, 0);
+LK.gui.top.addChild(scoreTxt);
+// Add tap to start text initially
+var startTxt = new Text2('Tap to Start', {
+ size: 80,
+ fill: 0xFFFFFF
+});
+startTxt.anchor.set(0.5, 0.5);
+LK.gui.center.addChild(startTxt);
+// Create background
+background = LK.getAsset('background', {
+ anchorX: 0,
+ anchorY: 0,
+ x: 0,
+ y: 0
+});
+game.addChild(background);
+// Create ground
+ground = LK.getAsset('ground', {
+ anchorX: 0,
+ anchorY: 0,
+ x: 0,
+ y: 2732 - 100
+});
+game.addChild(ground);
+// Create bird
+bird = new Bird();
+bird.x = 400;
+bird.y = 2732 / 2;
+game.addChild(bird);
+// Start music
+LK.playMusic('gameMusic', {
+ fade: {
+ start: 0,
+ end: 0.4,
+ duration: 1000
+ }
+});
+// Game functions
+function spawnPipe() {
+ var pipe = new Pipe();
+ pipe.x = 2048 + 150; // Start just off-screen
+ // Random gap position between 500 and 2732-500 (avoiding too close to top/bottom)
+ var minY = 500;
+ var maxY = 2732 - 500;
+ var gapY = minY + Math.random() * (maxY - minY);
+ pipe.setGapPosition(gapY);
+ pipes.push(pipe);
+ game.addChild(pipe);
+ // Place pipe behind bird but in front of background
+ game.setChildIndex(pipe, 1);
+ lastPipeX = pipe.x;
+}
+function startGame() {
+ if (!isGameStarted) {
+ isGameStarted = true;
+ gameover = false;
+ LK.setScore(0);
+ scoreTxt.setText(0);
+ // Remove start text
+ if (startTxt.parent) {
+ startTxt.parent.removeChild(startTxt);
+ }
+ // Initial bird flap
+ bird.flap();
+ }
+}
+function checkCollisions() {
+ // Check if bird hits ground
+ if (bird.y + 40 > ground.y) {
+ bird.y = ground.y - 40; // Prevent bird from going through ground
+ gameOver();
+ return true;
+ }
+ // Check if bird hits ceiling
+ if (bird.y - 40 < 0) {
+ bird.y = 40; // Prevent bird from going through ceiling
+ bird.velocity = 0;
+ }
+ // Check collision with pipes
+ for (var i = 0; i < pipes.length; i++) {
+ var pipe = pipes[i];
+ // Get pipe children (top and bottom pipes)
+ var topPipe = pipe.children[0];
+ var bottomPipe = pipe.children[1];
+ // Calculate collision areas
+ var birdLeft = bird.x - 40;
+ var birdRight = bird.x + 40;
+ var birdTop = bird.y - 40;
+ var birdBottom = bird.y + 40;
+ var pipeLeft = pipe.x - 75;
+ var pipeRight = pipe.x + 75;
+ var topPipeBottom = pipe.gapPosition - pipe.gapHeight / 2;
+ var bottomPipeTop = pipe.gapPosition + pipe.gapHeight / 2;
+ // Check for collision
+ if (birdRight > pipeLeft && birdLeft < pipeRight) {
+ if (birdTop < topPipeBottom || birdBottom > bottomPipeTop) {
+ gameOver();
+ return true;
+ }
+ }
+ // Check for score
+ if (!pipe.scored && birdLeft > pipe.x) {
+ pipe.scored = true;
+ LK.setScore(LK.getScore() + 1);
+ scoreTxt.setText(LK.getScore());
+ LK.getSound('score').play();
+ }
+ }
+ return false;
+}
+function gameOver() {
+ if (!gameover) {
+ gameover = true;
+ bird.die();
+ // Flash screen and show game over
+ LK.effects.flashScreen(0xFF0000, 500);
+ // Wait a moment before showing game over
+ LK.setTimeout(function () {
+ LK.showGameOver();
+ }, 1000);
+ }
+}
+function resetGame() {
+ // Remove all pipes
+ for (var i = pipes.length - 1; i >= 0; i--) {
+ game.removeChild(pipes[i]);
+ pipes[i].destroy();
+ }
+ pipes = [];
+ // Reset bird
+ bird.velocity = 0;
+ bird.rotation = 0;
+ bird.y = 2732 / 2;
+ bird.isDead = false;
+ // Reset game state
+ isGameStarted = false;
+ gameover = false;
+ pipeSpawnTimer = 0;
+ LK.setScore(0);
+ scoreTxt.setText("0");
+ // Show start text
+ LK.gui.center.addChild(startTxt);
+}
+// Input handlers
+game.down = function (x, y, obj) {
+ if (!isGameStarted) {
+ startGame();
+ } else if (!gameover) {
+ bird.flap();
+ }
+};
+// Game update loop
+game.update = function () {
+ if (!isGameStarted) {
+ // Bird gently floats up and down before game starts
+ bird.y = 2732 / 2 + Math.sin(LK.ticks / 30) * 20;
+ return;
+ }
+ if (!gameover) {
+ // Update bird
+ bird.update();
+ // Spawn pipes
+ pipeSpawnTimer++;
+ if (pipeSpawnTimer >= pipeSpawnInterval) {
+ spawnPipe();
+ pipeSpawnTimer = 0;
+ }
+ // Update and clean up pipes
+ for (var i = pipes.length - 1; i >= 0; i--) {
+ pipes[i].update();
+ // Remove pipes that are off-screen
+ if (pipes[i].x < -200) {
+ game.removeChild(pipes[i]);
+ pipes[i].destroy();
+ pipes.splice(i, 1);
+ }
+ }
+ // Check collisions
+ checkCollisions();
+ }
+};
\ No newline at end of file
Orman vektör tarzda. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Orman vektör gökyüzü gölgeli hafif siyah Arka plan. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Ağaç kütüğü vektör tarzda dik bir adet koyu kahverengi. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Sarı muhabbet kuşu sevimli küçük vektör ve piksel sanatı. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Bulut piksel sanatı. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows