User prompt
do not display lowest score.
User prompt
show high score after game over all time and clear lowest score
User prompt
show lowest score
User prompt
show high score.
User prompt
game end if more than 10 dinosaur is survive.
User prompt
If even one dinosaur survives and leaves the screen, the game is over.
Initial prompt
Sniper vs Dinosaur
/**** * Classes ****/ // Bullet class for shooting 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; }; }); //<Assets used in the game will automatically appear here> // Dinosaur class representing the target var Dinosaur = Container.expand(function () { var self = Container.call(this); var dinosaurGraphics = self.attachAsset('dinosaur', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 3; self.update = function () { self.x += self.speed; if (self.x > 2048) { self.x = 0; } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ var dinosaurs = []; var bullets = []; var score = 0; var scoreTxt = new Text2('0', { size: 150, fill: "#ffffff" }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Function to spawn a dinosaur function spawnDinosaur() { var dinosaur = new Dinosaur(); dinosaur.x = Math.random() * 2048; dinosaur.y = Math.random() * 2732 / 2; dinosaurs.push(dinosaur); game.addChild(dinosaur); } // Function to shoot a bullet function shootBullet(x, y) { var bullet = new Bullet(); bullet.x = x; bullet.y = y; bullets.push(bullet); game.addChild(bullet); } // Handle game updates game.update = function () { for (var i = bullets.length - 1; i >= 0; i--) { bullets[i].update(); if (bullets[i].y < 0) { bullets[i].destroy(); bullets.splice(i, 1); } } for (var j = dinosaurs.length - 1; j >= 0; j--) { dinosaurs[j].update(); if (dinosaurs[j].x > 2048) { LK.showGameOver(); return; } for (var k = bullets.length - 1; k >= 0; k--) { if (dinosaurs[j].intersects(bullets[k])) { score++; scoreTxt.setText(score); dinosaurs[j].destroy(); bullets[k].destroy(); dinosaurs.splice(j, 1); bullets.splice(k, 1); break; } } } if (LK.ticks % 120 == 0) { spawnDinosaur(); } }; // Handle touch events for shooting game.down = function (x, y, obj) { shootBullet(x, y); };
===================================================================
--- original.js
+++ change.js
@@ -1,98 +1,102 @@
-/****
+/****
* Classes
-****/
+****/
// Bullet class for shooting
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;
+ };
});
//<Assets used in the game will automatically appear here>
// Dinosaur class representing the target
var Dinosaur = Container.expand(function () {
- var self = Container.call(this);
- var dinosaurGraphics = self.attachAsset('dinosaur', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.speed = 3;
- self.update = function () {
- self.x += self.speed;
- if (self.x > 2048) {
- self.x = 0;
- }
- };
+ var self = Container.call(this);
+ var dinosaurGraphics = self.attachAsset('dinosaur', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 3;
+ self.update = function () {
+ self.x += self.speed;
+ if (self.x > 2048) {
+ self.x = 0;
+ }
+ };
});
-/****
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000 //Init game with black background
+ backgroundColor: 0x000000 //Init game with black background
});
-/****
+/****
* Game Code
-****/
+****/
var dinosaurs = [];
var bullets = [];
var score = 0;
var scoreTxt = new Text2('0', {
- size: 150,
- fill: "#ffffff"
+ size: 150,
+ fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Function to spawn a dinosaur
function spawnDinosaur() {
- var dinosaur = new Dinosaur();
- dinosaur.x = Math.random() * 2048;
- dinosaur.y = Math.random() * 2732 / 2;
- dinosaurs.push(dinosaur);
- game.addChild(dinosaur);
+ var dinosaur = new Dinosaur();
+ dinosaur.x = Math.random() * 2048;
+ dinosaur.y = Math.random() * 2732 / 2;
+ dinosaurs.push(dinosaur);
+ game.addChild(dinosaur);
}
// Function to shoot a bullet
function shootBullet(x, y) {
- var bullet = new Bullet();
- bullet.x = x;
- bullet.y = y;
- bullets.push(bullet);
- game.addChild(bullet);
+ var bullet = new Bullet();
+ bullet.x = x;
+ bullet.y = y;
+ bullets.push(bullet);
+ game.addChild(bullet);
}
// Handle game updates
game.update = function () {
- for (var i = bullets.length - 1; i >= 0; i--) {
- bullets[i].update();
- if (bullets[i].y < 0) {
- bullets[i].destroy();
- bullets.splice(i, 1);
- }
- }
- for (var j = dinosaurs.length - 1; j >= 0; j--) {
- dinosaurs[j].update();
- for (var k = bullets.length - 1; k >= 0; k--) {
- if (dinosaurs[j].intersects(bullets[k])) {
- score++;
- scoreTxt.setText(score);
- dinosaurs[j].destroy();
- bullets[k].destroy();
- dinosaurs.splice(j, 1);
- bullets.splice(k, 1);
- break;
- }
- }
- }
- if (LK.ticks % 120 == 0) {
- spawnDinosaur();
- }
+ for (var i = bullets.length - 1; i >= 0; i--) {
+ bullets[i].update();
+ if (bullets[i].y < 0) {
+ bullets[i].destroy();
+ bullets.splice(i, 1);
+ }
+ }
+ for (var j = dinosaurs.length - 1; j >= 0; j--) {
+ dinosaurs[j].update();
+ if (dinosaurs[j].x > 2048) {
+ LK.showGameOver();
+ return;
+ }
+ for (var k = bullets.length - 1; k >= 0; k--) {
+ if (dinosaurs[j].intersects(bullets[k])) {
+ score++;
+ scoreTxt.setText(score);
+ dinosaurs[j].destroy();
+ bullets[k].destroy();
+ dinosaurs.splice(j, 1);
+ bullets.splice(k, 1);
+ break;
+ }
+ }
+ }
+ if (LK.ticks % 120 == 0) {
+ spawnDinosaur();
+ }
};
// Handle touch events for shooting
game.down = function (x, y, obj) {
- shootBullet(x, y);
+ shootBullet(x, y);
};
\ No newline at end of file