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: 0x181818 }); /**** * 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); // 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) var speed = 12 + Math.random() * 4; 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); } // 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); // 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
@@ -1,6 +1,214 @@
-/****
+/****
+* 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
-});
\ No newline at end of file
+ backgroundColor: 0x181818
+});
+
+/****
+* 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);
+// 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)
+ var speed = 12 + Math.random() * 4;
+ 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);
+}
+// 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);
+// 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);
+};
\ No newline at end of file