Added save files and tweaked some of the store mechanics.
This commit is contained in:
parent
7766abcb37
commit
f0375c798b
26
src/Save.hx
Normal file
26
src/Save.hx
Normal file
|
@ -0,0 +1,26 @@
|
|||
import com.haxepunk.Entity;
|
||||
import com.haxepunk.utils.Data;
|
||||
|
||||
class Save extends Entity {
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
Data.load("savegame.save");
|
||||
}
|
||||
|
||||
public static function save(what:String, data:Dynamic) {
|
||||
Data.write(what, data);
|
||||
Data.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)
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
}
|
|
@ -10,6 +10,10 @@ class StoreArrows extends Entity {
|
|||
public function new(x:Float, y:Float, type:Int) {
|
||||
super(x - 230, y);
|
||||
which = type;
|
||||
if (type != 4)
|
||||
currentItem = 1;
|
||||
else
|
||||
currentItem = 0;
|
||||
|
||||
arrowLeft = new Image("graphics/fire05.png");
|
||||
arrowLeft.angle = 90;
|
||||
|
@ -32,16 +36,28 @@ class StoreArrows extends Entity {
|
|||
public override function update() {
|
||||
super.update();
|
||||
|
||||
var storeItems:Array<StoreItem> = [];
|
||||
this.scene.getClass(StoreItem, storeItems);
|
||||
|
||||
if (currentItem == 0)
|
||||
arrowLeft.visible = false;
|
||||
else
|
||||
arrowLeft.visible = true;
|
||||
if (currentItem == storeItems[which].items[which].length - 1)
|
||||
arrowRight.visible = false;
|
||||
else
|
||||
arrowRight.visible = true;
|
||||
|
||||
if (Input.mouseReleased) {
|
||||
var storeItems:Array<StoreItem> = [];
|
||||
this.scene.getClass(StoreItem, storeItems);
|
||||
|
||||
if (Input.mouseY > this.top && Input.mouseY < this.bottom) {
|
||||
if (Input.mouseX > this.left && Input.mouseX < this.left + 100) {
|
||||
storeItems[which].goLeft();
|
||||
if (currentItem != 0) currentItem--;
|
||||
}
|
||||
if (Input.mouseX < this.right && Input.mouseX > this.right - 100) {
|
||||
storeItems[which].goRight();
|
||||
storeItems[which].goRight();
|
||||
if (currentItem != storeItems[which].items[which].length - 1) currentItem++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -67,4 +83,5 @@ class StoreArrows extends Entity {
|
|||
private var arrowLeft:Image;
|
||||
private var arrowRight:Image;
|
||||
private var which:Int;
|
||||
private var currentItem:Int;
|
||||
}
|
|
@ -93,7 +93,7 @@ class StoreItem extends Entity {
|
|||
"Heavy Laser"
|
||||
];
|
||||
|
||||
private var items:Array<Array<String>> = [
|
||||
public var items:Array<Array<String>> = [
|
||||
[
|
||||
"playerShip3_green.png",
|
||||
"playerShip3_blue.png",
|
||||
|
|
|
@ -7,6 +7,8 @@ import openfl.Assets;
|
|||
import StoreItem;
|
||||
import StoreArrows;
|
||||
|
||||
import Save;
|
||||
|
||||
class StoreScene extends Scene {
|
||||
|
||||
public override function begin() {
|
||||
|
@ -20,6 +22,8 @@ class StoreScene extends Scene {
|
|||
add(new StoreItem(HXP.halfWidth, 200 + (i * 200), i));
|
||||
add(new StoreArrows(HXP.halfWidth, 200 + (i * 200), i));
|
||||
}
|
||||
|
||||
trace(Save.load());
|
||||
}
|
||||
|
||||
public override function update() {
|
||||
|
|
Reference in a new issue