Code edit (1 edits merged)
Please save this source code
Code edit (8 edits merged)
Please save this source code
User prompt
oyun bitince dieSound çalsın
User prompt
player zıplarken jumpSound çalsın
Code edit (1 edits merged)
Please save this source code
User prompt
highscore u sıfırla
Code edit (2 edits merged)
Please save this source code
User prompt
highscore geçildiğinde bir kez hgsound sesini çal
User prompt
startbutton a basılınca startsound çalsın
Code edit (1 edits merged)
Please save this source code
User prompt
skor her değiştiğinde scoreText nesnesi shrink animasyonu yapsın ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
skor her arttığında scoretext nesnesi shrink animasyonu yapsın ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
scoretext değeri her değiştiğinde scoretext nesnesi shrink animasyonu yapsın ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
scoretext ve highscoretext değeri her değiştiğinde shrink animasyonu yapsınlar ↪💡 Consider importing and using the following plugins: @upit/tween.v1
/****
* Plugins
****/
var storage = LK.import("@upit/storage.v1", {
highscore: 0
});
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
// Define a class for the bird
var Bird = Container.expand(function () {
var self = Container.call(this);
var birdGraphics1 = self.attachAsset('bird1', {
anchorX: 0.5,
anchorY: 0.5
});
var birdGraphics2 = self.attachAsset('bird2', {
anchorX: 0.5,
anchorY: 0.5
});
birdGraphics2.visible = false; // Initially, the second frame of the animation is not visible
self.animationCounter = 0; // Counter for the animation
self.speed = 35;
self.y = 100 + Math.random() * 550;
self.update = function () {
// Animation
self.animationCounter++;
if (self.animationCounter % 20 == 0) {
birdGraphics1.visible = !birdGraphics1.visible;
birdGraphics2.visible = !birdGraphics2.visible;
}
// Movement
self.x -= self.speed;
if (self.x < -50) {
self.destroy();
}
};
});
// Define a class for the cloud
var Cloud = Container.expand(function () {
var self = Container.call(this);
var cloudGraphics = self.attachAsset('cloud', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
self.x -= 4;
if (self.x < -50) {
self.destroy();
}
};
});
// Define a class for enemies
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyTypes = ['enemy', 'enemy2', 'enemy3'];
var randomEnemy = enemyTypes[Math.floor(Math.random() * enemyTypes.length)];
var enemyGraphics = self.attachAsset(randomEnemy, {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 20;
self.y = 2732 / 2 - 100; // Position the enemy 45px higher
self.update = function () {
self.x -= self.speed;
if (self.x < -50) {
self.destroy();
}
};
});
//<Assets used in the game will automatically appear here>
// Define a class for the player character
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics1 = self.attachAsset('p1', {
anchorX: 0.5,
anchorY: 0.5
});
var playerGraphics2 = self.attachAsset('p2', {
anchorX: 0.5,
anchorY: 0.5
});
var jumpingGraphics = self.attachAsset('jumping', {
anchorX: 0.5,
anchorY: 0.5
});
jumpingGraphics.visible = false; // Initially, the jumping graphic is not visible
playerGraphics2.visible = false; // Initially, the second frame of the animation is not visible
self.speed = 15;
self.jumpHeight = 25;
self.isJumping = false;
self.velocityY = 5;
self.animationCounter = 0; // Counter for the animation
self.update = function () {
if (self.isJumping) {
self.y += self.velocityY;
self.velocityY += 0.7; // Decreased gravity effect by 30%
if (self.y >= 2732 / 2 - 100) {
// Ground level
self.y = 2732 / 2 - 100;
self.isJumping = false;
self.velocityY = 0;
jumpingGraphics.visible = false; // Hide jumping graphic after jump
// Revert to player animation after jump
playerGraphics1.visible = true;
playerGraphics2.visible = false;
} else {
// Show jumping graphic during jump
playerGraphics1.visible = false;
playerGraphics2.visible = false;
jumpingGraphics.visible = true;
}
} else {
// Animation
self.animationCounter++;
if (self.animationCounter % 10 == 0) {
// Change the frame every 10 game ticks
playerGraphics1.visible = !playerGraphics1.visible;
playerGraphics2.visible = !playerGraphics2.visible;
}
}
};
self.jump = function () {
if (!self.isJumping) {
self.isJumping = true;
self.velocityY = -self.jumpHeight;
LK.getSound('jumpSound').play(); // Play jump sound when jumping
}
};
// Method to change player graphics to 'die' image
self.changeToDieImage = function () {
playerGraphics1.visible = false;
playerGraphics2.visible = false;
jumpingGraphics.visible = false;
var dieGraphics = self.attachAsset('die', {
anchorX: 0.5,
anchorY: 0.5
});
dieGraphics.visible = true;
};
// Method to stop player animation
self.stopAnimation = function () {
self.update = function () {}; // Override update to stop animation
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0xD3D3D3 // Light gray background
});
/****
* Game Code
****/
var ground1 = game.addChild(LK.getAsset('ground', {
anchorX: 0,
anchorY: 0.5
}));
ground1.x = 0;
ground1.y = 2732 / 2;
var ground2 = game.addChild(LK.getAsset('ground', {
anchorX: 0,
anchorY: 0.5
}));
ground2.x = ground1.width;
ground2.y = 2732 / 2;
// Create a large button in the center of the screen
var startButton = new Text2(' ', {
size: 150,
fill: 0xFFFFFF,
font: "'GillSans-Bold',Impact,'Arial Black',Tahoma"
});
// Create a black rectangle behind the start button
var startButtonBackground = LK.getAsset('rectangle', {
width: 600,
height: 240,
color: 0x000000,
anchorX: 0.5,
anchorY: 0.5
});
startButtonBackground.x = 2048 / 2;
startButtonBackground.y = 2732 / 2;
game.addChild(startButtonBackground);
// Center the button on the screen
startButton.anchor.set(0.5, 0.5);
startButton.x = 2048 / 2;
startButton.y = 2732 / 2;
// Add the button to the game
game.addChild(startButton);
// Add event listener to start the game when startButton is pressed
startButton.down = function (x, y, obj) {
// Play start sound
LK.getSound('startSound').play();
// Remove the start button from the game
tween(startButtonBackground, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 150,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(startButtonBackground, {
scaleX: 1,
scaleY: 1
}, {
duration: 150,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(startButtonBackground, {
alpha: 0
}, {
duration: 150,
easing: tween.easeOut,
onFinish: function onFinish() {
startButton.destroy();
startButtonBackground.destroy();
}
});
}
});
}
});
gameStarted = true; // Set the game as started
// Play background music
LK.playMusic('bg');
// Start the game logic
game.update = function () {
player.update();
// Spawn birds
if (LK.ticks % Math.floor(Math.random() * 600 + 60) == 0) {
var bird = new Bird();
bird.x = Math.max(2732, Math.floor(Math.random() * 500));
bird.y = 2732 / 2 - 900; // Random y position
game.addChild(bird);
}
// Update ground
ground1.x -= 30;
ground2.x -= 30;
if (ground1.x <= -ground1.width) {
ground1.x = ground2.x + ground2.width;
}
if (ground2.x <= -ground2.width) {
ground2.x = ground1.x + ground1.width;
}
// Spawn enemies
enemySpawnCounter++;
if (enemySpawnCounter >= enemySpawnInterval) {
var enemy = new Enemy();
enemy.x = 2048;
enemy.y = 2732 / 2 - 100;
enemies.push(enemy);
game.addChild(enemy);
// Randomize the spawn interval for the next enemy
// Decrease the spawn interval as the score increases
enemySpawnInterval = Math.max(50, Math.floor(Math.random() * 200) - LK.getScore() * 1.5);
enemySpawnCounter = 0;
}
// Spawn clouds at random intervals and positions
if (LK.ticks % Math.floor(Math.random() * 600 + 60) == 0) {
var cloud = new Cloud();
cloud.x = 2732 + Math.random() * 500;
cloud.y = 100 + Math.random() * 350; // Spawn cloud between 0-100px on the y-axis
game.addChild(cloud);
}
// Update enemies
for (var j = enemies.length - 1; j >= 0; j--) {
enemies[j].update();
if (player.intersects(enemies[j])) {
// Change player graphics to 'die' image
player.changeToDieImage();
// Stop player animation
player.stopAnimation();
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
// Check if the current score is higher than the stored highscore
if (LK.getScore() > storage.highscore) {
storage.highscore = LK.getScore(); // Update highscore in storage
highscoreText.setText("H.Score: " + storage.highscore); // Update highscore text
LK.getSound('hsSound').play(); // Play highscore sound//{2F.1}
}
} else if (player.x > enemies[j].x && !enemies[j].passed) {
enemies[j].passed = true;
LK.setScore(LK.getScore() + 1);
scoreText.setText("Score: " + LK.getScore());
if (LK.getScore() > storage.highscore) {
storage.highscore = LK.getScore(); // Update highscore in storage
highscoreText.setText("H.Score: " + LK.getScore()); // Update highscore text
}
}
}
};
};
var player = game.addChild(new Player());
player.x = 2048 / 2 - 2048 / 3; // Position the player a bit more to the left
player.y = 2732 / 2 - 100;
// Initialize bird
var bird = game.addChild(new Bird());
//bird.x = Math.max(2732, Math.floor(Math.random() * 500)); // Position the bird at a random x position
//bird.y = 2732 / 2 - 900; // Position the bird at y-axis 900px
// Initialize enemies
var enemies = [];
var enemySpawnInterval = 100;
var enemySpawnCounter = 0;
var gameStarted = false; // Flag to check if the game has started
// Create a new Text2 object to display the score
var scoreText = new Text2('Score: 0', {
size: 70,
fill: 0x615e5e,
// Dark gray color
font: "'GillSans-Bold',Impact,'Arial Black',Tahoma"
});
// Add the score text to the game GUI at the top-right corner of the screen
LK.gui.topRight.addChild(scoreText);
scoreText.x = -scoreText.width / 2 - 210; // Move 100px to the left
scoreText.y = scoreText.height / 2; // Adjust y to account for anchor
// Create a new Text2 object to display the highscore
var highscoreText = new Text2('H.Score: ' + storage.highscore, {
size: 50,
fill: 0x615e5e,
// Dark gray color
font: "'GillSans-Bold',Impact,'Arial Black',Tahoma"
});
// Add the highscore text below the score text
LK.gui.topRight.addChild(highscoreText);
highscoreText.x = scoreText.x;
highscoreText.y = scoreText.y + scoreText.height;
// Handle game updates
game.update = function () {
player.update();
// Spawn birds
if (LK.ticks % Math.floor(Math.random() * 600 + 60) == 0) {
var bird = new Bird();
bird.x = Math.max(2732, Math.floor(Math.random() * 500));
bird.y = 100 + Math.random() * 550; // Random y position
game.addChild(bird);
}
// Update ground
ground1.x -= 30;
ground2.x -= 30;
if (ground1.x <= -ground1.width) {
ground1.x = ground2.x + ground2.width;
}
if (ground2.x <= -ground2.width) {
ground2.x = ground1.x + ground1.width;
}
// Spawn enemies
if (gameStarted) {
enemySpawnCounter++;
if (enemySpawnCounter >= enemySpawnInterval) {
var enemy = new Enemy();
enemy.x = 2048;
enemy.y = 2732 / 2 - 100;
enemies.push(enemy);
game.addChild(enemy);
// Randomize the spawn interval for the next enemy
// Decrease the spawn interval as the score increases
enemySpawnInterval = Math.max(50, Math.floor(Math.random() * 200) - LK.getScore() * 1.5);
enemySpawnCounter = 0;
}
}
// Spawn clouds at random intervals and positions
if (LK.ticks % Math.floor(Math.random() * 600 + 60) == 0) {
var cloud = new Cloud();
cloud.x = 2732 + Math.random() * 500;
cloud.y = 100 + Math.random() * 350; // Spawn cloud between 0-100px on the y-axis
game.addChild(cloud);
}
// Update enemies
for (var j = enemies.length - 1; j >= 0; j--) {
enemies[j].update();
if (player.intersects(enemies[j])) {
LK.getSound('dieSound').play(); // Play die sound when the game is over
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
// Check if the current score is higher than the stored highscore
if (LK.getScore() > storage.highscore) {
storage.highscore = LK.getScore(); // Update highscore in storage
highscoreText.setText("H.Score: " + storage.highscore); // Update highscore text
}
} else if (player.x > enemies[j].x && !enemies[j].passed) {
enemies[j].passed = true;
LK.setScore(LK.getScore() + 1);
scoreText.setText("Score: " + LK.getScore());
if (LK.getScore() > storage.highscore) {
storage.highscore = LK.getScore(); // Update highscore in storage
highscoreText.setText("H.Score: " + LK.getScore()); // Update highscore text
}
}
}
};
// Handle player jump
game.down = function (x, y, obj) {
if (gameStarted) {
player.jump();
}
}; ===================================================================
--- original.js
+++ change.js
@@ -271,9 +271,8 @@
enemies[j].update();
if (player.intersects(enemies[j])) {
// Change player graphics to 'die' image
player.changeToDieImage();
- LK.getSound('dieSound').play(); // Play die sound when the game is over
// Stop player animation
player.stopAnimation();
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
@@ -373,8 +372,9 @@
// Update enemies
for (var j = enemies.length - 1; j >= 0; j--) {
enemies[j].update();
if (player.intersects(enemies[j])) {
+ LK.getSound('dieSound').play(); // Play die sound when the game is over
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
// Check if the current score is higher than the stored highscore
if (LK.getScore() > storage.highscore) {