#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) { GameEntityType other_type = (GameEntityType) entity_state->mType; if (other_type == GameEntityTypeRocket) { // First remove the rocket Engine::KillEntity (entity_state->mId); Engine::LogMessage ("You killed an Asteroid!"); int i; for (i = 0; i < mSubAsteroidsCount; i++) { AsteroidEntity *asteroid = (AsteroidEntity*) Engine::CreateEntity (GameEntityTypeAsteroid); 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; asteroid->mSubAsteroidsCount = 0; asteroid->mPhysicState->mRadius = 2. * mPhysicState->mRadius / mSubAsteroidsCount; static_cast(asteroid->mPhysicState->mShape)->setRadius (asteroid->mPhysicState->mRadius); } Engine::KillEntity (mId); return true; } else if (other_type == GameEntityTypeRocket) { return false; } return false; } }