User prompt
add a backroud
User prompt
add a 3-stage difficulty option to the game that will appear at the top right
Code edit (1 edits merged)
Please save this source code
User prompt
Bullet Bounce Arena
User prompt
i dont want too face control
User prompt
add more detail
Initial prompt
make me a detailed gta game add guns vehicles and polices to the game,
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
// Bullet class (enemy projectile)
var Bullet = Container.expand(function () {
var self = Container.call(this);
// Attach bullet asset (yellow ellipse)
var bulletAsset = self.attachAsset('bulletEllipse', {
anchorX: 0.5,
anchorY: 0.5
});
// Set initial speed and direction (randomized in game code)
self.vx = 0;
self.vy = 0;
// Update bullet position
self.update = function () {
self.x += self.vx;
self.y += self.vy;
};
return self;
});
// Player character class
var Player = Container.expand(function () {
var self = Container.call(this);
// Attach player asset (red box)
var playerAsset = self.attachAsset('playerBox', {
anchorX: 0.5,
anchorY: 0.5
});
// Set initial size (will be used for collision)
self.width = playerAsset.width;
self.height = playerAsset.height;
// No update needed for player (movement is handled by drag)
return self;
});
// Point collectible class
var Point = Container.expand(function () {
var self = Container.call(this);
// Attach point asset (green circle)
var pointAsset = self.attachAsset('pointCircle', {
anchorX: 0.5,
anchorY: 0.5
});
// No update needed for point
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000
});
/****
* Game Code
****/
// Score display
// Tween plugin for animations (not used in MVP, but included for future use)
// Asset initialization (shapes)
var score = 0;
var scoreTxt = new Text2('0', {
size: 120,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// --- Difficulty selection UI ---
var difficultyLevels = [{
label: "Easy",
value: 0
}, {
label: "Normal",
value: 1
}, {
label: "Hard",
value: 2
}];
var currentDifficulty = 1; // Default: Normal
// Create difficulty buttons
var difficultyButtons = [];
var buttonSpacing = 30;
var buttonWidth = 220;
var buttonHeight = 90;
for (var i = 0; i < difficultyLevels.length; i++) {
var btn = new Text2(difficultyLevels[i].label, {
size: 60,
fill: 0xFFFFFF
});
btn.anchor.set(1, 0); // right-top
btn.x = (buttonWidth + buttonSpacing) * (difficultyLevels.length - i - 1);
btn.y = 0;
btn.difficultyValue = difficultyLevels[i].value;
// Highlight default
btn.alpha = i === currentDifficulty ? 1 : 0.5;
// Touch event
btn.down = function (btnRef) {
return function (x, y, obj) {
// Set difficulty
currentDifficulty = btnRef.difficultyValue;
// Update button highlights
for (var j = 0; j < difficultyButtons.length; j++) {
difficultyButtons[j].alpha = difficultyButtons[j].difficultyValue === currentDifficulty ? 1 : 0.5;
}
};
}(btn);
difficultyButtons.push(btn);
LK.gui.topRight.addChild(btn);
}
// Game objects
var player = new Player();
game.addChild(player);
// Center player
player.x = 2048 / 2;
player.y = 2732 - 350;
// Arrays for bullets and points
var bullets = [];
var points = [];
// Dragging logic
var dragNode = null;
// Helper: spawn a bullet from a random edge, aimed at the play area
function spawnBullet() {
var bullet = new Bullet();
// Randomly pick an edge: 0=top, 1=bottom, 2=left, 3=right
var edge = Math.floor(Math.random() * 4);
var pos = {
x: 0,
y: 0
};
var angle = 0;
if (edge === 0) {
// Top
pos.x = 200 + Math.random() * (2048 - 400);
pos.y = -60;
angle = Math.PI / 2 + (Math.random() - 0.5) * 0.5;
} else if (edge === 1) {
// Bottom
pos.x = 200 + Math.random() * (2048 - 400);
pos.y = 2732 + 60;
angle = -Math.PI / 2 + (Math.random() - 0.5) * 0.5;
} else if (edge === 2) {
// Left
pos.x = -60;
pos.y = 300 + Math.random() * (2732 - 600);
angle = 0 + (Math.random() - 0.5) * 0.5;
} else {
// Right
pos.x = 2048 + 60;
pos.y = 300 + Math.random() * (2732 - 600);
angle = Math.PI + (Math.random() - 0.5) * 0.5;
}
bullet.x = pos.x;
bullet.y = pos.y;
// Set speed (randomized a bit, depends on difficulty)
var speed = getBulletSpeed();
bullet.vx = Math.cos(angle) * speed;
bullet.vy = Math.sin(angle) * speed;
bullets.push(bullet);
game.addChild(bullet);
}
// Helper: spawn a point collectible at a random position
function spawnPoint() {
var point = new Point();
// Avoid spawning too close to the player
var safe = false;
var px = 0,
py = 0;
while (!safe) {
px = 150 + Math.random() * (2048 - 300);
py = 250 + Math.random() * (2732 - 500);
var dx = px - player.x;
var dy = py - player.y;
if (dx * dx + dy * dy > 400 * 400) safe = true;
}
point.x = px;
point.y = py;
points.push(point);
game.addChild(point);
}
// Helper: get bullet spawn interval and speed by difficulty
function getBulletInterval() {
if (currentDifficulty === 0) return 1300; // Easy
if (currentDifficulty === 1) return 900; // Normal
return 600; // Hard
}
function getPointInterval() {
if (currentDifficulty === 0) return 1400;
if (currentDifficulty === 1) return 1800;
return 2200;
}
function getBulletSpeed() {
if (currentDifficulty === 0) return 8 + Math.random() * 2;
if (currentDifficulty === 1) return 12 + Math.random() * 4;
return 16 + Math.random() * 6;
}
// Initial spawns
for (var i = 0; i < 3; i++) spawnBullet();
for (var j = 0; j < 2; j++) spawnPoint();
// Timers for spawning (store timer ids for cleanup)
var bulletTimer = null;
var pointTimer = null;
function resetTimers() {
if (bulletTimer) LK.clearInterval(bulletTimer);
if (pointTimer) LK.clearInterval(pointTimer);
bulletTimer = LK.setInterval(function () {
spawnBullet();
}, getBulletInterval());
pointTimer = LK.setInterval(function () {
if (points.length < 3) spawnPoint();
}, getPointInterval());
}
resetTimers();
// When difficulty changes, reset timers
for (var i = 0; i < difficultyButtons.length; i++) {
(function (btn) {
var origDown = btn.down;
btn.down = function (x, y, obj) {
origDown.call(btn, x, y, obj);
resetTimers();
};
})(difficultyButtons[i]);
}
// Touch/drag logic
function handleMove(x, y, obj) {
if (dragNode) {
// Clamp player inside game area (with margin)
var margin = 80;
var nx = Math.max(margin, Math.min(2048 - margin, x));
var ny = Math.max(margin + 100, Math.min(2732 - margin, y));
dragNode.x = nx;
dragNode.y = ny;
}
}
game.move = handleMove;
game.down = function (x, y, obj) {
// Only start drag if touch is inside player
var dx = x - player.x;
var dy = y - player.y;
var r = player.width / 2;
if (dx * dx + dy * dy <= r * r) {
dragNode = player;
handleMove(x, y, obj);
}
};
game.up = function (x, y, obj) {
dragNode = null;
};
// Main game loop
game.update = function () {
// Update bullets
for (var i = bullets.length - 1; i >= 0; i--) {
var b = bullets[i];
b.update();
// Remove if off screen
if (b.x < -120 || b.x > 2048 + 120 || b.y < -120 || b.y > 2732 + 120) {
b.destroy();
bullets.splice(i, 1);
continue;
}
// Collision with player
if (b.intersects(player)) {
// Flash screen and game over
LK.effects.flashScreen(0xff0000, 800);
LK.showGameOver();
return;
}
}
// Update points
for (var j = points.length - 1; j >= 0; j--) {
var p = points[j];
if (p.intersects(player)) {
// Collect point
score += 1;
scoreTxt.setText(score);
p.destroy();
points.splice(j, 1);
}
}
};
// Clean up timers on game over (handled by LK, but for completeness)
game.onDestroy = function () {
LK.clearInterval(bulletTimer);
LK.clearInterval(pointTimer);
}; ===================================================================
--- original.js
+++ change.js
@@ -53,9 +53,9 @@
/****
* Initialize Game
****/
var game = new LK.Game({
- backgroundColor: 0x181818
+ backgroundColor: 0x000000
});
/****
* Game Code
@@ -69,8 +69,50 @@
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
+// --- Difficulty selection UI ---
+var difficultyLevels = [{
+ label: "Easy",
+ value: 0
+}, {
+ label: "Normal",
+ value: 1
+}, {
+ label: "Hard",
+ value: 2
+}];
+var currentDifficulty = 1; // Default: Normal
+// Create difficulty buttons
+var difficultyButtons = [];
+var buttonSpacing = 30;
+var buttonWidth = 220;
+var buttonHeight = 90;
+for (var i = 0; i < difficultyLevels.length; i++) {
+ var btn = new Text2(difficultyLevels[i].label, {
+ size: 60,
+ fill: 0xFFFFFF
+ });
+ btn.anchor.set(1, 0); // right-top
+ btn.x = (buttonWidth + buttonSpacing) * (difficultyLevels.length - i - 1);
+ btn.y = 0;
+ btn.difficultyValue = difficultyLevels[i].value;
+ // Highlight default
+ btn.alpha = i === currentDifficulty ? 1 : 0.5;
+ // Touch event
+ btn.down = function (btnRef) {
+ return function (x, y, obj) {
+ // Set difficulty
+ currentDifficulty = btnRef.difficultyValue;
+ // Update button highlights
+ for (var j = 0; j < difficultyButtons.length; j++) {
+ difficultyButtons[j].alpha = difficultyButtons[j].difficultyValue === currentDifficulty ? 1 : 0.5;
+ }
+ };
+ }(btn);
+ difficultyButtons.push(btn);
+ LK.gui.topRight.addChild(btn);
+}
// Game objects
var player = new Player();
game.addChild(player);
// Center player
@@ -113,10 +155,10 @@
angle = Math.PI + (Math.random() - 0.5) * 0.5;
}
bullet.x = pos.x;
bullet.y = pos.y;
- // Set speed (randomized a bit)
- var speed = 12 + Math.random() * 4;
+ // Set speed (randomized a bit, depends on difficulty)
+ var speed = getBulletSpeed();
bullet.vx = Math.cos(angle) * speed;
bullet.vy = Math.sin(angle) * speed;
bullets.push(bullet);
game.addChild(bullet);
@@ -139,18 +181,51 @@
point.y = py;
points.push(point);
game.addChild(point);
}
+// Helper: get bullet spawn interval and speed by difficulty
+function getBulletInterval() {
+ if (currentDifficulty === 0) return 1300; // Easy
+ if (currentDifficulty === 1) return 900; // Normal
+ return 600; // Hard
+}
+function getPointInterval() {
+ if (currentDifficulty === 0) return 1400;
+ if (currentDifficulty === 1) return 1800;
+ return 2200;
+}
+function getBulletSpeed() {
+ if (currentDifficulty === 0) return 8 + Math.random() * 2;
+ if (currentDifficulty === 1) return 12 + Math.random() * 4;
+ return 16 + Math.random() * 6;
+}
// Initial spawns
for (var i = 0; i < 3; i++) spawnBullet();
for (var j = 0; j < 2; j++) spawnPoint();
-// Timers for spawning
-var bulletTimer = LK.setInterval(function () {
- spawnBullet();
-}, 900);
-var pointTimer = LK.setInterval(function () {
- if (points.length < 3) spawnPoint();
-}, 1800);
+// Timers for spawning (store timer ids for cleanup)
+var bulletTimer = null;
+var pointTimer = null;
+function resetTimers() {
+ if (bulletTimer) LK.clearInterval(bulletTimer);
+ if (pointTimer) LK.clearInterval(pointTimer);
+ bulletTimer = LK.setInterval(function () {
+ spawnBullet();
+ }, getBulletInterval());
+ pointTimer = LK.setInterval(function () {
+ if (points.length < 3) spawnPoint();
+ }, getPointInterval());
+}
+resetTimers();
+// When difficulty changes, reset timers
+for (var i = 0; i < difficultyButtons.length; i++) {
+ (function (btn) {
+ var origDown = btn.down;
+ btn.down = function (x, y, obj) {
+ origDown.call(btn, x, y, obj);
+ resetTimers();
+ };
+ })(difficultyButtons[i]);
+}
// Touch/drag logic
function handleMove(x, y, obj) {
if (dragNode) {
// Clamp player inside game area (with margin)