Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/weaponFS15/src/modules/weapons/projectiles/GravityBomb.cc @ 10391

Last change on this file since 10391 was 10391, checked in by meggiman, 9 years ago

Implemented all necessary classes. No the weapon works without bugs.

File size: 2.2 KB
Line 
1/*
2 * GravityBomb.cc
3 *
4 *  Created on: Mar 26, 2015
5 *      Author: meggiman
6 */
7#include "GravityBomb.h"
8#include "graphics/Model.h"
9
10
11namespace orxonox{
12        RegisterClass(GravityBomb);
13
14        GravityBomb::GravityBomb(Context* context):
15                                BasicProjectile(),
16                                MovableEntity(context),
17                                RadarViewable(this,static_cast<WorldEntity*>(this))
18                {
19                        RegisterObject(GravityBomb);
20
21                        this->setMass(10.0);
22                        this->isDetonated_ = false;
23                        if (GameMode::isMaster())
24                        {
25                                //Define CollisionType of the bomb
26                                this->timeToLife_= 5;
27                                this->setCollisionResponse(false);
28                                this->setCollisionType(WorldEntity::Dynamic);
29                                this->enableCollisionCallback();
30
31                                //Add Collision Shape
32                                SphereCollisionShape* collisionShape = new SphereCollisionShape(context);
33                                collisionShape->setRadius(1.0);
34                                this->attachCollisionShape(collisionShape);
35
36                                //Create Bomb Model
37                    Model* model = new Model(this->getContext());
38                    model->setMeshSource("rocket.mesh"); //Demo Model from SimpleRocket
39                    model->scale(0.7f);
40                    this->attach(model);
41
42                        }
43                }
44
45        GravityBomb::~GravityBomb(){}
46
47        void GravityBomb::tick(float dt)
48        {
49                        SUPER(GravityBomb,tick,dt);
50                        timeToLife_ -= dt;
51                        if(timeToLife_ < 0)
52                        {
53                                orxout(debug_output) << "bomb has stoped moving" <<endl;
54                                setVelocity(Vector3::ZERO);
55                                setAcceleration(Vector3::ZERO);
56                                detonate();
57                        }
58                        else
59                        {
60                                orxout(debug_output)<< "Time to live:" << timeToLife_ <<endl;
61                                destroyCheck();
62                        }
63                        if(isDetonated_) detonate();
64        }
65
66        bool GravityBomb::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* cs, btManifoldPoint& contactPoint)
67        {
68                if(otherObject != getShooter())
69                {
70                        orxout(debug_output) << "collides" << endl;
71                        processCollision(otherObject, contactPoint,cs);
72                        isDetonated_ = true;
73                        return true;
74                }
75                else{
76                        orxout(debug_output) << "collided with shooter. Has no effect..." << endl;
77                        return false;
78                }
79        }
80
81        void GravityBomb::detonate()
82        {
83                GravityBombField* field = new GravityBombField(this->getContext());
84                field->setPosition(getPosition());
85                orxout(debug_output) << "detonating. Creating GravityBombField." <<endl;
86                orxout(debug_output) << "Field is at Position: " << getPosition() << endl;
87                this->destroy();
88        }
89}
90
91
Note: See TracBrowser for help on using the repository browser.