1 /* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 *
21 */
22
23 #include "bladerunner/item_pickup.h"
24
25 #include "bladerunner/audio_player.h"
26 #include "bladerunner/bladerunner.h"
27 #include "bladerunner/game_info.h"
28 #include "bladerunner/slice_animations.h"
29 #include "bladerunner/slice_renderer.h"
30 #include "bladerunner/time.h"
31 #include "bladerunner/zbuffer.h"
32 #include "bladerunner/game_constants.h"
33
34 namespace BladeRunner {
35
ItemPickup(BladeRunnerEngine * vm)36 ItemPickup::ItemPickup(BladeRunnerEngine *vm) {
37 _vm = vm;
38 _facingStep = float(2.0f / 3000.0f * (2.0f * M_PI));
39 reset();
40 }
41
~ItemPickup()42 ItemPickup::~ItemPickup() {
43 }
44
setup(int animationId,int screenX,int screenY)45 void ItemPickup::setup(int animationId, int screenX, int screenY) {
46 _animationId = animationId;
47 _animationFrame = 0;
48 _facing = 0.0;
49 _timeLeft = 3000u;
50 _scale = 0;
51 _screenX = CLIP(screenX, 40, 600);
52 _screenY = CLIP(screenY, 40, 440);
53 _screenRect.left = _screenX - 40;
54 _screenRect.right = _screenX + 40;
55 _screenRect.top = _screenY - 40;
56 _screenRect.bottom = _screenY + 40;
57
58 int pan = (75 * (2 * _screenX - 640)) / 640; // map [0..640] to [-75..75]
59 _vm->_audioPlayer->playAud(_vm->_gameInfo->getSfxTrack(kSfxGETITEM1), 80, pan, pan, 50, 0);
60
61 _timeLast = _vm->_time->currentSystem();
62 }
63
reset()64 void ItemPickup::reset() {
65 _animationId = -1;
66 _screenX = 0;
67 _screenY = 0;
68 _facing = 0.0f;
69 _scale = 1.0f;
70 _animationFrame = 0;
71 _timeLeft = 0u;
72 _timeLast = 0u;
73 }
74
tick()75 void ItemPickup::tick() {
76 if (_timeLeft == 0u) {
77 return;
78 }
79
80 uint32 timeNow = _vm->_time->currentSystem();
81 // unsigned difference is intentional
82 uint32 timeDiff = timeNow - _timeLast;
83 _timeLast = timeNow;
84 timeDiff = MIN(MIN<uint32>(timeDiff, 67u), _timeLeft);
85 _timeLeft = (_timeLeft < timeDiff) ? 0 : (_timeLeft - timeDiff);
86
87 if (_timeLeft >= 2000u) {
88 _scale = 1.0f - (((2000.0f - _timeLeft) / 1000.0f) * ((2000.0f - _timeLeft) / 1000.0f));
89 } else if (_timeLeft < 1000u) {
90 _scale = 1.0f - (((1000.0f - _timeLeft) / 1000.0f) * ((1000.0f - _timeLeft) / 1000.0f));
91 } else {
92 _scale = 1.0f;
93 }
94 _scale *= 75.0f;
95
96 _facing += _facingStep * timeDiff;
97 if (_facing > float(2.0f * M_PI)) {
98 _facing -= float(2.0f * M_PI);
99 }
100
101 _animationFrame = (_animationFrame + 1) % _vm->_sliceAnimations->getFrameCount(_animationId);
102 }
103
draw()104 void ItemPickup::draw() {
105 if (_timeLeft == 0u) {
106 return;
107 }
108
109 _vm->_sliceRenderer->drawOnScreen(_animationId, _animationFrame, _screenX, _screenY, _facing, _scale, _vm->_surfaceFront);
110 }
111 } // End of namespace BladeRunner
112