Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 7, 2005, 3:45:26 PM (18 years ago)
Author:
manuel
Message:

many changes:
created generic weapon_power_up that can contain any kind of weapon
space_ship is now extendable and can pickup weapon_power_ups

File:
1 copied

Legend:

Unmodified
Added
Removed
  • branches/powerups/src/world_entities/power_ups/weapon_power_up.cc

    r5958 r5965  
    1616#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY
    1717
    18 #include "laser_power_up.h"
     18#include "weapon_power_up.h"
    1919#include "factory.h"
    2020#include "state.h"
     
    2525using namespace std;
    2626
    27 CREATE_FACTORY(LaserPowerUp, CL_LASER_POWER_UP);
     27CREATE_FACTORY(WeaponPowerUp, CL_WEAPON_POWER_UP);
    2828
    29 LaserPowerUp::LaserPowerUp ()
     29WeaponPowerUp::WeaponPowerUp ()
    3030{
    3131  this->init();
    3232}
    3333
    34 LaserPowerUp::LaserPowerUp(const TiXmlElement* root)
     34WeaponPowerUp::WeaponPowerUp(const TiXmlElement* root)
    3535{
    3636  this->init();
    37 
    3837  this->loadParams(root);
    3938}
    4039
    4140
    42 LaserPowerUp::~LaserPowerUp ()
     41WeaponPowerUp::~WeaponPowerUp ()
    4342{
    44   delete this->sphereModel;
    45   delete this->sphereMaterial;
    4643}
    4744
    4845
    49 void LaserPowerUp::init()
     46void WeaponPowerUp::init()
    5047{
    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));
    6248}
    6349
    6450
    65 void LaserPowerUp::loadParams(const TiXmlElement* root)
     51void WeaponPowerUp::loadParams(const TiXmlElement* root)
    6652{
    6753  static_cast<PowerUp*>(this)->loadParams(root);
     
    6955}
    7056
    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)
     57Weapon* WeaponPowerUp::getWeapon()
    7958{
    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()));
    8360}
    8461
    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)
     62ClassID WeaponPowerUp::getWeaponID()
    9263{
    93   this->shiftDir(Quaternion(dt, this->rotation));
    94   this->cycle+=dt;
    95 
     64  return this->weaponID;
    9665}
    9766
    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();
     67long WeaponPowerUp::getCapsNeeded()
     68{
     69  return this->capsNeeded;
    11970}
    120 
Note: See TracChangeset for help on using the changeset viewer.