Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 8, 2005, 1:10:27 AM (19 years ago)
Author:
manuel
Message:

merge: factory has now create from class name string function (svn merge -r 5955:HEAD ../trunk/ powerups/)

Location:
branches/powerups/src/world_entities/space_ships
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/powerups/src/world_entities/space_ships/space_ship.cc

    r5973 r5985  
    3131#include "factory.h"
    3232#include "key_mapper.h"
     33#include "event_handler.h"
    3334
    3435#include "power_ups/weapon_power_up.h"
     36
     37#include "graphics_engine.h"
    3538
    3639using namespace std;
     
    8891  Weapon* wpLeft = new TestGun(1);
    8992  wpLeft->setName("testGun Left");
    90   Weapon* cannon = dynamic_cast<Weapon*>(Factory::getFirst()->fabricate(CL_CANNON));
     93  Weapon* cannon = dynamic_cast<Weapon*>(Factory::fabricate(CL_CANNON));
    9194
    9295  cannon->setName("BFG");
     
    112115  PRINTF(4)("SPACESHIP INIT\n");
    113116
    114 
    115   bUp = bDown = bLeft = bRight = bAscend = bDescend = false;
     117  EventHandler::getInstance()->grabEvents(true);
     118
     119  bUp = bDown = bLeft = bRight = bAscend = bDescend = bRollL = bRollR = false;
    116120  bFire = false;
     121  xMouse = yMouse = 0;
     122  mouseSensitivity = 0.001;
     123
     124  cycle = 0.0;
     125
    117126
    118127  travelSpeed = 15.0;
     
    126135
    127136  //add events to the eventlist
    128   registerEvent(KeyMapper::PEV_UP);
    129   registerEvent(KeyMapper::PEV_DOWN);
    130   registerEvent(KeyMapper::PEV_LEFT);
    131   registerEvent(KeyMapper::PEV_RIGHT);
     137  registerEvent(SDLK_w);
     138  registerEvent(SDLK_s);
     139  registerEvent(SDLK_a);
     140  registerEvent(SDLK_d);
     141  registerEvent(SDLK_q);
     142  registerEvent(SDLK_e);
    132143  registerEvent(KeyMapper::PEV_FIRE1);
    133144  registerEvent(KeyMapper::PEV_NEXT_WEAPON);
     
    135146  registerEvent(SDLK_PAGEUP);
    136147  registerEvent(SDLK_PAGEDOWN);
     148  registerEvent(EV_MOUSE_MOTION);
    137149
    138150  this->getWeaponManager()->setSlotCount(7);
     
    255267void SpaceShip::tick (float time)
    256268{
     269     cycle += time;
    257270  // spaceship controlled movement
    258271  this->calculateVelocity(time);
     
    261274
    262275  //orient the spaceship model in the direction of movement.
     276
     277  // this is the air friction (necessary for a smooth control)
     278  if(velocity.len() != 0) velocity -= velocity*0.01;
     279
     280  this->shiftCoor(Vector(0,1,0)*cos(this->cycle*2.0)*0.02);
     281
     282  //SDL_WarpMouse(GraphicsEngine::getInstance()->getResolutionX()/2, GraphicsEngine::getInstance()->getResolutionY()/2);
    263283
    264284  this->shiftCoor (move);
     
    283303  if( this->bUp )
    284304   {
    285      this->shiftCoor(this->getAbsDirX());
    286       //if(travelSpeed <= 5000)  travelSpeed += 10;
     305     //this->shiftCoor(this->getAbsDirX());
     306      accel += (this->getAbsDirX())*2;
    287307   }
    288308
    289309  if( this->bDown )
    290310   {
    291      this->shiftCoor(Vector()-this->getAbsDirX());
    292      //if(travelSpeed >= 10) travelSpeed -= 10;
     311     //this->shiftCoor((this->getAbsDirX())*-1);
     312     accel -= (this->getAbsDirX())*2;
    293313   }
    294314
     
    310330    //rotVal += .4;
    311331  }
     332
     333  if( this->bRollL /* > -this->getRelCoor().z*2*/)
     334  {
     335    this->shiftDir(Quaternion(-time, Vector(1,0,0)));
     336//    accel -= rightDirection;
     337    //velocityDir.normalize();
     338    //rot +=Vector(1,0,0);
     339    //rotVal -= .4;
     340  }
     341  if( this->bRollR /* > this->getRelCoor().z*2*/)
     342  {
     343    this->shiftDir(Quaternion(time, Vector(1,0,0)));
     344
     345    //    accel += rightDirection;
     346    //velocityDir.normalize();
     347    //rot += Vector(1,0,0);
     348    //rotVal += .4;
     349  }
    312350  if (this->bAscend )
    313351  {
     
    329367  }
    330368
    331   velocity += accel*(time);
     369  velocity += accel;
    332370  //rot.normalize();
    333371  //this->setRelDirSoft(Quaternion(rotVal, rot), 5);
     
    350388void SpaceShip::process(const Event &event)
    351389{
    352   if( event.type == KeyMapper::PEV_UP)
    353       this->bUp = event.bPressed;
    354   else if( event.type == KeyMapper::PEV_DOWN)
    355       this->bDown = event.bPressed;
    356   else if( event.type == KeyMapper::PEV_RIGHT)
    357       this->bRight= event.bPressed;
    358   else if( event.type == KeyMapper::PEV_LEFT)
    359       this->bLeft = event.bPressed;
     390
     391
     392  if( event.type == SDLK_a)
     393      this->bRollL = event.bPressed;
     394  else if( event.type == SDLK_d)
     395      this->bRollR = event.bPressed;
    360396  else if( event.type == KeyMapper::PEV_FIRE1)
    361397      this->bFire = event.bPressed;
     
    365401    this->getWeaponManager()->previousWeaponConfig();
    366402
    367   else if( event.type == SDLK_PAGEUP)
    368     this->bAscend = event.bPressed; //this->shiftCoor(0,.1,0);
    369   else if( event.type == SDLK_PAGEDOWN)
    370     this->bDescend = event.bPressed; //this->shiftCoor(0,-.1,0);
     403  else if( event.type == SDLK_w)
     404    this->bUp = event.bPressed; //this->shiftCoor(0,.1,0);
     405  else if( event.type == SDLK_s)
     406    this->bDown = event.bPressed; //this->shiftCoor(0,-.1,0);
     407  else if( event.type == EV_MOUSE_MOTION)
     408  {
     409    this->xMouse = event.xRel;
     410    this->yMouse = event.yRel;
     411    this->shiftDir(Quaternion(-M_PI/4*xMouse*mouseSensitivity, Vector(0,1,0))*Quaternion(-M_PI/4*yMouse*mouseSensitivity, Vector(0,0,1)));
     412  }
    371413}
    372414
  • branches/powerups/src/world_entities/space_ships/space_ship.h

    r5965 r5985  
    5858    bool                  bDescend;           //!< descend button presses.
    5959    bool                  bFire;              //!< fire button pressed.
     60    bool                  bRollL;             //!< rolling button pressed (left)
     61    bool                  bRollR;             //!< rolling button pressed (right)
     62   
     63    float                 xMouse;             //!< mouse moved in x-Direction
     64    float                 yMouse;             //!< mouse moved in y-Direction
     65    float                 mouseSensitivity;   //!< the mouse sensitivity
     66    float                 cycle;              //!< hovercycle
    6067
    6168    Vector                velocity;           //!< the velocity of the player.
Note: See TracChangeset for help on using the changeset viewer.