[10050] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
| 3 | * > www.orxonox.net < |
---|
| 4 | * |
---|
| 5 | * |
---|
| 6 | * License notice: |
---|
| 7 | * |
---|
| 8 | * This program is free software; you can redistribute it and/or |
---|
| 9 | * modify it under the terms of the GNU General Public License |
---|
| 10 | * as published by the Free Software Foundation; either version 2 |
---|
| 11 | * of the License, or (at your option) any later version. |
---|
| 12 | * |
---|
| 13 | * This program is distributed in the hope that it will be useful, |
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | * GNU General Public License for more details. |
---|
| 17 | * |
---|
| 18 | * You should have received a copy of the GNU General Public License |
---|
| 19 | * along with this program; if not, write to the Free Software |
---|
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 21 | * |
---|
| 22 | * Author: |
---|
| 23 | * Fabian 'x3n' Landau |
---|
| 24 | * Co-authors: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | /** |
---|
| 30 | @file JumpItem.cc |
---|
| 31 | @brief Implementation of the JumpItem class. |
---|
| 32 | */ |
---|
| 33 | |
---|
| 34 | #include "JumpItem.h" |
---|
| 35 | |
---|
| 36 | #include "core/CoreIncludes.h" |
---|
| 37 | #include "core/GameMode.h" |
---|
| 38 | #include "graphics/Model.h" |
---|
| 39 | #include "gametypes/Gametype.h" |
---|
| 40 | |
---|
| 41 | #include "JumpFigure.h" |
---|
| 42 | |
---|
| 43 | #include "sound/WorldSound.h" |
---|
| 44 | #include "core/XMLPort.h" |
---|
| 45 | |
---|
| 46 | namespace orxonox |
---|
| 47 | { |
---|
| 48 | RegisterClass(JumpItem); |
---|
| 49 | |
---|
| 50 | /** |
---|
| 51 | @brief |
---|
| 52 | Constructor. Registers and initializes the object. |
---|
| 53 | */ |
---|
| 54 | JumpItem::JumpItem(Context* context) : MovableEntity(context) |
---|
| 55 | { |
---|
| 56 | RegisterObject(JumpItem); |
---|
| 57 | |
---|
[10074] | 58 | attachedToFigure_ = false; |
---|
| 59 | |
---|
| 60 | figure_ = 0; |
---|
| 61 | height_ = 0.0; |
---|
| 62 | width_ = 0.0; |
---|
| 63 | setPosition(Vector3(0,0,0)); |
---|
| 64 | setVelocity(Vector3(0,0,0)); |
---|
| 65 | setAcceleration(Vector3(0,0,0)); |
---|
[10050] | 66 | } |
---|
| 67 | |
---|
| 68 | /** |
---|
| 69 | @brief |
---|
| 70 | Destructor. |
---|
| 71 | */ |
---|
| 72 | JumpItem::~JumpItem() |
---|
| 73 | { |
---|
| 74 | |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | //xml port for loading sounds |
---|
| 78 | void JumpItem::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
| 79 | { |
---|
| 80 | SUPER(JumpItem, XMLPort, xmlelement, mode); |
---|
[10074] | 81 | |
---|
| 82 | XMLPortParam(JumpItem, "height", setHeight, getHeight, xmlelement, mode); |
---|
| 83 | XMLPortParam(JumpItem, "width", setWidth, getWidth, xmlelement, mode); |
---|
[10050] | 84 | } |
---|
| 85 | |
---|
| 86 | /** |
---|
| 87 | @brief |
---|
| 88 | Is called every tick. |
---|
| 89 | Handles the movement of the ball and its interaction with the boundaries and bats. |
---|
| 90 | @param dt |
---|
| 91 | The time since the last tick. |
---|
| 92 | */ |
---|
| 93 | void JumpItem::tick(float dt) |
---|
| 94 | { |
---|
| 95 | SUPER(JumpItem, tick, dt); |
---|
[10074] | 96 | // Get the current position, velocity and acceleration of the item. |
---|
| 97 | Vector3 position = getWorldPosition(); |
---|
[10050] | 98 | Vector3 velocity = getVelocity(); |
---|
| 99 | |
---|
| 100 | if ((position.x < leftBoundary_ && velocity.x < 0) || (position.x > rightBoundary_ && velocity.x > 0)) |
---|
| 101 | { |
---|
| 102 | velocity.x = -velocity.x; |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | if ((position.z < lowerBoundary_ && velocity.z < 0) || (position.z > upperBoundary_ && velocity.z > 0)) |
---|
| 106 | { |
---|
| 107 | velocity.z = -velocity.z; |
---|
| 108 | } |
---|
| 109 | |
---|
[10074] | 110 | // Set the position, velocity and acceleration of the item, if they have changed. |
---|
[10050] | 111 | if (velocity != getVelocity()) |
---|
[10074] | 112 | { |
---|
[10050] | 113 | setVelocity(velocity); |
---|
[10074] | 114 | } |
---|
[10050] | 115 | } |
---|
| 116 | |
---|
| 117 | void JumpItem::setProperties(float newLeftBoundary, float newRightBoundary, float newLowerBoundary, float newUpperBoundary, float newHSpeed, float newVSpeed) |
---|
| 118 | { |
---|
| 119 | leftBoundary_ = newLeftBoundary; |
---|
| 120 | rightBoundary_ = newRightBoundary; |
---|
| 121 | lowerBoundary_ = newLowerBoundary; |
---|
| 122 | upperBoundary_ = newUpperBoundary; |
---|
| 123 | |
---|
[10074] | 124 | setVelocity(Vector3(newHSpeed,0,newVSpeed)); |
---|
[10050] | 125 | } |
---|
| 126 | |
---|
| 127 | /** |
---|
| 128 | @brief |
---|
| 129 | Set the bats for the ball. |
---|
| 130 | @param bats |
---|
| 131 | An array (of size 2) of weak pointers, to be set as the new bats. |
---|
| 132 | */ |
---|
| 133 | void JumpItem::setFigure(WeakPtr<JumpFigure> newFigure) |
---|
| 134 | { |
---|
| 135 | figure_ = newFigure; |
---|
| 136 | } |
---|
| 137 | |
---|
| 138 | void JumpItem::touchFigure() |
---|
| 139 | { |
---|
| 140 | |
---|
| 141 | } |
---|
| 142 | } |
---|