diff --git a/assets/font/04B_03__.eot b/assets/font/04B_03__.eot new file mode 100644 index 0000000..e69de29 diff --git a/assets/font/kenpixel_mini_square.ttf b/assets/font/kenpixel_mini_square.ttf new file mode 100644 index 0000000..d88dd5b Binary files /dev/null and b/assets/font/kenpixel_mini_square.ttf differ diff --git a/project.xml b/project.xml index 5510952..fb8d802 100644 --- a/project.xml +++ b/project.xml @@ -12,6 +12,7 @@ + diff --git a/src/Asteroid.hx b/src/Asteroid.hx index 06f2038..c3df63c 100644 --- a/src/Asteroid.hx +++ b/src/Asteroid.hx @@ -13,6 +13,10 @@ class Asteroid extends Entity { 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; @@ -28,7 +32,7 @@ class Asteroid extends Entity { } public override function update() { - this.y += 3; + this.y += speed; if (this.y > HXP.height) { this.scene.remove(this); @@ -37,7 +41,10 @@ class Asteroid extends Entity { this.originX = Math.floor(sprite.width / 2); this.originY = Math.floor(sprite.height / 2); - this.sprite.angle += 3; + if (side > .5) + this.sprite.angle += angleSpeed; + else + this.sprite.angle -= angleSpeed; super.update(); @@ -65,4 +72,8 @@ class Asteroid extends Entity { ]; 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/Bullet.hx b/src/Bullet.hx index 154bcc5..8869e91 100644 --- a/src/Bullet.hx +++ b/src/Bullet.hx @@ -21,7 +21,7 @@ class Bullet extends Entity { public override function update() { super.update(); - this.y -= 10; + this.y -= 20; timer -= HXP.elapsed; diff --git a/src/Enemy.hx b/src/Enemy.hx index 85fbf8b..39a26dc 100644 --- a/src/Enemy.hx +++ b/src/Enemy.hx @@ -2,25 +2,85 @@ import com.haxepunk.Entity; import com.haxepunk.graphics.Image; import com.haxepunk.HXP; +import Player; +import Score; + class Enemy extends Entity { public function new (x:Float, y:Float) { super(x, y); - color = Math.floor(Math.random() * 3); + color = Math.floor(Math.random() * 4); enemyType = Math.floor(Math.random() * 5) + 1; - sprite = new Image("graphics/" + enemies[color] + enemyType + ".png"); - graphic = sprite; + sprite = new Image("graphics/" + enemies[color] + enemyType + ".png"); + healthSprite = Image.createRect(sprite.width, 10, 0x00FF00); + healthSprite.y -= 50; + + originalHealth = health = (enemyType * 2 * color); + + sprite.centerOrigin(); + healthSprite.centerOrigin(); + + addGraphic(sprite); + addGraphic(healthSprite); setHitbox(sprite.width, sprite.height); layer = -1; } + + private function assignLocation() { + if (enemyType <= 2) { + arr = [ + Math.floor(Math.random() * (HXP.width - this.width)), + Math.floor(Math.random() * 400) + ]; + } + 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() * 400 + ]; + } + 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() * 400 + ]; + } + + return arr; + } + public override function update() { turnTimer -= HXP.elapsed; + this.centerOrigin(); + + healthSprite.scaledWidth = (sprite.width / originalHealth) * health; if (this.x != loc[0] && this.y != loc[1]) this.moveTowards(loc[0], loc[1], moveSpeed); @@ -28,32 +88,47 @@ class Enemy extends Entity { if (turnTimer < 0) { loc = assignLocation(); - if (enemyType == 3) + if (enemyType == 2) turnTimer = 2; - else + else if (enemyType == 3 || enemyType == 4) turnTimer = 1; + else if (enemyType == 1) + turnTimer = .5; } + + 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(15); + + this.scene.remove(bullet); + } + + if (health == 0) + this.scene.remove(this); } - - private function assignLocation() { - var arr:Array = [ - Math.random() * (HXP.width - this.width), - Math.random() * 400 - ]; - - return arr; - } - + private var enemies:Array = [ - "enemyBlack", "enemyGreen", - "enemyBlue" + "enemyBlue", + "enemyRed", + "enemyBlack" ]; private var sprite:Image; + private var healthSprite:Image; private var color:Int; private var enemyType:Int; + private var health:Int; + private var originalHealth:Int; + + private var arr:Array; + private var antX:Float; private var turnTimer:Float = 0; private var moveSpeed:Int = 10; diff --git a/src/Lives.hx b/src/Lives.hx new file mode 100644 index 0000000..09ed1a3 --- /dev/null +++ b/src/Lives.hx @@ -0,0 +1,54 @@ +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") + ]; + + baseSprite.scale = .75; + + for (i in 0...sprite.length) { + sprite[i].scale = .75; + } + + super(HXP.width - (baseSprite.width * .75 + 20), HXP.height - (baseSprite.height * .75 + 20)); + + graphic = baseSprite; + + this.addGraphic(sprite[0]); + + + damage = 0; + + } + + public inline function addDamage() {damage++;} + + public override function update() { + graphic = baseSprite; + this.addGraphic(sprite[damage]); + 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 damage:Int; + +} \ No newline at end of file diff --git a/src/MainScene.hx b/src/MainScene.hx index 5419fea..56a8834 100644 --- a/src/MainScene.hx +++ b/src/MainScene.hx @@ -6,16 +6,20 @@ 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 backdrop = new Backdrop("graphics/darkPurple.png", true, true); - var enemy = new Enemy(160, 100); + var enemy = new Enemy(160, 0); + var lives = new Lives(); + var score = new Score(); addGraphic(backdrop); @@ -23,10 +27,17 @@ class MainScene extends Scene add(button); #end - add(enemy); - add(player); + add(lives); + add(score); add(spawner); } + + public override function update() { + super.update(); + backdrop.y += 1; + } + + private var backdrop:Backdrop; } \ No newline at end of file diff --git a/src/MenuButton.hx b/src/MenuButton.hx index 6c2507b..6f28c1c 100644 --- a/src/MenuButton.hx +++ b/src/MenuButton.hx @@ -5,8 +5,10 @@ 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 { @@ -22,6 +24,7 @@ class MenuButton extends Entity { text = new Text(txt); text.color = 0x000000; text.size = 40; + text.font = Assets.getFont("font/kenpixel_mini_square.ttf").fontName; text.centerOrigin(); sprite.centerOrigin(); @@ -30,25 +33,48 @@ class MenuButton extends Entity { 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 = new MainScene(); + } + else { + HXP.scene = new MenuScene(); + } + } + } + if (Input.check("enter")) { - HXP.scene = new MainScene(); + if (this.text.text != "Menu") { + HXP.scene = new MainScene(); + } + else { + 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)) { - HXP.scene = new MainScene(); + if (this.text.text != "Menu") { + HXP.scene = new MainScene(); + } + else { + HXP.scene = new MenuScene(); + } } } private var txt:String; private var sprite:Image; - public var text:Text; + private var text:Text; } \ No newline at end of file diff --git a/src/MenuScene.hx b/src/MenuScene.hx index ad06f2e..50c4953 100644 --- a/src/MenuScene.hx +++ b/src/MenuScene.hx @@ -1,22 +1,40 @@ 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(HXP.width / 2, (HXP.height / 2) - 400); + var title = new Title(); var copy = new Text("By Bram \"96AA48\" van der Veen, 2014", HXP.width / 2, HXP.height - 50); + 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 update() { + super.update(); + backdrop.y += 1; + } + + private var backdrop:Backdrop; } \ No newline at end of file diff --git a/src/Player.hx b/src/Player.hx index 346d928..ee39a3c 100644 --- a/src/Player.hx +++ b/src/Player.hx @@ -4,14 +4,43 @@ 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 openfl.Assets; import Bullet; +import Lives; +import Score; class Player extends Entity { public function new() { super(HXP.halfWidth - 16, HXP.height - 200); + baseSprite = new Image("graphics/playerShip1_green.png"); - graphic = new Image("graphics/playerShip1_green.png"); + 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 = 17; + fireEffectLeft.y = 55; + + fireEffectRight = fireEffectsRight[currentAnim]; + fireEffectRight.x = 67; + fireEffectRight.y = 55; + + + this.addGraphic(fireEffectLeft); + this.addGraphic(fireEffectRight); setHitbox(99, 75); @@ -21,7 +50,7 @@ class Player extends Entity { Input.define("up", [Key.UP, Key.W]); Input.define("shoot", [Key.SPACE]); - type = "player"; + name = type = "player"; layer = -1; @@ -34,14 +63,14 @@ class Player extends Entity { if (Input.check("right") && this.right < HXP.width) { this.x += moveSpeed; } - if (Input.check("down") && this.bottom < HXP.height) { + if (Input.check("down") && this.bottom < HXP.height && this.bottom > 0) { this.y += moveSpeed; } - if (Input.check("up") && this.top > 0) { + if (Input.check("up") && this.top > 700) { this.y -= moveSpeed; } - if (Input.check("shoot")) { + if (Input.pressed("shoot")) { shoot(); } @@ -54,20 +83,74 @@ class Player extends Entity { } public function shoot() { + var score:Array = []; + + this.scene.getClass(Score, score); + + score[0].rem(5); + this.scene.add(new Bullet(this.x + this.width / 2, this.y)); } + public function die() { + this.visible = false; + 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; - var asteroid = collide("asteroid", this.x, this.y); + if (animWait < 0) { - if (asteroid != null) { - + if (currentAnim == 3) + currentAnim = 0; + + fireEffectLeft = fireEffectsLeft[currentAnim]; + fireEffectLeft.x = 17; + fireEffectLeft.y = 60; + + fireEffectRight = fireEffectsRight[currentAnim]; + fireEffectRight.x = 67; + fireEffectRight.y = 60; + + graphic = baseSprite; + this.addGraphic(fireEffectLeft); + this.addGraphic(fireEffectRight); + + currentAnim++; + animWait = .75; + } + + if (collide("asteroid", this.x, this.y) != null && hitPause < 0) { + var lives:Array = []; + this.scene.getClass(Lives, lives); + lives[0].addDamage(); + hitPause = 1.5; } super.update(); } - private var moveSpeed:Int = 5; + private var baseSprite:Image; + 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 = 1.5; + + private var animWait:Float = .75; + private var currentAnim:Int = 0; } \ No newline at end of file diff --git a/src/Score.hx b/src/Score.hx new file mode 100644 index 0000000..bb37317 --- /dev/null +++ b/src/Score.hx @@ -0,0 +1,42 @@ +import com.haxepunk.Entity; +import com.haxepunk.HXP; +import com.haxepunk.graphics.Text; + +class Score extends Entity { + + public function new() { + super(0, 100); + super(HXP.width, 30); + + name = "score"; + score = 0; + scoreText = new Text("0", 0, 0, {size : 50}); + + 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 + ""; + } + } + + public override function update() { + scoreText.originX = this.originX = 100; + + 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 5464c17..872a084 100644 --- a/src/Spawner.hx +++ b/src/Spawner.hx @@ -1,6 +1,8 @@ import com.haxepunk.Entity; import com.haxepunk.HXP; + import Asteroid; +import Enemy; class Spawner extends Entity { public function new () { @@ -10,10 +12,11 @@ class Spawner extends Entity { public override function update() { spawnStarTime -= HXP.elapsed; spawnAsteroidTime -= HXP.elapsed; + spawnEnemyTime -= HXP.elapsed; if (spawnAsteroidTime < 0) { this.scene.add(new Asteroid(HXP.width * Math.random(), -16)); - spawnAsteroidTime = 1.5; + spawnAsteroidTime = .5; } if (spawnStarTime < 0) { @@ -21,9 +24,21 @@ class Spawner extends Entity { spawnStarTime = .5; } + if (spawnEnemyTime < 0 && this.scene.getInstance("player") != null) { + var enemies:Array = []; + this.scene.getClass(Enemy, enemies); + + if (enemies[0] == null) { + this.scene.add(new Enemy(HXP.halfWidth, -50)); + } + + spawnEnemyTime = 5; + } + super.update(); } - private var spawnAsteroidTime:Float = 1.5; + private var spawnAsteroidTime:Float = .5; private var spawnStarTime:Float = .5; + private var spawnEnemyTime:Float = 5; } \ No newline at end of file diff --git a/src/Title.hx b/src/Title.hx index 05d7e5b..e11481c 100644 --- a/src/Title.hx +++ b/src/Title.hx @@ -1,19 +1,22 @@ 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 (x:Float, y:Float) { - super(x, y); + public function new () { + super(HXP.width / 2, (HXP.height / 2) - 400); var icon = new Image("graphics/cursor.png"); icon.scale = 3.5; - icon.x += 200; + icon.x += 220; var txt = new Text("Spaaace"); txt.size = 80; - txt.x -= 20; + txt.x -= 30; + txt.font = Assets.getFont("font/kenpixel_mini_square.ttf").fontName; this.centerOrigin(); txt.centerOrigin(); @@ -21,6 +24,8 @@ class Title extends Entity { this.addGraphic(txt); this.addGraphic(icon); + + this.layer = -5; } } \ No newline at end of file