/**** * Plugins ****/ var facekit = LK.import("@upit/facekit.v1"); /**** * Classes ****/ // 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 = -15; self.update = function () { self.y += self.speed; }; }); // Enemy class var Enemy = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.attachAsset('enemy', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.update = function () { self.y += self.speed; if (self.y > 2732) { self.y = 0; self.x = Math.random() * 2048; } }; }); //<Assets used in the game will automatically appear here> // Hero class var Hero = Container.expand(function () { var self = Container.call(this); var heroGraphics = self.attachAsset('hero', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 10; self.update = function () { self.x = facekit.mouthCenter.x; self.y = facekit.mouthCenter.y; }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ //<Assets used in the game will automatically appear here> // Initialize hero var hero = game.addChild(new Hero()); hero.x = 1024; hero.y = 2500; // Initialize enemies var enemies = []; for (var i = 0; i < 5; i++) { var enemy = new Enemy(); enemy.x = Math.random() * 2048; enemy.y = Math.random() * 1000; enemies.push(enemy); game.addChild(enemy); } // Initialize bullets var bullets = []; // Handle game move event game.move = function (x, y, obj) { hero.x = facekit.mouthCenter.x; hero.y = facekit.mouthCenter.y; }; game.update = function () { if (facekit.mouthOpen) { var newBullet = new Bullet(); newBullet.x = hero.x; newBullet.y = hero.y; bullets.push(newBullet); game.addChild(newBullet); } }; // Handle game update event game.update = function () { // Update stopwatch stopwatch++; // Update bullets for (var i = bullets.length - 1; i >= 0; i--) { var bullet = bullets[i]; bullet.update(); if (bullet.y < 0) { bullet.destroy(); bullets.splice(i, 1); } } // Update enemies for (var j = enemies.length - 1; j >= 0; j--) { var enemy = enemies[j]; enemy.update(); if (hero.intersects(enemy)) { LK.effects.flashScreen(0xff0000, 1000); LK.setScore(totalKilled); LK.showGameOver(); } // Check for bullet collision for (var k = bullets.length - 1; k >= 0; k--) { var bullet = bullets[k]; if (bullet.intersects(enemy)) { // Destroy bullet and enemy bullet.destroy(); bullets.splice(k, 1); enemy.destroy(); enemies.splice(j, 1); break; } } } // Initialize enemy count var enemyCount = 5; // Initialize stopwatch var stopwatch = 0; // Initialize total killed enemies count var totalKilled = 0; // Spawn more enemies when all are killed if (enemies.length === 0 && totalKilled < 25) { for (var i = 0; i < enemyCount; i++) { var enemy = new Enemy(); enemy.x = Math.random() * 2048; enemy.y = Math.random() * 1000; enemies.push(enemy); game.addChild(enemy); } // Increase enemy count for next level enemyCount++; // Increase total killed enemies count totalKilled += enemyCount; } else if (totalKilled >= 25) { // End game after 25 robots are killed LK.setScore(totalKilled); LK.setScore(totalKilled); LK.setScore(totalKilled); LK.showGameOver("You killed " + totalKilled + " robots! Time: " + stopwatch / 60 + " seconds"); } };
===================================================================
--- original.js
+++ change.js
@@ -1,5 +1,10 @@
/****
+* Plugins
+****/
+var facekit = LK.import("@upit/facekit.v1");
+
+/****
* Classes
****/
// Bullet class
var Bullet = Container.expand(function () {
@@ -29,9 +34,8 @@
}
};
});
//<Assets used in the game will automatically appear here>
-//<Write imports for supported plugins here>
// Hero class
var Hero = Container.expand(function () {
var self = Container.call(this);
var heroGraphics = self.attachAsset('hero', {
@@ -39,9 +43,10 @@
anchorY: 0.5
});
self.speed = 10;
self.update = function () {
- // Hero update logic
+ self.x = facekit.mouthCenter.x;
+ self.y = facekit.mouthCenter.y;
};
});
/****
@@ -53,8 +58,9 @@
/****
* Game Code
****/
+//<Assets used in the game will automatically appear here>
// Initialize hero
var hero = game.addChild(new Hero());
hero.x = 1024;
hero.y = 2500;
@@ -70,17 +76,19 @@
// Initialize bullets
var bullets = [];
// Handle game move event
game.move = function (x, y, obj) {
- hero.x = x;
- hero.y = y;
+ hero.x = facekit.mouthCenter.x;
+ hero.y = facekit.mouthCenter.y;
};
-game.down = function (x, y, obj) {
- var newBullet = new Bullet();
- newBullet.x = hero.x;
- newBullet.y = hero.y;
- bullets.push(newBullet);
- game.addChild(newBullet);
+game.update = function () {
+ if (facekit.mouthOpen) {
+ var newBullet = new Bullet();
+ newBullet.x = hero.x;
+ newBullet.y = hero.y;
+ bullets.push(newBullet);
+ game.addChild(newBullet);
+ }
};
// Handle game update event
game.update = function () {
// Update stopwatch