Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

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

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