User prompt
Oyuncu arabasının gönderdiği mermiler düz çizgi olarak gitsin
User prompt
BossCar ın Asseti diğer arabalardan farklı olsun yeni bir Asset ekle
User prompt
bütün hataları düzelt
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'start')' in or related to this line: 'pulseTween.start();' Line Number: 248
User prompt
Please fix the bug: 'TypeError: tween.to is not a function' in or related to this line: 'var pulseTween = tween.to(box, {' Line Number: 241
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'to')' in or related to this line: 'var pulseTween = tween(box).to({' Line Number: 241
User prompt
Please fix the bug: 'TypeError: tween.to is not a function' in or related to this line: 'var pulseTween = tween.to(box, {' Line Number: 241
User prompt
Please fix the bug: 'TypeError: tween.create is not a function' in or related to this line: 'var pulseTween = tween.create(box).to({' Line Number: 241
User prompt
Please fix the bug: 'TypeError: tween.to is not a function' in or related to this line: 'var pulseTween = tween.to(box, {' Line Number: 241
User prompt
BossCar öldükten sonra bir kutu bıraksın ve bu kutuda oyuncu arabasının ateş etme hızı biraz arttıracak bir yetenek olsun
User prompt
BossCar öldükten sonra diğer araçlar tekrar doğmaya başlasın ve 20 kill olduğunda oyun bitsin
User prompt
Mouse kontrolcünün üzerinden ekranda farklı bir yerde olduğunda oyuncu arabasının hızı azalıyor bunu düzelt oyuncu arabasının hızı hep aynı olsun
User prompt
BossCar öldükten sonra bir kutu bıraksın ve bu kutuda oyuncu arabasının ateş etme hızını arttıracak bir yetenek olsun
User prompt
Mouse kontrolcünün alanından uzaklaştıkça oyuncu arabasının hızı azalıyor bunu düzelt oyuncu arabası mouse kontrolcüden uzaklaştığında da aynı hızda hareket etsin
User prompt
Please fix the bug: 'TypeError: tween.to is not a function' in or related to this line: 'tween.to(box, {' Line Number: 241 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Mouse kontrolcüden uzaklaştıkça oyuncu arabasının hızı azalıyor bunu düzelt oyuncu arabası mouse uzaklaştığında da aynı hızda hareket etsin
User prompt
Please fix the bug: 'TypeError: tween.to is not a function. (In 'tween.to(box, { scaleX: 1.2, scaleY: 1.2 }, 600)', 'tween.to' is undefined)' in or related to this line: 'tween.to(box, {' Line Number: 241
User prompt
BossCar öldükten sonra bir kutu bıraksın ve bu kutuda oyuncu arabasının hızını arttıracak bir yetenek olsun
User prompt
Mouse kontrolcüden uzaklaştıkça oyuncu arabası yavaşlıyor, yavaşlamasın aynı hızda devam etsin
User prompt
Oyuncu Arabası yavaşlıyor yavaşlamasın
User prompt
BossCar ın hitbox'ını küçült
User prompt
Kontrolcünün içindeki yuvarlak sürüklendiğinde oyuncu arabası sürüklenen yöne doğru gitsin mouse hareket etmese bile yönlendirme devam etsin
User prompt
Kontrolcünün içindeki yuvarlak sürüklendiğinde oyuncu arabası sürüklenen yöne doğru gitsin
User prompt
kontrolcü ekranın altında olsun kontrolcünün üstünde bir kenar olsun ve oyuncu arabası ve diğer arabalar bu kenarın üstünde oynasın
User prompt
Kontrolcüyü biraz daha yukarı al
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ // BossCar Class var BossCar = Container.expand(function () { var self = Container.call(this); // Use enemyCar asset but larger and different color var boss = self.attachAsset('enemyCar', { anchorX: 0.5, anchorY: 0.5, width: 320, height: 600, color: 0x8e44ad // purple for boss }); // Target position (player car) self.targetX = 2048 / 2; self.targetY = 2732 / 2; // Speed (increased for faster boss movement) self.speed = 7.8; // Reduced by 1 // Direction vector self.dirX = 0; self.dirY = 1; // For collision self.radius = 110; // Reduced hitbox radius for smaller collision area // Boss health self.maxHealth = 20; self.health = self.maxHealth; // Update method self.update = function () { // Move toward target (player car) var dx = self.targetX - self.x; var dy = self.targetY - self.y; var len = Math.sqrt(dx * dx + dy * dy); if (len > 0.01) { self.dirX = dx / len; self.dirY = dy / len; self.x += self.dirX * self.speed; self.y += self.dirY * self.speed; boss.rotation = Math.atan2(self.dirY, self.dirX) + Math.PI / 2; } }; // Set target (player car position) self.setTarget = function (x, y) { self.targetX = x; self.targetY = y; }; // Take damage self.takeDamage = function (amount) { self.health -= amount; if (self.health < 0) self.health = 0; }; return self; }); // Bullet Class var Bullet = Container.expand(function () { var self = Container.call(this); var bullet = self.attachAsset('bullet', { anchorX: 0.5, anchorY: 0.5 }); // Direction vector self.dirX = 0; self.dirY = -1; // Speed self.speed = 38; // For collision self.radius = 30; // Update self.update = function () { self.x += self.dirX * self.speed; self.y += self.dirY * self.speed; }; // Set direction self.setDirection = function (dx, dy) { var len = Math.sqrt(dx * dx + dy * dy); if (len > 0.01) { self.dirX = dx / len; self.dirY = dy / len; } }; return self; }); // Enemy Car Class var EnemyCar = Container.expand(function () { var self = Container.call(this); var car = self.attachAsset('enemyCar', { anchorX: 0.5, anchorY: 0.5 }); // Target position (player car) self.targetX = 2048 / 2; self.targetY = 2732 / 2; // Speed (pixels per tick) self.speed = 7; // Direction vector self.dirX = 0; self.dirY = 1; // For collision self.radius = 90; // Update method self.update = function () { // Move toward target (player car) var dx = self.targetX - self.x; var dy = self.targetY - self.y; var len = Math.sqrt(dx * dx + dy * dy); if (len > 0.01) { self.dirX = dx / len; self.dirY = dy / len; // Enemy car speed is always self.speed, never boosted self.x += self.dirX * self.speed; self.y += self.dirY * self.speed; // Rotate car to face movement car.rotation = Math.atan2(self.dirY, self.dirX) + Math.PI / 2; } }; // Set target (player car position) self.setTarget = function (x, y) { self.targetX = x; self.targetY = y; }; return self; }); // Player Car Class var PlayerCar = Container.expand(function () { var self = Container.call(this); // Attach car asset, anchor center var car = self.attachAsset('playerCar', { anchorX: 0.5, anchorY: 0.5 }); // For visual orientation, add a "gun" at the top (optional) // Not required for MVP // Movement speed (pixels per tick) self.baseSpeed = 12; self.boostSpeed = 24; self.currentSpeed = self.baseSpeed; // Direction vector (normalized) self.dirX = 0; self.dirY = -1; // Set initial position to center self.x = 2048 / 2; self.y = 2732 / 2; // For auto-shoot cooldown self.shootCooldown = 0; // Update method: called every tick self.update = function () { // Move in direction of pointer // Only move if playerIsMoving is true (set by handleMove) if (typeof playerIsMoving !== "undefined" && playerIsMoving) { // Calculate next position var nextX = self.x + self.dirX * self.currentSpeed; var nextY = self.y + self.dirY * self.currentSpeed; // Clamp next position to game area bounds var minX = 90; var maxX = 2048 - 90; var minY = 160; var maxY = 2732 - 160; // Only update X if within bounds if (nextX >= minX && nextX <= maxX) { self.x = nextX; } else if (nextX < minX) { self.x = minX; } else if (nextX > maxX) { self.x = maxX; } // Only update Y if within bounds if (nextY >= minY && nextY <= maxY) { self.y = nextY; } else if (nextY < minY) { self.y = minY; } else if (nextY > maxY) { self.y = maxY; } } // Clamp to game area (keep inside bounds) if (self.x < 90) self.x = 90; if (self.x > 2048 - 90) self.x = 2048 - 90; if (self.y < 160) self.y = 160; if (self.y > 2732 - 160) self.y = 2732 - 160; // Cooldown for shooting if (self.shootCooldown > 0) self.shootCooldown--; }; // Set direction toward pointer self.setDirection = function (targetX, targetY) { var dx = targetX - self.x; var dy = targetY - self.y; var len = Math.sqrt(dx * dx + dy * dy); if (len > 0.01) { self.dirX = dx / len; self.dirY = dy / len; // Rotate car to face direction car.rotation = Math.atan2(self.dirY, self.dirX) + Math.PI / 2; } }; // Boost on press self.setBoost = function (boosting) { self.currentSpeed = boosting ? self.boostSpeed : self.baseSpeed; }; return self; }); // PowerUpBox Class var PowerUpBox = Container.expand(function () { var self = Container.call(this); // Use a distinct color for the powerup box var box = self.attachAsset('centerCircle', { anchorX: 0.5, anchorY: 0.5, width: 120, height: 120, color: 0x00ffcc, alpha: 0.85 }); // For collision self.radius = 60; // Powerup type (could be extended for more types) self.type = "shootSpeed"; // Animate (optional: pulse effect) self.update = function () { if (typeof LK !== "undefined" && typeof LK.ticks !== "undefined") { var scale = 1 + 0.1 * Math.sin(LK.ticks / 10); box.scaleX = scale; box.scaleY = scale; } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x222222 }); /**** * Game Code ****/ // Bullet: yellow ellipse // Enemy car: red box // Player car: blue box // --- Global variables --- var player = new PlayerCar(); game.addChild(player); var enemies = []; var bullets = []; // Boss state var bossSpawned = false; var bossCar = null; // Powerup state var activePowerupBox = null; var shootSpeedBoostActive = false; var shootSpeedBoostTicks = 0; var SHOOT_SPEED_BOOST_DURATION = 60 * 8; // 8 seconds // Score var score = 0; var level = 1; var scoreTxt = new Text2('Score: 0', { size: 97.2, fill: 0xFFFFFF }); scoreTxt.anchor.set(1, 0); // right align score // Level text (centered between score and timer) var levelTxt = new Text2('Level 1', { size: 100, fill: 0xFFD700 // gold color for level }); levelTxt.anchor.set(0.5, 0); // center align // Timer text (elapsed time in seconds, right of score) var timerTxt = new Text2('0:00', { size: 99, fill: 0xFFFFFF }); timerTxt.anchor.set(0, 0); // left align timer // Position score, level, and timer // Arrange score, level, and timer in a single horizontal row, evenly spaced var guiRowY = 10; var guiSpacing = 80; // horizontal space between counters // Calculate total width of all counters and spacing var totalWidth = scoreTxt.width + levelTxt.width + timerTxt.width + 2 * guiSpacing; var startX = LK.gui.top.width / 2 - totalWidth / 2; // Score counter (left) scoreTxt.x = startX + scoreTxt.width; scoreTxt.y = guiRowY; // Level counter (center) levelTxt.x = scoreTxt.x + guiSpacing + levelTxt.width / 2; levelTxt.y = guiRowY; // Timer counter (right) timerTxt.x = levelTxt.x + levelTxt.width / 2 + guiSpacing; timerTxt.y = guiRowY; LK.gui.top.addChild(scoreTxt); LK.gui.top.addChild(levelTxt); LK.gui.top.addChild(timerTxt); // For pointer tracking (controller-based) var pointerX = 2048 / 2; var pointerY = 2732 / 2; var playerIsMoving = false; // Start as not moving // For boost var boosting = false; // --- Controller UI --- // Controller is a circular area at the bottom center of the screen var controllerRadius = 170; var controllerCenterX = 2048 / 2; var controllerCenterY = 2732 - controllerRadius - 60; // Controller visual (semi-transparent circle) var controllerBg = LK.getAsset('centerCircle', { anchorX: 0.5, anchorY: 0.5, width: controllerRadius * 2, height: controllerRadius * 2, color: 0x888888, alpha: 0.25, x: controllerCenterX, y: controllerCenterY }); game.addChild(controllerBg); // Controller knob (shows current direction) var knobRadius = 80; var controllerKnob = LK.getAsset('centerCircle', { anchorX: 0.5, anchorY: 0.5, width: knobRadius * 2, height: knobRadius * 2, color: 0x2980ff, alpha: 0.7, x: controllerCenterX, y: controllerCenterY }); game.addChild(controllerKnob); // Track controller state var controllerActive = false; var controllerTouchId = null; // Persistent controller direction for continuous movement var lastControllerActive = false; var lastControllerDirX = 0; var lastControllerDirY = 0; // Helper: get distance between two points function dist2(x1, y1, x2, y2) { var dx = x1 - x2; var dy = y1 - y2; return Math.sqrt(dx * dx + dy * dy); } // For enemy spawn timer var enemySpawnTicks = 0; // Dynamic spawn interval variables var ENEMY_SPAWN_INTERVAL_START = 180; // 3 seconds at 60fps var ENEMY_SPAWN_INTERVAL_END = 60; // 1 second at 60fps var ENEMY_SPAWN_INTERVAL = ENEMY_SPAWN_INTERVAL_START; // Timer for game progression (in ticks) var gameTimerTicks = 0; var GAME_TIMER_MAX = 60 * 60; // 60 seconds to reach max difficulty // --- Event Handlers --- // Move: handle controller input only if inside controller area function handleMove(x, y, obj) { // Only respond to touches inside controller area or if already dragging controller var isTouch = obj && obj.event && typeof obj.event.identifier !== "undefined"; var touchId = isTouch ? obj.event.identifier : null; // If not already active, only activate if touch is inside controller if (!controllerActive) { var d = dist2(x, y, controllerCenterX, controllerCenterY); if (d <= controllerRadius) { controllerActive = true; controllerTouchId = touchId; } else { // Ignore touches outside controller return; } } else { // If already active, only respond to the same touch if (isTouch && controllerTouchId !== null && touchId !== controllerTouchId) { return; } } // Calculate direction from controller center to touch var dx = x - controllerCenterX; var dy = y - controllerCenterY; var len = Math.sqrt(dx * dx + dy * dy); // Clamp knob to controller radius var knobX = controllerCenterX; var knobY = controllerCenterY; if (len > controllerRadius) { dx = dx * controllerRadius / len; dy = dy * controllerRadius / len; knobX += dx; knobY += dy; } else { knobX = x; knobY = y; } controllerKnob.x = knobX; controllerKnob.y = knobY; // If movement is significant, set direction and move if (len > 30) { // Move player in the direction of the knob relative to controller center player.setDirection(player.x + dx, player.y + dy); playerIsMoving = true; // Store last direction for persistent movement lastControllerDirX = dx / len; lastControllerDirY = dy / len; lastControllerActive = true; } else { playerIsMoving = false; lastControllerActive = false; } if (typeof LK !== "undefined" && typeof LK.ticks !== "undefined") { lastMoveTick = LK.ticks; } } game.move = handleMove; // Down: only activate boost if controller is pressed game.down = function (x, y, obj) { var d = dist2(x, y, controllerCenterX, controllerCenterY); // Do not activate boost on controller press anymore if (d <= controllerRadius) { handleMove(x, y, obj); } }; // Up: stop boost and controller movement game.up = function (x, y, obj) { boosting = false; player.setBoost(false); playerIsMoving = false; controllerActive = false; controllerTouchId = null; // Reset persistent controller direction lastControllerActive = false; lastControllerDirX = 0; lastControllerDirY = 0; // Reset knob to center controllerKnob.x = controllerCenterX; controllerKnob.y = controllerCenterY; }; // --- Main Game Loop --- game.update = function () { // Update player // If controller was last dragged in a direction, keep moving in that direction if (typeof lastControllerActive !== "undefined" && lastControllerActive && typeof lastControllerDirX !== "undefined" && typeof lastControllerDirY !== "undefined") { // Set direction to last drag direction player.dirX = lastControllerDirX; player.dirY = lastControllerDirY; playerIsMoving = true; } player.update(); // If no move event occurred this frame, stop player movement if (typeof LK !== "undefined" && typeof LK.ticks !== "undefined") { if (typeof lastMoveTick === "undefined") { lastMoveTick = LK.ticks; } if (lastMoveTick !== LK.ticks) { // Only stop if controller is not active if (!lastControllerActive) { playerIsMoving = false; } } } // --- Timer and Dynamic Enemy Spawning --- gameTimerTicks++; // Update timer text (show mm:ss) var elapsedSec = Math.floor(gameTimerTicks / 60); var min = Math.floor(elapsedSec / 60); var sec = elapsedSec % 60; timerTxt.setText(min + ':' + (sec < 10 ? '0' : '') + sec); // Every second, increase spawn rate by reducing ENEMY_SPAWN_INTERVAL_START, but clamp to ENEMY_SPAWN_INTERVAL_END if (gameTimerTicks % 60 === 0) { ENEMY_SPAWN_INTERVAL_START = Math.max(ENEMY_SPAWN_INTERVAL_END, ENEMY_SPAWN_INTERVAL_START - 5); } // Calculate progression (0 to 1) var progress = Math.min(gameTimerTicks / GAME_TIMER_MAX, 1); // Linearly interpolate spawn interval from start to end ENEMY_SPAWN_INTERVAL = Math.round(ENEMY_SPAWN_INTERVAL_START + (ENEMY_SPAWN_INTERVAL_END - ENEMY_SPAWN_INTERVAL_START) * progress); enemySpawnTicks++; // Determine how many enemies to spawn this cycle (1 + extra for every 10 kills) var spawnCount = 1 + Math.floor(score / 10); // Boss spawn logic if (!bossSpawned && score >= 10) { bossSpawned = true; bossCar = new BossCar(); // Spawn boss at random edge var edge = Math.floor(Math.random() * 4); var bx, by; if (edge === 0) { bx = 200 + Math.random() * (2048 - 400); by = -300; } else if (edge === 1) { bx = 2048 + 300; by = 200 + Math.random() * (2732 - 400); } else if (edge === 2) { bx = 200 + Math.random() * (2048 - 400); by = 2732 + 300; } else { bx = -300; by = 200 + Math.random() * (2732 - 400); } bossCar.x = bx; bossCar.y = by; bossCar.setTarget(player.x, player.y); game.addChild(bossCar); } // Only spawn normal enemies if boss is not spawned if (!bossSpawned && enemySpawnTicks >= ENEMY_SPAWN_INTERVAL) { enemySpawnTicks = 0; for (var spawnIdx = 0; spawnIdx < spawnCount; spawnIdx++) { // Spawn enemy at random edge var edge = Math.floor(Math.random() * 4); // 0:top, 1:right, 2:bottom, 3:left var ex, ey; if (edge === 0) { // top ex = 200 + Math.random() * (2048 - 400); ey = -160; } else if (edge === 1) { // right ex = 2048 + 160; ey = 200 + Math.random() * (2732 - 400); } else if (edge === 2) { // bottom ex = 200 + Math.random() * (2048 - 400); ey = 2732 + 160; } else { // left ex = -160; ey = 200 + Math.random() * (2732 - 400); } var enemy = new EnemyCar(); enemy.x = ex; enemy.y = ey; enemy.setTarget(player.x, player.y); enemies.push(enemy); game.addChild(enemy); } } // --- Update Enemies --- for (var i = enemies.length - 1; i >= 0; i--) { var enemy = enemies[i]; enemy.setTarget(player.x, player.y); enemy.update(); // Check collision with player (circle collision) var dx = enemy.x - player.x; var dy = enemy.y - player.y; var dist = Math.sqrt(dx * dx + dy * dy); if (dist < 160) { // Game over LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); return; } } // --- Update BossCar --- if (bossSpawned && bossCar) { bossCar.setTarget(player.x, player.y); bossCar.update(); // Check collision with player (circle collision, bigger radius) var bdx = bossCar.x - player.x; var bdy = bossCar.y - player.y; var bdist = Math.sqrt(bdx * bdx + bdy * bdy); if (bdist < 220) { // Game over LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); return; } // BossCar damages enemies it collides with (just like player does) for (var i = enemies.length - 1; i >= 0; i--) { var enemy = enemies[i]; var edx = bossCar.x - enemy.x; var edy = bossCar.y - enemy.y; var edist = Math.sqrt(edx * edx + edy * edy); if (edist < 160) { // Remove enemy enemy.destroy(); enemies.splice(i, 1); // Optionally, you could increment score or add effect, but for now just remove } } // If boss defeated, spawn powerup box (shoot speed boost) if (bossCar.health <= 0) { // Spawn powerup at boss position var powerupBox = new PowerUpBox(); powerupBox.x = bossCar.x; powerupBox.y = bossCar.y; game.addChild(powerupBox); activePowerupBox = powerupBox; // Track in global for collision bossCar.destroy(); bossCar = null; level = 2; if (typeof levelTxt !== "undefined") { levelTxt.setText("Level " + level); } // Do NOT show win yet; wait for player to collect powerup LK.effects.flashScreen(0x00ff00, 1000); // Do not return here; let game continue so player can collect powerup // return; } } // --- Powerup Box Update & Pickup --- if (activePowerupBox) { activePowerupBox.update && activePowerupBox.update(); // Check collision with player var pdx = activePowerupBox.x - player.x; var pdy = activePowerupBox.y - player.y; var pdist = Math.sqrt(pdx * pdx + pdy * pdy); if (pdist < 120) { // Pickup! activePowerupBox.destroy(); activePowerupBox = null; shootSpeedBoostActive = true; shootSpeedBoostTicks = SHOOT_SPEED_BOOST_DURATION; // Optional: flash effect LK.effects.flashObject(player, 0x00ffcc, 800); } } // --- Shoot Speed Boost Timer --- if (shootSpeedBoostActive) { shootSpeedBoostTicks--; if (shootSpeedBoostTicks <= 0) { shootSpeedBoostActive = false; } } // --- Auto-shoot at nearest enemy or bossCar --- // If there are enemies, shoot at nearest enemy. If not, and bossCar is present, shoot at bossCar. if (player.shootCooldown === 0) { var target = null; if (enemies.length > 0) { // Find nearest enemy var minDist = 999999; for (var i = 0; i < enemies.length; i++) { var dx = enemies[i].x - player.x; var dy = enemies[i].y - player.y; var d = dx * dx + dy * dy; if (d < minDist) { minDist = d; target = enemies[i]; } } } else if (bossSpawned && bossCar) { // Only target bossCar if within enemy range (same as enemy targeting) var dx = bossCar.x - player.x; var dy = bossCar.y - player.y; var dist = Math.sqrt(dx * dx + dy * dy); if (dist < 900) { // 900 is 30*30, but enemy targeting uses squared distance, so use same target = bossCar; } } if (target) { // Shoot bullet toward target from top of car var bullet = new Bullet(); // Place bullet at top of car (offset in direction of car) var carDir = Math.atan2(player.dirY, player.dirX); var offsetX = Math.cos(carDir) * 180; var offsetY = Math.sin(carDir) * 180; bullet.x = player.x + offsetX; bullet.y = player.y + offsetY; // Direction: from bullet to target var bdx = target.x - bullet.x; var bdy = target.y - bullet.y; bullet.setDirection(bdx, bdy); bullets.push(bullet); game.addChild(bullet); // Set shoot cooldown based on boost player.shootCooldown = shootSpeedBoostActive ? 10 : 30; // 0.17s vs 0.5s } } // --- Update Bullets --- for (var i = bullets.length - 1; i >= 0; i--) { var bullet = bullets[i]; bullet.update(); // Remove if out of bounds if (bullet.x < -100 || bullet.x > 2048 + 100 || bullet.y < -100 || bullet.y > 2732 + 100) { bullet.destroy(); bullets.splice(i, 1); continue; } // Check collision with enemies var hit = false; for (var j = enemies.length - 1; j >= 0; j--) { var enemy = enemies[j]; var dx = bullet.x - enemy.x; var dy = bullet.y - enemy.y; var dist = Math.sqrt(dx * dx + dy * dy); if (dist < 100) { // Hit! hit = true; // Remove enemy enemy.destroy(); enemies.splice(j, 1); // Remove bullet bullet.destroy(); bullets.splice(i, 1); // Score score++; scoreTxt.setText('Score: ' + score); break; } } // Check collision with bossCar if spawned, but only if in range (same as enemy range) if (!hit && bossSpawned && bossCar && function () { var dx = bullet.x - bossCar.x; var dy = bullet.y - bossCar.y; var dist = Math.sqrt(dx * dx + dy * dy); return dist < 100; // Use same range as enemy hit }()) { // Hit boss! hit = true; bossCar.takeDamage(1); bullet.destroy(); bullets.splice(i, 1); // Optionally, flash boss or show health bar (not required for MVP) } if (hit) continue; } // --- Camera: keep player centered --- // (In LK, the game area is fixed, so we simulate by keeping player in center and moving everything else if needed) // For MVP, player always stays in center, so no need to move camera. }; // --- Initial pointer direction --- // No initial movement; player will move when controller is used player.setDirection(player.x, player.y - 1);
===================================================================
--- original.js
+++ change.js
@@ -202,75 +202,32 @@
self.currentSpeed = boosting ? self.boostSpeed : self.baseSpeed;
};
return self;
});
-// SpeedBoostBox Class
-var SpeedBoostBox = Container.expand(function () {
+// PowerUpBox Class
+var PowerUpBox = Container.expand(function () {
var self = Container.call(this);
- // Use a distinct color for the box (green)
+ // Use a distinct color for the powerup box
var box = self.attachAsset('centerCircle', {
anchorX: 0.5,
anchorY: 0.5,
width: 120,
height: 120,
- color: 0x2ecc40,
+ color: 0x00ffcc,
alpha: 0.85
});
+ // For collision
self.radius = 60;
- // Optional: animate box (pulse)
- if (typeof tween !== "undefined") {
- tween(box, {
- scaleX: 1.2,
- scaleY: 1.2
- }, {
- duration: 600,
- easing: tween.linear,
- onFinish: function onFinish() {
- // Yoyo effect: reverse the tween
- tween(box, {
- scaleX: 1.0,
- scaleY: 1.0
- }, {
- duration: 600,
- easing: tween.linear,
- onFinish: function onFinish() {
- // Repeat the pulse forever
- if (!self.collected) {
- // Only repeat if not collected/destroyed
- if (typeof self.updateTween === "function") self.updateTween();
- }
- }
- });
- }
- });
- // Helper to keep repeating the pulse
- self.updateTween = function () {
- tween(box, {
- scaleX: 1.2,
- scaleY: 1.2
- }, {
- duration: 600,
- easing: tween.linear,
- onFinish: function onFinish() {
- tween(box, {
- scaleX: 1.0,
- scaleY: 1.0
- }, {
- duration: 600,
- easing: tween.linear,
- onFinish: function onFinish() {
- if (!self.collected) {
- if (typeof self.updateTween === "function") self.updateTween();
- }
- }
- });
- }
- });
- };
- self.updateTween();
- }
- // For tracking
- self.collected = false;
+ // Powerup type (could be extended for more types)
+ self.type = "shootSpeed";
+ // Animate (optional: pulse effect)
+ self.update = function () {
+ if (typeof LK !== "undefined" && typeof LK.ticks !== "undefined") {
+ var scale = 1 + 0.1 * Math.sin(LK.ticks / 10);
+ box.scaleX = scale;
+ box.scaleY = scale;
+ }
+ };
return self;
});
/****
@@ -293,8 +250,13 @@
var bullets = [];
// Boss state
var bossSpawned = false;
var bossCar = null;
+// Powerup state
+var activePowerupBox = null;
+var shootSpeedBoostActive = false;
+var shootSpeedBoostTicks = 0;
+var SHOOT_SPEED_BOOST_DURATION = 60 * 8; // 8 seconds
// Score
var score = 0;
var level = 1;
var scoreTxt = new Text2('Score: 0', {
@@ -432,20 +394,15 @@
controllerKnob.x = knobX;
controllerKnob.y = knobY;
// If movement is significant, set direction and move
if (len > 30) {
- // Always use only the direction, not the distance, for speed
- var normDx = dx / len;
- var normDy = dy / len;
- // Move player in the direction of the knob relative to controller center, always at constant speed
- player.setDirection(player.x + normDx, player.y + normDy);
+ // Move player in the direction of the knob relative to controller center
+ player.setDirection(player.x + dx, player.y + dy);
playerIsMoving = true;
// Store last direction for persistent movement
- lastControllerDirX = normDx;
- lastControllerDirY = normDy;
+ lastControllerDirX = dx / len;
+ lastControllerDirY = dy / len;
lastControllerActive = true;
- // Ensure player speed is always constant, not affected by distance from knob
- player.currentSpeed = player.baseSpeed;
} else {
playerIsMoving = false;
lastControllerActive = false;
}
@@ -617,52 +574,52 @@
enemies.splice(i, 1);
// Optionally, you could increment score or add effect, but for now just remove
}
}
- // If boss defeated, show win
+ // If boss defeated, spawn powerup box (shoot speed boost)
if (bossCar.health <= 0) {
- // Spawn speed boost box at boss position
- var speedBoostBox = new SpeedBoostBox();
- speedBoostBox.x = bossCar.x;
- speedBoostBox.y = bossCar.y;
- game.addChild(speedBoostBox);
- // Store reference globally for collision check
- game._speedBoostBox = speedBoostBox;
+ // Spawn powerup at boss position
+ var powerupBox = new PowerUpBox();
+ powerupBox.x = bossCar.x;
+ powerupBox.y = bossCar.y;
+ game.addChild(powerupBox);
+ activePowerupBox = powerupBox; // Track in global for collision
bossCar.destroy();
bossCar = null;
level = 2;
if (typeof levelTxt !== "undefined") {
levelTxt.setText("Level " + level);
}
+ // Do NOT show win yet; wait for player to collect powerup
LK.effects.flashScreen(0x00ff00, 1000);
- // Do NOT show win yet; wait for player to collect the box
- // LK.showYouWin();
- // return; (do not return, continue game until box is collected)
+ // Do not return here; let game continue so player can collect powerup
+ // return;
}
}
- // --- Speed Boost Box Collection ---
- if (game._speedBoostBox && !game._speedBoostBox.collected) {
- var box = game._speedBoostBox;
- var pdx = player.x - box.x;
- var pdy = player.y - box.y;
+ // --- Powerup Box Update & Pickup ---
+ if (activePowerupBox) {
+ activePowerupBox.update && activePowerupBox.update();
+ // Check collision with player
+ var pdx = activePowerupBox.x - player.x;
+ var pdy = activePowerupBox.y - player.y;
var pdist = Math.sqrt(pdx * pdx + pdy * pdy);
- if (pdist < player.baseSpeed * 7 + box.radius) {
- // generous pickup radius
- // Collect box
- box.collected = true;
- box.destroy();
- // Apply speed boost to player
- player.setBoost(true);
- // Show win after short delay to let player feel the boost
- LK.effects.flashObject(player, 0x2ecc40, 800);
- LK.setTimeout(function () {
- player.setBoost(false);
- LK.showYouWin();
- }, 1200);
- // Remove reference
- game._speedBoostBox = null;
+ if (pdist < 120) {
+ // Pickup!
+ activePowerupBox.destroy();
+ activePowerupBox = null;
+ shootSpeedBoostActive = true;
+ shootSpeedBoostTicks = SHOOT_SPEED_BOOST_DURATION;
+ // Optional: flash effect
+ LK.effects.flashObject(player, 0x00ffcc, 800);
}
}
+ // --- Shoot Speed Boost Timer ---
+ if (shootSpeedBoostActive) {
+ shootSpeedBoostTicks--;
+ if (shootSpeedBoostTicks <= 0) {
+ shootSpeedBoostActive = false;
+ }
+ }
// --- Auto-shoot at nearest enemy or bossCar ---
// If there are enemies, shoot at nearest enemy. If not, and bossCar is present, shoot at bossCar.
if (player.shootCooldown === 0) {
var target = null;
@@ -702,9 +659,10 @@
var bdy = target.y - bullet.y;
bullet.setDirection(bdx, bdy);
bullets.push(bullet);
game.addChild(bullet);
- player.shootCooldown = 30; // 0.5s cooldown for both enemies and bossCar
+ // Set shoot cooldown based on boost
+ player.shootCooldown = shootSpeedBoostActive ? 10 : 30; // 0.17s vs 0.5s
}
}
// --- Update Bullets ---
for (var i = bullets.length - 1; i >= 0; i--) {
Kalitesini arttır
kalitesini arttır
kalitesini arttır yuvarlak olsun
remove the holes and get a flat land
mavi ve kırmızı renklerinde siyah çizgileri olan bir airdrop kutusu yap, kuş bakışı olsun üstten gözüksün. In-Game asset. 2d. High contrast. No shadows. bird eye
Bir tank savaşı temalı arkaplan görseli hazırla görselde 2 tank olsun ve bu 2 tankın önündeki 1 tankı yakalamaya çalışsın.. In-Game asset. 2d. High contrast. No shadows
daha kaliteli yap
War dropbox a bird view blue and red. In-Game asset. 2d. High contrast. No shadows. In-Game asset. 2d. High contrast. No shadows
real explosion. In-Game asset. 2d. High contrast. No shadows
Arka Planını temizle
clear background
Erase background