/* 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; _isTarget = false; _isSpinning = false; _facingChange = 0; _isVisible = true; _isPoliceMazeEnemy = true; _screenRectangle.bottom = -1; _screenRectangle.right = -1; _screenRectangle.top = -1; _screenRectangle.left = -1; } void Item::getXYZ(float *x, float *y, float *z) const { *x = _position.x; *y = _position.y; *z = _position.z; } void Item::getWidthHeight(int *width, int *height) const { *width = _width; *height = _height; } bool Item::isTarget() const { return _isTarget; } 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->_surfaceFront, _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 isTargetFlag, bool isVisible, bool isPoliceMazeEnemy) { _itemId = itemId; _setId = setId; _animationId = animationId; _facing = facing; _angle = facing * (M_PI / 512.0f); _width = width; _height = height; _isTarget = isTargetFlag; _isVisible = isVisible; _isPoliceMazeEnemy = isPoliceMazeEnemy; setXYZ(position); _screenRectangle.bottom = -1; _screenRectangle.right = -1; _screenRectangle.top = -1; _screenRectangle.left = -1; } bool Item::isUnderMouse(int mouseX, int mouseY) const { return _isVisible && mouseX >= _screenRectangle.left - 10 && mouseX <= _screenRectangle.right + 10 && mouseY >= _screenRectangle.top - 10 && mouseY <= _screenRectangle.bottom + 10; } } // End of namespace BladeRunner