diff --git a/assets/graphics/laserBlue01.png b/assets/graphics/laserBlue01.png new file mode 100644 index 0000000..b76aaf7 Binary files /dev/null and b/assets/graphics/laserBlue01.png differ diff --git a/assets/graphics/laserBlue02.png b/assets/graphics/laserBlue02.png new file mode 100644 index 0000000..3f923a3 Binary files /dev/null and b/assets/graphics/laserBlue02.png differ diff --git a/assets/graphics/laserBlue03.png b/assets/graphics/laserBlue03.png new file mode 100644 index 0000000..a16e9a8 Binary files /dev/null and b/assets/graphics/laserBlue03.png differ diff --git a/assets/graphics/laserBlue04.png b/assets/graphics/laserBlue04.png new file mode 100644 index 0000000..6f3b910 Binary files /dev/null and b/assets/graphics/laserBlue04.png differ diff --git a/assets/graphics/laserBlue05.png b/assets/graphics/laserBlue05.png new file mode 100644 index 0000000..85cff7d Binary files /dev/null and b/assets/graphics/laserBlue05.png differ diff --git a/assets/graphics/laserBlue06.png b/assets/graphics/laserBlue06.png new file mode 100644 index 0000000..a621875 Binary files /dev/null and b/assets/graphics/laserBlue06.png differ diff --git a/assets/graphics/laserBlue07.png b/assets/graphics/laserBlue07.png new file mode 100644 index 0000000..e1848bf Binary files /dev/null and b/assets/graphics/laserBlue07.png differ diff --git a/assets/graphics/laserBlue08.png b/assets/graphics/laserBlue08.png new file mode 100644 index 0000000..7a46396 Binary files /dev/null and b/assets/graphics/laserBlue08.png differ diff --git a/assets/graphics/laserBlue09.png b/assets/graphics/laserBlue09.png new file mode 100644 index 0000000..35624e6 Binary files /dev/null and b/assets/graphics/laserBlue09.png differ diff --git a/assets/graphics/laserBlue10.png b/assets/graphics/laserBlue10.png new file mode 100644 index 0000000..dd6b766 Binary files /dev/null and b/assets/graphics/laserBlue10.png differ diff --git a/assets/graphics/laserBlue11.png b/assets/graphics/laserBlue11.png new file mode 100644 index 0000000..c062349 Binary files /dev/null and b/assets/graphics/laserBlue11.png differ diff --git a/assets/graphics/laserBlue12.png b/assets/graphics/laserBlue12.png new file mode 100644 index 0000000..48b6103 Binary files /dev/null and b/assets/graphics/laserBlue12.png differ diff --git a/assets/graphics/laserBlue13.png b/assets/graphics/laserBlue13.png new file mode 100644 index 0000000..c5ec6a3 Binary files /dev/null and b/assets/graphics/laserBlue13.png differ diff --git a/assets/graphics/laserBlue14.png b/assets/graphics/laserBlue14.png new file mode 100644 index 0000000..254601e Binary files /dev/null and b/assets/graphics/laserBlue14.png differ diff --git a/assets/graphics/laserBlue15.png b/assets/graphics/laserBlue15.png new file mode 100644 index 0000000..1ea1966 Binary files /dev/null and b/assets/graphics/laserBlue15.png differ diff --git a/assets/graphics/laserBlue16.png b/assets/graphics/laserBlue16.png new file mode 100644 index 0000000..1def98f Binary files /dev/null and b/assets/graphics/laserBlue16.png differ diff --git a/assets/graphics/playerShip1_blue.png b/assets/graphics/playerShip1_blue.png new file mode 100644 index 0000000..cecbbed Binary files /dev/null and b/assets/graphics/playerShip1_blue.png differ diff --git a/assets/graphics/playerShip1_orange.png b/assets/graphics/playerShip1_orange.png new file mode 100644 index 0000000..3902283 Binary files /dev/null and b/assets/graphics/playerShip1_orange.png differ diff --git a/assets/graphics/playerShip1_red.png b/assets/graphics/playerShip1_red.png new file mode 100644 index 0000000..3695e09 Binary files /dev/null and b/assets/graphics/playerShip1_red.png differ diff --git a/assets/graphics/playerShip2_blue.png b/assets/graphics/playerShip2_blue.png new file mode 100644 index 0000000..e277114 Binary files /dev/null and b/assets/graphics/playerShip2_blue.png differ diff --git a/assets/graphics/playerShip2_green.png b/assets/graphics/playerShip2_green.png new file mode 100644 index 0000000..72e18c7 Binary files /dev/null and b/assets/graphics/playerShip2_green.png differ diff --git a/assets/graphics/playerShip2_orange.png b/assets/graphics/playerShip2_orange.png new file mode 100644 index 0000000..82ddc80 Binary files /dev/null and b/assets/graphics/playerShip2_orange.png differ diff --git a/assets/graphics/playerShip2_red.png b/assets/graphics/playerShip2_red.png new file mode 100644 index 0000000..8213e97 Binary files /dev/null and b/assets/graphics/playerShip2_red.png differ diff --git a/assets/graphics/playerShip3_blue.png b/assets/graphics/playerShip3_blue.png new file mode 100644 index 0000000..f34faf0 Binary files /dev/null and b/assets/graphics/playerShip3_blue.png differ diff --git a/assets/graphics/playerShip3_green.png b/assets/graphics/playerShip3_green.png new file mode 100644 index 0000000..b853be4 Binary files /dev/null and b/assets/graphics/playerShip3_green.png differ diff --git a/assets/graphics/playerShip3_orange.png b/assets/graphics/playerShip3_orange.png new file mode 100644 index 0000000..0b6b7ec Binary files /dev/null and b/assets/graphics/playerShip3_orange.png differ diff --git a/assets/graphics/playerShip3_red.png b/assets/graphics/playerShip3_red.png new file mode 100644 index 0000000..796e81d Binary files /dev/null and b/assets/graphics/playerShip3_red.png differ diff --git a/src/Asteroid.hx b/src/Asteroid.hx index 0b766ba..c20f232 100644 --- a/src/Asteroid.hx +++ b/src/Asteroid.hx @@ -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 = [ - "meteorBrown_", - "meteorGrey_" - ]; - - private var sprites:Array> = [ - [ - "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 = [ + "meteorBrown_", + "meteorGrey_" + ]; + + private var sprites:Array> = [ + [ + "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; } \ No newline at end of file diff --git a/src/Boss.hx b/src/Boss.hx index ed6c4b2..62bfc68 100644 --- a/src/Boss.hx +++ b/src/Boss.hx @@ -17,7 +17,7 @@ class Boss extends Entity { currentSprite.scale = 8; currentSprite.smooth = false; - maxEnemies = Math.floor(Math.random() * (color + 1) * 2); + maxEnemies = Math.floor((color + 1) * 2); graphic = currentSprite; @@ -51,7 +51,9 @@ class Boss extends Entity { var enemies:Array = []; this.scene.getClass(Enemy, enemies); - if (spawnTimer < 0 && enemies.length != maxEnemies - 1 && canSpawn) { + trace(enemies.length + ", " + maxEnemies); + + if (spawnTimer < 0 && enemies.length != maxEnemies && canSpawn) { this.scene.add(new Enemy(this.width / 2, 20, color, Math.floor(Math.random() * 4) + 1)); spawnTimer = .75; } @@ -115,5 +117,4 @@ class Boss extends Entity { private var explosionTimer:Float = 0; private var counter:Int = 0; private var dead:Bool = false; - } \ No newline at end of file diff --git a/src/Bullet.hx b/src/Bullet.hx index 8869e91..a8b75cd 100644 --- a/src/Bullet.hx +++ b/src/Bullet.hx @@ -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/laserGreen04.png"); + laser2 = new Image("graphics/laserGreen12.png"); + + graphic = laser1; + + setHitboxTo(laser1); + + 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; } \ No newline at end of file diff --git a/src/Button.hx b/src/Button.hx index 744be5f..6756de9 100644 --- a/src/Button.hx +++ b/src/Button.hx @@ -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 = []; - 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 = []; + this.scene.getClass(Player, players); + players[0].shoot(); + } + } + } + + private var sprite:Image; } \ No newline at end of file diff --git a/src/Enemy.hx b/src/Enemy.hx index 5345462..9a1260f 100644 --- a/src/Enemy.hx +++ b/src/Enemy.hx @@ -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 = []; - 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 = []; - 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 = []; - 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 = [ - "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; - private var antX:Float; - - private var turnTimer:Float = 0; - private var shootTimer:Float = 0; - private var moveSpeed:Int = 10; - private var loc:Array = []; +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 = []; + 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 = []; + 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 = []; + 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 = [ + "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; + private var antX:Float; + + private var turnTimer:Float = 0; + private var shootTimer:Float = 0; + private var moveSpeed:Int = 10; + private var loc:Array = []; } \ No newline at end of file diff --git a/src/EnemyBullet.hx b/src/EnemyBullet.hx index fe2e6fa..a8a1f79 100644 --- a/src/EnemyBullet.hx +++ b/src/EnemyBullet.hx @@ -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; - 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; + private var timer:Float = .5; } \ No newline at end of file diff --git a/src/Explosion.hx b/src/Explosion.hx index 3a10df1..b9d656e 100644 --- a/src/Explosion.hx +++ b/src/Explosion.hx @@ -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; + } \ No newline at end of file diff --git a/src/Lives.hx b/src/Lives.hx index a0d34bf..43fb1e8 100644 --- a/src/Lives.hx +++ b/src/Lives.hx @@ -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 = []; - this.scene.getClass(Player, player); - player[0].die(); - - damage = 0; - } - super.update(); - } - - private var sprite:Array = []; - 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 = []; + this.scene.getClass(Player, player); + player[0].die(); + + damage = 0; + } + super.update(); + } + + private var sprite:Array = []; + private var baseSprite:Image; + private var liveBar:Image; + private var damage:Int; + } \ No newline at end of file diff --git a/src/Main.hx b/src/Main.hx index 78683fe..d9b07b2 100644 --- a/src/Main.hx +++ b/src/Main.hx @@ -1,24 +1,23 @@ -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 StoreScene(); + } + + public static function main() { new Main(); } + } \ No newline at end of file diff --git a/src/MainScene.hx b/src/MainScene.hx index cad3b41..ffc9db0 100644 --- a/src/MainScene.hx +++ b/src/MainScene.hx @@ -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; } \ No newline at end of file diff --git a/src/MenuButton.hx b/src/MenuButton.hx index 54585f2..2f0c7cf 100644 --- a/src/MenuButton.hx +++ b/src/MenuButton.hx @@ -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; + } \ No newline at end of file diff --git a/src/MenuScene.hx b/src/MenuScene.hx index e6ad504..cc2ab71 100644 --- a/src/MenuScene.hx +++ b/src/MenuScene.hx @@ -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; } \ No newline at end of file diff --git a/src/Pickup.hx b/src/Pickup.hx index 3ba7c28..2d09b6f 100644 --- a/src/Pickup.hx +++ b/src/Pickup.hx @@ -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 = []; - this.scene.getClass(Score, score); - - //Shield pickup - if (this.randType == 0) { - var player:Array = []; - 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 = []; - 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> = [ - [ - 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 = []; + this.scene.getClass(Score, score); + + //Shield pickup + if (this.randType == 0) { + var player:Array = []; + 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 = []; + 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> = [ + [ + 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; + } \ No newline at end of file diff --git a/src/Player.hx b/src/Player.hx index a21bd5d..8b998cc 100644 --- a/src/Player.hx +++ b/src/Player.hx @@ -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 = []; - - 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 = []; - 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 = []; - 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 = []; - private var fireEffectsRight:Array = []; - - - 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 = []; + + 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 = []; + 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 = []; + 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 = []; + private var fireEffectsRight:Array = []; + + + 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; } \ No newline at end of file diff --git a/src/Score.hx b/src/Score.hx index e049c35..d086b1b 100644 --- a/src/Score.hx +++ b/src/Score.hx @@ -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; + } \ No newline at end of file diff --git a/src/Spawner.hx b/src/Spawner.hx index 73b5942..fcd429f 100644 --- a/src/Spawner.hx +++ b/src/Spawner.hx @@ -3,12 +3,14 @@ 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() { @@ -49,6 +51,26 @@ class Spawner extends Entity { 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; @@ -58,4 +80,8 @@ class Spawner extends Entity { 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; } \ No newline at end of file diff --git a/src/Star.hx b/src/Star.hx index 1ff0feb..858d4d4 100644 --- a/src/Star.hx +++ b/src/Star.hx @@ -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; } \ No newline at end of file diff --git a/src/StoreItem.hx b/src/StoreItem.hx new file mode 100644 index 0000000..23117d7 --- /dev/null +++ b/src/StoreItem.hx @@ -0,0 +1,124 @@ +import com.haxepunk.Entity; +import com.haxepunk.graphics.Image; +import com.haxepunk.graphics.Text; +import openfl.Assets; + +class StoreItem extends Entity { + + public function new(x:Float, y:Float, type:Int) { + super(x, y); + + button = new Image("graphics/buttonGreen.png"); + button.scale = 2; + + + text = new Text(itemnames[type]); + text.color = 0x000000; + text.size = 40; + text.font = Assets.getFont("font/kenpixel_mini_square.ttf").fontName; + + this.x += 120; + + setHitbox(button.width * 2, button.height * 2); + + text.centerOrigin(); + button.centerOrigin(); + this.centerOrigin(); + + for (i in 0...items[type].length) { + sprites[i] = new Image("graphics/" + items[type][i]); + sprites[i].x = -350; + sprites[i].centerOrigin(); + } + + arrowLeft = new Image("graphics/fire05.png"); + arrowLeft.angle = 90; + arrowLeft.x = -440; + arrowLeft.centerOrigin(); + + arrowRight = new Image("graphics/fire05.png"); + arrowRight.angle = -90; + arrowRight.x = -260; + arrowRight.centerOrigin(); + + + this.addGraphic(sprites[0]); + + this.addGraphic(arrowLeft); + this.addGraphic(arrowRight); + + this.addGraphic(button); + this.addGraphic(text); + + } + + private var button:Image; + + private var sprites:Array = []; + private var arrowLeft:Image; + private var arrowRight:Image; + + private var text:Text; + + public static var itemnames:Array = [ + "Fat Jumper", + "Speeder Jumper", + "X3 Jumper", + "V2 Laser", + "Heavy Laser" + ]; + + private var items:Array> = [ + [ + "playerShip3_green.png", + "playerShip3_blue.png", + "playerShip3_orange.png" + ], + [ + "playerShip1_green.png", + "playerShip1_blue.png", + "playerShip1_orange.png" + ], + [ + "playerShip2_green.png", + "playerShip2_blue.png", + "playerShip2_orange.png" + ], + [ + "laserGreen06.png", + "laserBlue06.png" + ], + [ + "laserBlue16.png" + ] + ]; + + private var prices:Array> = [ + [ + 50000, + 50000, + 50000 + ], + [ + 100000, + 100000, + 100000 + ], + [ + 150000, + 150000, + 150000 + ], + [ + 50000, + 100000 + ], + [ + 150000 + ] + + ]; + + + +} \ No newline at end of file diff --git a/src/StoreScene.hx b/src/StoreScene.hx new file mode 100644 index 0000000..e1d5cdc --- /dev/null +++ b/src/StoreScene.hx @@ -0,0 +1,24 @@ +import com.haxepunk.Scene; +import com.haxepunk.graphics.Backdrop; +import com.haxepunk.HXP; + +import StoreItem; + +class StoreScene extends Scene { + + public override function begin() { + backdrop = new Backdrop("graphics/darkPurple.png", true, true); + addGraphic(backdrop); + + for (i in 0...StoreItem.itemnames.length) { + add(new StoreItem(HXP.halfWidth, 200 + (i * 200), i)); + } + } + + public override function update() { + super.update(); + backdrop.y += 1; + } + + private var backdrop:Backdrop; +} \ No newline at end of file diff --git a/src/Title.hx b/src/Title.hx index 9161977..1de4a71 100644 --- a/src/Title.hx +++ b/src/Title.hx @@ -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; + } + } \ No newline at end of file