Rewrote a lot of things.

This commit is contained in:
Bram van der Veen 2014-07-11 00:29:32 +02:00
parent 33a034bc94
commit 24b54b5c8b
18 changed files with 1318 additions and 1272 deletions

View file

@ -6,6 +6,7 @@ import com.haxepunk.HXP;
import Enemy; import Enemy;
import Explosion; import Explosion;
import Spawner;
class Boss extends Entity { class Boss extends Entity {
@ -16,7 +17,7 @@ class Boss extends Entity {
currentSprite.scale = 8; currentSprite.scale = 8;
currentSprite.smooth = false; currentSprite.smooth = false;
maxEnemies = Math.floor(Math.random() * (color + 1) * 2); maxEnemies = Math.floor((color + 1) * 2);
graphic = currentSprite; graphic = currentSprite;
@ -50,7 +51,9 @@ class Boss extends Entity {
var enemies:Array<Enemy> = []; var enemies:Array<Enemy> = [];
this.scene.getClass(Enemy, enemies); this.scene.getClass(Enemy, enemies);
if (spawnTimer < 0 && enemies.length != maxEnemies - 1 && canSpawn) { trace(enemies.length + ", " + maxEnemies);
if (spawnTimer < 0 && enemies.length != maxEnemies && canSpawn) {
this.scene.add(new Enemy(this.width / 2, 20, color, Math.floor(Math.random() * 4) + 1)); this.scene.add(new Enemy(this.width / 2, 20, color, Math.floor(Math.random() * 4) + 1));
spawnTimer = .75; spawnTimer = .75;
} }
@ -72,8 +75,15 @@ class Boss extends Entity {
this.scene.add(new Explosion(this.x + (Math.random() * currentSprite.width * 8), this.y + (Math.random() * currentSprite.height * 8) + 100, this.scene.getInstance("player"))); 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; explosionTimer = Math.random() * .2;
counter++; counter++;
var spawner:Array<Spawner> = [];
this.scene.getClass(Spawner, spawner);
spawner[0].sublevel = 3;
} }
else if (counter == 100) { else if (counter == 100) {
var spawner:Array<Spawner> = [];
this.scene.getClass(Spawner, spawner);
spawner[0].bossSpawned = false;
this.scene.remove(this); this.scene.remove(this);
} }
} }

View file

@ -45,10 +45,12 @@ class MenuButton extends Entity {
if ((Input.mouseX > this.left && Input.mouseX < this.right) && (Input.mouseY > this.top && Input.mouseY < this.bottom)) { if ((Input.mouseX > this.left && Input.mouseX < this.right) && (Input.mouseY > this.top && Input.mouseY < this.bottom)) {
if (this.text.text != "Menu") { if (this.text.text != "Menu") {
HXP.scene = null; HXP.scene = null;
Assets.cache.clear();
HXP.scene = new MainScene(); HXP.scene = new MainScene();
} }
else { else {
HXP.scene = null; HXP.scene = null;
Assets.cache.clear();
HXP.scene = new MenuScene(); HXP.scene = new MenuScene();
} }
} }
@ -57,10 +59,12 @@ class MenuButton extends Entity {
if (Input.check("enter")) { if (Input.check("enter")) {
if (this.text.text != "Menu") { if (this.text.text != "Menu") {
HXP.scene = null; HXP.scene = null;
Assets.cache.clear();
HXP.scene = new MainScene(); HXP.scene = new MainScene();
} }
else { else {
HXP.scene = null; HXP.scene = null;
Assets.cache.clear();
HXP.scene = new MenuScene(); HXP.scene = new MenuScene();
} }
} }
@ -70,10 +74,12 @@ class MenuButton extends Entity {
if ((touch.x > this.left && touch.x < this.right) && (touch.y > this.top && touch.y < this.bottom)) { if ((touch.x > this.left && touch.x < this.right) && (touch.y > this.top && touch.y < this.bottom)) {
if (this.text.text != "Menu") { if (this.text.text != "Menu") {
HXP.scene = null; HXP.scene = null;
Assets.cache.clear();
HXP.scene = new MainScene(); HXP.scene = new MainScene();
} }
else { else {
HXP.scene = null; HXP.scene = null;
Assets.cache.clear();
HXP.scene = new MenuScene(); HXP.scene = new MenuScene();
} }
} }

View file

@ -81,7 +81,7 @@ class Player extends Entity {
this.y -= moveSpeed; this.y -= moveSpeed;
} }
if (Input.check("shoot")) { if (Input.pressed("shoot")) {
shoot(); shoot();
} }

View file

@ -3,12 +3,14 @@ import com.haxepunk.HXP;
import Enemy; import Enemy;
import Boss; import Boss;
import Star;
import Pickup;
import Asteroid;
class Spawner extends Entity { class Spawner extends Entity {
public function new() { public function new() {
super(0,0); super(0,0);
} }
public override function update() { public override function update() {
@ -18,40 +20,68 @@ class Spawner extends Entity {
this.scene.getClass(Enemy, enemies); this.scene.getClass(Enemy, enemies);
this.scene.getClass(Boss, bosses); this.scene.getClass(Boss, bosses);
if (level == 4) {level = 0; trace("YOU BEAT IT!");} if (level != 4) {
if (enemyType == 6) {sublevel++; enemyType = 1;} 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));
}
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));
} }
}
else {
enemyTimer = 1;
}
if (sublevel == 2 && !bossSpawned) {
this.scene.add(new Boss(level));
bossSpawned = true;
}
if (sublevel == 3 && !bossSpawned && bosses.length != 1) {
level++; enemyType = 1; sublevel = 0; trace("Next level!");
} }
} }
else { else {
enemyTimer = 1; trace("YOU BEAT THE GAME!");
} }
if (sublevel == 2 && !bossSpawned) {
this.scene.add(new Boss(level)); spawnStarTime -= HXP.elapsed;
bossSpawned = true; spawnAsteroidTime -= HXP.elapsed;
spawnPickupTime -= HXP.elapsed;
if (spawnAsteroidTime < 0) {
this.scene.add(new Asteroid(HXP.width * Math.random(), -16));
spawnAsteroidTime = .5;
} }
if (sublevel == 2 && bossSpawned && bosses.length != 1) { if (spawnStarTime < 0) {
level++; enemyType = 1; sublevel = 0; bossSpawned = false; trace("Next level!"); this.scene.add(new Star(HXP.width * Math.random()));
spawnStarTime = .5;
}
if (spawnPickupTime < 0) {
this.scene.add(new Pickup(HXP.width * Math.random(), -50));
spawnPickupTime = 5 * Math.random() + 5;
} }
} }
private var level:Int = 0; private var level:Int = 0;
private var sublevel:Int = 0; public var sublevel:Int = 0;
private var enemyTimer:Float = 1; private var enemyTimer:Float = 1;
private var enemyType:Int = 1; private var enemyType:Int = 1;
private var bossSpawned:Bool = false; public var bossSpawned:Bool = false;
private var spawnPickupTime:Float = 10;
private var spawnAsteroidTime:Float = .5;
private var spawnStarTime:Float = .5;
} }