1
0
mirror of https://github.com/Melon-Bread/Pet.GB synced 2024-11-28 13:58:20 -05:00

Added more features 🏄

- Able to see the Current in-game hour
- Able to set day length when making new clock
This commit is contained in:
Rain Clark 2016-10-08 01:09:11 -04:00
parent aecd13a460
commit ee1fca4709
2 changed files with 49 additions and 9 deletions

View File

@ -7,14 +7,16 @@ class Clock
{ {
private var _timer:FlxTimer; private var _timer:FlxTimer;
public var CurrentHour:Int = 0;
public var HourPassed:Bool = false; public var HourPassed:Bool = false;
public var DayPassed: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(); _timer = new FlxTimer();
// Every 3 real-time minutes 1 in-game hour passes // Every 3 real-time minutes 1 in-game hour passes
_timer.start(RtG, hourEnd, 5); //24 _timer.start(RtG, hourEnd, HtD);
// DEBUG // DEBUG
FlxG.watch.add(_timer, "progress", "Day Completion:"); FlxG.watch.add(_timer, "progress", "Day Completion:");
@ -30,6 +32,7 @@ class Clock
private function hourEnd(Timer:FlxTimer):Void private function hourEnd(Timer:FlxTimer):Void
{ {
HourPassed = true; HourPassed = true;
CurrentHour = _timer.elapsedLoops;
} }
private function dayEnd():Void private function dayEnd():Void

View File

@ -4,6 +4,7 @@ import flixel.FlxG;
import flixel.FlxSprite; import flixel.FlxSprite;
import flixel.FlxState; import flixel.FlxState;
import flixel.system.debug.FlxDebugger; import flixel.system.debug.FlxDebugger;
import flixel.util.FlxSave;
class PlayState extends FlxState class PlayState extends FlxState
{ {
@ -11,40 +12,43 @@ class PlayState extends FlxState
private var _gelPet:Gel; private var _gelPet:Gel;
private var _clock:Clock;
private var _hud:HUD; private var _hud:HUD;
private var _infoMenu:InfoMenu; private var _infoMenu:InfoMenu;
public static var GameVolume = 1;
override public function create():Void override public function create():Void
{ {
// SAVE BEGIN // SAVE BEGIN
var _save:FlxSave = new FlxSave(); var _save:FlxSave = new FlxSave();
_save.bind("Pet.GB") _save.bind("Pet.GB");
_sprBackground = new FlxSprite(0, 0, AssetPaths.background__png); _sprBackground = new FlxSprite(0, 0, AssetPaths.background__png);
add(_sprBackground); add(_sprBackground);
_clock = new Clock();
if (_save.data.GelPet == null) if (_save.data.GelPet == null)
{ {
_gelPet = new Gel(); _gelPet = new Gel(0, 0, _clock);
_gelPet.x = ((FlxG.width/2) - (_gelPet.width/2)); _gelPet.x = ((FlxG.width/2) - (_gelPet.width/2));
_gelPet.y = ((FlxG.height/2) - (_gelPet.height/2)); _gelPet.y = ((FlxG.height/2) - (_gelPet.height/2));
} }
else else
{ {
_gelPet = _save.data.GelPet; _gelPet = _save.data.gel;
_gelPet._clock = _save.data.GelPet.Clock; _gelPet._clock = _save.data.clock;
} }
add(_gelPet); add(_gelPet);
// Interface // Interface
_infoMenu = new InfoMenu(_gelPet); _infoMenu = new InfoMenu(_gelPet);
if (_save.data.HUD == null) if (_save.data.HUD == null)
_hud = new HUD(_gelPet, _infoMenu); _hud = new HUD(_gelPet, _clock, _infoMenu);
else else
_hud = _save.data.HUD; _hud = _save.data.hud;
add(_hud); add(_hud);
add(_infoMenu); add(_infoMenu);
@ -71,6 +75,39 @@ class PlayState extends FlxState
_gelPet.active = true; _gelPet.active = true;
_gelPet._clock.pause(false); _gelPet._clock.pause(false);
_hud.active = true; _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;
}
} }