1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- #include "game.h"
- #include "droidobject.h"
- #include "droidworld.h"
- DroidObject::DroidObject(DroidWorld *dw, eDROIDOBJECTTYPE t )
- {
- type = t;
- mass = 1.0f;
- drawSize = 128.0f;
- angle = (float)(rand() & 255)/255.0f * 360.0f;
- angleInc = ((float)(rand() & 255) / 255.0f - 0.5f)*360.0f;
- switch (type) {
- case eASTEROID:
- default:
- angleInc = 40.0f;
- drawSize = 64.0f;
- position = QVector3D( ((rand() & 255)/255.0f - 0.5f)*2.0f, ((rand() & 255)/255.0f - 0.5f)*2.0f, 0.0f );
- break;
- case ePLANET:
- mass = 4.0f;
- position = QVector3D(0,0,0);
- break;
- }
- world = dw;
- alive = true;
- }
- DroidObject::~DroidObject()
- {
- }
- void DroidObject::run( float secsPassed ) {
- angle+=angleInc*secsPassed;
- if (type==ePLANET) {
- position = QVector3D(0,0,0);
- direction = QVector3D(0,0,0);
- return; // down move
- }
- // run here.
- QVector3D t = direction * secsPassed;
- position += t;
- // slowdown
- }
- void DroidObject::draw()
- {
- world->setMyTransform( this );
- switch (type) {
- case ePLANET:
- vgDrawImage(world->imageBall);
- break;
- case eASTEROID:
- vgDrawImage(world->imageAsteroid);
- break;
- }
- }
|