Skip to content

Commit

Permalink
BLADERUNNER: added item pickup effect
Browse files Browse the repository at this point in the history
also added support for rendering items on screen (not in the world)
pickup effect can be tested in debug compilation by clicking on any object (not item, but object like, hydrant, or doors) in first scene
  • Loading branch information
peterkohaut committed Oct 8, 2016
1 parent c934941 commit f30f3c4
Show file tree
Hide file tree
Showing 12 changed files with 298 additions and 48 deletions.
2 changes: 1 addition & 1 deletion engines/bladerunner/actor.cpp
Expand Up @@ -510,7 +510,7 @@ void Actor::draw() {

// TODO: Handle SHORTY mode

_vm->_sliceRenderer->drawFrame(_animationId, _animationFrame, drawPosition, drawAngle, drawScale, _vm->_surface2, _vm->_zBuffer2);
_vm->_sliceRenderer->drawInWorld(_animationId, _animationFrame, drawPosition, drawAngle, drawScale, _vm->_surface2, _vm->_zBuffer2);
//todo udpate screenrect
}

Expand Down
16 changes: 12 additions & 4 deletions engines/bladerunner/bladerunner.cpp
Expand Up @@ -34,6 +34,7 @@
#include "bladerunner/gameflags.h"
#include "bladerunner/gameinfo.h"
#include "bladerunner/image.h"
#include "bladerunner/item_pickup.h"
#include "bladerunner/items.h"
#include "bladerunner/lights.h"
#include "bladerunner/mouse.h"
Expand Down Expand Up @@ -77,6 +78,7 @@ BladeRunnerEngine::BladeRunnerEngine(OSystem *syst)
_combat = new Combat(this);
_adq = new ADQ(this);
_obstacles = new Obstacles(this);
_itemPickup = new ItemPickup(this);

_walkSoundId = -1;
_walkSoundVolume = 0;
Expand Down Expand Up @@ -104,6 +106,7 @@ BladeRunnerEngine::~BladeRunnerEngine() {
// delete[] _zBuffer1;
// delete[] _zBuffer2;

delete _itemPickup;
delete _obstacles;
delete _adq;
delete _combat;
Expand Down Expand Up @@ -158,6 +161,8 @@ bool BladeRunnerEngine::startup(bool hasSavegames) {
if (!r)
return false;

// TODO: Create datetime - not used

// TODO: Create graphics surfaces 1-4

// TODO: Allocate audio cache
Expand Down Expand Up @@ -463,9 +468,10 @@ void BladeRunnerEngine::shutdown() {

// TODO: Delete KIA

// TODO: Delete SDB
delete _suspectsDatabase;
_suspectsDatabase = nullptr;

// TODO: Delete unknown stuff
// TODO: Delete datetime - not used

// TODO: Delete actors

Expand Down Expand Up @@ -614,7 +620,9 @@ void BladeRunnerEngine::gameTick() {

_items->tick();

// TODO: Draw item pickup
_itemPickup->tick();
_itemPickup->draw();

// TODO: Draw dialogue menu

Common::Point p = _eventMan->getMousePos();
Expand All @@ -630,7 +638,7 @@ void BladeRunnerEngine::gameTick() {
_walkSoundId = -1;
}

#if _DEBUG
#if false
//draw scene objects
int count = _sceneObjects->_count;
if (count > 0) {
Expand Down
2 changes: 2 additions & 0 deletions engines/bladerunner/bladerunner.h
Expand Up @@ -48,6 +48,7 @@ class Combat;
class Font;
class GameFlags;
class GameInfo;
class ItemPickup;
class Items;
class Lights;
class Mouse;
Expand Down Expand Up @@ -79,6 +80,7 @@ class BladeRunnerEngine : public Engine {
Combat *_combat;
GameFlags *_gameFlags;
GameInfo *_gameInfo;
ItemPickup *_itemPickup;
Items *_items;
Lights *_lights;
Font *_mainFont;
Expand Down
37 changes: 13 additions & 24 deletions engines/bladerunner/font.cpp
Expand Up @@ -68,7 +68,7 @@ bool Font::open(const Common::String &fileName, int screenWidth, int screenHeigh
_characters[i]._height = stream->readUint32LE();
_characters[i]._dataOffset = stream->readUint32LE();
}
for(int i = 0; i < _dataSize; i++) {
for (int i = 0; i < _dataSize; i++) {
_data[i] = stream->readUint16LE();
}
return true;
Expand Down Expand Up @@ -100,20 +100,8 @@ void Font::draw(const Common::String &text, Graphics::Surface &surface, int x, i
return;
}

if (x < 0) {
x = 0;
}
if (y < 0) {
y = 0;
}

int textWidth = getTextWidth(text);
if (textWidth + x >= _screenWidth) {
x = _screenWidth - (textWidth + 1);
}
if (_maxHeight + y >= _screenHeight) {
y = _screenHeight - _maxHeight;
}
x = CLIP(x, 0, _screenWidth - getTextWidth(text) + 1);
y = CLIP(y, 0, _screenHeight - _maxHeight);

const char *character = text.c_str();
while (*character != 0) {
Expand Down Expand Up @@ -176,16 +164,17 @@ void Font::replaceColor(uint16 oldColor, uint16 newColor) {
}

void Font::drawCharacter(const char character, Graphics::Surface &surface, int x, int y) {
if (x < 0 || x >= _screenWidth || y < 0 || y >= _screenHeight || !_data || character + 1 >= _characterCount) {
char characterIndex = character + 1;

This comment has been minimized.

Copy link
@sev-

sev- Oct 8, 2016

Member

Array indexes of type 'char' are not very portable since chars could be signed or unsigned on different platforms, so your 128 could be interpreted as -1.

if (x < 0 || x >= _screenWidth || y < 0 || y >= _screenHeight || !_data || characterIndex >= _characterCount) {
return;
}

uint16 *dstPtr = (uint16*)surface.getBasePtr(x + _characters[character + 1]._x, y + _characters[character + 1]._y);
uint16 *srcPtr = &_data[_characters[character + 1]._dataOffset];
int width = _characters[character + 1]._width;
int height = _characters[character + 1]._height;
uint16 *dstPtr = (uint16*)surface.getBasePtr(x + _characters[characterIndex]._x, y + _characters[characterIndex]._y);
uint16 *srcPtr = &_data[_characters[characterIndex]._dataOffset];
int width = _characters[characterIndex]._width;
int height = _characters[characterIndex]._height;
if (_intersperse && y & 1) {
dstPtr += surface.w;
dstPtr += surface.pitch / 2;
}

int endY = height + y - 1;
Expand All @@ -194,17 +183,17 @@ void Font::drawCharacter(const char character, Graphics::Surface &surface, int x
int currentX = x;
int endX = width + x - 1;
while (currentX <= endX && currentX < _screenWidth) {
if (!(*srcPtr & 0x8000)) {
if ((*srcPtr & 0x8000) == 0) {
*dstPtr = *srcPtr;
}
dstPtr++;
srcPtr++;
currentX++;
}
dstPtr += surface.w - width;
dstPtr += surface.pitch / 2 - width;
if (_intersperse) {
srcPtr += width;
dstPtr += surface.w;
dstPtr += surface.pitch / 2;
currentY++;
}
currentY++;
Expand Down
2 changes: 1 addition & 1 deletion engines/bladerunner/item.cpp
Expand Up @@ -79,7 +79,7 @@ void Item::tick(bool special) {
if (_isVisible) {
Vector3 postition(_position.x, -_position.z, _position.y);
int animationId = _animationId + (special ? 1 : 0);
_vm->_sliceRenderer->drawFrame(animationId, 0, postition, M_PI - _angle, 1.0f, _vm->_surface2, _vm->_zBuffer2);
_vm->_sliceRenderer->drawInWorld(animationId, 0, postition, M_PI - _angle, 1.0f, _vm->_surface2, _vm->_zBuffer2);
//todo udpate screenrect
if (_isSpinning) {
_facing += _facingChange;
Expand Down
108 changes: 108 additions & 0 deletions engines/bladerunner/item_pickup.cpp
@@ -0,0 +1,108 @@
/* 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 "bladerunner/item_pickup.h"

#include "bladerunner/bladerunner.h"

#include "bladerunner/audio_player.h"
#include "bladerunner/gameinfo.h"
#include "slice_animations.h"
#include "slice_renderer.h"

namespace BladeRunner {

ItemPickup::ItemPickup(BladeRunnerEngine *vm) {
_vm = vm;
_facingStep = float(1.0f / 3000.0f * M_PI);
reset();
}

ItemPickup::~ItemPickup() {
}

void ItemPickup::setup(int animationId, int screenX, int screenY) {
_animationId = animationId;
_animationFrame = 0;
_facing = 0.0;
_timeLeft = 3000;
_scale = 0;
_screenX = CLIP(screenX, 40, 600);
_screenY = CLIP(screenY, 40, 440);
_screenRect.left = _screenX - 40;
_screenRect.right = _screenX + 40;
_screenRect.top = _screenY - 40;
_screenRect.bottom = _screenY + 40;

int pan = (150 * _screenX - 48000) / 640;
_vm->_audioPlayer->playAud(_vm->_gameInfo->getSfxTrack(335), 80, pan, pan, 50, 0);

_timeLast = _vm->getTotalPlayTime();
}

void ItemPickup::reset() {
_animationId = -1;
_screenX = 0;
_screenY = 0;
_facing = 0.0f;
_scale = 1.0f;
_animationFrame = 0;
_timeLeft = 0;
_timeLast = 0;
}

void ItemPickup::tick() {
if (_timeLeft == 0) {
return;
}

int timeNow = _vm->getTotalPlayTime();
int timeDiff = timeNow - _timeLast;
_timeLast = timeNow;
timeDiff = MIN(MIN(timeDiff, 67), _timeLeft);
_timeLeft -= timeDiff;

if (_timeLeft >= 2000) {
_scale = 1.0f - (((2000.0f - _timeLeft) / 1000.0f) * ((2000.0f - _timeLeft) / 1000.0f));
} else if (_timeLeft < 1000) {
_scale = 1.0f - (((1000.0f - _timeLeft) / 1000.0f) * ((1000.0f - _timeLeft) / 1000.0f));
} else {
_scale = 1.0f;
}
_scale *= 75.0f;

_facing += _facingStep * timeDiff;
if (_facing > float(2.0f * M_PI)) {
_facing -= float(2.0f * M_PI);
}

_animationFrame = (_animationFrame + 1) % _vm->_sliceAnimations->getFrameCount(_animationId);
}

void ItemPickup::draw() {
if (_timeLeft == 0) {
return;
}

_vm->_sliceRenderer->drawOnScreen(_animationId, _animationFrame, _screenX, _screenY, _facing, _scale, _vm->_surface2, _vm->_zBuffer2);
}
} // End of namespace BladeRunner
61 changes: 61 additions & 0 deletions engines/bladerunner/item_pickup.h
@@ -0,0 +1,61 @@
/* 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 BLADERUNNER_ITEMPICKUP_H
#define BLADERUNNER_ITEMPICKUP_H

#include "common/rect.h"
#include "graphics/surface.h"

namespace BladeRunner {

class BladeRunnerEngine;

class ItemPickup {
BladeRunnerEngine *_vm;

float _facingStep;

int _animationId;
int _screenX;
int _screenY;
float _facing;
float _scale;
int _animationFrame;
int _timeLeft;
int _timeLast;
Common::Rect _screenRect;

public:
ItemPickup(BladeRunnerEngine *vm);
~ItemPickup();

void setup(int animationId, int screenX, int screenY);
void reset();

void tick();
void draw();
};

} // End of namespace BladeRunner

#endif
1 change: 1 addition & 0 deletions engines/bladerunner/module.mk
Expand Up @@ -26,6 +26,7 @@ MODULE_OBJS = \
gameinfo.o \
image.o \
item.o \
item_pickup.o \
items.o \
light.o \
lights.o \
Expand Down
3 changes: 3 additions & 0 deletions engines/bladerunner/script/rc01.cpp
Expand Up @@ -202,6 +202,9 @@ bool ScriptRC01::MouseClick(int x, int y) {
}

bool ScriptRC01::ClickedOn3DObject(const char *objectName, bool a2) {
#if _DEBUG
Item_Pickup_Spin_Effect(938, 426, 316);
#endif
if (Object_Query_Click("BARICADE01", objectName)
|| Object_Query_Click("BARICADE03", objectName)
|| Object_Query_Click("BARICADE04", objectName)
Expand Down
8 changes: 4 additions & 4 deletions engines/bladerunner/script/script.cpp
Expand Up @@ -34,6 +34,8 @@
#include "bladerunner/combat.h"
#include "bladerunner/gameflags.h"
#include "bladerunner/gameinfo.h"
#include "bladerunner/items.h"
#include "bladerunner/item_pickup.h"
#include "bladerunner/movement_track.h"
#include "bladerunner/settings.h"
#include "bladerunner/set_effects.h"
Expand All @@ -47,7 +49,6 @@

#include "bladerunner/script/ai_00_mccoy.h"
#include "bladerunner/script/aiscript_officer_leroy.h"
#include "bladerunner/items.h"

namespace BladeRunner {

Expand Down Expand Up @@ -680,9 +681,8 @@ void ScriptBase::Item_Flag_As_Non_Target(int itemId) {
warning("Item_Flag_As_Non_Target(%d)", itemId);
}

void ScriptBase::Item_Pickup_Spin_Effect(int a1, int a2, int a3) {
//TODO
warning("Item_Pickup_Spin_Effect(%d, %d, %d)", a1, a2, a3);
void ScriptBase::Item_Pickup_Spin_Effect(int animationId, int x, int y) {
_vm->_itemPickup->setup(animationId, x, y);
}

int ScriptBase::Animation_Open() {
Expand Down

0 comments on commit f30f3c4

Please sign in to comment.