From 0efb5228abfe8de14996d218fe547953793fe70c Mon Sep 17 00:00:00 2001 From: Bram van der Veen <96aa48@gmail.com> Date: Sun, 6 Jul 2014 20:29:59 +0200 Subject: [PATCH] Added a lot of new shit, think it's looking better. --- assets/font/04B_03__.eot | 0 assets/font/kenpixel_mini_square.ttf | Bin 0 -> 23968 bytes project.xml | 1 + src/Asteroid.hx | 15 +++- src/Bullet.hx | 2 +- src/Enemy.hx | 109 ++++++++++++++++++++++----- src/Lives.hx | 54 +++++++++++++ src/MainScene.hx | 19 ++++- src/MenuButton.hx | 32 +++++++- src/MenuScene.hx | 20 ++++- src/Player.hx | 101 ++++++++++++++++++++++--- src/Score.hx | 42 +++++++++++ src/Spawner.hx | 19 ++++- src/Title.hx | 13 +++- 14 files changed, 384 insertions(+), 43 deletions(-) create mode 100644 assets/font/04B_03__.eot create mode 100644 assets/font/kenpixel_mini_square.ttf create mode 100644 src/Lives.hx create mode 100644 src/Score.hx 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 0000000000000000000000000000000000000000..d88dd5b102df88546f5f5a63464b291973b965ba GIT binary patch literal 23968 zcmeHPTa29Ld46Yi#$KPmfH~XnW4mOb_=w#Y>Jl3hgB3_Ej8K#!g-FQ#g9cS$b zRe#i8q)INh2o*}xlt_^xrAR?)E+UnSMB*Z9b3r9gdJ!ou%}u0KqUu3N1W%vm`M&o* z%|Ekamr$kJG4Fh*_kG^u_x=Arvy3&&Y`vv6YRMm;+Oxm;m#t^bZrqI7=TFa0Ed2G> z7ybqYA53AQX;*%O@ez!7PR({M zp0Z7UgYg-&(UUXtrzfm2{}Z#%K8f)&vlAB=x^LSlv#}q5Kbf1DZU6kc-#CczTW0GX zT9{wz*hu#S=v&}AXaqD0+JbjjK61#KBRetPYMU{$(f-uBjf;1EE7_9Vl_bgbO)#>bi3Vu?f$rX;+>t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tM2{1dIbuf?hK_h_!>yfqsIYB7Xq%qS?n2 z&>Lolz<&rh58Vb@0KIAU@LtgCW`B49Gz0n$e*Je01bYv^X7)!%KrezWn>_;DM}BSg ziIX7UeBwQ`BaeZweiSlCA%FCzW{(2@QOq5~+%fog>}3#i90SH#c@X9wd(-Tb aTR}%akohEdj_(D%0D2d{uMVA$zy3db8I>vk literal 0 HcmV?d00001 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