fysxasteroids/asteroids/AsteroidEntity.cc

48 lines
1.4 KiB
C++
Raw Normal View History

2010-04-05 23:38:59 +02:00
#include "Engine.h"
#include "ModelBase.h"
#include "AsteroidEntity.h"
#include "Controller.h"
#include "Model.h"
#include "EntityBase.h"
#include "coll2d.h"
namespace asteroids {
bool AsteroidEntity::CollisionEvent (Engine::EntityBase* entity_state, vector3d point, vector3d normal) {
2010-04-05 23:38:59 +02:00
GameEntityType other_type = (GameEntityType) entity_state->mType;
if (other_type == GameEntityTypeRocket) {
// First remove the rocket
Engine::KillEntity (entity_state->mId);
2010-04-08 20:04:39 +02:00
Engine::LogMessage ("You killed an Asteroid!");
2010-04-05 23:38:59 +02:00
int i;
for (i = 0; i < mSubAsteroidsCount; i++) {
AsteroidEntity *asteroid = (AsteroidEntity*) Engine::CreateEntity (GameEntityTypeAsteroid);
2010-04-05 23:38:59 +02:00
vector3d position (rand()/float(RAND_MAX) * 1. - 0.5, 0., rand()/float(RAND_MAX) * 1. - 0.5);
asteroid->mPhysicState->mPosition = mPhysicState->mPosition + position;
asteroid->mPhysicState->mVelocity = position + mPhysicState->mVelocity * 0.5;
asteroid->mPhysicState->mAngleVelocity = mPhysicState->mAngleVelocity + (rand()/float(RAND_MAX) * 2. - 1) * mPhysicState->mAngleVelocity;
2010-04-05 23:38:59 +02:00
asteroid->mSubAsteroidsCount = 0;
asteroid->mPhysicState->mRadius = 2. * mPhysicState->mRadius / mSubAsteroidsCount;
static_cast<coll2d::Sphere*>(asteroid->mPhysicState->mShape)->setRadius (asteroid->mPhysicState->mRadius);
}
Engine::KillEntity (mId);
return true;
} else if (other_type == GameEntityTypeRocket) {
return false;
}
return false;
}
}