#include "Powerups.h" #include "WorldManager.h" void InitPowerup(VPowerup * p) { InitObject(&p->Object); p->Type = POWERUPTYPENONE; p->Amount = 0; p->taggedForRemoval = 0; } void CleanUpPowerup(VPowerup * p) { CleanUpObject(&p->Object); } void SetupPowerup(VPowerup * p, int type, int amount) { p->Type = type; switch (type) { case POWERUPTYPEROCKETS: p->Amount = amount; BuildRocketPowerupModel(&p->Object.Model); CalculateRadius(&p->Object); p->Object.Front.x = 0.0; p->Object.Front.y = 1.0; p->Object.Front.z = 0.0; p->Object.Right.x = 1.0; p->Object.Right.y = 0.0; p->Object.Right.z = 0.0; p->Object.Up.x = 0.0; p->Object.Up.y = 0.0; p->Object.Up.z = -1.0; break; case POWERUPTYPEHEALTH: p->Amount = amount; BuildHealthPowerupModel(&p->Object.Model); CalculateRadius(&p->Object); break; } } void RunPowerup(VPowerup * p, float interval, void * w) { VWorld * world; Quaternion quat; Vector axis = {0.0, 1.0, 0.0}; world = (VWorld *) w; if (world != NULL && fabs(((world->Camera.Position.x - p->Object.Position.x) * (world->Camera.Position.x - p->Object.Position.x)) + ((world->Camera.Position.y - p->Object.Position.y) * (world->Camera.Position.y - p->Object.Position.y)) + ((world->Camera.Position.z - p->Object.Position.z) * (world->Camera.Position.z - p->Object.Position.z))) <= (PLAYERSHIPRADIUS + p->Object.Radius)) { p->taggedForRemoval = true; switch (p->Type) { case POWERUPTYPEROCKETS: world->Player.NumRockets += p->Amount; if (world->Player.NumRockets > MAXROCKETS) world->Player.NumRockets = MAXROCKETS; break; case POWERUPTYPEHEALTH: world->Player.Shields += p->Amount; if (world->Player.Shields > MAXSHIELDS) world->Player.Shields = MAXSHIELDS; break; } return; } QuaternionRotateVector(POWERUPROTATESPEED, interval, &axis, &p->Object.Right, &quat); p->Object.Right.x = quat.v.x; p->Object.Right.y = quat.v.y; p->Object.Right.z = quat.v.z; NormalizeVector(&p->Object.Right); CrossProduct(&p->Object.Right, &p->Object.Up, &p->Object.Front); NormalizeVector(&p->Object.Front); CrossProduct(&p->Object.Front, &p->Object.Right, &p->Object.Up); NormalizeVector(&p->Object.Up); } void DrawPowerup(VPowerup * p) { DrawObject(&p->Object); }