Skip to content

Commit

Permalink
GOB: Implement health gain/loss for mouths
Browse files Browse the repository at this point in the history
  • Loading branch information
DrMcCoy committed Jun 5, 2012
1 parent 7377640 commit 4392e4d
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 13 deletions.
22 changes: 18 additions & 4 deletions engines/gob/minigames/geisha/meter.cpp
Expand Up @@ -63,22 +63,36 @@ void Meter::setMaxValue() {
setValue(_maxValue);
}

void Meter::increase(int32 n) {
int32 Meter::increase(int32 n) {
if (n < 0)
return decrease(-n);

int32 overflow = MAX(0, (_value + n) - _maxValue);

int32 value = CLIP<int32>(_value + n, 0, _maxValue);
if (_value == value)
return;
return overflow;

_value = value;
_needUpdate = true;

return overflow;
}

void Meter::decrease(int32 n) {
int32 Meter::decrease(int32 n) {
if (n < 0)
return increase(-n);

int32 underflow = -MIN(0, _value - n);

int32 value = CLIP<int32>(_value - n, 0, _maxValue);
if (_value == value)
return;
return underflow;

_value = value;
_needUpdate = true;

return underflow;
}

void Meter::draw(Surface &dest, int16 &left, int16 &top, int16 &right, int16 &bottom) {
Expand Down
8 changes: 4 additions & 4 deletions engines/gob/minigames/geisha/meter.h
Expand Up @@ -55,10 +55,10 @@ class Meter {
/** Set the current value the meter is measuring to the max value. */
void setMaxValue();

/** Increase the current value the meter is measuring. */
void increase(int32 n = 1);
/** Decrease the current value the meter is measuring. */
void decrease(int32 n = 1);
/** Increase the current value the meter is measuring, returning the overflow. */
int32 increase(int32 n = 1);
/** Decrease the current value the meter is measuring, returning the underflow. */
int32 decrease(int32 n = 1);

/** Draw the meter onto the surface and return the affected rectangle. */
void draw(Surface &dest, int16 &left, int16 &top, int16 &right, int16 &bottom);
Expand Down
24 changes: 19 additions & 5 deletions engines/gob/minigames/geisha/penetration.cpp
Expand Up @@ -226,8 +226,8 @@ Penetration::Penetration(GobEngine *vm) : _vm(vm), _background(0), _sprites(0),

_background = new Surface(320, 200, 1);

_shieldMeter = new Meter(11, 119, 92, 3, kColorShield, kColorBlack, 1020, Meter::kFillToRight);
_healthMeter = new Meter(11, 137, 92, 3, kColorHealth, kColorBlack, 1020, Meter::kFillToRight);
_shieldMeter = new Meter(11, 119, 92, 3, kColorShield, kColorBlack, 920, Meter::kFillToRight);
_healthMeter = new Meter(11, 137, 92, 3, kColorHealth, kColorBlack, 920, Meter::kFillToRight);

_map = new Surface(kMapWidth * kMapTileWidth + kPlayAreaWidth ,
kMapHeight * kMapTileHeight + kPlayAreaHeight, 1);
Expand Down Expand Up @@ -563,15 +563,29 @@ void Penetration::checkMouths() {

m->mouth->activate();

// Play the mouth sound
if (m->type == kMouthTypeBite)
// Play the mouth sound and do health gain/loss
if (m->type == kMouthTypeBite) {
_vm->_sound->blasterPlay(&_soundBite, 1, 0);
else if (m->type == kMouthTypeKiss)
healthLose(230);
} else if (m->type == kMouthTypeKiss) {
_vm->_sound->blasterPlay(&_soundKiss, 1, 0);
healthGain(120);
}
}
}
}

void Penetration::healthGain(int amount) {
if (_shieldMeter->getValue() > 0)
_healthMeter->increase(_shieldMeter->increase(amount));
else
_healthMeter->increase(amount);
}

void Penetration::healthLose(int amount) {
_healthMeter->decrease(_shieldMeter->decrease(amount));
}

void Penetration::updateAnims() {
int16 left = 0, top = 0, right = 0, bottom = 0;

Expand Down
3 changes: 3 additions & 0 deletions engines/gob/minigames/geisha/penetration.h
Expand Up @@ -132,6 +132,9 @@ class Penetration {

void checkShields();
void checkMouths();

void healthGain(int amount);
void healthLose(int amount);
};

} // End of namespace Geisha
Expand Down

0 comments on commit 4392e4d

Please sign in to comment.