Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/BigShip_HS16/src/modules/invader/InvaderEnemyShooter.cc @ 11370

Last change on this file since 11370 was 11083, checked in by muemart, 9 years ago

Fix some clang-tidy warnings.
Also, Serialise.h was doing some C-style casts that ended up being const casts. I moved those const casts as close to the source as possible and changed the loadAndIncrease functions to not do that.

  • Property svn:eol-style set to native
File size: 2.6 KB
Line 
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 *      Florian Zinggeler
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29/**
30    @file InvaderEnemyShooter.h
31    @brief Declaration of the InvaderEnemyShooter class.
32*/
33
34#include "InvaderEnemyShooter.h"
35
36#include "core/CoreIncludes.h"
37#include "core/command/Executor.h"
38#include "Invader.h"
39#include "InvaderShip.h"
40
41namespace orxonox
42{
43    RegisterClass(InvaderEnemyShooter);
44
45    InvaderEnemyShooter::InvaderEnemyShooter(Context* context) : InvaderEnemy(context)
46    {
47        RegisterObject(InvaderEnemyShooter);
48        enableCollisionCallback();
49        lifetime = 0;
50        // shoot every second
51        shootTimer.setTimer(1.0f, true, createExecutor(createFunctor(&InvaderEnemyShooter::shoot, this)));
52    }
53
54    void InvaderEnemyShooter::tick(float dt)
55    {
56        lifetime += dt;
57        // die after 20 seconds.
58        if (lifetime > 20000)
59            removeHealth(2000);
60
61        if (player != nullptr)
62        {
63            float distPlayer = player->getPosition().z - getPosition().z;
64            // orxout() << "i'm different!" << endl;
65            float newZ = 2/(pow(std::abs(getPosition().x - player->getPosition().x) * 0.01f, 2) + 1) * distPlayer;
66            setVelocity(Vector3(950 - std::abs(distPlayer), 0, newZ));
67        }
68        Pawn::tick(dt);
69    }
70
71    void InvaderEnemyShooter::shoot()
72    {
73        ControllableEntity::fire(0);
74    }
75
76    void InvaderEnemyShooter::damage(float damage, float healthdamage, float shielddamage, Pawn* originator, const btCollisionShape* cs)
77    {
78        Pawn::damage(damage, healthdamage, shielddamage, originator, cs);
79        if (getGame() && orxonox_cast<InvaderShip*>(originator) != nullptr && getHealth() <= 0)
80            getGame()->addPoints(3*42);
81    }
82}
Note: See TracBrowser for help on using the repository browser.