User prompt
Increase the size of the enemies a bit
User prompt
Make the player a bit bigger
User prompt
Add a score
User prompt
Spawn new enemies every 8 seconds randomly on the map
User prompt
Make the player faster every 5 seconds as well
User prompt
Increase the speed of the enemies every 5 seconds
User prompt
Add touch function to move the player around
User prompt
Make the player move, using Touch
User prompt
Add touch control
Initial prompt
Manhunt
var Hero = Container.expand(function () { var self = Container.call(this); var heroGraphics = self.createAsset('hero', 'Hero character', .5, .5); self.speed = 5; self.move = function (touchStart, touchEnd) { var dx = touchEnd.x - touchStart.x; var dy = touchEnd.y - touchStart.y; var distance = Math.sqrt(dx * dx + dy * dy); self.x += dx / distance * self.speed; self.y += dy / distance * self.speed; }; }); var Enemy = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.createAsset('enemy', 'Enemy character', .5, .5); self.speed = 3; self.chase = function (hero) { var dx = hero.x - self.x; var dy = hero.y - self.y; var distance = Math.sqrt(dx * dx + dy * dy); self.x += dx / distance * self.speed; self.y += dy / distance * self.speed; }; }); var Game = Container.expand(function () { var self = Container.call(this); var hero = self.addChild(new Hero()); var enemies = []; var isGameOver = false; var lastSpeedIncrease = 0; var score = 0; var scoreTxt = new Text2('0', { size: 150, fill: '#ffffff' }); scoreTxt.anchor.set(.5, 0); LK.gui.topCenter.addChild(scoreTxt); hero.x = 2048 / 2; hero.y = 2732 / 2; var spawnEnemy = function () { var enemy = self.addChild(new Enemy()); enemy.x = Math.random() * 2048; enemy.y = Math.random() * 2732; enemies.push(enemy); }; for (var i = 0; i < 5; i++) { spawnEnemy(); } var enemySpawnInterval = LK.setInterval(spawnEnemy, 8000); var touchStart = { x: 0, y: 0 }; var touchEnd = { x: 0, y: 0 }; stage.on('down', function (obj) { touchStart = obj.event.getLocalPosition(self); hero.move(touchStart, touchStart); }); stage.on('move', function (obj) { touchEnd = obj.event.getLocalPosition(self); hero.move(touchStart, touchEnd); }); stage.on('up', function (obj) { touchStart = obj.event.getLocalPosition(self); hero.move(touchStart, touchStart); }); LK.on('tick', function () { if (LK.ticks - lastSpeedIncrease >= 300) { for (var i = 0; i < enemies.length; i++) { enemies[i].speed += 1; } hero.speed += 1; lastSpeedIncrease = LK.ticks; } score += 1; scoreTxt.setText(score); for (var i = 0; i < enemies.length; i++) { enemies[i].chase(hero); if (enemies[i].intersects(hero)) { isGameOver = true; LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } } }); });
===================================================================
--- original.js
+++ change.js
@@ -27,8 +27,15 @@
var hero = self.addChild(new Hero());
var enemies = [];
var isGameOver = false;
var lastSpeedIncrease = 0;
+ var score = 0;
+ var scoreTxt = new Text2('0', {
+ size: 150,
+ fill: '#ffffff'
+ });
+ scoreTxt.anchor.set(.5, 0);
+ LK.gui.topCenter.addChild(scoreTxt);
hero.x = 2048 / 2;
hero.y = 2732 / 2;
var spawnEnemy = function () {
var enemy = self.addChild(new Enemy());
@@ -67,8 +74,10 @@
}
hero.speed += 1;
lastSpeedIncrease = LK.ticks;
}
+ score += 1;
+ scoreTxt.setText(score);
for (var i = 0; i < enemies.length; i++) {
enemies[i].chase(hero);
if (enemies[i].intersects(hero)) {
isGameOver = true;