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