User prompt
Show lives
User prompt
My game is lagging fix lagging
User prompt
Give player three lives
User prompt
Decrease player firing rate
User prompt
Fix the game
User prompt
Make bots fire
User prompt
Make a scorecard
User prompt
Make bullets autofire
User prompt
Make bots move
User prompt
Fix the game
Initial prompt
Shooter
/**** * Classes ****/ // Bot class var Bot = Container.expand(function () { var self = Container.call(this); var botGraphics = self.attachAsset('bot', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 3; self.update = function () { // Bot movement logic goes here }; }); // Bullet class var Bullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.attachAsset('bullet', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 10; self.update = function () { self.y -= self.speed; }; }); // The assets will be automatically created and loaded by the LK engine // Player class var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.update = function () { // Player movement logic goes here }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ // Initialize player var player = game.addChild(new Player()); player.x = 2048 / 2; player.y = 2732 - 100; // Initialize bots and bullets var bots = []; var bullets = []; // Game update function game.update = function () { // Update player player.update(); // Update bots for (var i = 0; i < bots.length; i++) { bots[i].update(); } // Update bullets for (var i = 0; i < bullets.length; i++) { bullets[i].update(); } // Collision detection for (var i = bots.length - 1; i >= 0; i--) { for (var j = bullets.length - 1; j >= 0; j--) { if (bots[i].intersects(bullets[j])) { bots[i].destroy(); bullets[j].destroy(); bots.splice(i, 1); bullets.splice(j, 1); break; } } } // Spawn bots if (LK.ticks % 120 == 0) { var bot = new Bot(); bot.x = Math.random() * 2048; bot.y = 0; bots.push(bot); game.addChild(bot); } }; // Player control game.down = function (x, y, obj) { player.x = x; player.y = y; }; game.move = function (x, y, obj) { player.x = x; player.y = y; }; game.up = function (x, y, obj) { var bullet = new Bullet(); bullet.x = player.x; bullet.y = player.y; bullets.push(bullet); game.addChild(bullet); };
===================================================================
--- original.js
+++ change.js
@@ -1,55 +1,55 @@
-/****
+/****
* Classes
-****/
+****/
// Bot class
var Bot = Container.expand(function () {
- var self = Container.call(this);
- var botGraphics = self.attachAsset('bot', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.speed = 3;
- self.update = function () {
- // Bot movement logic goes here
- };
+ var self = Container.call(this);
+ var botGraphics = self.attachAsset('bot', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 3;
+ self.update = function () {
+ // Bot movement logic goes here
+ };
});
// Bullet class
var Bullet = Container.expand(function () {
- var self = Container.call(this);
- var bulletGraphics = self.attachAsset('bullet', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.speed = 10;
- self.update = function () {
- self.y -= self.speed;
- };
+ var self = Container.call(this);
+ var bulletGraphics = self.attachAsset('bullet', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 10;
+ self.update = function () {
+ self.y -= self.speed;
+ };
});
// The assets will be automatically created and loaded by the LK engine
// Player class
var Player = Container.expand(function () {
- var self = Container.call(this);
- var playerGraphics = self.attachAsset('player', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.speed = 5;
- self.update = function () {
- // Player movement logic goes here
- };
+ var self = Container.call(this);
+ var playerGraphics = self.attachAsset('player', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 5;
+ self.update = function () {
+ // Player movement logic goes here
+ };
});
-/****
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000 //Init game with black background
+ backgroundColor: 0x000000 //Init game with black background
});
-/****
+/****
* Game Code
-****/
+****/
// Initialize player
var player = game.addChild(new Player());
player.x = 2048 / 2;
player.y = 2732 - 100;
@@ -57,51 +57,51 @@
var bots = [];
var bullets = [];
// Game update function
game.update = function () {
- // Update player
- player.update();
- // Update bots
- for (var i = 0; i < bots.length; i++) {
- bots[i].update();
- }
- // Update bullets
- for (var i = 0; i < bullets.length; i++) {
- bullets[i].update();
- }
- // Collision detection
- for (var i = 0; i < bots.length; i++) {
- for (var j = 0; j < bullets.length; j++) {
- if (bots[i].intersects(bullets[j])) {
- bots[i].destroy();
- bullets[j].destroy();
- bots.splice(i, 1);
- bullets.splice(j, 1);
- break;
- }
- }
- }
- // Spawn bots
- if (LK.ticks % 120 == 0) {
- var bot = new Bot();
- bot.x = Math.random() * 2048;
- bot.y = 0;
- bots.push(bot);
- game.addChild(bot);
- }
+ // Update player
+ player.update();
+ // Update bots
+ for (var i = 0; i < bots.length; i++) {
+ bots[i].update();
+ }
+ // Update bullets
+ for (var i = 0; i < bullets.length; i++) {
+ bullets[i].update();
+ }
+ // Collision detection
+ for (var i = bots.length - 1; i >= 0; i--) {
+ for (var j = bullets.length - 1; j >= 0; j--) {
+ if (bots[i].intersects(bullets[j])) {
+ bots[i].destroy();
+ bullets[j].destroy();
+ bots.splice(i, 1);
+ bullets.splice(j, 1);
+ break;
+ }
+ }
+ }
+ // Spawn bots
+ if (LK.ticks % 120 == 0) {
+ var bot = new Bot();
+ bot.x = Math.random() * 2048;
+ bot.y = 0;
+ bots.push(bot);
+ game.addChild(bot);
+ }
};
// Player control
game.down = function (x, y, obj) {
- player.x = x;
- player.y = y;
+ player.x = x;
+ player.y = y;
};
game.move = function (x, y, obj) {
- player.x = x;
- player.y = y;
+ player.x = x;
+ player.y = y;
};
game.up = function (x, y, obj) {
- var bullet = new Bullet();
- bullet.x = player.x;
- bullet.y = player.y;
- bullets.push(bullet);
- game.addChild(bullet);
+ var bullet = new Bullet();
+ bullet.x = player.x;
+ bullet.y = player.y;
+ bullets.push(bullet);
+ game.addChild(bullet);
};
\ No newline at end of file