Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Added new models and fixed dammage bug. Bomb now fully working.

File size: 2.5 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
[10435]14        const float GravityBomb::LIFETIME = 5;
15
[10336]16        GravityBomb::GravityBomb(Context* context):
[10341]17                                BasicProjectile(),
18                                MovableEntity(context),
19                                RadarViewable(this,static_cast<WorldEntity*>(this))
[10336]20                {
21                        RegisterObject(GravityBomb);
22
[10391]23                        this->setMass(10.0);
24                        this->isDetonated_ = false;
[10341]25                        if (GameMode::isMaster())
26                        {
[10369]27                                //Define CollisionType of the bomb
[10435]28                                this->timeToLife_= LIFETIME;
[10369]29                                this->setCollisionResponse(false);
[10391]30                                this->setCollisionType(WorldEntity::Dynamic);
[10341]31                                this->enableCollisionCallback();
[10336]32
[10341]33                                //Add Collision Shape
34                                SphereCollisionShape* collisionShape = new SphereCollisionShape(context);
[10369]35                                collisionShape->setRadius(1.0);
[10341]36                                this->attachCollisionShape(collisionShape);
37
38                                //Create Bomb Model
[10435]39                    Model* rocketModel = new Model(this->getContext());
40                    rocketModel->setMeshSource("GravityBombRocket.mesh"); //Demo Model from SimpleRocket
41                    rocketModel->scale(3.0f);
42                    this->attach(rocketModel);
[10341]43
[10435]44                    Model* bombModel =  new Model(this->getContext());
45                    bombModel->setMeshSource("GravityBomb.mesh"); //Demo Model from SimpleRocket
46                                bombModel->scale(3.0f);
47                                this->attach(bombModel);
48
[10341]49                        }
[10336]50                }
51
52        GravityBomb::~GravityBomb(){}
53
54        void GravityBomb::tick(float dt)
55        {
[10369]56                        SUPER(GravityBomb,tick,dt);
[10391]57                        timeToLife_ -= dt;
58                        if(timeToLife_ < 0)
[10341]59                        {
[10369]60                                orxout(debug_output) << "bomb has stoped moving" <<endl;
[10341]61                                setVelocity(Vector3::ZERO);
62                                setAcceleration(Vector3::ZERO);
63                                detonate();
64                        }
[10369]65                        else
66                        {
[10391]67                                orxout(debug_output)<< "Time to live:" << timeToLife_ <<endl;
[10369]68                                destroyCheck();
69                        }
[10391]70                        if(isDetonated_) detonate();
[10336]71        }
72
73        bool GravityBomb::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* cs, btManifoldPoint& contactPoint)
74        {
[10391]75                if(otherObject != getShooter())
76                {
77                        orxout(debug_output) << "collides" << endl;
78                        processCollision(otherObject, contactPoint,cs);
79                        isDetonated_ = true;
80                        return true;
81                }
82                else{
83                        orxout(debug_output) << "collided with shooter. Has no effect..." << endl;
84                        return false;
85                }
[10336]86        }
[10341]87
88        void GravityBomb::detonate()
89        {
90                GravityBombField* field = new GravityBombField(this->getContext());
[10435]91                field->setShooter(this->getShooter());
[10391]92                field->setPosition(getPosition());
93                orxout(debug_output) << "detonating. Creating GravityBombField." <<endl;
94                orxout(debug_output) << "Field is at Position: " << getPosition() << endl;
[10369]95                this->destroy();
[10341]96        }
[10336]97}
98
99
Note: See TracBrowser for help on using the repository browser.