diff --git a/assets/save/savegame.save b/assets/save/savegame.save
new file mode 100644
index 0000000..e69de29
diff --git a/project.xml b/project.xml
index 3c80093..5aafdb3 100644
--- a/project.xml
+++ b/project.xml
@@ -15,6 +15,7 @@
+
diff --git a/src/Boss.hx b/src/Boss.hx
index 62bfc68..be85b91 100644
--- a/src/Boss.hx
+++ b/src/Boss.hx
@@ -50,8 +50,6 @@ class Boss extends Entity {
var enemies:Array = [];
this.scene.getClass(Enemy, enemies);
-
- trace(enemies.length + ", " + maxEnemies);
if (spawnTimer < 0 && enemies.length != maxEnemies && canSpawn) {
this.scene.add(new Enemy(this.width / 2, 20, color, Math.floor(Math.random() * 4) + 1));
diff --git a/src/Bullet.hx b/src/Bullet.hx
index a8b75cd..4ce0945 100644
--- a/src/Bullet.hx
+++ b/src/Bullet.hx
@@ -13,6 +13,9 @@ class Bullet extends Entity {
graphic = laser1;
setHitboxTo(laser1);
+ laser1.centerOrigin();
+ laser2.centerOrigin();
+ this.centerOrigin();
type = "bullet";
diff --git a/src/Lives.hx b/src/Lives.hx
index 43fb1e8..38f7436 100644
--- a/src/Lives.hx
+++ b/src/Lives.hx
@@ -3,17 +3,20 @@ import com.haxepunk.graphics.Image;
import com.haxepunk.HXP;
import Player;
+import Save;
class Lives extends Entity {
public function new () {
- baseSprite = new Image("graphics/playerShip1_green.png");
+ baseSprite = new Image("graphics/playerShip" + Save.load().ship_type + "_green.png");
sprite = [
baseSprite,
- new Image("graphics/playerShip1_damage1.png"),
- new Image("graphics/playerShip1_damage2.png"),
- new Image("graphics/playerShip1_damage3.png")
+ new Image("graphics/playerShip" + Save.load().ship_type + "_damage1.png"),
+ new Image("graphics/playerShip" + Save.load().ship_type + "_damage2.png"),
+ new Image("graphics/playerShip" + Save.load().ship_type + "_damage3.png")
];
+
+ maxDamage = Save.load().ship_type + Save.load().ship_color;
liveBar = Image.createRect(Math.floor(baseSprite.width * .75), 10, 0x00FF00);
liveBar.y += 65;
@@ -42,13 +45,13 @@ class Lives extends Entity {
public override function update() {
graphic = baseSprite;
- this.addGraphic(sprite[damage]);
+ this.addGraphic(sprite[Math.floor((damage / maxDamage) * 4)]);
- liveBar.scaledWidth = (liveBar.width / 4) * (4 - damage);
+ liveBar.scaledWidth = (liveBar.width / maxDamage) * (maxDamage - damage);
this.addGraphic(liveBar);
- if (damage > 3) {
+ if (damage == maxDamage) {
var player:Array = [];
this.scene.getClass(Player, player);
player[0].die();
@@ -61,6 +64,8 @@ class Lives extends Entity {
private var sprite:Array = [];
private var baseSprite:Image;
private var liveBar:Image;
+
private var damage:Int;
+ private var maxDamage:Int;
}
\ No newline at end of file
diff --git a/src/Main.hx b/src/Main.hx
index d9b07b2..8c27b7a 100644
--- a/src/Main.hx
+++ b/src/Main.hx
@@ -15,7 +15,7 @@ class Main extends Engine
HXP.resize(360, 640);
#end
- HXP.scene = new StoreScene();
+ HXP.scene = new MenuScene();
}
public static function main() { new Main(); }
diff --git a/src/MenuButton.hx b/src/MenuButton.hx
index 2f0c7cf..299ccb5 100644
--- a/src/MenuButton.hx
+++ b/src/MenuButton.hx
@@ -39,15 +39,19 @@ class MenuButton extends Entity {
}
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") {
+ if ((Input.mouseX > this.left && Input.mouseX < this.right) && (Input.mouseY > this.top && Input.mouseY < this.bottom) || Input.pressed("enter")) {
+ if (this.text.text == "Retry" || this.text.text == "Play!") {
HXP.scene = null;
Assets.cache.clear();
HXP.scene = new MainScene();
}
+ else if (this.text.text == "Store") {
+ HXP.scene = null;
+ Assets.cache.clear();
+ HXP.scene = new StoreScene();
+ }
else {
HXP.scene = null;
Assets.cache.clear();
@@ -55,34 +59,6 @@ class MenuButton extends Entity {
}
}
}
-
- 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;
diff --git a/src/Player.hx b/src/Player.hx
index 8b998cc..7f7dad5 100644
--- a/src/Player.hx
+++ b/src/Player.hx
@@ -12,11 +12,23 @@ import Bullet;
import Lives;
import Score;
import Explosion;
+import StoreScene;
+import Save;
class Player extends Entity {
public function new() {
super(HXP.halfWidth - 16, HXP.height - 200);
- baseSprite = new Image("graphics/playerShip1_green.png");
+ baseSprite = new Image("graphics/" + Save.load().ship);
+
+ if (Save.load().ship_type == 1)
+ moveSpeed = 10;
+ else if (Save.load().ship_type == 2)
+ moveSpeed = 7;
+ else
+ moveSpeed = 5;
+
+ trace(moveSpeed + ", " + Save.load().ship_type);
+
shield = new Image("graphics/shield1.png");
#if flash
@@ -39,18 +51,22 @@ class Player extends Entity {
new Image("graphics/fire17.png"),
];
- fireEffectLeft = fireEffectsLeft[currentAnim];
- fireEffectLeft.x = -30;
- fireEffectLeft.y = 24;
+ for (i in 0...fireEffectsLeft.length) {
+ fireEffectsLeft[i].originX = fireEffectsLeft[i].width / 2;
+ fireEffectsLeft[i].x = -30;
+ fireEffectsLeft[i].y = 24;
+ fireEffectsRight[i].originX = fireEffectsLeft[i].width / 2;
+ fireEffectsRight[i].x = 30;
+ fireEffectsRight[i].y = 24;
+ }
+ fireEffectLeft = fireEffectsLeft[currentAnim];
fireEffectRight = fireEffectsRight[currentAnim];
- fireEffectRight.x = 19;
- fireEffectRight.y = 24;
this.addGraphic(fireEffectLeft);
this.addGraphic(fireEffectRight);
- setHitbox(99, 75);
+ setHitboxTo(baseSprite);
Input.define("left", [Key.LEFT, Key.A]);
Input.define("right", [Key.RIGHT, Key.D]);
@@ -96,17 +112,32 @@ class Player extends Entity {
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));
+ score[0].rem(250);
+ var ship:Int = Save.load().ship_type;
+
+ if (ship == 3){
+ this.scene.add(new Bullet(this.x, this.y - this.height / 2));
+ }
+ else if (ship == 1) {
+ this.scene.add(new Bullet(this.x + 40, this.y - 20));
+ this.scene.add(new Bullet(this.x - 40, this.y - 20));
+ }
+ else if (ship == 2) {
+ this.scene.add(new Bullet(this.x, this.y - this.height / 2));
+ this.scene.add(new Bullet(this.x - 40, this.y - 20));
+ this.scene.add(new Bullet(this.x + 40, this.y - 20));
+ }
laser.play();
}
}
public function die() {
this.visible = false;
+ var score:Array = [];
+ this.scene.getClass(Score, score);
+
this.scene.add(new Explosion(this.x, this.y, this));
@@ -115,8 +146,10 @@ class Player extends Entity {
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;
+ Save.save("money", score[0].score);
+
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, "Store"));
this.scene.add(new MenuButton(HXP.halfWidth, HXP.halfHeight + 50, "Menu"));
}
@@ -135,12 +168,8 @@ class Player extends Entity {
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);
@@ -185,13 +214,14 @@ class Player extends Entity {
private var fireEffectsLeft:Array = [];
private var fireEffectsRight:Array = [];
+ private var moveSpeed:Float;
+ public var health:Int;
private var fireEffectLeft:Image;
private var fireEffectRight:Image;
- private var moveSpeed:Int = 7;
- private var hitPause:Float = 0;
+ private var hitPause:Float = 0;
private var animWait:Float = .75;
private var currentAnim:Int = 0;
diff --git a/src/Save.hx b/src/Save.hx
index f681c75..0790781 100644
--- a/src/Save.hx
+++ b/src/Save.hx
@@ -5,19 +5,22 @@ class Save extends Entity {
public function new() {
super();
- Data.load("savegame.save");
+ Data.load("save/savegame.save");
}
public static function save(what:String, data:Dynamic) {
Data.write(what, data);
- Data.save("savegame.save", true);
+ Data.save("save/savegame.save", true);
}
public static function load() {
var data = {
- "current_ship" : Data.readString("ship" , "playerShip3_green"),
- "current_laser" : Data.readString("laser", "laserGreen04.png"),
- "has_heavy_laser" : Data.readBool("heavy_laser", false)
+ "ship" : Data.readString("ship" , "playerShip3_green.png"),
+ "ship_type" : Data.readInt("ship_type", 3),
+ "ship_color" : Data.readInt("ship_color", 1),
+ "laser" : Data.readString("laser", "laserGreen04.png"),
+ "has_heavy_laser" : Data.readBool("heavy_laser", false),
+ "money" : Data.readInt("money", 1000)
};
return data;
diff --git a/src/Score.hx b/src/Score.hx
index d086b1b..339ebbe 100644
--- a/src/Score.hx
+++ b/src/Score.hx
@@ -4,14 +4,16 @@ import com.haxepunk.graphics.Text;
import openfl.Assets;
+import Save;
+
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});
+ score = Save.load().money;
+ scoreText = new Text("$" + score, 0, 0, 0, 0, {size : 50, align : "center", color : 0xFFF000});
scoreText.font = Assets.getFont("font/kenpixel_mini_square.ttf").fontName;
layer = -3;
diff --git a/src/StoreArrows.hx b/src/StoreArrows.hx
index e615e80..34855c6 100644
--- a/src/StoreArrows.hx
+++ b/src/StoreArrows.hx
@@ -62,8 +62,6 @@ class StoreArrows extends Entity {
}
}
- Input.touchPoints(onTouch);
-
}
private function onTouch(touch:Touch) {
diff --git a/src/StoreItem.hx b/src/StoreItem.hx
index 46c5f4d..4859e21 100644
--- a/src/StoreItem.hx
+++ b/src/StoreItem.hx
@@ -2,6 +2,8 @@ import com.haxepunk.Entity;
import com.haxepunk.graphics.Image;
import com.haxepunk.graphics.Text;
import com.haxepunk.utils.Input;
+import com.haxepunk.utils.Touch;
+
import openfl.Assets;
class StoreItem extends Entity {
@@ -64,6 +66,23 @@ class StoreItem extends Entity {
this.addGraphic(button);
this.addGraphic(text);
this.addGraphic(description);
+
+ if (Input.mouseReleased) {
+ if ((Input.mouseX > this.left && Input.mouseX < this.right) && (Input.mouseY > this.top && Input.mouseY < this.bottom)) {
+ buy();
+ }
+ }
+ }
+
+ private function buy() {
+ var save = Save.load();
+ if (save.money >= prices[which][currentSprite]) {
+ Save.save("ship", items[which][currentSprite]);
+ Save.save("ship_type", which);
+ Save.save("ship_color", currentSprite);
+ Save.save("money", save.money - prices[which][currentSprite]);
+ trace("Bought something");
+ }
}
public function goLeft() {
diff --git a/src/StoreScene.hx b/src/StoreScene.hx
index 677a435..54f8692 100644
--- a/src/StoreScene.hx
+++ b/src/StoreScene.hx
@@ -14,7 +14,7 @@ class StoreScene extends Scene {
public override function begin() {
backdrop = new Backdrop("graphics/darkPurple.png", true, true);
addGraphic(backdrop);
- var buyText:Text = new Text("Buy :", HXP.halfWidth - 100, 50, 0, 0, {size: 40});
+ buyText = new Text("$" + Save.load().money + ", Buy :", HXP.halfWidth - 100, 50, 0, 0, {size: 40});
buyText.font = Assets.getFont("font/kenpixel_mini_square.ttf").fontName;
addGraphic(buyText);
@@ -23,13 +23,16 @@ class StoreScene extends Scene {
add(new StoreArrows(HXP.halfWidth, 200 + (i * 200), i));
}
- trace(Save.load());
+ this.add(new MenuButton(HXP.halfWidth - 220, HXP.height - 50, "Retry"));
+ this.add(new MenuButton(HXP.halfWidth + 220, HXP.height - 50, "Menu"));
}
public override function update() {
super.update();
+ buyText.text = "$" + Save.load().money + ", Buy :";
backdrop.y += 1;
}
private var backdrop:Backdrop;
-}
\ No newline at end of file
+ private var buyText:Text;
+}