2016-10-03 20:43:09 -04:00
|
|
|
package;
|
|
|
|
|
|
|
|
import flixel.FlxG;
|
|
|
|
import flixel.FlxSprite;
|
2016-10-09 05:29:51 -04:00
|
|
|
import flixel.system.FlxSound;
|
2016-10-03 20:43:09 -04:00
|
|
|
|
|
|
|
class Gel extends FlxSprite
|
|
|
|
{
|
|
|
|
// Modifiers Range
|
|
|
|
private var MIN_LEVEL(default, never):Int = 0;
|
|
|
|
private var MAX_LEVEL(default, never):Int = 100;
|
|
|
|
|
|
|
|
// Usless Stats that have no pupose yet
|
2016-10-07 06:00:22 -04:00
|
|
|
public var Intellect:Int = 1; // Had to be somewhat smart to get out of the egg
|
2016-10-07 01:19:45 -04:00
|
|
|
public var Age:Int = 1;
|
2016-10-03 20:43:09 -04:00
|
|
|
|
|
|
|
// Mood Modifiers
|
|
|
|
public var Happiness:Int = 50;
|
|
|
|
public var Discipline:Int = 50;
|
|
|
|
public var Fullness = 50;
|
2016-10-04 01:30:51 -04:00
|
|
|
public var Sleepiness = 0;
|
2016-10-04 07:11:27 -04:00
|
|
|
public var Waste = 0;
|
2016-10-03 20:43:09 -04:00
|
|
|
|
|
|
|
//private var _inEgg:Bool = true;
|
2016-10-05 03:00:48 -04:00
|
|
|
public var _isHungry:Bool = false;
|
|
|
|
public var _wasteReady:Bool = false;
|
2016-10-05 07:28:10 -04:00
|
|
|
public var _madeWaste:Bool = false;
|
2016-10-05 03:00:48 -04:00
|
|
|
public var _isTired:Bool = false;
|
2016-10-05 07:28:10 -04:00
|
|
|
public var _isAsleep:Bool = false;
|
2016-10-03 20:43:09 -04:00
|
|
|
|
2016-10-05 23:36:42 -04:00
|
|
|
// Menu Locks
|
2016-10-06 01:18:02 -04:00
|
|
|
public var Wait:Bool = false;
|
2016-10-05 23:36:42 -04:00
|
|
|
private var _hasStudied:Bool = false;
|
|
|
|
|
2016-10-05 03:00:48 -04:00
|
|
|
// Mood/Needs
|
2016-10-05 07:28:10 -04:00
|
|
|
public var CurrentMood:Mood = NEUTRAL;
|
2016-10-05 03:00:48 -04:00
|
|
|
public var CurrentNeed:Need = NONE;
|
2016-10-03 20:43:09 -04:00
|
|
|
|
2016-10-06 01:18:02 -04:00
|
|
|
// Sleep Timer
|
|
|
|
private var _hoursAsleep:Int = 0;
|
|
|
|
|
2016-10-09 05:29:51 -04:00
|
|
|
// Sound Effects
|
|
|
|
private var _sndExcited:FlxSound;
|
|
|
|
private var _sndAshamed:FlxSound;
|
2016-10-03 20:43:09 -04:00
|
|
|
|
2016-10-05 07:28:10 -04:00
|
|
|
// Gels internal clock
|
2016-10-07 06:00:22 -04:00
|
|
|
public var _clock:Clock;
|
2016-10-05 07:28:10 -04:00
|
|
|
|
2016-10-08 01:15:21 -04:00
|
|
|
public function new(?X:Float=0, ?Y:Float=0, clock:Clock)
|
2016-10-03 20:43:09 -04:00
|
|
|
{
|
|
|
|
super(X, Y);
|
|
|
|
|
|
|
|
loadGraphic(AssetPaths.Player__png, true, 64, 64);
|
2016-10-07 07:19:05 -04:00
|
|
|
animation.add("neutral", [0, 1, 2, 3, 4, 5, 4, 3, 2, 1], 5, true);
|
2016-10-08 01:15:21 -04:00
|
|
|
animation.add("happy", [6, 7, 8, 9, 10, 11, 10, 9, 8, 7], 5, true);
|
2016-10-07 07:19:05 -04:00
|
|
|
animation.add("angry", [12, 13, 14, 13], 5, true);
|
|
|
|
animation.add("sleeping", [15, 16, 17, 16], 3, true);
|
2016-10-09 05:29:51 -04:00
|
|
|
animation.add("excited", [18, 19, 20, 20, 19, 18], 6, false);
|
2016-10-07 07:19:05 -04:00
|
|
|
animation.add("ashamed", [21, 22, 23, 22], 4, false);
|
2016-10-05 07:28:10 -04:00
|
|
|
|
2016-10-08 01:15:21 -04:00
|
|
|
_clock = clock;
|
2016-10-03 20:43:09 -04:00
|
|
|
|
2016-10-09 05:29:51 -04:00
|
|
|
// Sound Effects
|
|
|
|
_sndExcited = FlxG.sound.load(AssetPaths.Excited__ogg);
|
|
|
|
_sndAshamed = FlxG.sound.load(AssetPaths.Ashamed__ogg);
|
|
|
|
|
2016-10-03 20:43:09 -04:00
|
|
|
// DEBUG
|
2016-10-05 07:28:10 -04:00
|
|
|
FlxG.watch.add(this, "Age");
|
2016-10-05 03:00:48 -04:00
|
|
|
FlxG.watch.add(this, "CurrentMood");
|
2016-10-09 05:29:51 -04:00
|
|
|
FlxG.watch.add(animation, "finished");
|
2016-10-05 03:00:48 -04:00
|
|
|
FlxG.watch.add(this, "CurrentNeed");
|
2016-10-07 00:59:34 -04:00
|
|
|
FlxG.watch.add(this.animation, "name", "Gel.animation");
|
2016-10-04 04:11:36 -04:00
|
|
|
FlxG.watch.add(this, "Wait");
|
2016-10-05 23:36:42 -04:00
|
|
|
FlxG.watch.add(this, "Intellect");
|
|
|
|
FlxG.watch.add(this, "_hasStudied");
|
2016-10-03 20:43:09 -04:00
|
|
|
FlxG.watch.add(this, "Happiness");
|
2016-10-04 07:11:27 -04:00
|
|
|
FlxG.watch.add(this, "Discipline");
|
2016-10-03 20:43:09 -04:00
|
|
|
FlxG.watch.add(this, "Fullness");
|
2016-10-05 07:28:10 -04:00
|
|
|
FlxG.watch.add(this, "_isHungry");
|
|
|
|
FlxG.watch.add(this, "Waste");
|
|
|
|
FlxG.watch.add(this, "_wasteReady");
|
|
|
|
FlxG.watch.add(this, "_madeWaste");
|
|
|
|
FlxG.watch.add(this, "Sleepiness");
|
|
|
|
FlxG.watch.add(this, "_isTired");
|
|
|
|
FlxG.watch.add(this, "_isAsleep");
|
2016-10-06 01:18:02 -04:00
|
|
|
FlxG.watch.add(this, "_hoursAsleep");
|
2016-10-03 20:43:09 -04:00
|
|
|
}
|
|
|
|
|
2016-10-05 03:00:48 -04:00
|
|
|
override function update(elapsed:Float):Void
|
2016-10-03 20:43:09 -04:00
|
|
|
{
|
2016-10-05 03:00:48 -04:00
|
|
|
super.update(elapsed);
|
2016-10-03 20:43:09 -04:00
|
|
|
|
2016-10-05 07:28:10 -04:00
|
|
|
_clock.update();
|
|
|
|
if (_clock.HourPassed)
|
|
|
|
newHour();
|
|
|
|
if (_clock.DayPassed)
|
|
|
|
newDay();
|
|
|
|
|
2016-10-09 05:29:51 -04:00
|
|
|
if (animation.name == "excited" && !_sndExcited.playing)
|
|
|
|
resumeMood();
|
|
|
|
else if (animation.name == "ashamed" && !_sndAshamed.playing)
|
|
|
|
resumeMood();
|
|
|
|
|
2016-10-05 03:00:48 -04:00
|
|
|
checkMood();
|
|
|
|
checkNeed();
|
2016-10-05 07:28:10 -04:00
|
|
|
checkRange();
|
2016-10-03 20:43:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
private function checkMood():Void
|
|
|
|
{
|
2016-10-06 01:18:02 -04:00
|
|
|
if (_isAsleep)
|
2016-10-07 00:59:34 -04:00
|
|
|
CurrentMood = SLEEPING;
|
2016-10-09 05:29:51 -04:00
|
|
|
else if (CurrentMood == EXCITED)
|
|
|
|
return;
|
|
|
|
else if (CurrentMood == ASHAMED)
|
|
|
|
return;
|
2016-10-06 01:18:02 -04:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (Happiness >= 61)
|
|
|
|
CurrentMood = HAPPY;
|
|
|
|
else if (Happiness >= 40 && Happiness <= 60)
|
|
|
|
CurrentMood = NEUTRAL;
|
|
|
|
else if (Happiness <= 39)
|
|
|
|
CurrentMood = ANGRY;
|
|
|
|
}
|
2016-10-05 03:00:48 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
private function checkNeed():Void
|
|
|
|
{
|
2016-10-05 07:28:10 -04:00
|
|
|
// Fullness Checks
|
|
|
|
if(Fullness < 50)
|
|
|
|
_isHungry = true;
|
|
|
|
else
|
|
|
|
_isHungry = false;
|
|
|
|
|
|
|
|
// Waste Check
|
2016-10-08 01:15:21 -04:00
|
|
|
if (Waste > 85 && Waste < 100)
|
2016-10-05 07:28:10 -04:00
|
|
|
_wasteReady = true;
|
|
|
|
else if (Waste >= 100)
|
|
|
|
makeWaste();
|
|
|
|
else
|
|
|
|
_wasteReady = false;
|
|
|
|
|
2016-10-06 01:18:02 -04:00
|
|
|
// Sleepy Check
|
|
|
|
if (Sleepiness >= 90)
|
|
|
|
_isTired = true;
|
|
|
|
else
|
|
|
|
_isTired = false;
|
2016-10-05 07:28:10 -04:00
|
|
|
|
2016-10-06 01:18:02 -04:00
|
|
|
// Sets active needs
|
2016-10-05 03:00:48 -04:00
|
|
|
if (_isHungry)
|
|
|
|
CurrentNeed = HUNGRY;
|
|
|
|
else if (_wasteReady)
|
|
|
|
CurrentNeed = POOPY;
|
|
|
|
else if (_isTired)
|
|
|
|
CurrentNeed = SLEEPY;
|
|
|
|
else
|
|
|
|
CurrentNeed = NONE;
|
2016-10-03 20:43:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function EatFood():Void
|
|
|
|
{
|
2016-10-04 04:11:36 -04:00
|
|
|
Wait = true;
|
2016-10-03 20:43:09 -04:00
|
|
|
// Stat changes
|
2016-10-04 04:11:36 -04:00
|
|
|
|
|
|
|
if ((Fullness + 25) > 100)
|
|
|
|
{
|
|
|
|
Happiness -= 5; // Unhappy from over feeding
|
2016-10-06 01:18:02 -04:00
|
|
|
Discipline -= 5;
|
2016-10-09 05:29:51 -04:00
|
|
|
beAshamed();
|
2016-10-04 04:11:36 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Fullness += 25;
|
|
|
|
Happiness += 10;
|
2016-10-06 01:18:02 -04:00
|
|
|
//Discipline -=5;
|
2016-10-05 07:28:10 -04:00
|
|
|
Waste +=5;
|
2016-10-04 04:11:36 -04:00
|
|
|
}
|
2016-10-05 08:04:07 -04:00
|
|
|
}
|
2016-10-03 20:43:09 -04:00
|
|
|
|
2016-10-05 23:36:42 -04:00
|
|
|
public function Study():Void
|
|
|
|
{
|
2016-10-07 01:19:45 -04:00
|
|
|
var _ageBonus:Float = Age/4;
|
|
|
|
|
|
|
|
if (FlxG.random.bool(Discipline))
|
2016-10-05 23:36:42 -04:00
|
|
|
{
|
2016-10-07 01:19:45 -04:00
|
|
|
if (!_hasStudied && !_isTired)
|
|
|
|
{
|
|
|
|
Intellect += (1 * (1 + Std.int(_ageBonus)));
|
|
|
|
Happiness -= 5;
|
|
|
|
Fullness -= 5;
|
|
|
|
Sleepiness += 15;
|
2016-10-09 05:29:51 -04:00
|
|
|
beExcited();
|
2016-10-07 01:19:45 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-10-09 05:29:51 -04:00
|
|
|
beAshamed();
|
2016-10-05 23:36:42 -04:00
|
|
|
}
|
2016-10-07 01:19:45 -04:00
|
|
|
// Can only study once per hour, even if check failed
|
2016-10-05 23:36:42 -04:00
|
|
|
_hasStudied = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function Sleep():Void
|
|
|
|
{
|
2016-10-06 01:18:02 -04:00
|
|
|
if (!_isTired)
|
|
|
|
{
|
|
|
|
Happiness -= 5;
|
2016-10-09 05:29:51 -04:00
|
|
|
beAshamed();
|
2016-10-06 01:18:02 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_isAsleep = true;
|
|
|
|
_isTired = false;
|
|
|
|
Sleepiness = 0;
|
|
|
|
}
|
2016-10-05 23:36:42 -04:00
|
|
|
}
|
|
|
|
|
2016-10-04 07:11:27 -04:00
|
|
|
public function Praise():Void
|
|
|
|
{
|
|
|
|
Wait = true;
|
|
|
|
|
2016-10-05 07:28:10 -04:00
|
|
|
// Can't Prasie if you have no Happiness to give
|
|
|
|
if (Discipline < 10)
|
|
|
|
return;
|
|
|
|
|
2016-10-04 07:11:27 -04:00
|
|
|
Happiness += 10;
|
|
|
|
Discipline -= 10;
|
2016-10-09 05:29:51 -04:00
|
|
|
beExcited();
|
2016-10-04 07:11:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function Scold():Void
|
|
|
|
{
|
|
|
|
Wait = true;
|
|
|
|
|
2016-10-05 07:28:10 -04:00
|
|
|
// Can't Scold if you have no Discipline to give
|
|
|
|
if (Discipline < 10)
|
|
|
|
return;
|
|
|
|
|
2016-10-04 07:11:27 -04:00
|
|
|
Happiness -= 10;
|
|
|
|
Discipline += 10;
|
2016-10-09 05:29:51 -04:00
|
|
|
beAshamed();
|
2016-10-04 07:11:27 -04:00
|
|
|
}
|
2016-10-05 07:28:10 -04:00
|
|
|
public function Wipe():Void
|
2016-10-03 20:43:09 -04:00
|
|
|
{
|
2016-10-05 07:28:10 -04:00
|
|
|
Wait = true;
|
2016-10-08 01:15:21 -04:00
|
|
|
|
2016-10-05 07:28:10 -04:00
|
|
|
// Early Wipe
|
2016-10-08 01:15:21 -04:00
|
|
|
if (!_wasteReady && !_madeWaste)
|
2016-10-05 07:28:10 -04:00
|
|
|
{
|
|
|
|
Happiness -=5;
|
2016-10-09 05:29:51 -04:00
|
|
|
beAshamed();
|
2016-10-05 07:28:10 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Good Wipe
|
2016-10-08 01:15:21 -04:00
|
|
|
else if (!_madeWaste)
|
2016-10-05 07:28:10 -04:00
|
|
|
{
|
|
|
|
Happiness += 10;
|
|
|
|
Discipline += 10;
|
2016-10-09 05:29:51 -04:00
|
|
|
beExcited();
|
2016-10-05 07:28:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Late Wipe
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Happiness -= 10;
|
|
|
|
Discipline -= 10;
|
|
|
|
_madeWaste = false;
|
|
|
|
}
|
|
|
|
Waste = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function makeWaste():Void
|
|
|
|
{
|
|
|
|
Waste = 0;
|
|
|
|
_madeWaste = true;
|
|
|
|
_wasteReady = false;
|
|
|
|
}
|
2016-10-06 01:18:02 -04:00
|
|
|
|
|
|
|
private function wakeUp():Void
|
|
|
|
{
|
|
|
|
_isAsleep = false;
|
|
|
|
_hoursAsleep = 0;
|
|
|
|
|
|
|
|
// Reset back to one of the 3 normal moods
|
|
|
|
checkMood();
|
|
|
|
if (CurrentMood == Mood.HAPPY)
|
|
|
|
Happiness -= 15;
|
|
|
|
else if (CurrentMood == Mood.NEUTRAL)
|
|
|
|
Happiness += 10;
|
|
|
|
else if (CurrentMood == Mood.ANGRY)
|
|
|
|
Happiness += 15;
|
|
|
|
|
|
|
|
Fullness -= 50;
|
|
|
|
Waste += 10;
|
|
|
|
|
|
|
|
checkRange();
|
|
|
|
}
|
|
|
|
|
2016-10-08 01:15:21 -04:00
|
|
|
private function beExcited():Void
|
|
|
|
{
|
2016-10-09 05:29:51 -04:00
|
|
|
CurrentMood = EXCITED;
|
|
|
|
this.animation.play("excited");
|
|
|
|
_sndExcited.play(true);
|
|
|
|
}
|
2016-10-08 01:15:21 -04:00
|
|
|
|
|
|
|
private function beAshamed():Void
|
|
|
|
{
|
2016-10-09 05:29:51 -04:00
|
|
|
CurrentMood = ASHAMED;
|
|
|
|
this.animation.play("ashamed");
|
|
|
|
_sndAshamed.play(true);
|
|
|
|
}
|
2016-10-08 01:15:21 -04:00
|
|
|
|
2016-10-09 05:29:51 -04:00
|
|
|
private function resumeMood():Void
|
|
|
|
{
|
|
|
|
CurrentMood = NEUTRAL;
|
|
|
|
checkMood;
|
2016-10-08 01:15:21 -04:00
|
|
|
}
|
|
|
|
|
2016-10-05 07:28:10 -04:00
|
|
|
private function newHour():Void
|
|
|
|
{
|
2016-10-06 01:18:02 -04:00
|
|
|
if (!_isAsleep)
|
2016-10-05 07:28:10 -04:00
|
|
|
{
|
2016-10-06 01:18:02 -04:00
|
|
|
Fullness -= 10;
|
|
|
|
Sleepiness += 5;
|
|
|
|
if (!_madeWaste)
|
|
|
|
Waste += (FlxG.random.int(2, 5) * 5);
|
|
|
|
|
|
|
|
// TODO: Add other stat changing conditions
|
|
|
|
if (_isHungry)
|
|
|
|
Happiness -= 10;
|
|
|
|
if (_isTired)
|
|
|
|
{
|
|
|
|
Happiness -= 10;
|
|
|
|
Discipline -= 5;
|
|
|
|
}
|
|
|
|
if (_madeWaste)
|
|
|
|
{
|
|
|
|
Happiness -=10;
|
|
|
|
Discipline -=10;
|
|
|
|
}
|
2016-10-05 07:28:10 -04:00
|
|
|
}
|
2016-10-06 01:18:02 -04:00
|
|
|
else
|
2016-10-05 07:28:10 -04:00
|
|
|
{
|
2016-10-06 01:18:02 -04:00
|
|
|
if (_hoursAsleep >= 9)
|
|
|
|
wakeUp();
|
|
|
|
else if (_hoursAsleep > 5 && _hoursAsleep < 9)
|
|
|
|
{
|
|
|
|
// Discipline determines chance of early wake up
|
|
|
|
if (FlxG.random.bool(Discipline))
|
|
|
|
wakeUp();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
_hoursAsleep++;
|
2016-10-05 07:28:10 -04:00
|
|
|
}
|
2016-10-05 23:36:42 -04:00
|
|
|
// Unlock menu options
|
|
|
|
_hasStudied = false;
|
2016-10-03 20:43:09 -04:00
|
|
|
|
2016-10-05 07:28:10 -04:00
|
|
|
_clock.HourPassed = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function newDay():Void
|
|
|
|
{
|
|
|
|
Age++;
|
|
|
|
// TODO: Add END_GAME checks here
|
|
|
|
_clock.DayPassed = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function checkRange():Void
|
|
|
|
{
|
|
|
|
// TODO: clean this up, make a for loop to loop array ints
|
2016-10-03 20:43:09 -04:00
|
|
|
if (Happiness > MAX_LEVEL)
|
|
|
|
Happiness = MAX_LEVEL;
|
|
|
|
else if (Happiness < MIN_LEVEL)
|
|
|
|
Happiness = MIN_LEVEL;
|
|
|
|
|
|
|
|
if (Discipline > MAX_LEVEL)
|
|
|
|
Discipline = MAX_LEVEL;
|
|
|
|
else if (Discipline < MIN_LEVEL)
|
|
|
|
Discipline = MIN_LEVEL;
|
2016-10-05 07:28:10 -04:00
|
|
|
|
|
|
|
if (Fullness > MAX_LEVEL)
|
|
|
|
Fullness = MAX_LEVEL;
|
|
|
|
else if (Fullness < MIN_LEVEL)
|
|
|
|
Fullness = MIN_LEVEL;
|
|
|
|
|
|
|
|
if (Sleepiness > MAX_LEVEL)
|
|
|
|
Sleepiness = MAX_LEVEL;
|
|
|
|
else if (Sleepiness < MIN_LEVEL)
|
|
|
|
Sleepiness = MIN_LEVEL;
|
|
|
|
|
|
|
|
if (Waste > MAX_LEVEL)
|
|
|
|
Waste = MAX_LEVEL;
|
|
|
|
else if (Waste < MIN_LEVEL)
|
|
|
|
Waste = MIN_LEVEL;
|
2016-10-03 20:43:09 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
enum Mood
|
|
|
|
{
|
2016-10-04 04:11:36 -04:00
|
|
|
NEUTRAL;
|
2016-10-03 20:43:09 -04:00
|
|
|
HAPPY;
|
|
|
|
ANGRY;
|
2016-10-04 07:11:27 -04:00
|
|
|
SLEEPING;
|
2016-10-08 01:15:21 -04:00
|
|
|
EXCITED;
|
|
|
|
ASHAMED;
|
2016-10-05 03:00:48 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
enum Need
|
|
|
|
{
|
|
|
|
NONE;
|
|
|
|
HUNGRY;
|
|
|
|
SLEEPY;
|
|
|
|
POOPY;
|
2016-10-03 20:43:09 -04:00
|
|
|
}
|