diff options
author | Sven Hesse | 2012-01-28 17:02:43 +0100 |
---|---|---|
committer | Sven Hesse | 2012-01-28 17:46:38 +0100 |
commit | 9dd703532706c049b14b4bc1e239c9cd08366f2a (patch) | |
tree | 082e964997d3a22d7a50fe9a7c34d95d07888094 /engines/gob/minigames | |
parent | 7ee77cbd26f131ce00cd4a9ddf6515a283b646a3 (diff) | |
download | scummvm-rg350-9dd703532706c049b14b4bc1e239c9cd08366f2a.tar.gz scummvm-rg350-9dd703532706c049b14b4bc1e239c9cd08366f2a.tar.bz2 scummvm-rg350-9dd703532706c049b14b4bc1e239c9cd08366f2a.zip |
GOB: Add the air and health meters in Geisha's Diving minigame
Diffstat (limited to 'engines/gob/minigames')
-rw-r--r-- | engines/gob/minigames/geisha/diving.cpp | 20 | ||||
-rw-r--r-- | engines/gob/minigames/geisha/diving.h | 4 | ||||
-rw-r--r-- | engines/gob/minigames/geisha/meter.cpp | 112 | ||||
-rw-r--r-- | engines/gob/minigames/geisha/meter.h | 86 |
4 files changed, 221 insertions, 1 deletions
diff --git a/engines/gob/minigames/geisha/diving.cpp b/engines/gob/minigames/geisha/diving.cpp index 4b08a21fb4..59ebe7f7b1 100644 --- a/engines/gob/minigames/geisha/diving.cpp +++ b/engines/gob/minigames/geisha/diving.cpp @@ -32,6 +32,7 @@ #include "gob/minigames/geisha/evilfish.h" #include "gob/minigames/geisha/oko.h" +#include "gob/minigames/geisha/meter.h" #include "gob/minigames/geisha/diving.h" namespace Gob { @@ -57,10 +58,14 @@ const Diving::PlantLevel Diving::kPlantLevels[] = { Diving::Diving(GobEngine *vm) : _vm(vm), _background(0), _objects(0), _gui(0), _okoAnim(0), _lungs(0), _heart(0), - _blackPearl(0), _whitePearlCount(0), _blackPearlCount(0) { + _blackPearl(0), _airMeter(0), _healthMeter(0), + _whitePearlCount(0), _blackPearlCount(0) { _blackPearl = new Surface(11, 8, 1); + _airMeter = new Meter(4 , 195, 38, 2, 5, 7, 38, Meter::kFillToLeft); + _healthMeter = new Meter(276, 195, 38, 2, 6, 7, 38, Meter::kFillToLeft); + for (uint i = 0; i < kEvilFishCount; i++) _evilFish[i].evilFish = 0; @@ -79,6 +84,9 @@ Diving::Diving(GobEngine *vm) : _vm(vm), _background(0), } Diving::~Diving() { + delete _airMeter; + delete _healthMeter; + delete _blackPearl; deinit(); @@ -234,6 +242,9 @@ void Diving::init() { _anims.push_back(_oko); _anims.push_back(_lungs); _anims.push_back(_heart); + + _airMeter->setValue(38); + _healthMeter->setValue(38); } void Diving::deinit() { @@ -584,6 +595,13 @@ void Diving::updateAnims() { (*a)->advance(); } + + // Draw the meters + _airMeter->draw(*_vm->_draw->_backSurface, left, top, right, bottom); + _vm->_draw->dirtiedRect(_vm->_draw->_backSurface, left, top, right, bottom); + + _healthMeter->draw(*_vm->_draw->_backSurface, left, top, right, bottom); + _vm->_draw->dirtiedRect(_vm->_draw->_backSurface, left, top, right, bottom); } int16 Diving::checkInput(int16 &mouseX, int16 &mouseY, MouseButtons &mouseButtons) { diff --git a/engines/gob/minigames/geisha/diving.h b/engines/gob/minigames/geisha/diving.h index b00252ca0a..50a5d49a8c 100644 --- a/engines/gob/minigames/geisha/diving.h +++ b/engines/gob/minigames/geisha/diving.h @@ -41,6 +41,7 @@ namespace Geisha { class EvilFish; class Oko; +class Meter; /** Geisha's "Diving" minigame. */ class Diving { @@ -132,6 +133,9 @@ private: uint8 _whitePearlCount; uint8 _blackPearlCount; + Meter *_airMeter; + Meter *_healthMeter; + uint8 _currentShot; SoundDesc _soundShoot; diff --git a/engines/gob/minigames/geisha/meter.cpp b/engines/gob/minigames/geisha/meter.cpp new file mode 100644 index 0000000000..82318a303d --- /dev/null +++ b/engines/gob/minigames/geisha/meter.cpp @@ -0,0 +1,112 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include "common/util.h" + +#include "gob/surface.h" + +#include "gob/minigames/geisha/meter.h" + +namespace Gob { + +namespace Geisha { + +Meter::Meter(int16 x, int16 y, int16 width, int16 height, uint8 frontColor, + uint8 backColor, int32 maxValue, Direction direction) : + _x(x), _y(y), _width(width), _height(height), _frontColor(frontColor), + _backColor(backColor), _value(0), _maxValue(maxValue), _direction(direction), + _needUpdate(true), _surface(0) { + +} + +Meter::~Meter() { + delete _surface; +} + +int32 Meter::getValue() const { + return _value; +} + +void Meter::setValue(int32 value) { + value = CLIP<int32>(value, 0, _maxValue); + if (_value == value) + return; + + _value = value; + _needUpdate = true; +} + +void Meter::increase(int32 n) { + int32 value = CLIP<int32>(_value + n, 0, _maxValue); + if (_value == value) + return; + + _value = value; + _needUpdate = true; +} + +void Meter::decrease(int32 n) { + int32 value = CLIP<int32>(_value - n, 0, _maxValue); + if (_value == value) + return; + + _value = value; + _needUpdate = true; +} + +void Meter::draw(Surface &dest, int16 &left, int16 &top, int16 &right, int16 &bottom) { + if (!_surface) { + _surface = new Surface(_width, _height, dest.getBPP()); + _needUpdate = true; + } + + update(); + + left = CLIP<int16>(_x , 0, dest.getWidth () - 1); + top = CLIP<int16>(_y , 0, dest.getHeight() - 1); + right = CLIP<int16>(_x + _width - 1, 0, dest.getWidth () - 1); + bottom = CLIP<int16>(_y + _height - 1, 0, dest.getHeight() - 1); + + dest.blit(*_surface, left - _x, top - _y, _width, _height, left, top); +} + +void Meter::update() { + if (!_needUpdate) + return; + + _needUpdate = false; + + _surface->fill(_backColor); + + int32 n = floor((((float) _width) / _maxValue * _value) + 0.5); + if (n <= 0) + return; + + if (_direction == kFillToLeft) + _surface->fillRect(_width - n, 0, _width - 1, _height - 1, _frontColor); + else + _surface->fillRect(0 , 0, n - 1, _height - 1, _frontColor); +} + +} // End of namespace Geisha + +} // End of namespace Gob diff --git a/engines/gob/minigames/geisha/meter.h b/engines/gob/minigames/geisha/meter.h new file mode 100644 index 0000000000..398128712a --- /dev/null +++ b/engines/gob/minigames/geisha/meter.h @@ -0,0 +1,86 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#ifndef GOB_MINIGAMES_GEISHA_METER_H +#define GOB_MINIGAMES_GEISHA_METER_H + +#include "gob/aniobject.h" + +namespace Gob { + +class Surface; + +namespace Geisha { + +/** A meter measuring a value. */ +class Meter { +public: + enum Direction { + kFillToLeft, + kFillToRight + }; + + Meter(int16 x, int16 y, int16 width, int16 height, + uint8 frontColor, uint8 backColor, int32 maxValue, + Direction direction); + ~Meter(); + + /** Return the current value the meter is measuring. */ + int32 getValue() const; + + /** Set the current value the meter is measuring. */ + void setValue(int32 value); + + /** 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); + + /** Draw the meter onto the surface and return the affected rectangle. */ + void draw(Surface &dest, int16 &left, int16 &top, int16 &right, int16 &bottom); + +private: + int16 _x; + int16 _y; + int16 _width; + int16 _height; + + uint8 _frontColor; + uint8 _backColor; + + int32 _value; + int32 _maxValue; + + Direction _direction; + + bool _needUpdate; + + Surface *_surface; + + void update(); +}; + +} // End of namespace Geisha + +} // End of namespace Gob + +#endif // GOB_MINIGAMES_GEISHA_METER_H |