Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/modules/jump/JumpEnemy.cc @ 10763

Last change on this file since 10763 was 10624, checked in by landauf, 9 years ago

merged branch core7 back to trunk

  • Property svn:eol-style set to native
File size: 4.6 KB
RevLine 
[10078]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 *      Fabien Vultier
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29/**
30    @file JumpEnemy.cc
31    @brief All enemies in the minigame inherit from this class. This class manages the movement of all enemies and allows enemies to touch the figure to kill it.
32*/
33
34#include "JumpEnemy.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
46namespace orxonox
47{
48    RegisterClass(JumpEnemy);
49
50    /**
51    @brief
52        Constructor. Registers and initializes the object.
53    */
54    JumpEnemy::JumpEnemy(Context* context) : MovableEntity(context)
55    {
56        RegisterObject(JumpEnemy);
57
58        dead_ = false;
59        figure_ = 0;
60        width_ = 0.0;
61        height_ = 0.0;
62        setPosition(Vector3(0,0,0));
63        setVelocity(Vector3(0,0,0));
64        setAcceleration(Vector3(0,0,0));
65        setProperties(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
66    }
67
68    /**
69    @brief
70        Destructor.
71    */
72    JumpEnemy::~JumpEnemy()
73    {
74        /*if (this->isInitialized())
75        {
76            if (this->bDeleteBats_)
77                delete this->figure_;
78
79            delete[] this->batID_;
80        }*/
81    }
82
83    //xml port for loading sounds
84    void JumpEnemy::XMLPort(Element& xmlelement, XMLPort::Mode mode)
85    {
86        SUPER(JumpEnemy, XMLPort, xmlelement, mode);
87
88        XMLPortParam(JumpEnemy, "height", setHeight, getHeight, xmlelement, mode);
89        XMLPortParam(JumpEnemy, "width", setWidth, getWidth, xmlelement, mode);
90    }
91
92    /**
93    @brief
94        Is called every tick.
95        Handles the movement of the ball and its interaction with the boundaries and bats.
96    @param dt
97        The time since the last tick.
98    */
99    void JumpEnemy::tick(float dt)
100    {
101        SUPER(JumpEnemy, tick, dt);
102
103        // Get the current position, velocity and acceleration of the enemy.
104        Vector3 position = getPosition();
105        Vector3 velocity = getVelocity();
106
107        if ((position.x < leftBoundary_ && velocity.x < 0) || (position.x > rightBoundary_ && velocity.x > 0))
108        {
[10215]109            velocity.x = -velocity.x;
[10078]110        }
111
112        if ((position.z < lowerBoundary_ && velocity.z < 0) || (position.z > upperBoundary_ && velocity.z > 0))
113        {
[10215]114            velocity.z = -velocity.z;
[10078]115        }
116
117        // Set the position, velocity and acceleration of the enemy, if they have changed.
118        if (velocity != getVelocity())
119            setVelocity(velocity);
120        if (position != getPosition())
121            setPosition(position);
122
123
124        // Interact with Figure
125        Vector3 enemyPosition = getPosition();
126
127        if (figure_ != NULL)
128        {
129            Vector3 figurePosition = figure_->getPosition();
130            if(figurePosition.x > enemyPosition.x-width_ && figurePosition.x < enemyPosition.x+width_ && figurePosition.z > enemyPosition.z-height_ && figurePosition.z < enemyPosition.z+height_)
131            {
[10215]132                touchFigure();
[10078]133            }
134        }
135    }
136
137    void JumpEnemy::setProperties(float newLeftBoundary, float newRightBoundary, float newLowerBoundary, float newUpperBoundary, float newHSpeed, float newVSpeed)
138    {
139        leftBoundary_ = newLeftBoundary;
140        rightBoundary_ = newRightBoundary;
141        lowerBoundary_ = newLowerBoundary;
142        upperBoundary_ = newUpperBoundary;
143
144        this->setVelocity(Vector3(newHSpeed,0,newVSpeed));
145    }
146
147    /**
148    @brief
149        Set the bats for the ball.
150    @param bats
151        An array (of size 2) of weak pointers, to be set as the new bats.
152    */
[10624]153    void JumpEnemy::setFigure(JumpFigure* newFigure)
[10078]154    {
155        figure_ = newFigure;
156    }
157
158    void JumpEnemy::touchFigure()
159    {
[10215]160        if (dead_ == false)
161        {
162            figure_->CollisionWithEnemy(this);
163        }
[10078]164    }
165}
Note: See TracBrowser for help on using the repository browser.