From b3059e75e2597671abe501e62e73138f0825976b Mon Sep 17 00:00:00 2001 From: Matthew Hoops Date: Sun, 23 Oct 2011 22:50:54 -0400 Subject: PEGASUS: Add the space junk stuff --- engines/pegasus/neighborhood/mars/spacejunk.cpp | 213 ++++++++++++++++++++++++ 1 file changed, 213 insertions(+) create mode 100755 engines/pegasus/neighborhood/mars/spacejunk.cpp (limited to 'engines/pegasus/neighborhood/mars/spacejunk.cpp') diff --git a/engines/pegasus/neighborhood/mars/spacejunk.cpp b/engines/pegasus/neighborhood/mars/spacejunk.cpp new file mode 100755 index 0000000000..8c78db4050 --- /dev/null +++ b/engines/pegasus/neighborhood/mars/spacejunk.cpp @@ -0,0 +1,213 @@ +/* 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. + * + * Additional copyright for this file: + * Copyright (C) 1995-1997 Presto Studios, Inc. + * + * 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 "pegasus/pegasus.h" +#include "pegasus/neighborhood/mars/spacejunk.h" + +namespace Pegasus { + +//const TimeValue kWeaponReboundTime = kTwoSeconds * kJunkTimeScale; +//const TimeValue kCollisionReboundTime = kOneSecond * kJunkTimeScale; +const tCoordType kMaxBounceSize = 90; +const tCoordType kBounceTargetHRange = 640 - kMaxBounceSize - 2; +const tCoordType kBounceTargetVRange = 480 - kMaxBounceSize - 2; + +const float kJunkXTarget = 0; +const float kJunkYTarget = 0; +const float kJunkZTarget = kJunkMinDistance; + +SpaceJunk *g_spaceJunk = 0; + +SpaceJunk::SpaceJunk(const tDisplayElementID id) : ScalingMovie(id) { + _timer.setScale(kJunkTimeScale); + _bouncing = false; + g_spaceJunk = this; +} + +SpaceJunk::~SpaceJunk() { + g_spaceJunk = 0; +} + +void SpaceJunk::launchJunk(int16 whichJunk, tCoordType xOrigin, tCoordType yOrigin) { + _bouncing = false; + TimeValue startTime = whichJunk * 16 * 40; + TimeValue stopTime = startTime + 16 * 40; + + _launchPoint = Point3D(convertScreenHToSpaceX(xOrigin, kJunkMaxDistance), + convertScreenVToSpaceY(yOrigin, kJunkMaxDistance), kJunkMaxDistance); + startIdling(); + stop(); + setFlags(0); + setSegment(startTime, stopTime); + setFlags(kLoopTimeBase); + setTime(startTime); + start(); + show(); + _timer.stop(); + _timer.setSegment(0, kJunkTravelTime); + _timer.setTime(0); + + // Force it to set up correctly from the get-go + useIdleTime(); + + _timer.start(); +} + +void SpaceJunk::setCenter(const tCoordType centerX, const tCoordType centerY) { + _center.x = centerX; + _center.y = centerY; + + Common::Rect r; + getBounds(r); + r.moveTo(centerX - (r.width() >> 1), centerY - (r.height() >> 1)); + setBounds(r); +} + +void SpaceJunk::setScaleSize(const tCoordType size) { + Common::Rect r; + r.left = _center.x - (size >> 1); + r.top = _center.y - (size >> 1); + r.right = r.left + size; + r.bottom = r.top + size; + setBounds(r); +} + +void SpaceJunk::useIdleTime() { + if (_bouncing) { + TimeValue time = _timer.getTime(); + Common::Point pt; + pt.x = linearInterp(0, _bounceTime, time, _bounceStart.x, _bounceStop.x); + pt.y = linearInterp(0, _bounceTime, time, _bounceStart.y, _bounceStop.y); + tCoordType size = linearInterp(0, _bounceTime, time, _bounceSizeStart, _bounceSizeStop); + setCenter(pt.x, pt.y); + setScaleSize(size); + + if (time == _bounceTime) { + stop(); + stopIdling(); + hide(); + ((Mars *)g_neighborhood)->setUpNextDropTime(); + } + } else { + float t = (float)_timer.getTime() / kJunkTravelTime; + linearInterp(_launchPoint, kJunkXTarget, kJunkYTarget, kJunkZTarget, t, _junkPosition); + + Common::Point pt2D; + project3DTo2D(_junkPosition, pt2D); + setCenter(pt2D.x, pt2D.y); + setScaleSize((int)(convertSpaceYToScreenV(_junkPosition.y - kJunkSize / 2, _junkPosition.z) - + convertSpaceYToScreenV(_junkPosition.y + kJunkSize / 2, _junkPosition.z))); + + if (t == 1.0) { + rebound(kCollisionReboundTime); + ((Mars *)g_neighborhood)->hitByJunk(); + } + } +} + +bool SpaceJunk::pointInJunk(const Common::Point &pt) { + Common::Rect r; + getBounds(r); + + int dx = r.width() / 4; + int dy = r.height() / 4; + + r.left += dx; + r.right -= dx; + r.top += dy; + r.top -= dy; + + return r.contains(pt); +} + +void SpaceJunk::rebound(const TimeValue reboundTime) { + Common::Rect bounds; + getBounds(bounds); + + _bounceStart.x = (bounds.left + bounds.right) >> 1; + _bounceStart.y = (bounds.top + bounds.bottom) >> 1; + + PegasusEngine *vm = (PegasusEngine *)g_engine; + + switch (vm->getRandomNumber(3)) { + case 0: + _bounceStop.x = kMaxBounceSize / 2 + 1 + vm->getRandomNumber(kBounceTargetHRange - 1); + _bounceStop.y = kMaxBounceSize / 2 + 1; + break; + case 1: + _bounceStop.x = kMaxBounceSize / 2 + 1 + vm->getRandomNumber(kBounceTargetHRange - 1); + _bounceStop.y = 480 - kMaxBounceSize / 2 + 1; + break; + case 2: + _bounceStop.x = kMaxBounceSize / 2 + 1; + _bounceStop.y = kMaxBounceSize / 2 + 1 + vm->getRandomNumber(kBounceTargetVRange - 1); + break; + case 3: + _bounceStop.x = 640 - kMaxBounceSize / 2 + 1; + _bounceStop.y = kMaxBounceSize / 2 + 1 + vm->getRandomNumber(kBounceTargetVRange - 1); + break; + } + + _bounceSizeStart = bounds.width(); + _bounceSizeStop = MIN(_bounceSizeStart, kMaxBounceSize); + + _timer.stop(); + _timer.setSegment(0, reboundTime); + _bounceTime = reboundTime; + _timer.setTime(0); + _timer.start(); + + _bouncing = true; +} + +void SpaceJunk::hitByEnergyBeam(Common::Point) { + rebound(kWeaponReboundTime); + setGlowing(true); + ((PegasusEngine *)g_engine)->delayShell(1, 3); + setGlowing(false); +} + +void SpaceJunk::hitByGravitonCannon(Common::Point impactPoint) { + stop(); + stopIdling(); + hide(); + + Common::Rect r; + getBounds(r); + r = Common::Rect::center(impactPoint.x, impactPoint.y, r.width(), r.height()); + + ((Mars *)g_neighborhood)->showBigExplosion(r, kShuttleJunkOrder); + ((Mars *)g_neighborhood)->setUpNextDropTime(); +} + +void SpaceJunk::getJunkPosition(Point3D &position) { + position = _junkPosition; +} + +bool SpaceJunk::isJunkFlying() { + return isIdling(); +} + +} // End of namespace Pegasus -- cgit v1.2.3 From 3f69c195ae5824a7f3037add447cca40e8827e6c Mon Sep 17 00:00:00 2001 From: Matthew Hoops Date: Fri, 28 Oct 2011 01:24:57 -0400 Subject: PEGASUS: Allow for initial support of the space chase It's not ready yet, but it's slowly becoming playable. For instance, scaling, the shuttle HUD, and the energy beam work on the first try which is nothing short of a miracle. This commit also moved around some Mars constants because the previous include setup did not work; I hope to make the other neighborhoods have a separate constants file too. --- engines/pegasus/neighborhood/mars/spacejunk.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'engines/pegasus/neighborhood/mars/spacejunk.cpp') diff --git a/engines/pegasus/neighborhood/mars/spacejunk.cpp b/engines/pegasus/neighborhood/mars/spacejunk.cpp index 8c78db4050..8ae36cec0f 100755 --- a/engines/pegasus/neighborhood/mars/spacejunk.cpp +++ b/engines/pegasus/neighborhood/mars/spacejunk.cpp @@ -24,6 +24,7 @@ */ #include "pegasus/pegasus.h" +#include "pegasus/neighborhood/mars/mars.h" #include "pegasus/neighborhood/mars/spacejunk.h" namespace Pegasus { -- cgit v1.2.3 From bcf5ea1dc246b86a06ca9f1f97fa5525bd0a006b Mon Sep 17 00:00:00 2001 From: Matthew Hoops Date: Sat, 29 Oct 2011 12:19:58 -0400 Subject: PEGASUS: Keep the space junk from flying beyond the screen boundary --- engines/pegasus/neighborhood/mars/spacejunk.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/pegasus/neighborhood/mars/spacejunk.cpp') diff --git a/engines/pegasus/neighborhood/mars/spacejunk.cpp b/engines/pegasus/neighborhood/mars/spacejunk.cpp index 8ae36cec0f..a1f9bf7c37 100755 --- a/engines/pegasus/neighborhood/mars/spacejunk.cpp +++ b/engines/pegasus/neighborhood/mars/spacejunk.cpp @@ -82,7 +82,7 @@ void SpaceJunk::setCenter(const tCoordType centerX, const tCoordType centerY) { Common::Rect r; getBounds(r); - r.moveTo(centerX - (r.width() >> 1), centerY - (r.height() >> 1)); + r.moveTo(MAX(centerX - (r.width() >> 1), 0), MAX(centerY - (r.height() >> 1), 0)); setBounds(r); } @@ -170,7 +170,7 @@ void SpaceJunk::rebound(const TimeValue reboundTime) { _bounceStop.y = kMaxBounceSize / 2 + 1 + vm->getRandomNumber(kBounceTargetVRange - 1); break; } - + _bounceSizeStart = bounds.width(); _bounceSizeStop = MIN(_bounceSizeStart, kMaxBounceSize); -- cgit v1.2.3 From faa6018cad43c89c415397112e9fd7ca46fff5da Mon Sep 17 00:00:00 2001 From: Matthew Hoops Date: Tue, 1 Nov 2011 20:38:22 -0400 Subject: PEGASUS: Just clip the junk from going off right or bottom too --- engines/pegasus/neighborhood/mars/spacejunk.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/pegasus/neighborhood/mars/spacejunk.cpp') diff --git a/engines/pegasus/neighborhood/mars/spacejunk.cpp b/engines/pegasus/neighborhood/mars/spacejunk.cpp index a1f9bf7c37..a751dc2a71 100755 --- a/engines/pegasus/neighborhood/mars/spacejunk.cpp +++ b/engines/pegasus/neighborhood/mars/spacejunk.cpp @@ -82,7 +82,7 @@ void SpaceJunk::setCenter(const tCoordType centerX, const tCoordType centerY) { Common::Rect r; getBounds(r); - r.moveTo(MAX(centerX - (r.width() >> 1), 0), MAX(centerY - (r.height() >> 1), 0)); + r.moveTo(CLIP(centerX - (r.width() >> 1), 0, 640), CLIP(centerY - (r.height() >> 1), 0, 480)); setBounds(r); } -- cgit v1.2.3 From 12efb47b536d2f663c9cde2739a1fd40599da669 Mon Sep 17 00:00:00 2001 From: Matthew Hoops Date: Fri, 16 Dec 2011 14:17:50 -0500 Subject: PEGASUS: Remove t prefix from typedefs Some other minor cleanup too --- engines/pegasus/neighborhood/mars/spacejunk.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'engines/pegasus/neighborhood/mars/spacejunk.cpp') diff --git a/engines/pegasus/neighborhood/mars/spacejunk.cpp b/engines/pegasus/neighborhood/mars/spacejunk.cpp index a751dc2a71..28847136f6 100755 --- a/engines/pegasus/neighborhood/mars/spacejunk.cpp +++ b/engines/pegasus/neighborhood/mars/spacejunk.cpp @@ -31,9 +31,9 @@ namespace Pegasus { //const TimeValue kWeaponReboundTime = kTwoSeconds * kJunkTimeScale; //const TimeValue kCollisionReboundTime = kOneSecond * kJunkTimeScale; -const tCoordType kMaxBounceSize = 90; -const tCoordType kBounceTargetHRange = 640 - kMaxBounceSize - 2; -const tCoordType kBounceTargetVRange = 480 - kMaxBounceSize - 2; +const CoordType kMaxBounceSize = 90; +const CoordType kBounceTargetHRange = 640 - kMaxBounceSize - 2; +const CoordType kBounceTargetVRange = 480 - kMaxBounceSize - 2; const float kJunkXTarget = 0; const float kJunkYTarget = 0; @@ -41,7 +41,7 @@ const float kJunkZTarget = kJunkMinDistance; SpaceJunk *g_spaceJunk = 0; -SpaceJunk::SpaceJunk(const tDisplayElementID id) : ScalingMovie(id) { +SpaceJunk::SpaceJunk(const DisplayElementID id) : ScalingMovie(id) { _timer.setScale(kJunkTimeScale); _bouncing = false; g_spaceJunk = this; @@ -51,7 +51,7 @@ SpaceJunk::~SpaceJunk() { g_spaceJunk = 0; } -void SpaceJunk::launchJunk(int16 whichJunk, tCoordType xOrigin, tCoordType yOrigin) { +void SpaceJunk::launchJunk(int16 whichJunk, CoordType xOrigin, CoordType yOrigin) { _bouncing = false; TimeValue startTime = whichJunk * 16 * 40; TimeValue stopTime = startTime + 16 * 40; @@ -76,7 +76,7 @@ void SpaceJunk::launchJunk(int16 whichJunk, tCoordType xOrigin, tCoordType yOrig _timer.start(); } -void SpaceJunk::setCenter(const tCoordType centerX, const tCoordType centerY) { +void SpaceJunk::setCenter(const CoordType centerX, const CoordType centerY) { _center.x = centerX; _center.y = centerY; @@ -86,7 +86,7 @@ void SpaceJunk::setCenter(const tCoordType centerX, const tCoordType centerY) { setBounds(r); } -void SpaceJunk::setScaleSize(const tCoordType size) { +void SpaceJunk::setScaleSize(const CoordType size) { Common::Rect r; r.left = _center.x - (size >> 1); r.top = _center.y - (size >> 1); @@ -101,7 +101,7 @@ void SpaceJunk::useIdleTime() { Common::Point pt; pt.x = linearInterp(0, _bounceTime, time, _bounceStart.x, _bounceStop.x); pt.y = linearInterp(0, _bounceTime, time, _bounceStart.y, _bounceStop.y); - tCoordType size = linearInterp(0, _bounceTime, time, _bounceSizeStart, _bounceSizeStop); + CoordType size = linearInterp(0, _bounceTime, time, _bounceSizeStart, _bounceSizeStop); setCenter(pt.x, pt.y); setScaleSize(size); -- cgit v1.2.3 From f72884cb7bbe594888f6d14a3e03c7839ef2c508 Mon Sep 17 00:00:00 2001 From: Matthew Hoops Date: Fri, 16 Dec 2011 23:24:55 -0500 Subject: PEGASUS: Cleanup some constants Added missing static qualifiers, get rid of some short/long --- engines/pegasus/neighborhood/mars/spacejunk.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'engines/pegasus/neighborhood/mars/spacejunk.cpp') diff --git a/engines/pegasus/neighborhood/mars/spacejunk.cpp b/engines/pegasus/neighborhood/mars/spacejunk.cpp index 28847136f6..9f34c21461 100755 --- a/engines/pegasus/neighborhood/mars/spacejunk.cpp +++ b/engines/pegasus/neighborhood/mars/spacejunk.cpp @@ -29,15 +29,13 @@ namespace Pegasus { -//const TimeValue kWeaponReboundTime = kTwoSeconds * kJunkTimeScale; -//const TimeValue kCollisionReboundTime = kOneSecond * kJunkTimeScale; -const CoordType kMaxBounceSize = 90; -const CoordType kBounceTargetHRange = 640 - kMaxBounceSize - 2; -const CoordType kBounceTargetVRange = 480 - kMaxBounceSize - 2; - -const float kJunkXTarget = 0; -const float kJunkYTarget = 0; -const float kJunkZTarget = kJunkMinDistance; +static const CoordType kMaxBounceSize = 90; +static const CoordType kBounceTargetHRange = 640 - kMaxBounceSize - 2; +static const CoordType kBounceTargetVRange = 480 - kMaxBounceSize - 2; + +static const float kJunkXTarget = 0; +static const float kJunkYTarget = 0; +static const float kJunkZTarget = kJunkMinDistance; SpaceJunk *g_spaceJunk = 0; -- cgit v1.2.3 From b2c29410b9e66566ee5c9faad79b58696a6f3095 Mon Sep 17 00:00:00 2001 From: Matthew Hoops Date: Tue, 20 Mar 2012 14:50:06 -0400 Subject: PEGASUS: Add some more protection about junk flying off-screen --- engines/pegasus/neighborhood/mars/spacejunk.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/pegasus/neighborhood/mars/spacejunk.cpp') diff --git a/engines/pegasus/neighborhood/mars/spacejunk.cpp b/engines/pegasus/neighborhood/mars/spacejunk.cpp index 9f34c21461..ac8b1a23cc 100755 --- a/engines/pegasus/neighborhood/mars/spacejunk.cpp +++ b/engines/pegasus/neighborhood/mars/spacejunk.cpp @@ -80,7 +80,7 @@ void SpaceJunk::setCenter(const CoordType centerX, const CoordType centerY) { Common::Rect r; getBounds(r); - r.moveTo(CLIP(centerX - (r.width() >> 1), 0, 640), CLIP(centerY - (r.height() >> 1), 0, 480)); + r.moveTo(CLIP(centerX - (r.width() >> 1), 0, 640 - r.width()), CLIP(centerY - (r.height() >> 1), 0, 480 - r.height())); setBounds(r); } -- cgit v1.2.3 From 983bd16bb78b1a6aa8872f2086dbcbca6954f2fb Mon Sep 17 00:00:00 2001 From: Matthew Hoops Date: Tue, 3 Apr 2012 15:23:08 -0400 Subject: PEGASUS: Fix file permissions --- engines/pegasus/neighborhood/mars/spacejunk.cpp | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 engines/pegasus/neighborhood/mars/spacejunk.cpp (limited to 'engines/pegasus/neighborhood/mars/spacejunk.cpp') diff --git a/engines/pegasus/neighborhood/mars/spacejunk.cpp b/engines/pegasus/neighborhood/mars/spacejunk.cpp old mode 100755 new mode 100644 -- cgit v1.2.3