diff options
author | Sven Hesse | 2012-01-26 19:44:17 +0100 |
---|---|---|
committer | Sven Hesse | 2012-01-26 19:47:03 +0100 |
commit | a19eb264855b236b8d68dfaeb7e0f7a8dd6579a2 (patch) | |
tree | acb7ac61ca978a6aa66efd55b971e8e75356b18c /engines | |
parent | d1de75a6ca828ab2fcdbce6352a12337f93fc21c (diff) | |
download | scummvm-rg350-a19eb264855b236b8d68dfaeb7e0f7a8dd6579a2.tar.gz scummvm-rg350-a19eb264855b236b8d68dfaeb7e0f7a8dd6579a2.tar.bz2 scummvm-rg350-a19eb264855b236b8d68dfaeb7e0f7a8dd6579a2.zip |
GOB: Add the background plants in Geisha's Diving minigame
Diffstat (limited to 'engines')
-rw-r--r-- | engines/gob/minigames/geisha/diving.cpp | 101 | ||||
-rw-r--r-- | engines/gob/minigames/geisha/diving.h | 33 |
2 files changed, 129 insertions, 5 deletions
diff --git a/engines/gob/minigames/geisha/diving.cpp b/engines/gob/minigames/geisha/diving.cpp index e3bc69a503..8fe3d63990 100644 --- a/engines/gob/minigames/geisha/diving.cpp +++ b/engines/gob/minigames/geisha/diving.cpp @@ -37,14 +37,22 @@ namespace Gob { namespace Geisha { -static const int kEvilFishTypeCount = 3; - -static const int kEvilFishTypes[kEvilFishTypeCount][5] = { +const uint16 Diving::kEvilFishTypes[kEvilFishTypeCount][5] = { { 0, 14, 8, 9, 3}, // Shark {15, 1, 12, 13, 3}, // Moray {16, 2, 10, 11, 3} // Ray }; +const uint16 Diving::kPlantLevel1[] = { 18, 19, 20, 21 }; +const uint16 Diving::kPlantLevel2[] = { 22, 23, 24, 25 }; +const uint16 Diving::kPlantLevel3[] = { 26, 27, 28, 29, 30 }; + +const Diving::PlantLevel Diving::kPlantLevels[] = { + { 150, ARRAYSIZE(kPlantLevel1), kPlantLevel1 }, + { 120, ARRAYSIZE(kPlantLevel2), kPlantLevel2 }, + { 108, ARRAYSIZE(kPlantLevel3), kPlantLevel3 }, +}; + Diving::Diving(GobEngine *vm) : _vm(vm), _background(0), _objects(0), _gui(0), _oko(0), _lungs(0), _heart(0), @@ -63,6 +71,7 @@ bool Diving::play(uint16 playerCount, bool hasPearlLocation) { init(); initScreen(); initCursor(); + initPlants(); _vm->_draw->blitInvalidated(); _vm->_video->retrace(); @@ -71,6 +80,7 @@ bool Diving::play(uint16 playerCount, bool hasPearlLocation) { checkShots(); updateEvilFish(); updateDecorFish(); + updatePlants(); updateAnims(); _vm->_draw->animateCursor(1); @@ -135,14 +145,24 @@ void Diving::init() { _decorFish[i].decorFish = new ANIObject(*_objects); } + for (uint i = 0; i < kPlantCount; i++) { + _plant[i].level = i / kPlantPerLevelCount; + _plant[i].deltaX = (kPlantLevelCount - _plant[i].level) * -2; + + _plant[i].x = -1; + _plant[i].y = -1; + + _plant[i].plant = new ANIObject(*_objects); + } + _decorFish[0].decorFish->setAnimation( 6); // Jellyfish _decorFish[0].deltaX = 0; _decorFish[1].decorFish->setAnimation(32); // Swarm of red/green fish - _decorFish[1].deltaX = -6; + _decorFish[1].deltaX = -5; _decorFish[2].decorFish->setAnimation(33); // Swarm of orange fish - _decorFish[2].deltaX = -6; + _decorFish[2].deltaX = -5; for (uint i = 0; i < kMaxShotCount; i++) { _shot[i] = new ANIObject(*_objects); @@ -168,6 +188,8 @@ void Diving::init() { _anims.push_back(_decorFish[i].decorFish); for (uint i = 0; i < kEvilFishCount; i++) _anims.push_back(_evilFish[i].evilFish); + for (int i = kPlantCount - 1; i >= 0; i--) + _anims.push_back(_plant[i].plant); _anims.push_back(_lungs); _anims.push_back(_heart); @@ -208,6 +230,12 @@ void Diving::deinit() { _decorFish[i].decorFish = 0; } + for (uint i = 0; i < kPlantCount; i++) { + delete _plant[i].plant; + + _plant[i].plant = 0; + } + delete _heart; delete _lungs; delete _water; @@ -259,6 +287,37 @@ void Diving::initCursor() { _vm->_draw->_cursorHotspotY = 8; } + +void Diving::initPlants() { + for (uint i = 0; i < kPlantLevelCount; i++) { + for (uint j = 0; j < kPlantPerLevelCount; j++) { + int16 prevPlantX = -100; + if (j > 0) + prevPlantX = _plant[i * kPlantPerLevelCount + j - 1].x; + + enterPlant(_plant[i * kPlantPerLevelCount + j], prevPlantX); + } + } +} + +void Diving::enterPlant(ManagedPlant &plant, int16 prevPlantX) { + const PlantLevel &level = kPlantLevels[plant.level]; + const uint anim = level.plants[_vm->_util->getRandom(kPlantLevels[plant.level].plantCount)]; + + plant.plant->setAnimation(anim); + plant.plant->rewind(); + + int16 width, height; + plant.plant->getFrameSize(width, height); + + plant.x = prevPlantX + 150 - 10 + _vm->_util->getRandom(21); + plant.y = kPlantLevels[plant.level].y - height; + + plant.plant->setPosition(plant.x, plant.y); + plant.plant->setVisible(true); + plant.plant->setPause(false); +} + void Diving::updateEvilFish() { for (uint i = 0; i < kEvilFishCount; i++) { ManagedEvilFish &fish = _evilFish[i]; @@ -333,6 +392,38 @@ void Diving::updateDecorFish() { } } +void Diving::updatePlants() { + for (uint i = 0; i < kPlantCount; i++) { + ManagedPlant &plant = _plant[i]; + + if (plant.plant->isVisible()) { + // Move the plant + plant.plant->setPosition(plant.x += plant.deltaX, plant.y); + + // Check if the plant has left the screen + int16 x, y, width, height; + plant.plant->getFramePosition(x, y); + plant.plant->getFrameSize(width, height); + + if ((x + width) <= 0) { + plant.plant->setVisible(false); + plant.plant->setPause(true); + + plant.x = 0; + } + + } else { + // Find the right-most plant in this level and enter the plant to the right of it + + int16 rightX = 320; + for (uint j = 0; j < kPlantPerLevelCount; j++) + rightX = MAX(rightX, _plant[plant.level * kPlantPerLevelCount + j].x); + + enterPlant(plant, rightX); + } + } +} + void Diving::foundBlackPearl() { _blackPearlCount++; diff --git a/engines/gob/minigames/geisha/diving.h b/engines/gob/minigames/geisha/diving.h index e386d783d7..af224401e3 100644 --- a/engines/gob/minigames/geisha/diving.h +++ b/engines/gob/minigames/geisha/diving.h @@ -54,6 +54,26 @@ private: static const uint kDecorFishCount = 3; static const uint kMaxShotCount = 10; + static const uint kEvilFishTypeCount = 3; + static const uint16 kEvilFishTypes[kEvilFishTypeCount][5]; + + struct PlantLevel { + int16 y; + uint plantCount; + const uint16 *plants; + }; + + static const uint kPlantLevelCount = 3; + static const uint kPlantPerLevelCount = 5; + + static const uint16 kPlantLevel1[]; + static const uint16 kPlantLevel2[]; + static const uint16 kPlantLevel3[]; + + static const PlantLevel kPlantLevels[kPlantLevelCount]; + + static const uint kPlantCount = kPlantLevelCount * kPlantPerLevelCount; + struct ManagedEvilFish { EvilFish *evilFish; @@ -68,6 +88,14 @@ private: int8 deltaX; }; + struct ManagedPlant { + ANIObject *plant; + + uint level; + int8 deltaX; + int16 x, y; + }; + GobEngine *_vm; DECFile *_background; @@ -81,6 +109,7 @@ private: ManagedEvilFish _evilFish[kEvilFishCount]; ManagedDecorFish _decorFish[kDecorFishCount]; + ManagedPlant _plant[kPlantCount]; ANIObject *_shot[kMaxShotCount]; @@ -106,12 +135,16 @@ private: void initScreen(); void initCursor(); + void initPlants(); + + void enterPlant(ManagedPlant &plant, int16 prevPlantX); void foundBlackPearl(); void foundWhitePearl(); void updateEvilFish(); void updateDecorFish(); + void updatePlants(); void updateAnims(); int16 checkInput(int16 &mouseX, int16 &mouseY, MouseButtons &mouseButtons); |