1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
/* 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.h"
#include "bladerunner/bladerunner.h"
#include "bladerunner/slice_renderer.h"
#include "bladerunner/zbuffer.h"
namespace BladeRunner {
Item::Item(BladeRunnerEngine *vm) {
_vm = vm;
_itemId = -1;
_setId = -1;
_animationId = -1;
_position.x = 0;
_position.y = 0;
_position.z = 0;
_facing = 0;
_angle = 0.0f;
_width = 0;
_height = 0;
_boundingBox.setXYZ(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);
_screenX = 0;
_screenY = 0;
_depth = 0.0f;
_isTargetable = false;
_isSpinning = false;
_facingChange = 0;
_isVisible = true;
_isPoliceMazeEnemy = true;
_screenRectangle.bottom = -1;
_screenRectangle.right = -1;
_screenRectangle.top = -1;
_screenRectangle.left = -1;
}
Item::~Item() {
}
void Item::getXYZ(float *x, float *y, float *z) {
*x = _position.x;
*y = _position.y;
*z = _position.z;
}
void Item::getWidthHeight(int *width, int *height) {
*width = _width;
*height = _height;
}
bool Item::isTargetable() {
return _isTargetable;
}
bool Item::tick(Common::Rect *screenRect, bool special) {
if (!_isVisible) {
*screenRect = Common::Rect();
return false;
}
bool isVisible = false;
Vector3 position(_position.x, -_position.z, _position.y);
int animationId = _animationId + (special ? 1 : 0);
_vm->_sliceRenderer->drawInWorld(animationId, 0, position, M_PI - _angle, 1.0f, _vm->_surfaceGame, _vm->_zbuffer->getData());
_vm->_sliceRenderer->getScreenRectangle(&_screenRectangle, animationId, 0, position, M_PI - _angle, 1.0f);
if (!_screenRectangle.isEmpty()) {
*screenRect = _screenRectangle;
isVisible = true;
} else {
*screenRect = Common::Rect();
}
if (_isSpinning) {
_facing += _facingChange;
if (_facing >= 1024) {
_facing -= 1024;
} else if (_facing < 0) {
_facing += 1024;
}
_angle = _facing * (M_PI / 512.0f);
if (_facingChange > 0) {
_facingChange = _facingChange - 20;
if (_facingChange < 0) {
_facingChange = 0;
_isSpinning = false;
}
} else if (_facingChange < 0) {
_facingChange = _facingChange + 20;
if (_facingChange > 0) {
_facingChange = 0;
_isSpinning = false;
}
} else {
_isSpinning = false;
}
}
return isVisible;
}
void Item::setXYZ(Vector3 position) {
_position = position;
int halfWidth = _width / 2;
_boundingBox.setXYZ(_position.x - halfWidth, _position.y, _position.z - halfWidth,
_position.x + halfWidth, _position.y + _height, _position.z + halfWidth);
Vector3 screenPosition = _vm->_view->calculateScreenPosition(_position);
_screenX = screenPosition.x;
_screenY = screenPosition.y;
_depth = screenPosition.z * 25.5f;
}
void Item::setup(int itemId, int setId, int animationId, Vector3 position, int facing, int height, int width, bool isTargetableFlag, bool isVisibleFlag, bool isPoliceMazeEnemyFlag) {
_itemId = itemId;
_setId = setId;
_animationId = animationId;
_facing = facing;
_angle = facing * (M_PI / 512.0f);
_width = width;
_height = height;
_isTargetable = isTargetableFlag;
_isVisible = isVisibleFlag;
_isPoliceMazeEnemy = isPoliceMazeEnemyFlag;
setXYZ(position);
_screenRectangle.bottom = -1;
_screenRectangle.right = -1;
_screenRectangle.top = -1;
_screenRectangle.left = -1;
}
} // End of namespace BladeRunner
|