User prompt
Ana menü butonuna tıklanıldığında ve Store butonuna tıklanıldığında oyun durmalı
User prompt
Ana menü butonuna tıklanıldığında Mağaza Butonu olmalı
User prompt
Please fix the bug: 'Uncaught TypeError: LK.pauseGame is not a function' in or related to this line: 'LK.pauseGame();' Line Number: 417
User prompt
Ana menü butonunu dahada aşağıya koy
User prompt
Menu yazısı biraz daha aşağıda olmalı
User prompt
Ekrana ana Menü butonu ekle
User prompt
Coin ve diğer metinler biraz dahada gözükmesi gerek
User prompt
Metinler dahada görünür olmalı
User prompt
Eğer Cam Ballı geçerse 1 canımız gitmeli
User prompt
Her cama vurulduğunda canımız gitmesin
User prompt
Canımızın gittiği gözükmeli
User prompt
İki kere Mouse tıklanırsa Ball yükseğe zıplamalı
User prompt
Eğer Ball camı kıramassa 1 canı gitmeli
User prompt
Oyundaki Leveller biraz uzun olsun
User prompt
Oyunda coinler her level kazandığımızda 500 olarak verilmeli ↪💡 Consider importing and using the following plugins: @upit/storage.v1
Code edit (1 edits merged)
Please save this source code
User prompt
Glass Smasher: First-Person Ball
Initial prompt
Create a 2D first-person-style game where the player controls a metal ball from its own point of view (POV). The game starts at Level 1, and in each level, the player must smash through glass obstacles to progress. The ball automatically moves forward, and the player can control its speed and jump. If the ball fails to break a glass, it loses 1 life. The player has 3 lives total. After breaking all required glass pieces in a level, the player earns 500 coins. Coins can be used in the shop to buy new balls with unique appearances and superpowers, such as: Fireball mode (instantly melts glass), Shockwave burst (breaks multiple glasses at once), Time slow (slows time to react faster), Steel upgrade (makes the ball stronger for 10 seconds). As levels progress, the glass becomes thicker, moves, or includes trap glass (explodes or reduces vision). The game gets harder with each level, adding new challenges and faster pace. The camera is always from the ball’s perspective, creating a fast, immersive, smashing experience. Add background music, particle effects on smash, and intense sound design. Make the game visually satisfying. Include a main menu, a level selection screen, and a shop interface. Make it playable with keyboard or touch controls.
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1", {
coins: 0,
highScore: 0,
ballLevel: 1,
speedLevel: 1
});
/****
* Classes
****/
var Ball = Container.expand(function () {
var self = Container.call(this);
var ballGraphics = self.attachAsset('ball', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1,
scaleY: 1
});
self.velocityY = 0;
self.gravity = 0.5;
self.jumpForce = -15;
self.grounded = false;
self.canJump = true;
self.health = 3;
self.speed = 5 + (storage.speedLevel - 1) * 2;
self.radius = 50;
self.power = storage.ballLevel;
// Set color based on ball level/power
if (self.power === 2) {
ballGraphics.tint = 0xFF6600; // Orange for fireball
} else if (self.power === 3) {
ballGraphics.tint = 0x0066FF; // Blue for shockwave
} else if (self.power === 4) {
ballGraphics.tint = 0x666666; // Dark gray for steel
}
self.jump = function () {
if (self.grounded && self.canJump) {
self.velocityY = self.jumpForce;
self.grounded = false;
LK.getSound('jump').play();
// Jump cooldown
self.canJump = false;
LK.setTimeout(function () {
self.canJump = true;
}, 300);
}
};
self.takeDamage = function () {
self.health--;
LK.getSound('damage').play();
LK.effects.flashObject(self, 0xFF0000, 500);
if (self.health <= 0) {
LK.showGameOver();
}
};
self.update = function () {
// Apply gravity
self.velocityY += self.gravity;
self.y += self.velocityY;
// Visual rotation to simulate rolling
ballGraphics.rotation += 0.05 * self.speed;
// Ground collision
if (self.y + self.radius > groundY) {
self.y = groundY - self.radius;
self.velocityY = 0;
self.grounded = true;
}
};
return self;
});
var Coin = Container.expand(function () {
var self = Container.call(this);
var coinGraphics = self.attachAsset('coin', {
anchorX: 0.5,
anchorY: 0.5
});
self.collected = false;
self.collect = function () {
if (!self.collected) {
self.collected = true;
LK.getSound('coinCollect').play();
// Animation
tween(self, {
scaleX: 1.5,
scaleY: 1.5,
alpha: 0
}, {
duration: 300,
onFinish: function onFinish() {
self.destroy();
}
});
// Update coins
storage.coins += 1;
updateCoinsDisplay();
}
};
self.update = function () {
// Coin rotation animation
coinGraphics.rotation += 0.05;
// Move coin toward player
self.x -= ball.speed;
// Floating animation
self.y += Math.sin(LK.ticks / 10) * 0.5;
// Remove if passed player
if (self.x < -100) {
if (collectibles.indexOf(self) !== -1) {
collectibles.splice(collectibles.indexOf(self), 1);
}
self.destroy();
}
};
return self;
});
var Glass = Container.expand(function () {
var self = Container.call(this);
var glassGraphics = self.attachAsset('glass', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.7
});
self.width = glassGraphics.width;
self.height = glassGraphics.height;
self.broken = false;
self.health = 1;
self.type = 'normal'; // normal, moving, trap
self.movingDirection = 1;
self.movingSpeed = 0;
self.setup = function (type, difficulty) {
self.type = type || 'normal';
self.health = difficulty || 1;
if (self.type === 'moving') {
self.movingSpeed = Math.random() * 3 + 2;
glassGraphics.tint = 0x33CCFF;
} else if (self.type === 'trap') {
glassGraphics.tint = 0xFF3333;
}
};
self["break"] = function () {
if (!self.broken) {
self.broken = true;
LK.getSound('glassBreak').play();
// Create glass breaking particles
self.createParticles();
// Remove from active obstacles after animation
LK.setTimeout(function () {
if (obstacles.includes(self)) {
var index = obstacles.indexOf(self);
if (index !== -1) {
obstacles.splice(index, 1);
}
}
self.destroy();
}, 100);
}
};
self.createParticles = function () {
for (var i = 0; i < 8; i++) {
var particle = LK.getAsset('particleGlass', {
anchorX: 0.5,
anchorY: 0.5,
x: self.x + (Math.random() * 100 - 50),
y: self.y + (Math.random() * 100 - 50),
alpha: 0.8
});
game.addChild(particle);
// Animate particle flying out
var targetX = particle.x + (Math.random() * 200 - 100);
var targetY = particle.y + (Math.random() * 200 - 100);
tween(particle, {
x: targetX,
y: targetY,
alpha: 0,
rotation: Math.random() * Math.PI * 2
}, {
duration: 500,
onFinish: function onFinish() {
particle.destroy();
}
});
}
};
self.takeDamage = function (power) {
self.health -= power;
LK.effects.flashObject(self, 0xFFFFFF, 100);
if (self.health <= 0) {
self["break"]();
// If trap glass, damage player
if (self.type === 'trap') {
ball.takeDamage();
}
// Add score based on glass type
var scoreValue = 10;
if (self.type === 'moving') scoreValue = 20;
if (self.type === 'trap') scoreValue = 30;
LK.setScore(LK.getScore() + scoreValue);
updateScoreDisplay();
} else {
// Just show crack effect
glassGraphics.alpha -= 0.2;
}
};
self.update = function () {
if (self.type === 'moving' && !self.broken) {
self.y += self.movingDirection * self.movingSpeed;
// Reverse direction when reaching boundaries
if (self.y < 500 || self.y > groundY - 400) {
self.movingDirection *= -1;
}
}
// Move obstacle toward player (creating the effect of moving forward)
self.x -= ball.speed;
// Remove if passed player
if (self.x < -300) {
if (obstacles.includes(self)) {
var index = obstacles.indexOf(self);
if (index !== -1) {
obstacles.splice(index, 1);
}
}
self.destroy();
}
};
return self;
});
var Powerup = Container.expand(function () {
var self = Container.call(this);
var type = "speed"; // Default
var graphics;
self.setup = function (powerupType) {
type = powerupType || "speed";
if (type === "speed") {
graphics = self.attachAsset('speedBoost', {
anchorX: 0.5,
anchorY: 0.5
});
} else if (type === "health") {
graphics = self.attachAsset('health', {
anchorX: 0.5,
anchorY: 0.5
});
}
};
self.collect = function () {
LK.getSound('coinCollect').play();
if (type === "speed") {
// Temporary speed boost
var originalSpeed = ball.speed;
ball.speed += 5;
LK.setTimeout(function () {
ball.speed = originalSpeed;
}, 5000);
} else if (type === "health") {
// Health up to maximum 5
if (ball.health < 5) {
ball.health++;
updateHealthDisplay();
}
}
// Animation
tween(self, {
scaleX: 1.5,
scaleY: 1.5,
alpha: 0
}, {
duration: 300,
onFinish: function onFinish() {
self.destroy();
}
});
if (collectibles.indexOf(self) !== -1) {
collectibles.splice(collectibles.indexOf(self), 1);
}
};
self.update = function () {
// Rotate the powerup
if (graphics) {
graphics.rotation += 0.05;
}
// Move powerup toward player
self.x -= ball.speed;
// Floating animation
self.y += Math.sin(LK.ticks / 8) * 0.7;
// Remove if passed player
if (self.x < -100) {
if (collectibles.indexOf(self) !== -1) {
collectibles.splice(collectibles.indexOf(self), 1);
}
self.destroy();
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB // Sky blue background
});
/****
* Game Code
****/
// Game variables
var obstacles = [];
var collectibles = [];
var groundY = 2732 - 250; // Ground position
var distance = 0;
var nextObstacleDistance = 500;
var level = 1;
var levelDistance = 1000; // Distance required to advance a level
var isPaused = false;
var upgradeMenuOpen = false;
// Initialize ground
var ground = LK.getAsset('ground', {
anchorX: 0.5,
anchorY: 0,
scaleX: 1,
scaleY: 1
});
ground.x = 2048 / 2;
ground.y = groundY;
game.addChild(ground);
// Create player ball
var ball = new Ball();
ball.x = 400;
ball.y = groundY - ball.radius;
game.addChild(ball);
// Create UI elements
var scoreTxt = new Text2("Score: 0", {
size: 50,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0, 0);
LK.gui.topRight.addChild(scoreTxt);
var coinsTxt = new Text2("Coins: " + storage.coins, {
size: 50,
fill: 0xFFD700
});
coinsTxt.anchor.set(0, 0);
coinsTxt.y = 60;
LK.gui.topRight.addChild(coinsTxt);
var levelTxt = new Text2("Level: 1", {
size: 50,
fill: 0xFFFFFF
});
levelTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(levelTxt);
var healthDisplay = new Container();
LK.gui.topLeft.addChild(healthDisplay);
healthDisplay.x = 120; // Add some margin from the left edge
healthDisplay.y = 50;
// Show stats and upgrades
var ballLevelTxt = new Text2("Ball Power: " + storage.ballLevel, {
size: 40,
fill: 0xFFFFFF
});
ballLevelTxt.anchor.set(0, 0);
ballLevelTxt.y = 150;
LK.gui.topRight.addChild(ballLevelTxt);
var speedLevelTxt = new Text2("Speed: " + storage.speedLevel, {
size: 40,
fill: 0xFFFFFF
});
speedLevelTxt.anchor.set(0, 0);
speedLevelTxt.y = 200;
LK.gui.topRight.addChild(speedLevelTxt);
function updateHealthDisplay() {
// Clear existing health icons
while (healthDisplay.children.length > 0) {
healthDisplay.removeChild(healthDisplay.children[0]);
}
// Add health icons
for (var i = 0; i < ball.health; i++) {
var healthIcon = LK.getAsset('health', {
anchorX: 0.5,
anchorY: 0.5,
x: i * 40,
y: 0,
scaleX: 1,
scaleY: 1
});
healthDisplay.addChild(healthIcon);
}
}
function updateScoreDisplay() {
scoreTxt.setText("Score: " + LK.getScore());
}
function updateCoinsDisplay() {
coinsTxt.setText("Coins: " + storage.coins);
}
function updateLevelDisplay() {
levelTxt.setText("Level: " + level);
}
function createGlassObstacle() {
var glass = new Glass();
// Determine glass type based on level
var typeRand = Math.random();
var type = 'normal';
if (level >= 3 && typeRand > 0.7) {
type = 'moving';
} else if (level >= 5 && typeRand > 0.8) {
type = 'trap';
}
// Difficulty increases with level
var difficulty = Math.min(Math.floor(level / 2) + 1, 5);
glass.setup(type, difficulty);
// Position glass ahead of player
glass.x = 2500;
// Random vertical position for some obstacles
if (type === 'normal') {
glass.y = groundY - glass.height / 2;
} else {
glass.y = Math.random() * (groundY - 700) + 500;
}
game.addChild(glass);
obstacles.push(glass);
// Sometimes add coins near obstacles
if (Math.random() > 0.5) {
createCoin(glass.x + Math.random() * 300 - 150, glass.y - 200 - Math.random() * 200);
}
// Sometimes add powerups
if (Math.random() > 0.9) {
if (Math.random() > 0.7) {
createPowerup("health", glass.x + Math.random() * 300 - 150, glass.y - 300);
} else {
createPowerup("speed", glass.x + Math.random() * 300 - 150, glass.y - 300);
}
}
// Sometimes add ground obstacles
if (level >= 2 && Math.random() > 0.7) {
var groundObstacle = LK.getAsset('obstacleGround', {
anchorX: 0.5,
anchorY: 0.5,
x: glass.x - 300 - Math.random() * 300,
y: groundY - 50
});
game.addChild(groundObstacle);
// Add to obstacles array
var obstacleObj = {
object: groundObstacle,
x: groundObstacle.x,
update: function update() {
this.x -= ball.speed;
this.object.x = this.x;
if (this.object.x < -200) {
game.removeChild(this.object);
var index = obstacles.indexOf(this);
if (index !== -1) {
obstacles.splice(index, 1);
}
}
}
};
obstacles.push(obstacleObj);
}
}
function createCoin(x, y) {
var coin = new Coin();
coin.x = x;
coin.y = y;
game.addChild(coin);
collectibles.push(coin);
}
function createPowerup(type, x, y) {
var powerup = new Powerup();
powerup.setup(type);
powerup.x = x;
powerup.y = y;
game.addChild(powerup);
collectibles.push(powerup);
}
function checkCollisions() {
// Check collision with obstacles
for (var i = 0; i < obstacles.length; i++) {
var obstacle = obstacles[i];
// Handle different obstacle types
if (obstacle instanceof Glass) {
// Distance-based check for glass
var dx = ball.x - obstacle.x;
var dy = ball.y - obstacle.y;
var distance = Math.sqrt(dx * dx + dy * dy);
// Consider the obstacle width
if (distance < ball.radius + obstacle.width / 2 && !obstacle.broken) {
// Handle collision
if (ball.power >= obstacle.health) {
obstacle.takeDamage(ball.power);
} else {
// Ball not powerful enough
ball.takeDamage();
obstacle.takeDamage(ball.power);
}
}
} else if (obstacle.object && obstacle.object.name === 'obstacleGround') {
// Simple box collision for ground obstacles
var obstacleObj = obstacle.object;
var ballRight = ball.x + ball.radius;
var ballLeft = ball.x - ball.radius;
var ballBottom = ball.y + ball.radius;
var obstacleLeft = obstacleObj.x - obstacleObj.width / 2;
var obstacleRight = obstacleObj.x + obstacleObj.width / 2;
var obstacleTop = obstacleObj.y - obstacleObj.height / 2;
if (ballRight > obstacleLeft && ballLeft < obstacleRight && ballBottom > obstacleTop) {
// Collision with ground obstacle (jump over it!)
ball.takeDamage();
LK.effects.flashObject(obstacleObj, 0xFF0000, 300);
}
}
}
// Check collision with collectibles
for (var j = collectibles.length - 1; j >= 0; j--) {
var collectible = collectibles[j];
var cdx = ball.x - collectible.x;
var cdy = ball.y - collectible.y;
var cDistance = Math.sqrt(cdx * cdx + cdy * cdy);
if (cDistance < ball.radius + 25) {
// Collect item
if (collectible instanceof Coin) {
collectible.collect();
collectibles.splice(j, 1);
} else if (collectible instanceof Powerup) {
collectible.collect();
// Removing from collectibles is handled in the collect method
}
}
}
}
function updateLevel() {
if (distance >= level * levelDistance) {
level++;
updateLevelDisplay();
LK.effects.flashScreen(0xFFFFFF, 500);
// Award coins for completing level
storage.coins += 500;
updateCoinsDisplay();
// Show level up message
var levelUpText = new Text2("Level " + level + "! +500 coins", {
size: 120,
fill: 0xFFFFFF
});
levelUpText.anchor.set(0.5, 0.5);
levelUpText.x = 2048 / 2;
levelUpText.y = 2732 / 2;
game.addChild(levelUpText);
// Animate and remove
tween(levelUpText, {
alpha: 0,
scaleX: 2,
scaleY: 2
}, {
duration: 1000,
onFinish: function onFinish() {
game.removeChild(levelUpText);
}
});
}
}
// Initialize game state
updateHealthDisplay();
updateScoreDisplay();
updateCoinsDisplay();
updateLevelDisplay();
// Play background music
LK.playMusic('gameMusic');
// Handle game controls
game.down = function (x, y, obj) {
// Jump when tapping screen
ball.jump();
};
game.move = function (x, y, obj) {
// Not used for main game controls
};
game.up = function (x, y, obj) {
// Not used for main game controls
};
// Main game update loop
game.update = function () {
if (isPaused || upgradeMenuOpen) return;
// Update player
ball.update();
// Update obstacles
for (var i = obstacles.length - 1; i >= 0; i--) {
var obstacle = obstacles[i];
obstacle.update();
}
// Update collectibles
for (var j = collectibles.length - 1; j >= 0; j--) {
var collectible = collectibles[j];
collectible.update();
}
// Check for collisions
checkCollisions();
// Update distance traveled
distance += ball.speed;
// Check for level advancement
updateLevel();
// Generate obstacles
if (distance > nextObstacleDistance) {
createGlassObstacle();
nextObstacleDistance = distance + 500 + Math.random() * 500;
}
// Update high score
if (LK.getScore() > storage.highScore) {
storage.highScore = LK.getScore();
}
}; ===================================================================
--- original.js
+++ change.js
@@ -534,10 +534,13 @@
if (distance >= level * levelDistance) {
level++;
updateLevelDisplay();
LK.effects.flashScreen(0xFFFFFF, 500);
+ // Award coins for completing level
+ storage.coins += 500;
+ updateCoinsDisplay();
// Show level up message
- var levelUpText = new Text2("Level " + level + "!", {
+ var levelUpText = new Text2("Level " + level + "! +500 coins", {
size: 120,
fill: 0xFFFFFF
});
levelUpText.anchor.set(0.5, 0.5);