Changeset 5965 in orxonox.OLD for branches/powerups/src/world_entities/power_ups
- Timestamp:
- Dec 7, 2005, 3:45:26 PM (19 years ago)
- Location:
- branches/powerups/src/world_entities/power_ups
- Files:
-
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/powerups/src/world_entities/power_ups/weapon_power_up.cc
r5958 r5965 16 16 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY 17 17 18 #include " laser_power_up.h"18 #include "weapon_power_up.h" 19 19 #include "factory.h" 20 20 #include "state.h" … … 25 25 using namespace std; 26 26 27 CREATE_FACTORY( LaserPowerUp, CL_LASER_POWER_UP);27 CREATE_FACTORY(WeaponPowerUp, CL_WEAPON_POWER_UP); 28 28 29 LaserPowerUp::LaserPowerUp ()29 WeaponPowerUp::WeaponPowerUp () 30 30 { 31 31 this->init(); 32 32 } 33 33 34 LaserPowerUp::LaserPowerUp(const TiXmlElement* root)34 WeaponPowerUp::WeaponPowerUp(const TiXmlElement* root) 35 35 { 36 36 this->init(); 37 38 37 this->loadParams(root); 39 38 } 40 39 41 40 42 LaserPowerUp::~LaserPowerUp ()41 WeaponPowerUp::~WeaponPowerUp () 43 42 { 44 delete this->sphereModel;45 delete this->sphereMaterial;46 43 } 47 44 48 45 49 void LaserPowerUp::init()46 void WeaponPowerUp::init() 50 47 { 51 this->setClassID(CL_LASER_POWER_UP, "LaserPowerUp");52 this->loadModel("models/guns/test_gun.obj", 2.0);53 54 this->sphereModel = new PrimitiveModel(PRIM_SPHERE, 7, 5);55 this->sphereMaterial = new Material;56 this->sphereMaterial->setTransparency(.1);57 this->sphereMaterial->setDiffuse(.7, .7, .1);58 59 this->rotation = Vector(0,1,0);60 this->cycle = (float)rand()/RAND_MAX*M_2_PI;61 this->shiftDir(Quaternion((float)rand()/RAND_MAX*M_2_PI, this->rotation));62 48 } 63 49 64 50 65 void LaserPowerUp::loadParams(const TiXmlElement* root)51 void WeaponPowerUp::loadParams(const TiXmlElement* root) 66 52 { 67 53 static_cast<PowerUp*>(this)->loadParams(root); … … 69 55 } 70 56 71 72 /** 73 * this function is called, when two entities collide 74 * @param entity: the world entity with whom it collides 75 * 76 * Implement behaviour like damage application or other miscellaneous collision stuff in this function 77 */ 78 void LaserPowerUp::collidesWith(WorldEntity* entity, const Vector& location) 57 Weapon* WeaponPowerUp::getWeapon() 79 58 { 80 // PRINTF(3)("collision %s vs %s @ (%f,%f,%f)\n", this->getClassName(), entity->getClassName(), location.x, location.y, location.z); 81 if (entity->isA(CL_PLAYABLE)) 82 State::getWorldEntityList()->remove(this); 59 return dynamic_cast<Weapon*>(Factory::getFirst()->fabricate(this->getWeaponID())); 83 60 } 84 61 85 /** 86 * this method is called every frame 87 * @param time: the time in seconds that has passed since the last tick 88 * 89 * Handle all stuff that should update with time inside this method (movement, animation, etc.) 90 */ 91 void LaserPowerUp::tick(float dt) 62 ClassID WeaponPowerUp::getWeaponID() 92 63 { 93 this->shiftDir(Quaternion(dt, this->rotation)); 94 this->cycle+=dt; 95 64 return this->weaponID; 96 65 } 97 66 98 /** 99 * the entity is drawn onto the screen with this function 100 * 101 * This is a central function of an entity: call it to let the entity painted to the screen. 102 * Just override this function with whatever you want to be drawn. 103 */ 104 void LaserPowerUp::draw() const 105 { glMatrixMode(GL_MODELVIEW); 106 glPushMatrix(); 107 /* translate */ 108 glTranslatef (this->getAbsCoor ().x, 109 this->getAbsCoor ().y + cos(this->cycle*3.0)*2.0, 110 this->getAbsCoor ().z); 111 /* rotate */ 112 Vector tmpRot = this->getAbsDir().getSpacialAxis(); 113 glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); 114 this->model->draw(); 115 116 this->sphereMaterial->select(); 117 this->sphereModel->draw(); 118 glPopMatrix(); 67 long WeaponPowerUp::getCapsNeeded() 68 { 69 return this->capsNeeded; 119 70 } 120 -
branches/powerups/src/world_entities/power_ups/weapon_power_up.h
r5958 r5965 1 1 /*! 2 * @file laser_power_up.h3 * @brief A class representing a PowerUp in the world.2 * @file weapon_power_up.h 3 * @brief A class representing a PowerUp containing a weapon. 4 4 */ 5 5 6 #ifndef _ LASER_POWER_UP_H7 #define _ LASER_POWER_UP_H6 #ifndef _WEAPON_POWER_UP_H 7 #define _WEAPON_POWER_UP_H 8 8 9 9 #include "power_up.h" 10 #include "weapons/weapon.h" 10 11 11 12 /* FORWARD DEFINITION */ 12 class Material;13 13 14 class LaserPowerUp : public PowerUp {14 class WeaponPowerUp : public PowerUp { 15 15 16 17 LaserPowerUp();18 LaserPowerUp(const TiXmlElement* root);19 virtual ~ LaserPowerUp ();16 public: 17 WeaponPowerUp(); 18 WeaponPowerUp(const TiXmlElement* root); 19 virtual ~WeaponPowerUp (); 20 20 21 virtual void LaserPowerUp::collidesWith(WorldEntity* entity, const Vector& location);22 virtual void tick(float dt);23 virtual void draw() const;21 Weapon* getWeapon(); 22 ClassID getWeaponID(); 23 long getCapsNeeded(); 24 24 25 26 27 25 private: 26 void init(); 27 void loadParams(const TiXmlElement* root); 28 28 29 private: 30 Vector rotation; 31 float cycle; 32 33 Model* sphereModel; 34 Material* sphereMaterial; 29 private: 30 ClassID weaponID; 31 long capsNeeded; 35 32 }; 36 33 37 #endif /* _ LASER_POWER_UP_H */34 #endif /* _WEAPON_POWER_UP_H */
Note: See TracChangeset
for help on using the changeset viewer.