diff --git a/source/Clock.hx b/source/Clock.hx index 77d0124..711d6f7 100644 --- a/source/Clock.hx +++ b/source/Clock.hx @@ -7,14 +7,16 @@ class Clock { private var _timer:FlxTimer; + public var CurrentHour:Int = 0; + public var HourPassed:Bool = false; public var DayPassed:Bool = false; - public function new(RtG:Int = 20) //120 + public function new(RtG:Int = 10, HtD = 24) //60 & 24 { _timer = new FlxTimer(); // Every 3 real-time minutes 1 in-game hour passes - _timer.start(RtG, hourEnd, 5); //24 + _timer.start(RtG, hourEnd, HtD); // DEBUG FlxG.watch.add(_timer, "progress", "Day Completion:"); @@ -30,6 +32,7 @@ class Clock private function hourEnd(Timer:FlxTimer):Void { HourPassed = true; + CurrentHour = _timer.elapsedLoops; } private function dayEnd():Void diff --git a/source/PlayState.hx b/source/PlayState.hx index 1ac7ac0..993a601 100644 --- a/source/PlayState.hx +++ b/source/PlayState.hx @@ -4,6 +4,7 @@ import flixel.FlxG; import flixel.FlxSprite; import flixel.FlxState; import flixel.system.debug.FlxDebugger; +import flixel.util.FlxSave; class PlayState extends FlxState { @@ -11,40 +12,43 @@ class PlayState extends FlxState private var _gelPet:Gel; + private var _clock:Clock; + private var _hud:HUD; private var _infoMenu:InfoMenu; - public static var GameVolume = 1; override public function create():Void { // SAVE BEGIN var _save:FlxSave = new FlxSave(); - _save.bind("Pet.GB") + _save.bind("Pet.GB"); _sprBackground = new FlxSprite(0, 0, AssetPaths.background__png); add(_sprBackground); + _clock = new Clock(); + if (_save.data.GelPet == null) { - _gelPet = new Gel(); + _gelPet = new Gel(0, 0, _clock); _gelPet.x = ((FlxG.width/2) - (_gelPet.width/2)); _gelPet.y = ((FlxG.height/2) - (_gelPet.height/2)); } else { - _gelPet = _save.data.GelPet; - _gelPet._clock = _save.data.GelPet.Clock; + _gelPet = _save.data.gel; + _gelPet._clock = _save.data.clock; } add(_gelPet); // Interface _infoMenu = new InfoMenu(_gelPet); if (_save.data.HUD == null) - _hud = new HUD(_gelPet, _infoMenu); + _hud = new HUD(_gelPet, _clock, _infoMenu); else - _hud = _save.data.HUD; + _hud = _save.data.hud; add(_hud); add(_infoMenu); @@ -71,6 +75,39 @@ class PlayState extends FlxState _gelPet.active = true; _gelPet._clock.pause(false); _hud.active = true; + saveGame(); } } + + private function saveGame() + { + // SAVE BEGIN + var _save:FlxSave = new FlxSave(); + _save.bind("Pet.GB"); + + // SAVED DATA + _save.data.gel = _gelPet; + _save.data.clock = _gelPet._clock; + _save.data.hud = _hud; + //_save.data.age = _gel.age; + + // WRITE SAVE + //_save.flush(); + + // SAVE END + _save.close; + } + + private function quitGame():Void + { + // SAVE BEGIN + var _save:FlxSave = new FlxSave(); + _save.bind("Pet.GB"); + + // SAVED DATA + _save.data.HUD = _hud; + + // SAVE END + _save.close; + } }