droidobject.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #include "game.h"
  2. #include "droidobject.h"
  3. #include "droidworld.h"
  4. DroidObject::DroidObject(DroidWorld *dw, eDROIDOBJECTTYPE t )
  5. {
  6. type = t;
  7. mass = 1.0f;
  8. drawSize = 128.0f;
  9. angle = (float)(rand() & 255)/255.0f * 360.0f;
  10. angleInc = ((float)(rand() & 255) / 255.0f - 0.5f)*360.0f;
  11. switch (type) {
  12. case eASTEROID:
  13. default:
  14. angleInc = 40.0f;
  15. drawSize = 64.0f;
  16. position = QVector3D( ((rand() & 255)/255.0f - 0.5f)*2.0f, ((rand() & 255)/255.0f - 0.5f)*2.0f, 0.0f );
  17. break;
  18. case ePLANET:
  19. mass = 4.0f;
  20. position = QVector3D(0,0,0);
  21. break;
  22. }
  23. world = dw;
  24. alive = true;
  25. }
  26. DroidObject::~DroidObject()
  27. {
  28. }
  29. void DroidObject::run( float secsPassed ) {
  30. angle+=angleInc*secsPassed;
  31. if (type==ePLANET) {
  32. position = QVector3D(0,0,0);
  33. direction = QVector3D(0,0,0);
  34. return; // down move
  35. }
  36. // run here.
  37. QVector3D t = direction * secsPassed;
  38. position += t;
  39. // slowdown
  40. }
  41. void DroidObject::draw()
  42. {
  43. world->setMyTransform( this );
  44. switch (type) {
  45. case ePLANET:
  46. vgDrawImage(world->imageBall);
  47. break;
  48. case eASTEROID:
  49. vgDrawImage(world->imageAsteroid);
  50. break;
  51. }
  52. }