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

@ -1,78 +1,78 @@
import com.haxepunk.Entity; import com.haxepunk.Entity;
import com.haxepunk.graphics.Image; import com.haxepunk.graphics.Image;
import com.haxepunk.HXP; import com.haxepunk.HXP;
class Asteroid extends Entity { class Asteroid extends Entity {
public function new (x:Float, y:Float) { public function new (x:Float, y:Float) {
super(x, y); super(x, y);
var file = ''; var file = '';
var tempRand = Math.floor(Math.random() * sprites.length); var tempRand = Math.floor(Math.random() * sprites.length);
file += spritesTypes[Math.floor(Math.random() * 2)]; file += spritesTypes[Math.floor(Math.random() * 2)];
file += sprites[tempRand][Math.floor(Math.random() * sprites[tempRand].length)]; file += sprites[tempRand][Math.floor(Math.random() * sprites[tempRand].length)];
side = Math.random() * 1; side = Math.random() * 1;
angleSpeed = Math.random() * 3; angleSpeed = Math.random() * 3;
speed = (Math.random() * 2) + 9; speed = (Math.random() * 2) + 9;
sprite = new Image("graphics/" + file); sprite = new Image("graphics/" + file);
graphic = sprite; graphic = sprite;
setHitbox(sprite.width - 15, sprite.height); setHitbox(sprite.width - 15, sprite.height);
sprite.centerOrigin(); sprite.centerOrigin();
type = "asteroid"; type = "asteroid";
layer = -2; layer = -2;
} }
public override function update() { public override function update() {
this.y += speed; this.y += speed;
if (this.y > HXP.height) { if (this.y > HXP.height) {
this.scene.remove(this); this.scene.remove(this);
} }
this.centerOrigin(); this.centerOrigin();
sprite.centerOrigin(); sprite.centerOrigin();
if (side > .5) if (side > .5)
this.sprite.angle += angleSpeed; this.sprite.angle += angleSpeed;
else else
this.sprite.angle -= angleSpeed; this.sprite.angle -= angleSpeed;
super.update(); super.update();
} }
private var spritesTypes:Array<String> = [ private var spritesTypes:Array<String> = [
"meteorBrown_", "meteorBrown_",
"meteorGrey_" "meteorGrey_"
]; ];
private var sprites:Array<Array<String>> = [ private var sprites:Array<Array<String>> = [
[ [
"med1.png", "med1.png",
"med2.png" "med2.png"
], ],
[ [
"big1.png", "big1.png",
"big2.png", "big2.png",
"big3.png", "big3.png",
"big4.png" "big4.png"
], ],
[ [
"small1.png", "small1.png",
"small2.png" "small2.png"
] ]
]; ];
private var sprite:Image; private var sprite:Image;
private var side:Float; private var side:Float;
private var angleSpeed:Float; private var angleSpeed:Float;
private var speed:Float; private var speed:Float;
} }

View file

@ -1,111 +1,121 @@
import com.haxepunk.Entity; import com.haxepunk.Entity;
import com.haxepunk.graphics.Image; import com.haxepunk.graphics.Image;
import com.haxepunk.masks.Circle; import com.haxepunk.masks.Circle;
import com.haxepunk.masks.Hitbox; import com.haxepunk.masks.Hitbox;
import com.haxepunk.HXP; import com.haxepunk.HXP;
import Enemy; import Enemy;
import Explosion; import Explosion;
import Spawner;
class Boss extends Entity {
class Boss extends Entity {
public function new (clr:Int) {
public function new (clr:Int) {
color = clr;
currentSprite = sprites[color]; color = clr;
currentSprite.scale = 8; currentSprite = sprites[color];
currentSprite.smooth = false; currentSprite.scale = 8;
currentSprite.smooth = false;
maxEnemies = Math.floor(Math.random() * (color + 1) * 2);
maxEnemies = Math.floor((color + 1) * 2);
graphic = currentSprite;
graphic = currentSprite;
super(HXP.halfWidth - (currentSprite.width * 4), currentSprite.height * -8);
super(HXP.halfWidth - (currentSprite.width * 4), currentSprite.height * -8);
this.mask = new Circle(currentSprite.width * 4);
this.mask = new Circle(currentSprite.width * 4);
layer = -3;
layer = -3;
healthBarBackground = Image.createRect(350, 20, 0xFF0000);
healthBarBackground = Image.createRect(350, 20, 0xFF0000);
health = originalHealth = (color + 1) * 50;
healthBar = Image.createRect(350, 20, 0x00FF00); health = originalHealth = (color + 1) * 50;
healthBar = Image.createRect(350, 20, 0x00FF00);
this.addGraphic(healthBarBackground);
this.addGraphic(healthBar); this.addGraphic(healthBarBackground);
this.addGraphic(healthBar);
healthBarBackground.centerOrigin();
healthBar.centerOrigin(); healthBarBackground.centerOrigin();
healthBar.centerOrigin();
healthBarBackground.x = healthBar.x = this.width / 2;
healthBarBackground.y = healthBar.y = this.height - 100; healthBarBackground.x = healthBar.x = this.width / 2;
healthBarBackground.y = healthBar.y = this.height - 100;
}
}
public override function update() {
super.update(); public override function update() {
spawnTimer -= HXP.elapsed; super.update();
explosionTimer -= HXP.elapsed; spawnTimer -= HXP.elapsed;
explosionTimer -= HXP.elapsed;
var enemies:Array<Enemy> = [];
this.scene.getClass(Enemy, enemies); var enemies:Array<Enemy> = [];
this.scene.getClass(Enemy, enemies);
if (spawnTimer < 0 && enemies.length != maxEnemies - 1 && canSpawn) {
this.scene.add(new Enemy(this.width / 2, 20, color, Math.floor(Math.random() * 4) + 1)); trace(enemies.length + ", " + maxEnemies);
spawnTimer = .75;
} if (spawnTimer < 0 && enemies.length != maxEnemies && canSpawn) {
this.scene.add(new Enemy(this.width / 2, 20, color, Math.floor(Math.random() * 4) + 1));
enemies = null; spawnTimer = .75;
}
if (this.y < currentSprite.height * 8 * -.5)
this.y += 2; enemies = null;
else if (!dead)
canSpawn = true; if (this.y < currentSprite.height * 8 * -.5)
this.y += 2;
if (health > 0) healthBar.scaledWidth = (healthBar.width / originalHealth) * health; else if (!dead)
else { canSpawn = true;
dead = true;
canSpawn = false; if (health > 0) healthBar.scaledWidth = (healthBar.width / originalHealth) * health;
else {
if (explosionTimer < 0 && counter != 100) { dead = true;
healthBarBackground.alpha = healthBar.alpha = currentSprite.alpha -= 0.01; canSpawn = false;
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; if (explosionTimer < 0 && counter != 100) {
counter++; 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")));
else if (counter == 100) { explosionTimer = Math.random() * .2;
this.scene.remove(this); counter++;
} var spawner:Array<Spawner> = [];
} this.scene.getClass(Spawner, spawner);
spawner[0].sublevel = 3;
var bullet:Entity = this.collide("bullet", this.x, this.y); }
else if (counter == 100) {
if (bullet != null) { var spawner:Array<Spawner> = [];
this.health -= 1; this.scene.getClass(Spawner, spawner);
this.scene.remove(bullet); spawner[0].bossSpawned = false;
}
} this.scene.remove(this);
}
private var currentSprite:Image; }
private var sprites:Array<Image> = [ var bullet:Entity = this.collide("bullet", this.x, this.y);
new Image("graphics/ufoGreen.png"),
new Image("graphics/ufoBlue.png"), if (bullet != null) {
new Image("graphics/ufoRed.png"), this.health -= 1;
new Image("graphics/ufoYellow.png") this.scene.remove(bullet);
]; }
}
private var color:Int;
private var health:Int; private var currentSprite:Image;
private var originalHealth:Int;
private var healthBar:Image; private var sprites:Array<Image> = [
private var healthBarBackground:Image; new Image("graphics/ufoGreen.png"),
new Image("graphics/ufoBlue.png"),
private var maxEnemies:Int; new Image("graphics/ufoRed.png"),
private var canSpawn:Bool = false; new Image("graphics/ufoYellow.png")
private var spawnTimer:Float = .75; ];
private var explosionTimer:Float = 0;
private var counter:Int = 0; private var color:Int;
private var dead:Bool = false; 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;
} }

View file

@ -1,45 +1,45 @@
import com.haxepunk.Entity; import com.haxepunk.Entity;
import com.haxepunk.graphics.Image; import com.haxepunk.graphics.Image;
import com.haxepunk.HXP; import com.haxepunk.HXP;
class Bullet extends Entity { class Bullet extends Entity {
public function new(x:Float, y:Float) { public function new(x:Float, y:Float) {
super(x, y); super(x, y);
laser1 = new Image("graphics/laserGreen09.png"); laser1 = new Image("graphics/laserGreen09.png");
laser2 = new Image("graphics/laserGreen13.png"); laser2 = new Image("graphics/laserGreen13.png");
graphic = laser1; graphic = laser1;
setHitbox(9, 37); setHitbox(9, 37);
type = "bullet"; type = "bullet";
} }
public override function update() { public override function update() {
super.update(); super.update();
this.y -= 20; this.y -= 20;
timer -= HXP.elapsed; timer -= HXP.elapsed;
if (collide("asteroid", this.x, this.y) != null) { if (collide("asteroid", this.x, this.y) != null) {
this.scene.remove(this); this.scene.remove(this);
} }
if (timer < 0 || this.y < 200) { if (timer < 0 || this.y < 200) {
graphic = laser2; graphic = laser2;
} }
if (this.y < 0) { if (this.y < 0) {
this.scene.remove(this); this.scene.remove(this);
} }
} }
private var laser1:Image; private var laser1:Image;
private var laser2:Image; private var laser2:Image;
private var timer:Float = .5; private var timer:Float = .5;
} }

View file

@ -1,38 +1,38 @@
import com.haxepunk.Entity; import com.haxepunk.Entity;
import com.haxepunk.graphics.Image; import com.haxepunk.graphics.Image;
import com.haxepunk.utils.Input; import com.haxepunk.utils.Input;
import com.haxepunk.utils.Touch; import com.haxepunk.utils.Touch;
import com.haxepunk.HXP; import com.haxepunk.HXP;
import Player; import Player;
class Button extends Entity { class Button extends Entity {
public function new() { public function new() {
super(10, HXP.height - (this.height + 60 * 2)); super(10, HXP.height - (this.height + 60 * 2));
sprite = new Image("graphics/laserRed08.png"); sprite = new Image("graphics/laserRed08.png");
sprite.scale = 2; sprite.scale = 2;
graphic = sprite; graphic = sprite;
setHitbox(sprite.width * 2, sprite.height * 2); setHitbox(sprite.width * 2, sprite.height * 2);
layer = -3; layer = -3;
} }
public override function update() { public override function update() {
Input.touchPoints(onTouch); Input.touchPoints(onTouch);
} }
private function onTouch(touch:Touch) { private function onTouch(touch:Touch) {
if ((touch.x > this.x && touch.x < this.x + this.width) && (touch.y > this.y && touch.y < this.y + this.height)) { if ((touch.x > this.x && touch.x < this.x + this.width) && (touch.y > this.y && touch.y < this.y + this.height)) {
if (touch.pressed) { if (touch.pressed) {
var players:Array<Player> = []; var players:Array<Player> = [];
this.scene.getClass(Player, players); this.scene.getClass(Player, players);
players[0].shoot(); players[0].shoot();
} }
} }
} }
private var sprite:Image; private var sprite:Image;
} }

View file

@ -1,190 +1,190 @@
import com.haxepunk.Entity; import com.haxepunk.Entity;
import com.haxepunk.graphics.Image; import com.haxepunk.graphics.Image;
import com.haxepunk.HXP; import com.haxepunk.HXP;
import com.haxepunk.Sfx; import com.haxepunk.Sfx;
import Player; import Player;
import Score; import Score;
import EnemyBullet; import EnemyBullet;
class Enemy extends Entity { class Enemy extends Entity {
public function new (x:Float, y:Float, clr:Int, eT:Int) { public function new (x:Float, y:Float, clr:Int, eT:Int) {
super(x, y); super(x, y);
color = clr; color = clr;
enemyType = eT; enemyType = eT;
#if flash #if flash
bulletSound = new Sfx("audio/laser3.mp3"); bulletSound = new Sfx("audio/laser3.mp3");
#else #else
bulletSound = new Sfx("audio/laser3.wav"); bulletSound = new Sfx("audio/laser3.wav");
#end #end
sprite = new Image("graphics/" + enemies[color] + enemyType + ".png"); sprite = new Image("graphics/" + enemies[color] + enemyType + ".png");
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 + 1)); originalHealth = health = (enemyType * 2 * (color + 1));
sprite.centerOrigin(); sprite.centerOrigin();
healthSprite.centerOrigin(); healthSprite.centerOrigin();
addGraphic(sprite); addGraphic(sprite);
addGraphic(healthSprite); addGraphic(healthSprite);
setHitbox(sprite.width, sprite.height); setHitbox(sprite.width, sprite.height);
layer = -4; layer = -4;
} }
private function assignLocation() { private function assignLocation() {
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() * 200) + 350) Math.floor((Math.random() * 200) + 350)
]; ];
} }
else if (enemyType >= 3 && enemyType <= 4) { else if (enemyType >= 3 && enemyType <= 4) {
var player:Array<Player> = []; var player:Array<Player> = [];
this.scene.getClass(Player, player); this.scene.getClass(Player, player);
if (Math.random() * 1 > .5) if (Math.random() * 1 > .5)
antX = player[0].x; antX = player[0].x;
else else
antX = Math.random() * HXP.width; antX = Math.random() * HXP.width;
arr = [ arr = [
antX, antX,
(Math.random() * 200) + 350 (Math.random() * 200) + 350
]; ];
} }
else { else {
var player:Array<Player> = []; var player:Array<Player> = [];
this.scene.getClass(Player, player); this.scene.getClass(Player, player);
if (Math.random() * 1 > .5) if (Math.random() * 1 > .5)
antX = player[0].x; antX = player[0].x;
else else
antX = Math.random() * HXP.width; antX = Math.random() * HXP.width;
if (Math.random() * 1 > .5) if (Math.random() * 1 > .5)
antX -= this.width; antX -= this.width;
else else
antX += this.width; antX += this.width;
arr = [ arr = [
antX, antX,
(Math.random() * 200) + 350 (Math.random() * 200) + 350
]; ];
} }
return arr; return arr;
} }
private function shoot() { private function shoot() {
if (shootTimer < 0) { if (shootTimer < 0) {
if (enemyType != 3) { if (enemyType != 3) {
this.scene.add(new EnemyBullet(this.x, this.y + this.height)); this.scene.add(new EnemyBullet(this.x, this.y + this.height));
} }
else { else {
this.scene.add(new EnemyBullet(this.x - 30, this.y + this.height)); this.scene.add(new EnemyBullet(this.x - 30, this.y + this.height));
this.scene.add(new EnemyBullet(this.x + 30, this.y + this.height)); this.scene.add(new EnemyBullet(this.x + 30, this.y + this.height));
} }
if (enemyType == 4) { if (enemyType == 4) {
shootTimer = 1; shootTimer = 1;
} }
else { else {
shootTimer = 5; shootTimer = 5;
} }
bulletSound.play(); bulletSound.play();
} }
} }
public override function update() { public override function update() {
turnTimer -= HXP.elapsed; turnTimer -= HXP.elapsed;
shootTimer -= HXP.elapsed; shootTimer -= HXP.elapsed;
this.centerOrigin(); this.centerOrigin();
healthSprite.scaledWidth = (sprite.width / originalHealth) * health; healthSprite.scaledWidth = (sprite.width / originalHealth) * health;
if (this.x != loc[0] && this.y != loc[1] && !dying) if (this.x != loc[0] && this.y != loc[1] && !dying)
this.moveTowards(loc[0], loc[1], moveSpeed); this.moveTowards(loc[0], loc[1], moveSpeed);
if (turnTimer < 0) { if (turnTimer < 0) {
loc = assignLocation(); loc = assignLocation();
if (enemyType == 2) if (enemyType == 2)
turnTimer = 2; turnTimer = 2;
else if (enemyType == 3 || enemyType == 4) else if (enemyType == 3 || enemyType == 4)
turnTimer = 1; turnTimer = 1;
else if (enemyType == 1 || enemyType == 5) else if (enemyType == 1 || enemyType == 5)
turnTimer = .5; turnTimer = .5;
} }
if (enemyType > 2) { if (enemyType > 2) {
if (Math.random() < .1 && shootTimer < 0) { if (Math.random() < .1 && shootTimer < 0) {
var player = this.scene.getInstance("player"); var player = this.scene.getInstance("player");
if (this.x > player.left && this.x < player.right) { if (this.x > player.left && this.x < player.right) {
turnTimer = 1; turnTimer = 1;
loc = [this.x, this.y]; loc = [this.x, this.y];
shoot(); shoot();
} }
} }
} }
var bullet:Entity = collide("bullet", this.x, this.y); var bullet:Entity = collide("bullet", this.x, this.y);
if (bullet != null) { if (bullet != null) {
health -= 1; health -= 1;
var score:Array<Score> = []; var score:Array<Score> = [];
this.scene.getClass(Score, score); this.scene.getClass(Score, score);
score[0].add(1500); score[0].add(1500);
this.scene.remove(bullet); this.scene.remove(bullet);
} }
if (health == 0) { if (health == 0) {
die(); die();
} }
} }
private function die() { private function die() {
if (!died) { if (!died) {
dying = true; dying = true;
died = true; died = true;
this.visible = false; this.visible = false;
this.scene.add(new Explosion(this.x, this.y, this)); this.scene.add(new Explosion(this.x, this.y, this));
} }
} }
private var enemies:Array<String> = [ private var enemies:Array<String> = [
"enemyGreen", "enemyGreen",
"enemyBlue", "enemyBlue",
"enemyRed", "enemyRed",
"enemyBlack" "enemyBlack"
]; ];
private var sprite:Image; private var sprite:Image;
private var healthSprite:Image; private var healthSprite:Image;
private var bulletSound:Sfx; private var bulletSound:Sfx;
private var color:Int; private var color:Int;
private var enemyType:Int; private var enemyType:Int;
private var health:Int; private var health:Int;
private var originalHealth:Int; private var originalHealth:Int;
private var dying:Bool = false; private var dying:Bool = false;
private var died:Bool = false; private var died:Bool = false;
private var arr:Array<Float>; private var arr:Array<Float>;
private var antX:Float; private var antX:Float;
private var turnTimer:Float = 0; private var turnTimer:Float = 0;
private var shootTimer:Float = 0; private var shootTimer:Float = 0;
private var moveSpeed:Int = 10; private var moveSpeed:Int = 10;
private var loc:Array<Float> = []; private var loc:Array<Float> = [];
} }

View file

@ -1,46 +1,46 @@
import com.haxepunk.Entity; import com.haxepunk.Entity;
import com.haxepunk.graphics.Image; import com.haxepunk.graphics.Image;
import com.haxepunk.HXP; import com.haxepunk.HXP;
class EnemyBullet extends Entity { class EnemyBullet extends Entity {
public function new (x:Float, y:Float) { public function new (x:Float, y:Float) {
super(x, y); super(x, y);
sprite = [ sprite = [
new Image("graphics/laserRed14.png"), new Image("graphics/laserRed14.png"),
new Image("graphics/laserRed16.png") new Image("graphics/laserRed16.png")
]; ];
for (i in 0...sprite.length) { for (i in 0...sprite.length) {
sprite[i].angle = 180; sprite[i].angle = 180;
sprite[i].centerOrigin(); sprite[i].centerOrigin();
} }
setHitboxTo(sprite[0]); setHitboxTo(sprite[0]);
graphic = sprite[0]; graphic = sprite[0];
type = "enemybullet"; type = "enemybullet";
} }
public override function update() { public override function update() {
super.update(); super.update();
timer -= HXP.elapsed; timer -= HXP.elapsed;
this.centerOrigin(); this.centerOrigin();
this.y += 10; this.y += 10;
if (timer < 0) { if (timer < 0) {
graphic = sprite[1]; graphic = sprite[1];
} }
if (this.y > HXP.height) { if (this.y > HXP.height) {
this.scene.remove(this); this.scene.remove(this);
} }
} }
private var sprite:Array<Image>; private var sprite:Array<Image>;
private var timer:Float = .5; private var timer:Float = .5;
} }

View file

@ -1,33 +1,33 @@
import com.haxepunk.Entity; import com.haxepunk.Entity;
import com.haxepunk.graphics.Spritemap; import com.haxepunk.graphics.Spritemap;
class Explosion extends Entity { class Explosion extends Entity {
public function new (x:Float, y:Float, e:Entity) { public function new (x:Float, y:Float, e:Entity) {
super(x, y); super(x, y);
entity = e; entity = e;
sprite = new Spritemap("graphics/explosion.png", 49, 49, die); sprite = new Spritemap("graphics/explosion.png", 49, 49, die);
sprite.add("explosion", [0,1,2,3,4,5], 10); sprite.add("explosion", [0,1,2,3,4,5], 10);
sprite.scale = 3; sprite.scale = 3;
graphic = sprite; graphic = sprite;
sprite.play("explosion"); sprite.play("explosion");
this.centerOrigin(); this.centerOrigin();
sprite.centerOrigin(); sprite.centerOrigin();
layer = -4; layer = -4;
} }
private function die () { private function die () {
this.scene.remove(this); this.scene.remove(this);
if (entity.type != "player") if (entity.type != "player")
this.scene.remove(entity); this.scene.remove(entity);
} }
private var sprite:Spritemap; private var sprite:Spritemap;
private var entity:Entity; private var entity:Entity;
} }

View file

@ -1,66 +1,66 @@
import com.haxepunk.Entity; import com.haxepunk.Entity;
import com.haxepunk.graphics.Image; import com.haxepunk.graphics.Image;
import com.haxepunk.HXP; import com.haxepunk.HXP;
import Player; import Player;
class Lives extends Entity { class Lives extends Entity {
public function new () { public function new () {
baseSprite = new Image("graphics/playerShip1_green.png"); baseSprite = new Image("graphics/playerShip1_green.png");
sprite = [ sprite = [
baseSprite, baseSprite,
new Image("graphics/playerShip1_damage1.png"), new Image("graphics/playerShip1_damage1.png"),
new Image("graphics/playerShip1_damage2.png"), new Image("graphics/playerShip1_damage2.png"),
new Image("graphics/playerShip1_damage3.png") new Image("graphics/playerShip1_damage3.png")
]; ];
liveBar = Image.createRect(Math.floor(baseSprite.width * .75), 10, 0x00FF00); liveBar = Image.createRect(Math.floor(baseSprite.width * .75), 10, 0x00FF00);
liveBar.y += 65; liveBar.y += 65;
baseSprite.scale = .75; baseSprite.scale = .75;
for (i in 0...sprite.length) { for (i in 0...sprite.length) {
sprite[i].scale = .75; sprite[i].scale = .75;
} }
super(HXP.width - (baseSprite.width * .75 + 20), 10); super(HXP.width - (baseSprite.width * .75 + 20), 10);
graphic = baseSprite; graphic = baseSprite;
this.addGraphic(sprite[0]); this.addGraphic(sprite[0]);
this.addGraphic(liveBar); this.addGraphic(liveBar);
damage = 0; damage = 0;
layer = -4; layer = -4;
} }
public inline function addDamage() {damage++;} public inline function addDamage() {damage++;}
public inline function remDamage() {if (damage != 0) damage--;} public inline function remDamage() {if (damage != 0) damage--;}
public override function update() { public override function update() {
graphic = baseSprite; graphic = baseSprite;
this.addGraphic(sprite[damage]); this.addGraphic(sprite[damage]);
liveBar.scaledWidth = (liveBar.width / 4) * (4 - damage); liveBar.scaledWidth = (liveBar.width / 4) * (4 - damage);
this.addGraphic(liveBar); this.addGraphic(liveBar);
if (damage > 3) { if (damage > 3) {
var player:Array<Player> = []; var player:Array<Player> = [];
this.scene.getClass(Player, player); this.scene.getClass(Player, player);
player[0].die(); player[0].die();
damage = 0; damage = 0;
} }
super.update(); super.update();
} }
private var sprite:Array<Image> = []; private var sprite:Array<Image> = [];
private var baseSprite:Image; private var baseSprite:Image;
private var liveBar:Image; private var liveBar:Image;
private var damage:Int; private var damage:Int;
} }

View file

@ -1,24 +1,24 @@
import com.haxepunk.Engine; import com.haxepunk.Engine;
import com.haxepunk.HXP; import com.haxepunk.HXP;
class Main extends Engine class Main extends Engine
{ {
override public function init() override public function init()
{ {
#if debug #if debug
HXP.console.enable(); HXP.console.enable();
#end #end
#if !android #if !android
HXP.screen.scale = .5; HXP.screen.scale = .5;
HXP.resize(360, 640); HXP.resize(360, 640);
#end #end
// HXP.scene = new MainScene(); // HXP.scene = new MainScene();
HXP.scene = new MenuScene(); HXP.scene = new MenuScene();
} }
public static function main() { new Main(); } public static function main() { new Main(); }
} }

View file

@ -1,57 +1,57 @@
import com.haxepunk.Scene; import com.haxepunk.Scene;
import com.haxepunk.HXP; import com.haxepunk.HXP;
import com.haxepunk.graphics.Backdrop; import com.haxepunk.graphics.Backdrop;
import com.haxepunk.Sfx; import com.haxepunk.Sfx;
import Spawner; import Spawner;
import Player; import Player;
import Button; import Button;
import Enemy; import Enemy;
import Lives; import Lives;
import Score; import Score;
class MainScene extends Scene class MainScene extends Scene
{ {
public override function begin() public override function begin()
{ {
backdrop = new Backdrop("graphics/darkPurple.png", true, true); backdrop = new Backdrop("graphics/darkPurple.png", true, true);
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 lives = new Lives(); var lives = new Lives();
var score = new Score(); var score = new Score();
#if flash #if flash
music = new Sfx("audio/loop.mp3"); music = new Sfx("audio/loop.mp3");
#else #else
music = new Sfx("audio/loop.wav"); music = new Sfx("audio/loop.wav");
#end #end
addGraphic(backdrop); addGraphic(backdrop);
#if (android || ios) #if (android || ios)
add(button); add(button);
#end #end
add(player); add(player);
add(lives); add(lives);
add(score); add(score);
add(spawner); add(spawner);
music.play(.1, 0, true); music.play(.1, 0, true);
} }
public override function end() { public override function end() {
this.removeAll(); this.removeAll();
music.stop(); music.stop();
this.update(); this.update();
} }
public override function update() { public override function update() {
super.update(); super.update();
backdrop.y += 1; backdrop.y += 1;
} }
private var backdrop:Backdrop; private var backdrop:Backdrop;
private var music:Sfx; private var music:Sfx;
} }

View file

@ -1,86 +1,92 @@
import com.haxepunk.Entity; import com.haxepunk.Entity;
import com.haxepunk.graphics.Image; import com.haxepunk.graphics.Image;
import com.haxepunk.graphics.Text; import com.haxepunk.graphics.Text;
import com.haxepunk.HXP; import com.haxepunk.HXP;
import com.haxepunk.utils.Input; import com.haxepunk.utils.Input;
import com.haxepunk.utils.Touch; import com.haxepunk.utils.Touch;
import com.haxepunk.utils.Key; import com.haxepunk.utils.Key;
import openfl.Assets; import openfl.Assets;
import MainScene; import MainScene;
import MenuScene; import MenuScene;
class MenuButton extends Entity { class MenuButton extends Entity {
public function new (x:Float, y:Float, txt:String) { public function new (x:Float, y:Float, txt:String) {
super(x, y); super(x, y);
sprite = new Image("graphics/buttonGreen.png"); sprite = new Image("graphics/buttonGreen.png");
sprite.scale = 2; sprite.scale = 2;
setHitbox(sprite.width * 2, sprite.height * 2); setHitbox(sprite.width * 2, sprite.height * 2);
text = new Text(txt); text = new Text(txt);
text.color = 0x000000; text.color = 0x000000;
text.size = 40; text.size = 40;
text.font = Assets.getFont("font/kenpixel_mini_square.ttf").fontName; text.font = Assets.getFont("font/kenpixel_mini_square.ttf").fontName;
text.centerOrigin(); text.centerOrigin();
sprite.centerOrigin(); sprite.centerOrigin();
this.centerOrigin(); this.centerOrigin();
this.addGraphic(sprite); this.addGraphic(sprite);
this.addGraphic(text); this.addGraphic(text);
this.layer = -5; this.layer = -5;
Input.define("enter", [Key.ENTER, Key.SPACE]); Input.define("enter", [Key.ENTER, Key.SPACE]);
} }
public override function update() { public override function update() {
Input.touchPoints(onTouch); Input.touchPoints(onTouch);
if (Input.mouseReleased) { if (Input.mouseReleased) {
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;
HXP.scene = new MainScene(); Assets.cache.clear();
} HXP.scene = new MainScene();
else { }
HXP.scene = null; else {
HXP.scene = new MenuScene(); HXP.scene = null;
} Assets.cache.clear();
} HXP.scene = new MenuScene();
} }
}
if (Input.check("enter")) { }
if (this.text.text != "Menu") {
HXP.scene = null; if (Input.check("enter")) {
HXP.scene = new MainScene(); if (this.text.text != "Menu") {
} HXP.scene = null;
else { Assets.cache.clear();
HXP.scene = null; HXP.scene = new MainScene();
HXP.scene = new MenuScene(); }
} else {
} HXP.scene = null;
} Assets.cache.clear();
HXP.scene = new MenuScene();
private function onTouch(touch:Touch) { }
if ((touch.x > this.left && touch.x < this.right) && (touch.y > this.top && touch.y < this.bottom)) { }
if (this.text.text != "Menu") { }
HXP.scene = null;
HXP.scene = new MainScene(); private function onTouch(touch:Touch) {
} if ((touch.x > this.left && touch.x < this.right) && (touch.y > this.top && touch.y < this.bottom)) {
else { if (this.text.text != "Menu") {
HXP.scene = null; HXP.scene = null;
HXP.scene = new MenuScene(); Assets.cache.clear();
} HXP.scene = new MainScene();
} }
} else {
HXP.scene = null;
private var txt:String; Assets.cache.clear();
private var sprite:Image; HXP.scene = new MenuScene();
private var text:Text; }
}
}
private var txt:String;
private var sprite:Image;
private var text:Text;
} }

View file

@ -1,45 +1,45 @@
import com.haxepunk.Scene; import com.haxepunk.Scene;
import com.haxepunk.HXP; import com.haxepunk.HXP;
import com.haxepunk.graphics.Text; import com.haxepunk.graphics.Text;
import com.haxepunk.graphics.Backdrop; import com.haxepunk.graphics.Backdrop;
import openfl.Assets; import openfl.Assets;
import MenuButton; import MenuButton;
import Title; import Title;
import Spawner; import Spawner;
import MainScene; import MainScene;
class MenuScene extends Scene { class MenuScene extends Scene {
public override function begin() { public override function begin() {
backdrop = new Backdrop("graphics/darkPurple.png", true, true); backdrop = new Backdrop("graphics/darkPurple.png", true, true);
var play = new MenuButton(HXP.width / 2, HXP.height / 2, "Play!"); var play = new MenuButton(HXP.width / 2, HXP.height / 2, "Play!");
var title = new Title(); var title = new Title();
var copy = new Text("By Bram \"96AA48\" van der Veen, 2014\nGraphics and Sfx by Kenney\nMusic by Jensan", HXP.width / 2, HXP.height - 50, {align: "center"}); var copy = new Text("By Bram \"96AA48\" van der Veen, 2014\nGraphics and Sfx by Kenney\nMusic by Jensan", HXP.width / 2, HXP.height - 50, {align: "center"});
var spawner = new Spawner(); var spawner = new Spawner();
copy.size = 22; copy.size = 22;
copy.font = Assets.getFont("font/kenpixel_mini_square.ttf").fontName; copy.font = Assets.getFont("font/kenpixel_mini_square.ttf").fontName;
copy.centerOrigin(); copy.centerOrigin();
addGraphic(backdrop); addGraphic(backdrop);
add(spawner); add(spawner);
add(title); add(title);
add(play); add(play);
addGraphic(copy); addGraphic(copy);
} }
public override function end() { public override function end() {
this.removeAll(); this.removeAll();
update(); update();
} }
public override function update() { public override function update() {
super.update(); super.update();
backdrop.y += 1; backdrop.y += 1;
} }
private var backdrop:Backdrop; private var backdrop:Backdrop;
} }

View file

@ -1,108 +1,108 @@
import com.haxepunk.Entity; import com.haxepunk.Entity;
import com.haxepunk.graphics.Image; import com.haxepunk.graphics.Image;
import com.haxepunk.HXP; import com.haxepunk.HXP;
import com.haxepunk.Sfx; import com.haxepunk.Sfx;
import Score; import Score;
import Lives; import Lives;
class Pickup extends Entity { class Pickup extends Entity {
public function new (x:Float, y:Float) { public function new (x:Float, y:Float) {
super(x, y); super(x, y);
#if flash #if flash
sound = new Sfx("audio/powerUp6.mp3"); sound = new Sfx("audio/powerUp6.mp3");
#else #else
sound = new Sfx("audio/powerUp6.wav"); sound = new Sfx("audio/powerUp6.wav");
#end #end
var tempRand = Math.random(); var tempRand = Math.random();
if (tempRand < .15) if (tempRand < .15)
randType = 1; randType = 1;
else if (tempRand > .15 && tempRand < .80) else if (tempRand > .15 && tempRand < .80)
randType = 2; randType = 2;
else else
randType = 0; randType = 0;
rand = Math.floor(Math.random() * 3); rand = Math.floor(Math.random() * 3);
graphic = currentSprite = sprites[randType][rand]; graphic = currentSprite = sprites[randType][rand];
if (Math.random() > .5) if (Math.random() > .5)
turnSpeed = -1 * (Math.random() * 4); turnSpeed = -1 * (Math.random() * 4);
else else
turnSpeed = 1 * (Math.random() * 4); turnSpeed = 1 * (Math.random() * 4);
setHitboxTo(currentSprite); setHitboxTo(currentSprite);
} }
public override function update () { public override function update () {
this.y += (Math.random() * 3) + 6; this.y += (Math.random() * 3) + 6;
this.centerOrigin(); this.centerOrigin();
currentSprite.centerOrigin(); currentSprite.centerOrigin();
currentSprite.angle += turnSpeed; currentSprite.angle += turnSpeed;
if (this.y > HXP.height) { if (this.y > HXP.height) {
this.scene.remove(this); this.scene.remove(this);
} }
if (collide("player", this.x, this.y) != null) { if (collide("player", this.x, this.y) != null) {
var score:Array<Score> = []; var score:Array<Score> = [];
this.scene.getClass(Score, score); this.scene.getClass(Score, score);
//Shield pickup //Shield pickup
if (this.randType == 0) { if (this.randType == 0) {
var player:Array<Player> = []; var player:Array<Player> = [];
this.scene.getClass(Player, player); this.scene.getClass(Player, player);
player[0].shielded = true; player[0].shielded = true;
player[0].shieldTimer = (rand + 1) * 3; player[0].shieldTimer = (rand + 1) * 3;
} }
//"things" pickup //"things" pickup
else if (this.randType == 1) { else if (this.randType == 1) {
var lives:Array<Lives> = []; var lives:Array<Lives> = [];
this.scene.getClass(Lives, lives); this.scene.getClass(Lives, lives);
for(i in 0...rand + 1) for(i in 0...rand + 1)
lives[0].remDamage(); lives[0].remDamage();
} }
//Money pickup //Money pickup
else if (this.randType == 2) { else if (this.randType == 2) {
score[0].add(1000 * this.randType); score[0].add(1000 * this.randType);
} }
sound.play(); sound.play();
this.scene.remove(this); this.scene.remove(this);
} }
} }
private var sprites:Array<Array<Image>> = [ private var sprites:Array<Array<Image>> = [
[ [
new Image("graphics/shield_bronze.png"), new Image("graphics/shield_bronze.png"),
new Image("graphics/shield_silver.png"), new Image("graphics/shield_silver.png"),
new Image("graphics/shield_gold.png") new Image("graphics/shield_gold.png")
], ],
[ [
new Image("graphics/things_bronze.png"), new Image("graphics/things_bronze.png"),
new Image("graphics/things_silver.png"), new Image("graphics/things_silver.png"),
new Image("graphics/things_gold.png") new Image("graphics/things_gold.png")
], ],
[ [
new Image("graphics/star_bronze.png"), new Image("graphics/star_bronze.png"),
new Image("graphics/star_silver.png"), new Image("graphics/star_silver.png"),
new Image("graphics/star_gold.png") new Image("graphics/star_gold.png")
] ]
]; ];
private var turnSpeed:Float; private var turnSpeed:Float;
private var currentSprite:Image; private var currentSprite:Image;
private var sound:Sfx; private var sound:Sfx;
private var rand:Int; private var rand:Int;
private var randType:Int; private var randType:Int;
} }

View file

@ -1,200 +1,200 @@
import com.haxepunk.Entity; import com.haxepunk.Entity;
import com.haxepunk.graphics.Image; import com.haxepunk.graphics.Image;
import com.haxepunk.utils.Key; import com.haxepunk.utils.Key;
import com.haxepunk.utils.Input; import com.haxepunk.utils.Input;
import com.haxepunk.HXP; import com.haxepunk.HXP;
import com.haxepunk.utils.Touch; import com.haxepunk.utils.Touch;
import com.haxepunk.graphics.Text; import com.haxepunk.graphics.Text;
import com.haxepunk.Sfx; import com.haxepunk.Sfx;
import openfl.Assets; import openfl.Assets;
import Bullet; import Bullet;
import Lives; import Lives;
import Score; import Score;
import Explosion; import Explosion;
class Player extends Entity { class Player extends Entity {
public function new() { public function new() {
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");
#if flash #if flash
laser = new Sfx("audio/laser4.mp3"); laser = new Sfx("audio/laser4.mp3");
#else #else
laser = new Sfx("audio/laser4.wav"); laser = new Sfx("audio/laser4.wav");
#end #end
graphic = baseSprite; graphic = baseSprite;
fireEffectsLeft = [ fireEffectsLeft = [
new Image("graphics/fire13.png"), new Image("graphics/fire13.png"),
new Image("graphics/fire16.png"), new Image("graphics/fire16.png"),
new Image("graphics/fire17.png"), new Image("graphics/fire17.png"),
]; ];
fireEffectsRight = [ fireEffectsRight = [
new Image("graphics/fire13.png"), new Image("graphics/fire13.png"),
new Image("graphics/fire16.png"), new Image("graphics/fire16.png"),
new Image("graphics/fire17.png"), new Image("graphics/fire17.png"),
]; ];
fireEffectLeft = fireEffectsLeft[currentAnim]; fireEffectLeft = fireEffectsLeft[currentAnim];
fireEffectLeft.x = -30; fireEffectLeft.x = -30;
fireEffectLeft.y = 24; fireEffectLeft.y = 24;
fireEffectRight = fireEffectsRight[currentAnim]; fireEffectRight = fireEffectsRight[currentAnim];
fireEffectRight.x = 19; fireEffectRight.x = 19;
fireEffectRight.y = 24; fireEffectRight.y = 24;
this.addGraphic(fireEffectLeft); this.addGraphic(fireEffectLeft);
this.addGraphic(fireEffectRight); this.addGraphic(fireEffectRight);
setHitbox(99, 75); setHitbox(99, 75);
Input.define("left", [Key.LEFT, Key.A]); Input.define("left", [Key.LEFT, Key.A]);
Input.define("right", [Key.RIGHT, Key.D]); Input.define("right", [Key.RIGHT, Key.D]);
Input.define("down", [Key.DOWN, Key.S]); Input.define("down", [Key.DOWN, Key.S]);
Input.define("up", [Key.UP, Key.W]); Input.define("up", [Key.UP, Key.W]);
Input.define("shoot", [Key.SPACE]); Input.define("shoot", [Key.SPACE]);
name = type = "player"; name = type = "player";
this.centerOrigin(); this.centerOrigin();
baseSprite.centerOrigin(); baseSprite.centerOrigin();
layer = -1; layer = -1;
} }
private function handleInput() { private function handleInput() {
if (Input.check("left") && this.left > 0) { if (Input.check("left") && this.left > 0) {
this.x -= moveSpeed; this.x -= moveSpeed;
} }
if (Input.check("right") && this.right < HXP.width) { if (Input.check("right") && this.right < HXP.width) {
this.x += moveSpeed; this.x += moveSpeed;
} }
if (Input.check("down") && this.bottom < HXP.height && this.bottom > 0) { if (Input.check("down") && this.bottom < HXP.height && this.bottom > 0) {
this.y += moveSpeed; this.y += moveSpeed;
} }
if (Input.check("up") && this.top > 700) { if (Input.check("up") && this.top > 700) {
this.y -= moveSpeed; this.y -= moveSpeed;
} }
if (Input.check("shoot")) { if (Input.pressed("shoot")) {
shoot(); shoot();
} }
Input.touchPoints(onTouch); Input.touchPoints(onTouch);
} }
private function onTouch(touch:Touch) { private function onTouch(touch:Touch) {
if (touch.y < HXP.height - 100 && (touch.y > 700) && this.y > 0) if (touch.y < HXP.height - 100 && (touch.y > 700) && this.y > 0)
this.moveTowards(touch.x - (this.width / 2), touch.y - (this.height * 2), moveSpeed * 1.5); this.moveTowards(touch.x - (this.width / 2), touch.y - (this.height * 2), moveSpeed * 1.5);
} }
public function shoot() { public function shoot() {
if (this.y > 0) { if (this.y > 0) {
var score:Array<Score> = []; var score:Array<Score> = [];
this.scene.getClass(Score, score); this.scene.getClass(Score, score);
score[0].rem(500); score[0].rem(500);
this.scene.add(new Bullet(this.x, this.y - this.height / 2)); this.scene.add(new Bullet(this.x, this.y - this.height / 2));
laser.play(); laser.play();
} }
} }
public function die() { public function die() {
this.visible = false; this.visible = false;
this.scene.add(new Explosion(this.x, this.y, this)); this.scene.add(new Explosion(this.x, this.y, this));
this.x = HXP.halfWidth; this.x = HXP.halfWidth;
this.y = -200; this.y = -200;
var txt:Text = new Text("You died!", HXP.halfWidth - 225, HXP.halfHeight - 250, 500, 50, {size: 100}); var txt:Text = new Text("You died!", HXP.halfWidth - 225, HXP.halfHeight - 250, 500, 50, {size: 100});
txt.font = Assets.getFont("font/kenpixel_mini_square.ttf").fontName; txt.font = Assets.getFont("font/kenpixel_mini_square.ttf").fontName;
this.scene.addGraphic(txt); this.scene.addGraphic(txt);
this.scene.add(new MenuButton(HXP.halfWidth, HXP.halfHeight - 50, "Retry?")); this.scene.add(new MenuButton(HXP.halfWidth, HXP.halfHeight - 50, "Retry?"));
this.scene.add(new MenuButton(HXP.halfWidth, HXP.halfHeight + 50, "Menu")); this.scene.add(new MenuButton(HXP.halfWidth, HXP.halfHeight + 50, "Menu"));
} }
public override function update() { public override function update() {
handleInput(); handleInput();
hitPause -= HXP.elapsed; hitPause -= HXP.elapsed;
animWait -= HXP.elapsed; animWait -= HXP.elapsed;
shieldTimer -= HXP.elapsed; shieldTimer -= HXP.elapsed;
if (shieldTimer < 0) if (shieldTimer < 0)
shielded = false; shielded = false;
if (animWait < 0) { if (animWait < 0) {
if (currentAnim == 3) if (currentAnim == 3)
currentAnim = 0; currentAnim = 0;
fireEffectLeft = fireEffectsLeft[currentAnim]; fireEffectLeft = fireEffectsLeft[currentAnim];
fireEffectLeft.x = -30; fireEffectLeft.x = -30;
fireEffectLeft.y = 24; fireEffectLeft.y = 24;
fireEffectRight = fireEffectsRight[currentAnim]; fireEffectRight = fireEffectsRight[currentAnim];
fireEffectRight.x = 19; fireEffectRight.x = 19;
fireEffectRight.y = 24; fireEffectRight.y = 24;
graphic = baseSprite; graphic = baseSprite;
this.addGraphic(fireEffectLeft); this.addGraphic(fireEffectLeft);
this.addGraphic(fireEffectRight); this.addGraphic(fireEffectRight);
shield.centerOrigin(); shield.centerOrigin();
if (shielded) if (shielded)
this.addGraphic(shield); this.addGraphic(shield);
currentAnim++; currentAnim++;
animWait = .75; animWait = .75;
} }
if ((hitPause > 0 && hitPause < .3) || (hitPause > .6 && hitPause < .9) || (hitPause > 1.2 && hitPause < 1.5)) { if ((hitPause > 0 && hitPause < .3) || (hitPause > .6 && hitPause < .9) || (hitPause > 1.2 && hitPause < 1.5)) {
this.visible = false; this.visible = false;
} }
else { else {
this.visible = true; this.visible = true;
} }
if (collide("asteroid", this.x, this.y) != null && hitPause < 0 && !shielded) { if (collide("asteroid", this.x, this.y) != null && hitPause < 0 && !shielded) {
var lives:Array<Lives> = []; var lives:Array<Lives> = [];
this.scene.getClass(Lives, lives); this.scene.getClass(Lives, lives);
lives[0].addDamage(); lives[0].addDamage();
hitPause = 1.5; hitPause = 1.5;
} }
if (collide("enemybullet", this.x, this.y) != null && hitPause < 0 && !shielded) { if (collide("enemybullet", this.x, this.y) != null && hitPause < 0 && !shielded) {
var lives:Array<Lives> = []; var lives:Array<Lives> = [];
this.scene.getClass(Lives, lives); this.scene.getClass(Lives, lives);
lives[0].addDamage(); lives[0].addDamage();
hitPause = 1.5; hitPause = 1.5;
} }
super.update(); super.update();
} }
private var baseSprite:Image; private var baseSprite:Image;
private var shield:Image; private var shield:Image;
private var laser:Sfx; private var laser:Sfx;
private var fireEffectsLeft:Array<Image> = []; private var fireEffectsLeft:Array<Image> = [];
private var fireEffectsRight:Array<Image> = []; private var fireEffectsRight:Array<Image> = [];
private var fireEffectLeft:Image; private var fireEffectLeft:Image;
private var fireEffectRight:Image; private var fireEffectRight:Image;
private var moveSpeed:Int = 7; private var moveSpeed:Int = 7;
private var hitPause:Float = 0; private var hitPause:Float = 0;
private var animWait:Float = .75; private var animWait:Float = .75;
private var currentAnim:Int = 0; private var currentAnim:Int = 0;
public var shielded:Bool = false; public var shielded:Bool = false;
public var shieldTimer:Float = 1; public var shieldTimer:Float = 1;
} }

View file

@ -1,48 +1,48 @@
import com.haxepunk.Entity; import com.haxepunk.Entity;
import com.haxepunk.HXP; import com.haxepunk.HXP;
import com.haxepunk.graphics.Text; import com.haxepunk.graphics.Text;
import openfl.Assets; import openfl.Assets;
class Score extends Entity { class Score extends Entity {
public function new() { public function new() {
super(HXP.halfWidth, 30); super(HXP.halfWidth, 30);
name = "score"; name = "score";
score = 1000; score = 1000;
scoreText = new Text("$1000", 0, 0, 0, 0, {size : 50, /*align : "center",*/ color : 0xFFF000}); scoreText = new Text("$1000", 0, 0, 0, 0, {size : 50, /*align : "center",*/ color : 0xFFF000});
scoreText.font = Assets.getFont("font/kenpixel_mini_square.ttf").fontName; scoreText.font = Assets.getFont("font/kenpixel_mini_square.ttf").fontName;
layer = -3; layer = -3;
this.addGraphic(scoreText); this.addGraphic(scoreText);
} }
public function add(x:Int) { public function add(x:Int) {
score += x; score += x;
scoreText.text = "$" + score; scoreText.text = "$" + score;
} }
public function rem(x:Int) { public function rem(x:Int) {
if (score != 0) { if (score != 0) {
score -= x; score -= x;
scoreText.text = "$" + score; scoreText.text = "$" + score;
} }
if (score < 0) { if (score < 0) {
score = 0; score = 0;
scoreText.text = "$" + score; scoreText.text = "$" + score;
} }
} }
public override function update() { public override function update() {
scoreText.centerOrigin(); scoreText.centerOrigin();
this.centerOrigin(); this.centerOrigin();
super.update(); super.update();
} }
public var score:Int; public var score:Int;
private var scoreText:Text; private var scoreText:Text;
} }

View file

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

View file

@ -1,24 +1,24 @@
import com.haxepunk.Entity; import com.haxepunk.Entity;
import com.haxepunk.graphics.Image; import com.haxepunk.graphics.Image;
import com.haxepunk.HXP; import com.haxepunk.HXP;
class Star extends Entity { class Star extends Entity {
public function new(x:Float) { public function new(x:Float) {
super(x, -4); super(x, -4);
graphic = Image.createRect(4,4, 0xBBBBBB); graphic = Image.createRect(4,4, 0xBBBBBB);
moveSpeed = Math.floor(Math.random() * 12); moveSpeed = Math.floor(Math.random() * 12);
} }
public override function update() { public override function update() {
this.y += moveSpeed; this.y += moveSpeed;
if (this.y > HXP.height + 4) { if (this.y > HXP.height + 4) {
this.scene.remove(this); this.scene.remove(this);
} }
} }
private var moveSpeed:Int; private var moveSpeed:Int;
} }

View file

@ -1,34 +1,34 @@
import com.haxepunk.Entity; import com.haxepunk.Entity;
import com.haxepunk.graphics.Image; import com.haxepunk.graphics.Image;
import com.haxepunk.graphics.Text; import com.haxepunk.graphics.Text;
import com.haxepunk.HXP; import com.haxepunk.HXP;
import openfl.Assets; import openfl.Assets;
class Title extends Entity { class Title extends Entity {
public function new () { public function new () {
super(HXP.width / 2, (HXP.height / 2) - 400); super(HXP.width / 2, (HXP.height / 2) - 400);
var icon = new Image("graphics/playerShip1_green.png"); var icon = new Image("graphics/playerShip1_green.png");
icon.scale = 1; icon.scale = 1;
icon.angle = 45; icon.angle = 45;
icon.x += 180; icon.x += 180;
icon.y -= 10; icon.y -= 10;
var txt = new Text("Spáááce"); var txt = new Text("Spáááce");
txt.size = 80; txt.size = 80;
txt.x -= 30; txt.x -= 30;
txt.font = Assets.getFont("font/kenpixel_mini_square.ttf").fontName; txt.font = Assets.getFont("font/kenpixel_mini_square.ttf").fontName;
this.centerOrigin(); this.centerOrigin();
txt.centerOrigin(); txt.centerOrigin();
icon.centerOrigin(); icon.centerOrigin();
this.addGraphic(txt); this.addGraphic(txt);
this.addGraphic(icon); this.addGraphic(icon);
this.layer = -5; this.layer = -5;
} }
} }