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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,57 +1,87 @@
import com.haxepunk.Entity;
import com.haxepunk.HXP;
import Enemy;
import Boss;
class Spawner extends Entity {
public function new() {
super(0,0);
}
public override function update() {
enemyTimer -= HXP.elapsed;
var enemies:Array<Enemy> = [];
var bosses:Array<Boss> = [];
this.scene.getClass(Enemy, enemies);
this.scene.getClass(Boss, bosses);
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));
}
}
}
else {
enemyTimer = 1;
}
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!");
}
}
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;
import com.haxepunk.Entity;
import com.haxepunk.HXP;
import Enemy;
import Boss;
import Star;
import Pickup;
import Asteroid;
class Spawner extends Entity {
public function new() {
super(0,0);
}
public override function update() {
enemyTimer -= HXP.elapsed;
var enemies:Array<Enemy> = [];
var bosses:Array<Boss> = [];
this.scene.getClass(Enemy, enemies);
this.scene.getClass(Boss, bosses);
if (level != 4) {
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));
}
}
}
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 {
trace("YOU BEAT THE GAME!");
}
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.graphics.Image;
import com.haxepunk.HXP;
class Star extends Entity {
public function new(x:Float) {
super(x, -4);
graphic = Image.createRect(4,4, 0xBBBBBB);
moveSpeed = Math.floor(Math.random() * 12);
}
public override function update() {
this.y += moveSpeed;
if (this.y > HXP.height + 4) {
this.scene.remove(this);
}
}
private var moveSpeed:Int;
import com.haxepunk.Entity;
import com.haxepunk.graphics.Image;
import com.haxepunk.HXP;
class Star extends Entity {
public function new(x:Float) {
super(x, -4);
graphic = Image.createRect(4,4, 0xBBBBBB);
moveSpeed = Math.floor(Math.random() * 12);
}
public override function update() {
this.y += moveSpeed;
if (this.y > HXP.height + 4) {
this.scene.remove(this);
}
}
private var moveSpeed:Int;
}

View file

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