2016-10-03 20:43:09 -04:00
|
|
|
package;
|
|
|
|
|
|
|
|
import flixel.FlxG;
|
|
|
|
import flixel.FlxSprite;
|
|
|
|
import flixel.FlxState;
|
2016-10-06 01:18:02 -04:00
|
|
|
import flixel.system.debug.FlxDebugger;
|
2016-10-08 01:09:11 -04:00
|
|
|
import flixel.util.FlxSave;
|
2016-10-03 20:43:09 -04:00
|
|
|
|
|
|
|
class PlayState extends FlxState
|
|
|
|
{
|
|
|
|
private var _sprBackground:FlxSprite;
|
|
|
|
|
|
|
|
private var _gelPet:Gel;
|
|
|
|
|
2016-10-08 01:09:11 -04:00
|
|
|
private var _clock:Clock;
|
|
|
|
|
2016-10-03 20:43:09 -04:00
|
|
|
private var _hud:HUD;
|
|
|
|
|
2016-10-07 06:01:39 -04:00
|
|
|
private var _infoMenu:InfoMenu;
|
|
|
|
|
2016-10-06 01:18:02 -04:00
|
|
|
|
2016-10-03 20:43:09 -04:00
|
|
|
override public function create():Void
|
|
|
|
{
|
2016-10-07 07:19:05 -04:00
|
|
|
// SAVE BEGIN
|
|
|
|
var _save:FlxSave = new FlxSave();
|
2016-10-08 01:09:11 -04:00
|
|
|
_save.bind("Pet.GB");
|
2016-10-07 07:19:05 -04:00
|
|
|
|
2016-10-03 20:43:09 -04:00
|
|
|
_sprBackground = new FlxSprite(0, 0, AssetPaths.background__png);
|
|
|
|
add(_sprBackground);
|
|
|
|
|
2016-10-08 01:09:11 -04:00
|
|
|
_clock = new Clock();
|
|
|
|
|
2016-10-07 07:19:05 -04:00
|
|
|
if (_save.data.GelPet == null)
|
|
|
|
{
|
2016-10-08 01:09:11 -04:00
|
|
|
_gelPet = new Gel(0, 0, _clock);
|
2016-10-07 07:19:05 -04:00
|
|
|
_gelPet.x = ((FlxG.width/2) - (_gelPet.width/2));
|
|
|
|
_gelPet.y = ((FlxG.height/2) - (_gelPet.height/2));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-10-08 01:09:11 -04:00
|
|
|
_gelPet = _save.data.gel;
|
|
|
|
_gelPet._clock = _save.data.clock;
|
2016-10-07 07:19:05 -04:00
|
|
|
}
|
2016-10-03 20:43:09 -04:00
|
|
|
add(_gelPet);
|
|
|
|
|
2016-10-07 06:01:39 -04:00
|
|
|
// Interface
|
|
|
|
_infoMenu = new InfoMenu(_gelPet);
|
2016-10-07 07:19:05 -04:00
|
|
|
if (_save.data.HUD == null)
|
2016-10-08 01:09:11 -04:00
|
|
|
_hud = new HUD(_gelPet, _clock, _infoMenu);
|
2016-10-07 07:19:05 -04:00
|
|
|
else
|
2016-10-08 01:09:11 -04:00
|
|
|
_hud = _save.data.hud;
|
2016-10-03 20:43:09 -04:00
|
|
|
add(_hud);
|
2016-10-07 06:01:39 -04:00
|
|
|
add(_infoMenu);
|
2016-10-03 20:43:09 -04:00
|
|
|
|
|
|
|
super.create();
|
2016-10-07 00:16:45 -04:00
|
|
|
|
|
|
|
// DEBUG
|
|
|
|
FlxG.debugger.setLayout(FlxDebuggerLayout.RIGHT);
|
2016-10-07 07:19:05 -04:00
|
|
|
|
|
|
|
// SAVE END
|
|
|
|
_save.close();
|
2016-10-03 20:43:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
override public function update(elapsed:Float):Void
|
|
|
|
{
|
|
|
|
super.update(elapsed);
|
2016-10-07 06:01:39 -04:00
|
|
|
if (_infoMenu.visible)
|
|
|
|
{
|
|
|
|
_gelPet.active = false;
|
2016-10-09 05:30:25 -04:00
|
|
|
_clock.pause(true);
|
2016-10-07 06:01:39 -04:00
|
|
|
_hud.active = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_gelPet.active = true;
|
2016-10-09 05:30:25 -04:00
|
|
|
_clock.pause(false);
|
2016-10-07 06:01:39 -04:00
|
|
|
_hud.active = true;
|
2016-10-08 01:09:11 -04:00
|
|
|
saveGame();
|
2016-10-07 06:01:39 -04:00
|
|
|
}
|
2016-10-09 05:30:25 -04:00
|
|
|
|
|
|
|
if (_gelPet.CurrentMood == Gel.Mood.EXCITED || _gelPet.CurrentMood == Gel.Mood.ASHAMED)
|
|
|
|
_clock.pause();
|
|
|
|
else
|
|
|
|
_clock.pause(false);
|
2016-10-03 20:43:09 -04:00
|
|
|
}
|
2016-10-08 01:09:11 -04:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2016-10-03 20:43:09 -04:00
|
|
|
}
|