Added a lot of new shit, think it's looking better.

This commit is contained in:
Bram van der Veen 2014-07-06 20:29:59 +02:00
parent 21e68289a8
commit 0efb5228ab
14 changed files with 384 additions and 43 deletions

0
assets/font/04B_03__.eot Normal file
View file

Binary file not shown.

View file

@ -12,6 +12,7 @@
<source path="src" /> <source path="src" />
<haxelib name="HaxePunk" /> <haxelib name="HaxePunk" />
<haxelib name="openfl" version="1.4.0" />
<assets path="assets/graphics" rename="graphics" include="*.png|*.jpg" /> <assets path="assets/graphics" rename="graphics" include="*.png|*.jpg" />
<assets path="assets/audio" rename="audio" include="*.mp3" if="flash" /> <assets path="assets/audio" rename="audio" include="*.mp3" if="flash" />

View file

@ -13,6 +13,10 @@ class Asteroid extends Entity {
file += spritesTypes[Math.floor(Math.random() * 2)]; file += spritesTypes[Math.floor(Math.random() * 2)];
file += sprites[tempRand][Math.floor(Math.random() * sprites[tempRand].length)]; file += sprites[tempRand][Math.floor(Math.random() * sprites[tempRand].length)];
side = Math.random() * 1;
angleSpeed = Math.random() * 3;
speed = (Math.random() * 2) + 9;
sprite = new Image("graphics/" + file); sprite = new Image("graphics/" + file);
graphic = sprite; graphic = sprite;
@ -28,7 +32,7 @@ class Asteroid extends Entity {
} }
public override function update() { public override function update() {
this.y += 3; this.y += speed;
if (this.y > HXP.height) { if (this.y > HXP.height) {
this.scene.remove(this); this.scene.remove(this);
@ -37,7 +41,10 @@ class Asteroid extends Entity {
this.originX = Math.floor(sprite.width / 2); this.originX = Math.floor(sprite.width / 2);
this.originY = Math.floor(sprite.height / 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(); super.update();
@ -65,4 +72,8 @@ class Asteroid extends Entity {
]; ];
private var sprite:Image; private var sprite:Image;
private var side:Float;
private var angleSpeed:Float;
private var speed:Float;
} }

View file

@ -21,7 +21,7 @@ class Bullet extends Entity {
public override function update() { public override function update() {
super.update(); super.update();
this.y -= 10; this.y -= 20;
timer -= HXP.elapsed; timer -= HXP.elapsed;

View file

@ -2,25 +2,85 @@ import com.haxepunk.Entity;
import com.haxepunk.graphics.Image; import com.haxepunk.graphics.Image;
import com.haxepunk.HXP; import com.haxepunk.HXP;
import Player;
import Score;
class Enemy extends Entity { class Enemy extends Entity {
public function new (x:Float, y:Float) { public function new (x:Float, y:Float) {
super(x, y); super(x, y);
color = Math.floor(Math.random() * 3); color = Math.floor(Math.random() * 4);
enemyType = Math.floor(Math.random() * 5) + 1; 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); setHitbox(sprite.width, sprite.height);
layer = -1; 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<Player> = [];
this.scene.getClass(Player, player);
if (Math.random() * 1 > .5)
antX = player[0].x;
else
antX = Math.random() * HXP.width;
arr = [
antX,
Math.random() * 400
];
}
else {
var player:Array<Player> = [];
this.scene.getClass(Player, player);
if (Math.random() * 1 > .5)
antX = player[0].x;
else
antX = Math.random() * HXP.width;
if (Math.random() * 1 > .5)
antX -= this.width;
else
antX += this.width;
arr = [
antX,
Math.random() * 400
];
}
return arr;
}
public override function update() { public override function update() {
turnTimer -= HXP.elapsed; turnTimer -= HXP.elapsed;
this.centerOrigin();
healthSprite.scaledWidth = (sprite.width / originalHealth) * health;
if (this.x != loc[0] && this.y != loc[1]) if (this.x != loc[0] && this.y != loc[1])
this.moveTowards(loc[0], loc[1], moveSpeed); this.moveTowards(loc[0], loc[1], moveSpeed);
@ -28,32 +88,47 @@ class Enemy extends Entity {
if (turnTimer < 0) { if (turnTimer < 0) {
loc = assignLocation(); loc = assignLocation();
if (enemyType == 3) if (enemyType == 2)
turnTimer = 2; turnTimer = 2;
else else if (enemyType == 3 || enemyType == 4)
turnTimer = 1; turnTimer = 1;
else if (enemyType == 1)
turnTimer = .5;
} }
}
private function assignLocation() { var bullet:Entity = collide("bullet", this.x, this.y);
var arr:Array<Float> = [
Math.random() * (HXP.width - this.width),
Math.random() * 400
];
return arr; if (bullet != null) {
health -= 1;
var score:Array<Score> = [];
this.scene.getClass(Score, score);
score[0].add(15);
this.scene.remove(bullet);
}
if (health == 0)
this.scene.remove(this);
} }
private var enemies:Array<String> = [ private var enemies:Array<String> = [
"enemyBlack",
"enemyGreen", "enemyGreen",
"enemyBlue" "enemyBlue",
"enemyRed",
"enemyBlack"
]; ];
private var sprite:Image; private var sprite:Image;
private var healthSprite:Image;
private var color:Int; private var color:Int;
private var enemyType:Int; private var enemyType:Int;
private var health:Int;
private var originalHealth:Int;
private var arr:Array<Float>;
private var antX:Float;
private var turnTimer:Float = 0; private var turnTimer:Float = 0;
private var moveSpeed:Int = 10; private var moveSpeed:Int = 10;

54
src/Lives.hx Normal file
View file

@ -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<Player> = [];
this.scene.getClass(Player, player);
player[0].die();
damage = 0;
}
super.update();
}
private var sprite:Array<Image> = [];
private var baseSprite:Image;
private var damage:Int;
}

View file

@ -6,16 +6,20 @@ import Spawner;
import Player; import Player;
import Button; import Button;
import Enemy; import Enemy;
import Lives;
import Score;
class MainScene extends Scene class MainScene extends Scene
{ {
public override function begin() public override function begin()
{ {
backdrop = new Backdrop("graphics/darkPurple.png", true, true);
var player = new Player(); var player = new Player();
var button = new Button(); var button = new Button();
var spawner = new Spawner(); var spawner = new Spawner();
var backdrop = new Backdrop("graphics/darkPurple.png", true, true); var enemy = new Enemy(160, 0);
var enemy = new Enemy(160, 100); var lives = new Lives();
var score = new Score();
addGraphic(backdrop); addGraphic(backdrop);
@ -23,10 +27,17 @@ class MainScene extends Scene
add(button); add(button);
#end #end
add(enemy);
add(player); add(player);
add(lives);
add(score);
add(spawner); add(spawner);
} }
public override function update() {
super.update();
backdrop.y += 1;
}
private var backdrop:Backdrop;
} }

View file

@ -5,8 +5,10 @@ import com.haxepunk.HXP;
import com.haxepunk.utils.Input; import com.haxepunk.utils.Input;
import com.haxepunk.utils.Touch; import com.haxepunk.utils.Touch;
import com.haxepunk.utils.Key; import com.haxepunk.utils.Key;
import openfl.Assets;
import MainScene; import MainScene;
import MenuScene;
class MenuButton extends Entity { class MenuButton extends Entity {
@ -22,6 +24,7 @@ class MenuButton extends Entity {
text = new Text(txt); text = new Text(txt);
text.color = 0x000000; text.color = 0x000000;
text.size = 40; text.size = 40;
text.font = Assets.getFont("font/kenpixel_mini_square.ttf").fontName;
text.centerOrigin(); text.centerOrigin();
sprite.centerOrigin(); sprite.centerOrigin();
@ -30,25 +33,48 @@ class MenuButton extends Entity {
this.addGraphic(sprite); this.addGraphic(sprite);
this.addGraphic(text); this.addGraphic(text);
this.layer = -5;
Input.define("enter", [Key.ENTER, Key.SPACE]); Input.define("enter", [Key.ENTER, Key.SPACE]);
} }
public override function update() { public override function update() {
Input.touchPoints(onTouch); Input.touchPoints(onTouch);
if (Input.mouseReleased) {
if ((Input.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")) { 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) { private function onTouch(touch:Touch) {
if ((touch.x > this.left && touch.x < this.right) && (touch.y > this.top && touch.y < this.bottom)) { 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 txt:String;
private var sprite:Image; private var sprite:Image;
public var text:Text; private var text:Text;
} }

View file

@ -1,22 +1,40 @@
import com.haxepunk.Scene; import com.haxepunk.Scene;
import com.haxepunk.HXP; import com.haxepunk.HXP;
import com.haxepunk.graphics.Text; import com.haxepunk.graphics.Text;
import com.haxepunk.graphics.Backdrop;
import openfl.Assets;
import MenuButton; import MenuButton;
import Title; import Title;
import Spawner;
import MainScene;
class MenuScene extends Scene { class MenuScene extends Scene {
public override function begin() { public override function begin() {
backdrop = new Backdrop("graphics/darkPurple.png", true, true);
var play = new MenuButton(HXP.width / 2, HXP.height / 2, "Play!"); var play = new MenuButton(HXP.width / 2, HXP.height / 2, "Play!");
var title = new Title(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 copy = new Text("By Bram \"96AA48\" van der Veen, 2014", HXP.width / 2, HXP.height - 50);
var spawner = new Spawner();
copy.size = 22; copy.size = 22;
copy.font = Assets.getFont("font/kenpixel_mini_square.ttf").fontName;
copy.centerOrigin(); copy.centerOrigin();
addGraphic(backdrop);
add(spawner);
add(title); add(title);
add(play); add(play);
addGraphic(copy); addGraphic(copy);
} }
public override function update() {
super.update();
backdrop.y += 1;
}
private var backdrop:Backdrop;
} }

View file

@ -4,14 +4,43 @@ import com.haxepunk.utils.Key;
import com.haxepunk.utils.Input; import com.haxepunk.utils.Input;
import com.haxepunk.HXP; import com.haxepunk.HXP;
import com.haxepunk.utils.Touch; import com.haxepunk.utils.Touch;
import com.haxepunk.graphics.Text;
import openfl.Assets;
import Bullet; import Bullet;
import Lives;
import Score;
class Player extends Entity { class Player extends Entity {
public function new() { public function new() {
super(HXP.halfWidth - 16, HXP.height - 200); super(HXP.halfWidth - 16, HXP.height - 200);
baseSprite = new Image("graphics/playerShip1_green.png");
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); setHitbox(99, 75);
@ -21,7 +50,7 @@ class Player extends Entity {
Input.define("up", [Key.UP, Key.W]); Input.define("up", [Key.UP, Key.W]);
Input.define("shoot", [Key.SPACE]); Input.define("shoot", [Key.SPACE]);
type = "player"; name = type = "player";
layer = -1; layer = -1;
@ -34,14 +63,14 @@ class Player extends Entity {
if (Input.check("right") && this.right < HXP.width) { if (Input.check("right") && this.right < HXP.width) {
this.x += moveSpeed; this.x += moveSpeed;
} }
if (Input.check("down") && this.bottom < HXP.height) { if (Input.check("down") && this.bottom < HXP.height && this.bottom > 0) {
this.y += moveSpeed; this.y += moveSpeed;
} }
if (Input.check("up") && this.top > 0) { if (Input.check("up") && this.top > 700) {
this.y -= moveSpeed; this.y -= moveSpeed;
} }
if (Input.check("shoot")) { if (Input.pressed("shoot")) {
shoot(); shoot();
} }
@ -54,20 +83,74 @@ class Player extends Entity {
} }
public function shoot() { public function shoot() {
var score:Array<Score> = [];
this.scene.getClass(Score, score);
score[0].rem(5);
this.scene.add(new Bullet(this.x + this.width / 2, this.y)); 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() { public override function update() {
handleInput(); 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<Lives> = [];
this.scene.getClass(Lives, lives);
lives[0].addDamage();
hitPause = 1.5;
} }
super.update(); super.update();
} }
private var moveSpeed:Int = 5; private var baseSprite:Image;
private var fireEffectsLeft:Array<Image> = [];
private var fireEffectsRight:Array<Image> = [];
private var fireEffectLeft:Image;
private var fireEffectRight:Image;
private var moveSpeed:Int = 7;
private var hitPause:Float = 1.5;
private var animWait:Float = .75;
private var currentAnim:Int = 0;
} }

42
src/Score.hx Normal file
View file

@ -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;
}

View file

@ -1,6 +1,8 @@
import com.haxepunk.Entity; import com.haxepunk.Entity;
import com.haxepunk.HXP; import com.haxepunk.HXP;
import Asteroid; import Asteroid;
import Enemy;
class Spawner extends Entity { class Spawner extends Entity {
public function new () { public function new () {
@ -10,10 +12,11 @@ class Spawner extends Entity {
public override function update() { public override function update() {
spawnStarTime -= HXP.elapsed; spawnStarTime -= HXP.elapsed;
spawnAsteroidTime -= HXP.elapsed; spawnAsteroidTime -= HXP.elapsed;
spawnEnemyTime -= HXP.elapsed;
if (spawnAsteroidTime < 0) { if (spawnAsteroidTime < 0) {
this.scene.add(new Asteroid(HXP.width * Math.random(), -16)); this.scene.add(new Asteroid(HXP.width * Math.random(), -16));
spawnAsteroidTime = 1.5; spawnAsteroidTime = .5;
} }
if (spawnStarTime < 0) { if (spawnStarTime < 0) {
@ -21,9 +24,21 @@ class Spawner extends Entity {
spawnStarTime = .5; spawnStarTime = .5;
} }
if (spawnEnemyTime < 0 && this.scene.getInstance("player") != null) {
var enemies:Array<Entity> = [];
this.scene.getClass(Enemy, enemies);
if (enemies[0] == null) {
this.scene.add(new Enemy(HXP.halfWidth, -50));
}
spawnEnemyTime = 5;
}
super.update(); super.update();
} }
private var spawnAsteroidTime:Float = 1.5; private var spawnAsteroidTime:Float = .5;
private var spawnStarTime:Float = .5; private var spawnStarTime:Float = .5;
private var spawnEnemyTime:Float = 5;
} }

View file

@ -1,19 +1,22 @@
import com.haxepunk.Entity; import com.haxepunk.Entity;
import com.haxepunk.graphics.Image; import com.haxepunk.graphics.Image;
import com.haxepunk.graphics.Text; import com.haxepunk.graphics.Text;
import com.haxepunk.HXP;
import openfl.Assets;
class Title extends Entity { class Title extends Entity {
public function new (x:Float, y:Float) { public function new () {
super(x, y); super(HXP.width / 2, (HXP.height / 2) - 400);
var icon = new Image("graphics/cursor.png"); var icon = new Image("graphics/cursor.png");
icon.scale = 3.5; icon.scale = 3.5;
icon.x += 200; icon.x += 220;
var txt = new Text("Spaaace"); var txt = new Text("Spaaace");
txt.size = 80; txt.size = 80;
txt.x -= 20; txt.x -= 30;
txt.font = Assets.getFont("font/kenpixel_mini_square.ttf").fontName;
this.centerOrigin(); this.centerOrigin();
txt.centerOrigin(); txt.centerOrigin();
@ -21,6 +24,8 @@ class Title extends Entity {
this.addGraphic(txt); this.addGraphic(txt);
this.addGraphic(icon); this.addGraphic(icon);
this.layer = -5;
} }
} }