User prompt
green field asset should always be on the background
User prompt
There should be a background asset which is a beautiful green field with a lot of grass and a bit of sky on top
User prompt
Enemies should move faster
User prompt
The hero and enemy collide counts only when hero's bottom half collides
User prompt
The hero's collide box should be twice smaller (wings does not count, so it should be right-bottom of the asset)
User prompt
There should be a Score which is a number of seconds since the start, I should see the Score on top right
User prompt
The enemy spawn speed should increase over time
User prompt
The hero cannot perform a new dash when coming back from previous one
User prompt
There is green field background with a bit of sky on top
User prompt
Enemies can move randomly up and bottom, but still always move from right to left
User prompt
Hit Points text should update when hit points counter changes
User prompt
I should see hit points as a number in the top of the screen with text "Hit Points:" in front of it
User prompt
Hero should have 3 hit points, and when enemy cross left side of the screen, hit points counting down, when there is 0 hit points, there is game over
/****
* Classes
****/
var Hero = Container.expand(function () {
var self = Container.call(this);
var heroGraphics = self.createAsset('hero', 'Hero character', .5, .5);
self.hitPoints = 3;
self.move = function () {};
self.shoot = function () {};
self.dashToPointAndBack = function (targetX, targetY, onCompletion) {
var originalX = 2048 * 0.1;
var originalY = 2732 / 2;
var dashSpeed = 30;
var returnSpeed = 10;
var dashComplete = false;
self.isMovingRight = false;
self.move = function () {
if (!dashComplete) {
self.isMovingRight = targetX - self.x > 0;
}
if (!dashComplete) {
if (Math.abs(self.x - targetX) > dashSpeed || Math.abs(self.y - targetY) > dashSpeed) {
self.x += (targetX - self.x > 0 ? 1 : -1) * dashSpeed;
self.y += (targetY - self.y > 0 ? 1 : -1) * dashSpeed;
} else {
dashComplete = true;
self.isMovingRight = false;
}
} else {
if (Math.abs(self.x - originalX) > returnSpeed || Math.abs(self.y - originalY) > returnSpeed) {
self.x += (originalX - self.x > 0 ? 1 : -1) * returnSpeed;
self.y += (originalY - self.y > 0 ? 1 : -1) * returnSpeed;
} else {
self.x = originalX;
self.y = originalY;
self.move = function () {};
if (typeof onCompletion === 'function') {
onCompletion();
}
}
}
};
};
});
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.createAsset('enemy', 'Enemy character', .5, .5);
self.speed = -10;
self.move = function () {
self.x += self.speed;
};
self.attack = function () {};
});
var HeroBullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.createAsset('heroBullet', 'Hero Bullet', .5, .5);
self.move = function () {};
});
var EnemyBullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.createAsset('enemyBullet', 'Enemy Bullet', .5, .5);
self.move = function () {};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000
});
/****
* Game Code
****/
var heroes = [];
var enemies = [];
var heroBullets = [];
var enemyBullets = [];
var hero = game.addChild(new Hero());
hero.x = 2048 * 0.1;
hero.y = 2732 / 2;
heroes.push(hero);
game.on('down', function (obj) {
var event = obj.event;
var position = event.getLocalPosition(game);
if (!hero.intersects({
x: position.x,
y: position.y,
width: 1,
height: 1
})) {
hero.dashToPointAndBack(position.x, position.y, function () {
console.log('Hero has returned to the original position.');
});
}
});
var enemy = game.addChild(new Enemy());
enemy.x = 2048 - enemy.width / 2;
enemy.y = 2732 - enemy.height / 2;
enemies.push(enemy);
LK.on('tick', function () {
// Spawn enemies every second
if (LK.ticks % 60 == 0) {
var newEnemy = game.addChild(new Enemy());
newEnemy.x = 2048;
newEnemy.y = Math.random() * 2732;
enemies.push(newEnemy);
}
heroes.forEach(function (hero) {
hero.move();
enemies.forEach(function (enemy, enemyIndex) {
if (hero.intersects(enemy) && hero.isMovingRight) {
enemy.destroy();
enemies.splice(enemyIndex, 1);
}
});
});
enemies.forEach(function (enemy, index) {
enemy.move();
enemy.attack();
if (enemy.x < 0) {
hero.hitPoints--;
enemy.destroy();
enemies.splice(index, 1);
if (hero.hitPoints <= 0) {
LK.showGameOver();
}
}
});
heroBullets.forEach(function (bullet) {
bullet.move();
});
enemyBullets.forEach(function (bullet) {
bullet.move();
});
});