From a8d20101b711ec1f04c263f9619890baef72f7f3 Mon Sep 17 00:00:00 2001 From: neuromancer Date: Wed, 6 Apr 2022 09:05:06 +0200 Subject: [PATCH] HYPNO: moved arcade code to a specific file in boyz --- engines/hypno/boyz/arcade.cpp | 153 ++++++++++++++++++++++++++++++++++ engines/hypno/boyz/boyz.cpp | 125 --------------------------- engines/hypno/module.mk | 1 + 3 files changed, 154 insertions(+), 125 deletions(-) create mode 100644 engines/hypno/boyz/arcade.cpp diff --git a/engines/hypno/boyz/arcade.cpp b/engines/hypno/boyz/arcade.cpp new file mode 100644 index 00000000000..cc36ca876f1 --- /dev/null +++ b/engines/hypno/boyz/arcade.cpp @@ -0,0 +1,153 @@ +/* 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 3 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, see . + * + */ + +#include "hypno/grammar.h" +#include "hypno/hypno.h" + +#include "common/events.h" + +namespace Hypno { + +void BoyzEngine::runBeforeArcade(ArcadeShooting *arc) { + _checkpoint = _currentLevel; + assert(!arc->player.empty()); + _playerFrames = decodeFrames(arc->player); + _playerFrameSep = 0; + + Common::Rect healthBarBox(0, 3, 107, 18); + Common::Rect ammoBarBox(0, 20, 103, 34); + Common::Rect portraitBox(0, 40, 57, 94); + + for (int i = 0; i < int(_playerFrames.size()); i++) { + _healthBar[i] = _playerFrames[i]->getSubArea(healthBarBox); + _ammoBar[i] = _playerFrames[i]->getSubArea(ammoBarBox); + _portrait[i] = _playerFrames[i]->getSubArea(portraitBox); + } + + _playerFrameSep = _playerFrames.size(); + _playerFrameIdx = -1; + + _currentScript = arc->script; + ScriptInfo si = *_currentScript.begin(); + _currentActor = si.actor - 1; + _currentMode = si.mode; + _currentScript.pop_front(); +} + +void BoyzEngine::runAfterArcade(ArcadeShooting *arc) { + for (int i = 0; i < int(_playerFrames.size()); i++) { + _playerFrames[i]->free(); + delete _playerFrames[i]; + } +} + +void BoyzEngine::updateFromScript() { + if (_currentScript.size() > 0) { + ScriptInfo si = *_currentScript.begin(); + //debug("%d %d %d", si.time, _background->decoder->getCurFrame(), si.actor); + if (int(si.time) <= _background->decoder->getCurFrame()) { + _currentActor = si.actor - 1; + _currentMode = si.mode; + _currentScript.pop_front(); + } + } +} + +void BoyzEngine::drawPlayer() { + updateFromScript(); + drawImage(_portrait[_currentActor], 0, 200 - _portrait[_currentActor].h, true); +} + +void BoyzEngine::drawHealth() { + updateFromScript(); + drawImage(_healthBar[_currentActor], 0, 0, true); + drawImage(_ammoBar[_currentActor], 320 - _ammoBar[_currentActor].w, 0, true); +} +void BoyzEngine::hitPlayer() {} +void BoyzEngine::drawShoot(const Common::Point &target) {} + +void BoyzEngine::initSegment(ArcadeShooting *arc) { + _segmentShootSequenceOffset = 0; + _segmentShootSequenceMax = 0; + + uint32 randomSegmentShootSequence = _segmentShootSequenceOffset + _rnd->getRandomNumber(_segmentShootSequenceMax); + SegmentShoots segmentShoots = arc->shootSequence[randomSegmentShootSequence]; + _shootSequence = segmentShoots.shootSequence; + _segmentRepetitionMax = segmentShoots.segmentRepetition; // Usually zero + _segmentRepetition = 0; + _segmentOffset = 0; + _segmentIdx = _segmentOffset; +} + +void BoyzEngine::findNextSegment(ArcadeShooting *arc) { + _segmentIdx = _segmentIdx + 1; +} + +int BoyzEngine::detectTarget(const Common::Point &mousePos) { + Common::Point target = computeTargetPosition(mousePos); + assert(_shoots.size() <= 1); + for (Shoots::iterator it = _shoots.begin(); it != _shoots.end(); ++it) { + if (_mask->getPixel(target.x, target.y) == 1) + return 0; + } + return -1; +} + +void BoyzEngine::shoot(const Common::Point &mousePos, ArcadeShooting *arc, MVideo &background) { + incShotsFired(); + int i = detectTarget(mousePos); + if (i < 0) { + missNoTarget(arc, background); + } else { + if (!_shoots[i].hitSound.empty()) + playSound(_soundPath + _shoots[i].hitSound, 1); + + incEnemyHits(); + if (!_shoots[i].deathSound.empty()) + playSound(_soundPath + _shoots[i].deathSound, 1); + + incTargetsDestroyed(); + incScore(_shoots[i].pointsToShoot); + incBonus(_shoots[i].pointsToShoot); + _shoots[i].destroyed = true; + background.decoder->forceSeekToFrame(_shoots[i].explosionFrames[0].start - 3); + _masks->decoder->forceSeekToFrame(_shoots[i].explosionFrames[0].start - 3); + _shoots.clear(); + } +} + +void BoyzEngine::missedTarget(Shoot *s, ArcadeShooting *arc, MVideo &background) { + + if (s->missedAnimation == 0) + return; + else if (s->missedAnimation == uint32(-1)) { + uint32 last = background.decoder->getFrameCount()-1; + background.decoder->forceSeekToFrame(last); + _masks->decoder->forceSeekToFrame(last); + return; + } + + s->missedAnimation = s->missedAnimation + 3; + background.decoder->forceSeekToFrame(s->missedAnimation); + _masks->decoder->forceSeekToFrame(s->missedAnimation); +} + +} // namespace Hypno \ No newline at end of file diff --git a/engines/hypno/boyz/boyz.cpp b/engines/hypno/boyz/boyz.cpp index c74d042c359..ef954453755 100644 --- a/engines/hypno/boyz/boyz.cpp +++ b/engines/hypno/boyz/boyz.cpp @@ -46,131 +46,6 @@ void BoyzEngine::loadAssets() { _nextLevel = "c11.mi_"; } -void BoyzEngine::runBeforeArcade(ArcadeShooting *arc) { - _checkpoint = _currentLevel; - assert(!arc->player.empty()); - _playerFrames = decodeFrames(arc->player); - _playerFrameSep = 0; - - Common::Rect healthBarBox(0, 3, 107, 18); - Common::Rect ammoBarBox(0, 20, 103, 34); - Common::Rect portraitBox(0, 40, 57, 94); - - for (int i = 0; i < int(_playerFrames.size()); i++) { - _healthBar[i] = _playerFrames[i]->getSubArea(healthBarBox); - _ammoBar[i] = _playerFrames[i]->getSubArea(ammoBarBox); - _portrait[i] = _playerFrames[i]->getSubArea(portraitBox); - } - - _playerFrameSep = _playerFrames.size(); - _playerFrameIdx = -1; - - _currentScript = arc->script; - ScriptInfo si = *_currentScript.begin(); - _currentActor = si.actor - 1; - _currentMode = si.mode; - _currentScript.pop_front(); -} - -void BoyzEngine::runAfterArcade(ArcadeShooting *arc) { - for (int i = 0; i < int(_playerFrames.size()); i++) { - _playerFrames[i]->free(); - delete _playerFrames[i]; - } -} - -void BoyzEngine::updateFromScript() { - if (_currentScript.size() > 0) { - ScriptInfo si = *_currentScript.begin(); - //debug("%d %d %d", si.time, _background->decoder->getCurFrame(), si.actor); - if (int(si.time) <= _background->decoder->getCurFrame()) { - _currentActor = si.actor - 1; - _currentMode = si.mode; - _currentScript.pop_front(); - } - } -} - -void BoyzEngine::drawPlayer() { - updateFromScript(); - drawImage(_portrait[_currentActor], 0, 200 - _portrait[_currentActor].h, true); -} - -void BoyzEngine::drawHealth() { - updateFromScript(); - drawImage(_healthBar[_currentActor], 0, 0, true); - drawImage(_ammoBar[_currentActor], 320 - _ammoBar[_currentActor].w, 0, true); -} -void BoyzEngine::hitPlayer() {} -void BoyzEngine::drawShoot(const Common::Point &target) {} - Common::String BoyzEngine::findNextLevel(const Common::String &level) { return level; } -void BoyzEngine::initSegment(ArcadeShooting *arc) { - _segmentShootSequenceOffset = 0; - _segmentShootSequenceMax = 0; - - uint32 randomSegmentShootSequence = _segmentShootSequenceOffset + _rnd->getRandomNumber(_segmentShootSequenceMax); - SegmentShoots segmentShoots = arc->shootSequence[randomSegmentShootSequence]; - _shootSequence = segmentShoots.shootSequence; - _segmentRepetitionMax = segmentShoots.segmentRepetition; // Usually zero - _segmentRepetition = 0; - _segmentOffset = 0; - _segmentIdx = _segmentOffset; -} - -void BoyzEngine::findNextSegment(ArcadeShooting *arc) { - _segmentIdx = _segmentIdx + 1; -} - -int BoyzEngine::detectTarget(const Common::Point &mousePos) { - Common::Point target = computeTargetPosition(mousePos); - assert(_shoots.size() <= 1); - for (Shoots::iterator it = _shoots.begin(); it != _shoots.end(); ++it) { - if (_mask->getPixel(target.x, target.y) == 1) - return 0; - } - return -1; -} - -void BoyzEngine::shoot(const Common::Point &mousePos, ArcadeShooting *arc, MVideo &background) { - incShotsFired(); - int i = detectTarget(mousePos); - if (i < 0) { - missNoTarget(arc, background); - } else { - if (!_shoots[i].hitSound.empty()) - playSound(_soundPath + _shoots[i].hitSound, 1); - - incEnemyHits(); - if (!_shoots[i].deathSound.empty()) - playSound(_soundPath + _shoots[i].deathSound, 1); - - incTargetsDestroyed(); - incScore(_shoots[i].pointsToShoot); - incBonus(_shoots[i].pointsToShoot); - _shoots[i].destroyed = true; - background.decoder->forceSeekToFrame(_shoots[i].explosionFrames[0].start - 3); - _masks->decoder->forceSeekToFrame(_shoots[i].explosionFrames[0].start - 3); - _shoots.clear(); - } -} - -void BoyzEngine::missedTarget(Shoot *s, ArcadeShooting *arc, MVideo &background) { - - if (s->missedAnimation == 0) - return; - else if (s->missedAnimation == uint32(-1)) { - uint32 last = background.decoder->getFrameCount()-1; - background.decoder->forceSeekToFrame(last); - _masks->decoder->forceSeekToFrame(last); - return; - } - - s->missedAnimation = s->missedAnimation + 3; - background.decoder->forceSeekToFrame(s->missedAnimation); - _masks->decoder->forceSeekToFrame(s->missedAnimation); -} - - } // namespace Hypno diff --git a/engines/hypno/module.mk b/engines/hypno/module.mk index b4e5b291a8e..1d1c0569bc3 100644 --- a/engines/hypno/module.mk +++ b/engines/hypno/module.mk @@ -3,6 +3,7 @@ MODULE := engines/hypno MODULE_OBJS := \ actions.o \ arcade.o \ + boyz/arcade.o \ boyz/boyz.o \ cursors.o \ grammar_mis.o \