From f0375c798bc514c095f8b2159e13cdb2a160b001 Mon Sep 17 00:00:00 2001 From: Bram van der Veen <96aa48@gmail.com> Date: Tue, 15 Jul 2014 18:35:41 +0200 Subject: [PATCH] Added save files and tweaked some of the store mechanics. --- src/Save.hx | 26 ++++++++++++++++++++++++++ src/StoreArrows.hx | 23 ++++++++++++++++++++--- src/StoreItem.hx | 2 +- src/StoreScene.hx | 4 ++++ 4 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 src/Save.hx diff --git a/src/Save.hx b/src/Save.hx new file mode 100644 index 0000000..f681c75 --- /dev/null +++ b/src/Save.hx @@ -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; + } + +} \ No newline at end of file diff --git a/src/StoreArrows.hx b/src/StoreArrows.hx index 3d0ee7b..e615e80 100644 --- a/src/StoreArrows.hx +++ b/src/StoreArrows.hx @@ -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 = []; + 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 = []; - 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; } \ No newline at end of file diff --git a/src/StoreItem.hx b/src/StoreItem.hx index 33164a0..46c5f4d 100644 --- a/src/StoreItem.hx +++ b/src/StoreItem.hx @@ -93,7 +93,7 @@ class StoreItem extends Entity { "Heavy Laser" ]; - private var items:Array> = [ + public var items:Array> = [ [ "playerShip3_green.png", "playerShip3_blue.png", diff --git a/src/StoreScene.hx b/src/StoreScene.hx index afbf84e..677a435 100644 --- a/src/StoreScene.hx +++ b/src/StoreScene.hx @@ -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() {