Made the game linear
This commit is contained in:
parent
03054fbe9d
commit
33a034bc94
37
src/Boss.hx
37
src/Boss.hx
|
@ -5,17 +5,18 @@ import com.haxepunk.masks.Hitbox;
|
|||
import com.haxepunk.HXP;
|
||||
|
||||
import Enemy;
|
||||
import Explosion;
|
||||
|
||||
class Boss extends Entity {
|
||||
|
||||
public function new () {
|
||||
public function new (clr:Int) {
|
||||
|
||||
var color:Int = Math.floor(Math.random() * 4);
|
||||
color = clr;
|
||||
currentSprite = sprites[color];
|
||||
currentSprite.scale = 8;
|
||||
currentSprite.smooth = false;
|
||||
|
||||
maxEnemies = Math.floor(Math.random() * (color + 1) * 4);
|
||||
maxEnemies = Math.floor(Math.random() * (color + 1) * 2);
|
||||
|
||||
graphic = currentSprite;
|
||||
|
||||
|
@ -43,13 +44,14 @@ class Boss extends Entity {
|
|||
|
||||
public override function update() {
|
||||
super.update();
|
||||
|
||||
spawnTimer -= HXP.elapsed;
|
||||
explosionTimer -= HXP.elapsed;
|
||||
|
||||
var enemies:Array<Enemy> = [];
|
||||
this.scene.getClass(Enemy, enemies);
|
||||
|
||||
if (spawnTimer < 0 && enemies.length != maxEnemies) {
|
||||
this.scene.add(new Enemy(this.width / 2, this.height / 2));
|
||||
if (spawnTimer < 0 && enemies.length != maxEnemies - 1 && canSpawn) {
|
||||
this.scene.add(new Enemy(this.width / 2, 20, color, Math.floor(Math.random() * 4) + 1));
|
||||
spawnTimer = .75;
|
||||
}
|
||||
|
||||
|
@ -57,8 +59,24 @@ class Boss extends Entity {
|
|||
|
||||
if (this.y < currentSprite.height * 8 * -.5)
|
||||
this.y += 2;
|
||||
else if (!dead)
|
||||
canSpawn = true;
|
||||
|
||||
healthBar.scaledWidth = (healthBar.width / originalHealth) * health;
|
||||
if (health > 0) healthBar.scaledWidth = (healthBar.width / originalHealth) * health;
|
||||
else {
|
||||
dead = true;
|
||||
canSpawn = false;
|
||||
|
||||
if (explosionTimer < 0 && counter != 100) {
|
||||
healthBarBackground.alpha = healthBar.alpha = currentSprite.alpha -= 0.01;
|
||||
this.scene.add(new Explosion(this.x + (Math.random() * currentSprite.width * 8), this.y + (Math.random() * currentSprite.height * 8) + 100, this.scene.getInstance("player")));
|
||||
explosionTimer = Math.random() * .2;
|
||||
counter++;
|
||||
}
|
||||
else if (counter == 100) {
|
||||
this.scene.remove(this);
|
||||
}
|
||||
}
|
||||
|
||||
var bullet:Entity = this.collide("bullet", this.x, this.y);
|
||||
|
||||
|
@ -77,12 +95,17 @@ class Boss extends Entity {
|
|||
new Image("graphics/ufoYellow.png")
|
||||
];
|
||||
|
||||
private var color:Int;
|
||||
private var health:Int;
|
||||
private var originalHealth:Int;
|
||||
private var healthBar:Image;
|
||||
private var healthBarBackground:Image;
|
||||
|
||||
private var maxEnemies:Int;
|
||||
private var canSpawn:Bool = false;
|
||||
private var spawnTimer:Float = .75;
|
||||
private var explosionTimer:Float = 0;
|
||||
private var counter:Int = 0;
|
||||
private var dead:Bool = false;
|
||||
|
||||
}
|
14
src/Enemy.hx
14
src/Enemy.hx
|
@ -9,11 +9,11 @@ import EnemyBullet;
|
|||
|
||||
class Enemy extends Entity {
|
||||
|
||||
public function new (x:Float, y:Float) {
|
||||
public function new (x:Float, y:Float, clr:Int, eT:Int) {
|
||||
super(x, y);
|
||||
|
||||
color = Math.floor(Math.random() * 4);
|
||||
enemyType = Math.floor(Math.random() * 5) + 1;
|
||||
color = clr;
|
||||
enemyType = eT;
|
||||
|
||||
#if flash
|
||||
bulletSound = new Sfx("audio/laser3.mp3");
|
||||
|
@ -26,7 +26,7 @@ class Enemy extends Entity {
|
|||
healthSprite = Image.createRect(sprite.width, 10, 0x00FF00);
|
||||
healthSprite.y -= 50;
|
||||
|
||||
originalHealth = health = (enemyType * 2 * color);
|
||||
originalHealth = health = (enemyType * 2 * (color + 1));
|
||||
|
||||
sprite.centerOrigin();
|
||||
healthSprite.centerOrigin();
|
||||
|
@ -43,7 +43,7 @@ class Enemy extends Entity {
|
|||
if (enemyType < 3) {
|
||||
arr = [
|
||||
Math.floor(Math.random() * (HXP.width - this.width)),
|
||||
Math.floor(Math.random() * 400)
|
||||
Math.floor((Math.random() * 200) + 350)
|
||||
];
|
||||
}
|
||||
else if (enemyType >= 3 && enemyType <= 4) {
|
||||
|
@ -57,7 +57,7 @@ class Enemy extends Entity {
|
|||
|
||||
arr = [
|
||||
antX,
|
||||
Math.random() * 400
|
||||
(Math.random() * 200) + 350
|
||||
];
|
||||
}
|
||||
else {
|
||||
|
@ -76,7 +76,7 @@ class Enemy extends Entity {
|
|||
|
||||
arr = [
|
||||
antX,
|
||||
Math.random() * 400
|
||||
(Math.random() * 200) + 350
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,8 @@ class Explosion extends Entity {
|
|||
|
||||
this.centerOrigin();
|
||||
sprite.centerOrigin();
|
||||
|
||||
layer = -4;
|
||||
}
|
||||
|
||||
private function die () {
|
||||
|
|
|
@ -18,10 +18,8 @@ class MainScene extends Scene
|
|||
var player = new Player();
|
||||
var button = new Button();
|
||||
var spawner = new Spawner();
|
||||
var enemy = new Enemy(-160, 0);
|
||||
var lives = new Lives();
|
||||
var score = new Score();
|
||||
var boss = new Boss();
|
||||
|
||||
#if flash
|
||||
music = new Sfx("audio/loop.mp3");
|
||||
|
@ -36,7 +34,6 @@ class MainScene extends Scene
|
|||
add(button);
|
||||
#end
|
||||
|
||||
add(boss);
|
||||
add(player);
|
||||
add(lives);
|
||||
add(score);
|
||||
|
|
|
@ -18,8 +18,6 @@ class Player extends Entity {
|
|||
super(HXP.halfWidth - 16, HXP.height - 200);
|
||||
baseSprite = new Image("graphics/playerShip1_green.png");
|
||||
shield = new Image("graphics/shield1.png");
|
||||
shield.x -= 16;
|
||||
shield.y -= 20;
|
||||
|
||||
#if flash
|
||||
laser = new Sfx("audio/laser4.mp3");
|
||||
|
@ -83,7 +81,7 @@ class Player extends Entity {
|
|||
this.y -= moveSpeed;
|
||||
}
|
||||
|
||||
if (Input.pressed("shoot")) {
|
||||
if (Input.check("shoot")) {
|
||||
shoot();
|
||||
}
|
||||
|
||||
|
@ -148,6 +146,8 @@ class Player extends Entity {
|
|||
this.addGraphic(fireEffectLeft);
|
||||
this.addGraphic(fireEffectRight);
|
||||
|
||||
shield.centerOrigin();
|
||||
|
||||
if (shielded)
|
||||
this.addGraphic(shield);
|
||||
|
||||
|
|
|
@ -1,51 +1,57 @@
|
|||
import com.haxepunk.Entity;
|
||||
import com.haxepunk.HXP;
|
||||
|
||||
import Asteroid;
|
||||
import Enemy;
|
||||
import Boss;
|
||||
|
||||
class Spawner extends Entity {
|
||||
public function new () {
|
||||
super();
|
||||
|
||||
public function new() {
|
||||
super(0,0);
|
||||
|
||||
}
|
||||
|
||||
public override function update() {
|
||||
spawnStarTime -= HXP.elapsed;
|
||||
spawnAsteroidTime -= HXP.elapsed;
|
||||
// spawnEnemyTime -= HXP.elapsed;
|
||||
spawnPickupTime -= HXP.elapsed;
|
||||
|
||||
if (spawnAsteroidTime < 0) {
|
||||
this.scene.add(new Asteroid(HXP.width * Math.random(), -16));
|
||||
spawnAsteroidTime = .5;
|
||||
}
|
||||
|
||||
if (spawnStarTime < 0) {
|
||||
this.scene.add(new Star(HXP.width * Math.random()));
|
||||
spawnStarTime = .5;
|
||||
}
|
||||
|
||||
if (spawnEnemyTime < 0 && this.scene.getInstance("player") != null) {
|
||||
var enemies:Array<Entity> = [];
|
||||
enemyTimer -= HXP.elapsed;
|
||||
var enemies:Array<Enemy> = [];
|
||||
var bosses:Array<Boss> = [];
|
||||
this.scene.getClass(Enemy, enemies);
|
||||
this.scene.getClass(Boss, bosses);
|
||||
|
||||
if (enemies[0] == null) {
|
||||
this.scene.add(new Enemy(HXP.halfWidth, -50));
|
||||
if (level == 4) {level = 0; trace("YOU BEAT IT!");}
|
||||
if (enemyType == 6) {sublevel++; enemyType = 1;}
|
||||
|
||||
if (enemies.length < 1 && sublevel != 2) {
|
||||
if (enemyTimer < 0) {
|
||||
if (sublevel == 0)
|
||||
this.scene.add(new Enemy(HXP.halfWidth, -60, level, enemyType++));
|
||||
else {
|
||||
this.scene.add(new Enemy(HXP.halfWidth, -60, level, enemyType++));
|
||||
if (enemyType != 6) this.scene.add(new Enemy(HXP.halfWidth, -60, level, enemyType++));
|
||||
else this.scene.add(new Enemy(HXP.halfWidth, -60, level, enemyType - 1));
|
||||
}
|
||||
|
||||
spawnEnemyTime = 5;
|
||||
}
|
||||
}
|
||||
else {
|
||||
enemyTimer = 1;
|
||||
}
|
||||
|
||||
if (spawnPickupTime < 0) {
|
||||
this.scene.add(new Pickup(HXP.width * Math.random(), -50));
|
||||
spawnPickupTime = 5 * Math.random() + 5;
|
||||
if (sublevel == 2 && !bossSpawned) {
|
||||
this.scene.add(new Boss(level));
|
||||
bossSpawned = true;
|
||||
}
|
||||
|
||||
super.update();
|
||||
if (sublevel == 2 && bossSpawned && bosses.length != 1) {
|
||||
level++; enemyType = 1; sublevel = 0; bossSpawned = false; trace("Next level!");
|
||||
}
|
||||
}
|
||||
|
||||
private var spawnAsteroidTime:Float = .5;
|
||||
private var spawnStarTime:Float = .5;
|
||||
private var spawnEnemyTime:Float = 5;
|
||||
private var spawnPickupTime:Float = 10;
|
||||
private var level:Int = 0;
|
||||
private var sublevel:Int = 0;
|
||||
|
||||
private var enemyTimer:Float = 1;
|
||||
private var enemyType:Int = 1;
|
||||
|
||||
private var bossSpawned:Bool = false;
|
||||
}
|
Reference in a new issue