12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300 |
- /*
- ===========================================================================
- Doom 3 GPL Source Code
- Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
- This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
- Doom 3 Source Code is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- Doom 3 Source Code is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
- In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
- If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
- ===========================================================================
- */
- #include "../idlib/precompiled.h"
- #pragma hdrstop
- #include "../framework/Session_local.h"
- #include "DeviceContext.h"
- #include "Window.h"
- #include "UserInterfaceLocal.h"
- #include "GameSSDWindow.h"
- #define Z_NEAR 100.0f
- #define Z_FAR 4000.0f
- #define ENTITY_START_DIST 3000
- #define V_WIDTH 640.0f
- #define V_HEIGHT 480.0f
- /*
- *****************************************************************************
- * SSDCrossHair
- ****************************************************************************
- */
- #define CROSSHAIR_STANDARD_MATERIAL "game/SSD/crosshair_standard"
- #define CROSSHAIR_SUPER_MATERIAL "game/SSD/crosshair_super"
- SSDCrossHair::SSDCrossHair() {
- }
- SSDCrossHair::~SSDCrossHair() {
- }
- void SSDCrossHair::WriteToSaveGame( idFile *savefile ) {
-
- savefile->Write(¤tCrosshair, sizeof(currentCrosshair));
- savefile->Write(&crosshairWidth, sizeof(crosshairWidth));
- savefile->Write(&crosshairHeight, sizeof(crosshairHeight));
- }
- void SSDCrossHair::ReadFromSaveGame( idFile *savefile ) {
- InitCrosshairs();
- savefile->Read(¤tCrosshair, sizeof(currentCrosshair));
- savefile->Read(&crosshairWidth, sizeof(crosshairWidth));
- savefile->Read(&crosshairHeight, sizeof(crosshairHeight));
- }
- void SSDCrossHair::InitCrosshairs() {
-
- crosshairMaterial[CROSSHAIR_STANDARD] = declManager->FindMaterial( CROSSHAIR_STANDARD_MATERIAL );
- crosshairMaterial[CROSSHAIR_SUPER] = declManager->FindMaterial( CROSSHAIR_SUPER_MATERIAL );
- crosshairWidth = 64;
- crosshairHeight = 64;
- currentCrosshair = CROSSHAIR_STANDARD;
- }
- void SSDCrossHair::Draw(idDeviceContext *dc, const idVec2& cursor) {
- float x,y;
- x = cursor.x-(crosshairWidth/2);
- y = cursor.y-(crosshairHeight/2);
- dc->DrawMaterial(x, y, crosshairWidth, crosshairHeight, crosshairMaterial[currentCrosshair], colorWhite, 1.0f, 1.0f);
-
- }
- /*
- *****************************************************************************
- * SSDEntity
- ****************************************************************************
- */
- SSDEntity::SSDEntity() {
- EntityInit();
- }
- SSDEntity::~SSDEntity() {
- }
- void SSDEntity::WriteToSaveGame( idFile *savefile ) {
-
- savefile->Write(&type, sizeof(type));
- game->WriteSaveGameString(materialName, savefile);
- savefile->Write(&position, sizeof(position));
- savefile->Write(&size, sizeof(size));
- savefile->Write(&radius, sizeof(radius));
- savefile->Write(&hitRadius, sizeof(hitRadius));
- savefile->Write(&rotation, sizeof(rotation));
- savefile->Write(&matColor, sizeof(matColor));
-
- game->WriteSaveGameString(text, savefile);
- savefile->Write(&textScale, sizeof(textScale));
- savefile->Write(&foreColor, sizeof(foreColor));
-
- savefile->Write(¤tTime, sizeof(currentTime));
- savefile->Write(&lastUpdate, sizeof(lastUpdate));
- savefile->Write(&elapsed, sizeof(elapsed));
- savefile->Write(&destroyed, sizeof(destroyed));
- savefile->Write(&noHit, sizeof(noHit));
- savefile->Write(&noPlayerDamage, sizeof(noPlayerDamage));
- savefile->Write(&inUse, sizeof(inUse));
- }
- void SSDEntity::ReadFromSaveGame( idFile *savefile, idGameSSDWindow* _game ) {
- savefile->Read(&type, sizeof(type));
- game->ReadSaveGameString(materialName, savefile);
- SetMaterial(materialName);
- savefile->Read(&position, sizeof(position));
- savefile->Read(&size, sizeof(size));
- savefile->Read(&radius, sizeof(radius));
- savefile->Read(&hitRadius, sizeof(hitRadius));
- savefile->Read(&rotation, sizeof(rotation));
- savefile->Read(&matColor, sizeof(matColor));
- game->ReadSaveGameString(text, savefile);
- savefile->Read(&textScale, sizeof(textScale));
- savefile->Read(&foreColor, sizeof(foreColor));
- game = _game;
- savefile->Read(¤tTime, sizeof(currentTime));
- savefile->Read(&lastUpdate, sizeof(lastUpdate));
- savefile->Read(&elapsed, sizeof(elapsed));
- savefile->Read(&destroyed, sizeof(destroyed));
- savefile->Read(&noHit, sizeof(noHit));
- savefile->Read(&noPlayerDamage, sizeof(noPlayerDamage));
- savefile->Read(&inUse, sizeof(inUse));
- }
- void SSDEntity::EntityInit() {
- inUse = false;
- type = SSD_ENTITY_BASE;
-
- materialName = "";
- material = NULL;
- position.Zero();
- size.Zero();
- radius = 0.0f;
- hitRadius = 0.0f;
- rotation = 0.0f;
- currentTime = 0;
- lastUpdate = 0;
- destroyed = false;
- noHit = false;
- noPlayerDamage = false;
- matColor.Set(1, 1, 1, 1);
- text = "";
- textScale = 1.0f;
- foreColor.Set(1, 1, 1, 1);
- }
- void SSDEntity::SetGame(idGameSSDWindow* _game) {
- game = _game;
- }
- void SSDEntity::SetMaterial(const char* name) {
- materialName = name;
- material = declManager->FindMaterial( name );
- material->SetSort( SS_GUI );
- }
- void SSDEntity::SetPosition(const idVec3& _position) {
- position = _position;
- }
- void SSDEntity::SetSize(const idVec2& _size) {
- size = _size;
- }
- void SSDEntity::SetRadius(float _radius, float _hitFactor) {
- radius = _radius;
- hitRadius = _radius*_hitFactor;
- }
- void SSDEntity::SetRotation(float _rotation) {
- rotation = _rotation;
- }
- void SSDEntity::Update() {
- currentTime = game->ssdTime;
- //Is this the first update
- if(lastUpdate == 0) {
- lastUpdate = currentTime;
- return;
- }
- elapsed = currentTime - lastUpdate;
- EntityUpdate();
- lastUpdate = currentTime;
- }
- bool SSDEntity::HitTest(const idVec2& pt) {
- if(noHit) {
- return false;
- }
- idVec3 screenPos = WorldToScreen(position);
- //Scale the radius based on the distance from the player
- float scale = 1.0f -((screenPos.z-Z_NEAR)/(Z_FAR-Z_NEAR));
- float scaledRad = scale*hitRadius;
- //So we can compare against the square of the length between two points
- float scaleRadSqr = scaledRad*scaledRad;
- idVec2 diff = screenPos.ToVec2()-pt;
- float dist = idMath::Fabs(diff.LengthSqr());
- if(dist < scaleRadSqr) {
- return true;
- }
- return false;
- }
- void SSDEntity::Draw(idDeviceContext *dc) {
- idVec2 persize;
- float x,y;
- idBounds bounds;
- bounds[0] = idVec3(position.x - (size.x/2.0f), position.y - (size.y/2.0f), position.z);
- bounds[1] = idVec3(position.x + (size.x/2.0f), position.y + (size.y/2.0f), position.z);
- idBounds screenBounds = WorldToScreen(bounds);
- persize.x = idMath::Fabs(screenBounds[1].x - screenBounds[0].x);
- persize.y = idMath::Fabs(screenBounds[1].y - screenBounds[0].y);
- idVec3 center = screenBounds.GetCenter();
- x = screenBounds[0].x;
- y = screenBounds[1].y;
- dc->DrawMaterialRotated(x, y, persize.x, persize.y, material, matColor, 1.0f, 1.0f, DEG2RAD(rotation));
- if(text.Length() > 0) {
- idRectangle rect( x, y, VIRTUAL_WIDTH, VIRTUAL_HEIGHT );
- dc->DrawText( text, textScale, 0, foreColor, rect, false );
- }
- }
- void SSDEntity::DestroyEntity() {
- inUse = false;
- }
- idBounds SSDEntity::WorldToScreen(const idBounds worldBounds) {
- idVec3 screenMin = WorldToScreen(worldBounds[0]);
- idVec3 screenMax = WorldToScreen(worldBounds[1]);
- idBounds screenBounds(screenMin, screenMax);
- return screenBounds;
- }
- idVec3 SSDEntity::WorldToScreen(const idVec3& worldPos) {
-
- float d = 0.5f*V_WIDTH*idMath::Tan(DEG2RAD(90.0f)/2.0f);
- //World To Camera Coordinates
- idVec3 cameraTrans(0,0,d);
- idVec3 cameraPos;
- cameraPos = worldPos + cameraTrans;
- //Camera To Screen Coordinates
- idVec3 screenPos;
- screenPos.x = d*cameraPos.x/cameraPos.z + (0.5f*V_WIDTH-0.5f);
- screenPos.y = -d*cameraPos.y/cameraPos.z + (0.5f*V_HEIGHT-0.5f);
- screenPos.z = cameraPos.z;
- return screenPos;
- }
- idVec3 SSDEntity::ScreenToWorld(const idVec3& screenPos) {
- idVec3 worldPos;
- worldPos.x = screenPos.x - 0.5f * V_WIDTH;
- worldPos.y = -(screenPos.y - 0.5f * V_HEIGHT);
- worldPos.z = screenPos.z;
- return worldPos;
- }
- /*
- *****************************************************************************
- * SSDMover
- ****************************************************************************
- */
- SSDMover::SSDMover() {
- }
- SSDMover::~SSDMover() {
- }
- void SSDMover::WriteToSaveGame( idFile *savefile ) {
- SSDEntity::WriteToSaveGame(savefile);
-
- savefile->Write(&speed, sizeof(speed));
- savefile->Write(&rotationSpeed, sizeof(rotationSpeed));
- }
- void SSDMover::ReadFromSaveGame( idFile *savefile, idGameSSDWindow* _game ) {
- SSDEntity::ReadFromSaveGame(savefile, _game);
- savefile->Read(&speed, sizeof(speed));
- savefile->Read(&rotationSpeed, sizeof(rotationSpeed));
- }
- void SSDMover::MoverInit(const idVec3& _speed, float _rotationSpeed) {
-
- speed = _speed;
- rotationSpeed = _rotationSpeed;
- }
- void SSDMover::EntityUpdate() {
-
- SSDEntity::EntityUpdate();
- //Move forward based on speed (units per second)
- idVec3 moved = ((float)elapsed/1000.0f)*speed;
- position += moved;
- float rotated = ((float)elapsed/1000.0f)*rotationSpeed*360.0f;
- rotation += rotated;
- if(rotation >= 360) {
- rotation -= 360.0f;
- }
- if(rotation < 0) {
- rotation += 360.0f;
- }
- }
- /*
- *****************************************************************************
- * SSDAsteroid
- ****************************************************************************
- */
- SSDAsteroid SSDAsteroid::asteroidPool[MAX_ASTEROIDS];
- #define ASTEROID_MATERIAL "game/SSD/asteroid"
- SSDAsteroid::SSDAsteroid() {
- }
- SSDAsteroid::~SSDAsteroid() {
- }
- void SSDAsteroid::WriteToSaveGame( idFile *savefile ) {
- SSDMover::WriteToSaveGame(savefile);
- savefile->Write(&health, sizeof(health));
- }
- void SSDAsteroid::ReadFromSaveGame( idFile *savefile, idGameSSDWindow* _game ) {
- SSDMover::ReadFromSaveGame(savefile, _game);
- savefile->Read(&health, sizeof(health));
- }
- void SSDAsteroid::Init(idGameSSDWindow* _game, const idVec3& startPosition, const idVec2& _size, float _speed, float rotate, int _health) {
- EntityInit();
- MoverInit(idVec3(0,0, -_speed), rotate);
-
- SetGame(_game);
- type = SSD_ENTITY_ASTEROID;
- SetMaterial(ASTEROID_MATERIAL);
- SetSize(_size);
- SetRadius(Max(size.x, size.y), 0.3f);
- SetRotation(game->random.RandomInt(360));
-
- position = startPosition;
- health = _health;
- }
- void SSDAsteroid::EntityUpdate() {
-
- SSDMover::EntityUpdate();
- }
- SSDAsteroid* SSDAsteroid::GetNewAsteroid(idGameSSDWindow* _game, const idVec3& startPosition, const idVec2& _size, float _speed, float rotate, int _health) {
- for(int i = 0; i < MAX_ASTEROIDS; i++) {
- if(!asteroidPool[i].inUse) {
- asteroidPool[i].Init(_game, startPosition, _size, _speed, rotate, _health);
- asteroidPool[i].inUse = true;
- asteroidPool[i].id = i;
- return &asteroidPool[i];
- }
- }
- return NULL;
- }
- SSDAsteroid* SSDAsteroid::GetSpecificAsteroid(int id) {
- return &asteroidPool[id];
- }
- void SSDAsteroid::WriteAsteroids(idFile* savefile) {
- int count = 0;
- for(int i = 0; i < MAX_ASTEROIDS; i++) {
- if(asteroidPool[i].inUse) {
- count++;
- }
- }
- savefile->Write(&count, sizeof(count));
- for(int i = 0; i < MAX_ASTEROIDS; i++) {
- if(asteroidPool[i].inUse) {
- savefile->Write(&(asteroidPool[i].id), sizeof(asteroidPool[i].id));
- asteroidPool[i].WriteToSaveGame(savefile);
- }
- }
- }
- void SSDAsteroid::ReadAsteroids(idFile* savefile, idGameSSDWindow* _game) {
-
- int count;
- savefile->Read(&count, sizeof(count));
- for(int i = 0; i < count; i++) {
- int id;
- savefile->Read(&id, sizeof(id));
- SSDAsteroid* ent = GetSpecificAsteroid(id);
- ent->ReadFromSaveGame(savefile, _game);
- }
- }
- /*
- *****************************************************************************
- * SSDAstronaut
- ****************************************************************************
- */
- SSDAstronaut SSDAstronaut::astronautPool[MAX_ASTRONAUT];
- #define ASTRONAUT_MATERIAL "game/SSD/astronaut"
- SSDAstronaut::SSDAstronaut() {
- }
- SSDAstronaut::~SSDAstronaut() {
- }
- void SSDAstronaut::WriteToSaveGame( idFile *savefile ) {
- SSDMover::WriteToSaveGame(savefile);
- savefile->Write(&health, sizeof(health));
- }
- void SSDAstronaut::ReadFromSaveGame( idFile *savefile, idGameSSDWindow* _game ) {
- SSDMover::ReadFromSaveGame(savefile, _game);
- savefile->Read(&health, sizeof(health));
- }
- void SSDAstronaut::Init(idGameSSDWindow* _game, const idVec3& startPosition, float _speed, float rotate, int _health) {
- EntityInit();
- MoverInit(idVec3(0,0, -_speed), rotate);
- SetGame(_game);
- type = SSD_ENTITY_ASTRONAUT;
- SetMaterial(ASTRONAUT_MATERIAL);
- SetSize(idVec2(256,256));
- SetRadius(Max(size.x, size.y), 0.3f);
- SetRotation(game->random.RandomInt(360));
-
- position = startPosition;
- health = _health;
- }
- SSDAstronaut* SSDAstronaut::GetNewAstronaut(idGameSSDWindow* _game, const idVec3& startPosition, float _speed, float rotate, int _health) {
- for(int i = 0; i < MAX_ASTRONAUT; i++) {
- if(!astronautPool[i].inUse) {
- astronautPool[i].Init(_game, startPosition, _speed, rotate, _health);
- astronautPool[i].inUse = true;
- astronautPool[i].id = i;
- return &astronautPool[i];
- }
- }
- return NULL;
- }
- SSDAstronaut* SSDAstronaut::GetSpecificAstronaut(int id) {
- return &astronautPool[id];
-
- }
- void SSDAstronaut::WriteAstronauts(idFile* savefile) {
- int count = 0;
- for(int i = 0; i < MAX_ASTRONAUT; i++) {
- if(astronautPool[i].inUse) {
- count++;
- }
- }
- savefile->Write(&count, sizeof(count));
- for(int i = 0; i < MAX_ASTRONAUT; i++) {
- if(astronautPool[i].inUse) {
- savefile->Write(&(astronautPool[i].id), sizeof(astronautPool[i].id));
- astronautPool[i].WriteToSaveGame(savefile);
- }
- }
- }
- void SSDAstronaut::ReadAstronauts(idFile* savefile, idGameSSDWindow* _game) {
- int count;
- savefile->Read(&count, sizeof(count));
- for(int i = 0; i < count; i++) {
- int id;
- savefile->Read(&id, sizeof(id));
- SSDAstronaut* ent = GetSpecificAstronaut(id);
- ent->ReadFromSaveGame(savefile, _game);
- }
- }
- /*
- *****************************************************************************
- * SSDExplosion
- ****************************************************************************
- */
- SSDExplosion SSDExplosion::explosionPool[MAX_EXPLOSIONS];
- //#define EXPLOSION_MATERIAL "game/SSD/fball"
- //#define EXPLOSION_TELEPORT "game/SSD/teleport"
- const char* explosionMaterials[] = {
- "game/SSD/fball",
- "game/SSD/teleport"
- };
- #define EXPLOSION_MATERIAL_COUNT 2
- SSDExplosion::SSDExplosion() {
- type = SSD_ENTITY_EXPLOSION;
- }
- SSDExplosion::~SSDExplosion() {
- }
- void SSDExplosion::WriteToSaveGame( idFile *savefile ) {
- SSDEntity::WriteToSaveGame(savefile);
- savefile->Write(&finalSize, sizeof(finalSize));
- savefile->Write(&length, sizeof(length));
- savefile->Write(&beginTime, sizeof(beginTime));
- savefile->Write(&endTime, sizeof(endTime));
- savefile->Write(&explosionType, sizeof(explosionType));
-
- savefile->Write(&(buddy->type), sizeof(buddy->type));
- savefile->Write(&(buddy->id), sizeof(buddy->id));
- savefile->Write(&killBuddy, sizeof(killBuddy));
- savefile->Write(&followBuddy, sizeof(followBuddy));
- }
- void SSDExplosion::ReadFromSaveGame( idFile *savefile, idGameSSDWindow* _game ) {
- SSDEntity::ReadFromSaveGame(savefile, _game);
- savefile->Read(&finalSize, sizeof(finalSize));
- savefile->Read(&length, sizeof(length));
- savefile->Read(&beginTime, sizeof(beginTime));
- savefile->Read(&endTime, sizeof(endTime));
- savefile->Read(&explosionType, sizeof(explosionType));
- int type, id;
- savefile->Read(&type, sizeof(type));
- savefile->Read(&id, sizeof(id));
- //Get a pointer to my buddy
- buddy = _game->GetSpecificEntity(type, id);
- savefile->Read(&killBuddy, sizeof(killBuddy));
- savefile->Read(&followBuddy, sizeof(followBuddy));
- }
- void SSDExplosion::Init(idGameSSDWindow* _game, const idVec3& _position, const idVec2& _size, int _length, int _type, SSDEntity* _buddy, bool _killBuddy, bool _followBuddy) {
-
- EntityInit();
- SetGame(_game);
- type = SSD_ENTITY_EXPLOSION;
- explosionType = _type;
- SetMaterial(explosionMaterials[explosionType]);
- SetPosition(_position);
- position.z -= 50;
- finalSize = _size;
- length = _length;
- beginTime = game->ssdTime;
- endTime = beginTime + length;
- buddy = _buddy;
- killBuddy = _killBuddy;
- followBuddy = _followBuddy;
- //Explosion Starts from nothing and will increase in size until it gets to final size
- size.Zero();
- noPlayerDamage = true;
- noHit = true;
- }
- void SSDExplosion::EntityUpdate() {
-
- SSDEntity::EntityUpdate();
- //Always set my position to my buddies position except change z to be on top
- if(followBuddy) {
- position = buddy->position;
- position.z -= 50;
- } else {
- //Only mess with the z if we are not following
- position.z = buddy->position.z - 50;
- }
- //Scale the image based on the time
- size = finalSize*((float)(currentTime-beginTime)/(float)length);
- //Destroy myself after the explosion is done
- if(currentTime > endTime) {
- destroyed = true;
-
- if(killBuddy) {
- //Destroy the exploding object
- buddy->destroyed = true;
- }
- }
- }
- SSDExplosion* SSDExplosion::GetNewExplosion(idGameSSDWindow* _game, const idVec3& _position, const idVec2& _size, int _length, int _type, SSDEntity* _buddy, bool _killBuddy, bool _followBuddy) {
- for(int i = 0; i < MAX_EXPLOSIONS; i++) {
- if(!explosionPool[i].inUse) {
- explosionPool[i].Init(_game, _position, _size, _length, _type, _buddy, _killBuddy, _followBuddy);
- explosionPool[i].inUse = true;
- return &explosionPool[i];
- }
- }
- return NULL;
- }
- SSDExplosion* SSDExplosion::GetSpecificExplosion(int id) {
- return &explosionPool[id];
- }
- void SSDExplosion::WriteExplosions(idFile* savefile) {
- int count = 0;
- for(int i = 0; i < MAX_EXPLOSIONS; i++) {
- if(explosionPool[i].inUse) {
- count++;
- }
- }
- savefile->Write(&count, sizeof(count));
- for(int i = 0; i < MAX_EXPLOSIONS; i++) {
- if(explosionPool[i].inUse) {
- savefile->Write(&(explosionPool[i].id), sizeof(explosionPool[i].id));
- explosionPool[i].WriteToSaveGame(savefile);
- }
- }
- }
- void SSDExplosion::ReadExplosions(idFile* savefile, idGameSSDWindow* _game) {
- int count;
- savefile->Read(&count, sizeof(count));
- for(int i = 0; i < count; i++) {
- int id;
- savefile->Read(&id, sizeof(id));
- SSDExplosion* ent = GetSpecificExplosion(id);
- ent->ReadFromSaveGame(savefile, _game);
- }
- }
- /*
- *****************************************************************************
- * SSDPoints
- ****************************************************************************
- */
- SSDPoints SSDPoints::pointsPool[MAX_POINTS];
- SSDPoints::SSDPoints() {
- type = SSD_ENTITY_POINTS;
- }
- SSDPoints::~SSDPoints() {
- }
- void SSDPoints::WriteToSaveGame( idFile *savefile ) {
- SSDEntity::WriteToSaveGame(savefile);
- savefile->Write(&length, sizeof(length));
- savefile->Write(&distance, sizeof(distance));
- savefile->Write(&beginTime, sizeof(beginTime));
- savefile->Write(&endTime, sizeof(endTime));
- savefile->Write(&beginPosition, sizeof(beginPosition));
- savefile->Write(&endPosition, sizeof(endPosition));
- savefile->Write(&beginColor, sizeof(beginColor));
- savefile->Write(&endColor, sizeof(endColor));
-
- }
- void SSDPoints::ReadFromSaveGame( idFile *savefile, idGameSSDWindow* _game ) {
- SSDEntity::ReadFromSaveGame(savefile, _game);
- savefile->Read(&length, sizeof(length));
- savefile->Read(&distance, sizeof(distance));
- savefile->Read(&beginTime, sizeof(beginTime));
- savefile->Read(&endTime, sizeof(endTime));
- savefile->Read(&beginPosition, sizeof(beginPosition));
- savefile->Read(&endPosition, sizeof(endPosition));
- savefile->Read(&beginColor, sizeof(beginColor));
- savefile->Read(&endColor, sizeof(endColor));
- }
- void SSDPoints::Init(idGameSSDWindow* _game, SSDEntity* _ent, int _points, int _length, int _distance, const idVec4& color) {
- EntityInit();
-
- SetGame(_game);
- length = _length;
- distance = _distance;
- beginTime = game->ssdTime;
- endTime = beginTime + length;
- textScale = 0.4f;
- text = va("%d", _points);
- float width = 0;
- for(int i = 0; i < text.Length(); i++) {
- width += game->GetDC()->CharWidth(text[i], textScale);
- }
- size.Set(0,0);
- //Set the start position at the top of the passed in entity
- position = WorldToScreen(_ent->position);
- position = ScreenToWorld(position);
- position.z = 0;
- position.x -= (width/2.0f);
- beginPosition = position;
- endPosition = beginPosition;
- endPosition.y += _distance;
- //beginColor.Set(0,1,0,1);
- endColor.Set(1,1,1,0);
-
- beginColor = color;
- beginColor.w = 1;
- noPlayerDamage = true;
- noHit = true;
- }
- void SSDPoints::EntityUpdate() {
- float t = (float)(currentTime - beginTime)/(float)length;
- //Move up from the start position
- position.Lerp(beginPosition, endPosition, t);
- //Interpolate the color
- foreColor.Lerp(beginColor, endColor, t);
- if(currentTime > endTime) {
- destroyed = true;
- }
- }
- SSDPoints* SSDPoints::GetNewPoints(idGameSSDWindow* _game, SSDEntity* _ent, int _points, int _length, int _distance, const idVec4& color) {
- for(int i = 0; i < MAX_POINTS; i++) {
- if(!pointsPool[i].inUse) {
- pointsPool[i].Init(_game, _ent, _points, _length, _distance, color);
- pointsPool[i].inUse = true;
- return &pointsPool[i];
- }
- }
- return NULL;
- }
- SSDPoints* SSDPoints::GetSpecificPoints(int id) {
- return &pointsPool[id];
- }
- void SSDPoints::WritePoints(idFile* savefile) {
- int count = 0;
- for(int i = 0; i < MAX_POINTS; i++) {
- if(pointsPool[i].inUse) {
- count++;
- }
- }
- savefile->Write(&count, sizeof(count));
- for(int i = 0; i < MAX_POINTS; i++) {
- if(pointsPool[i].inUse) {
- savefile->Write(&(pointsPool[i].id), sizeof(pointsPool[i].id));
- pointsPool[i].WriteToSaveGame(savefile);
- }
- }
- }
- void SSDPoints::ReadPoints(idFile* savefile, idGameSSDWindow* _game) {
- int count;
- savefile->Read(&count, sizeof(count));
- for(int i = 0; i < count; i++) {
- int id;
- savefile->Read(&id, sizeof(id));
- SSDPoints* ent = GetSpecificPoints(id);
- ent->ReadFromSaveGame(savefile, _game);
- }
- }
- /*
- *****************************************************************************
- * SSDProjectile
- ****************************************************************************
- */
- SSDProjectile SSDProjectile::projectilePool[MAX_PROJECTILES];
- #define PROJECTILE_MATERIAL "game/SSD/fball"
- SSDProjectile::SSDProjectile() {
- type = SSD_ENTITY_PROJECTILE;
- }
- SSDProjectile::~SSDProjectile() {
- }
- void SSDProjectile::WriteToSaveGame( idFile *savefile ) {
- SSDEntity::WriteToSaveGame(savefile);
- savefile->Write(&dir, sizeof(dir));
- savefile->Write(&speed, sizeof(speed));
- savefile->Write(&beginTime, sizeof(beginTime));
- savefile->Write(&endTime, sizeof(endTime));
- savefile->Write(&endPosition, sizeof(endPosition));
- }
- void SSDProjectile::ReadFromSaveGame( idFile *savefile, idGameSSDWindow* _game ) {
- SSDEntity::ReadFromSaveGame(savefile, _game);
- savefile->Read(&dir, sizeof(dir));
- savefile->Read(&speed, sizeof(speed));
- savefile->Read(&beginTime, sizeof(beginTime));
- savefile->Read(&endTime, sizeof(endTime));
- savefile->Read(&endPosition, sizeof(endPosition));
- }
- void SSDProjectile::Init(idGameSSDWindow* _game, const idVec3& _beginPosition, const idVec3& _endPosition, float _speed, float _size) {
-
- EntityInit();
- SetGame(_game);
- SetMaterial(PROJECTILE_MATERIAL);
- size.Set(_size,_size);
- position = _beginPosition;
- endPosition = _endPosition;
- dir = _endPosition - position;
- dir.Normalize();
- //speed.Zero();
- speed.x = speed.y = speed.z = _speed;
- noHit = true;
- }
- void SSDProjectile::EntityUpdate() {
- SSDEntity::EntityUpdate();
- //Move forward based on speed (units per second)
- idVec3 moved = dir*((float)elapsed/1000.0f)*speed.z;
- position += moved;
- if(position.z > endPosition.z) {
- //We have reached our position
- destroyed = true;
- }
- }
- SSDProjectile* SSDProjectile::GetNewProjectile(idGameSSDWindow* _game, const idVec3& _beginPosition, const idVec3& _endPosition, float _speed, float _size) {
- for(int i = 0; i < MAX_PROJECTILES; i++) {
- if(!projectilePool[i].inUse) {
- projectilePool[i].Init(_game, _beginPosition, _endPosition, _speed, _size);
- projectilePool[i].inUse = true;
- return &projectilePool[i];
- }
- }
- return NULL;
- }
- SSDProjectile* SSDProjectile::GetSpecificProjectile(int id) {
- return &projectilePool[id];
- }
- void SSDProjectile::WriteProjectiles(idFile* savefile) {
- int count = 0;
- for(int i = 0; i < MAX_PROJECTILES; i++) {
- if(projectilePool[i].inUse) {
- count++;
- }
- }
- savefile->Write(&count, sizeof(count));
- for(int i = 0; i < MAX_PROJECTILES; i++) {
- if(projectilePool[i].inUse) {
- savefile->Write(&(projectilePool[i].id), sizeof(projectilePool[i].id));
- projectilePool[i].WriteToSaveGame(savefile);
- }
- }
- }
- void SSDProjectile::ReadProjectiles(idFile* savefile, idGameSSDWindow* _game) {
- int count;
- savefile->Read(&count, sizeof(count));
- for(int i = 0; i < count; i++) {
- int id;
- savefile->Read(&id, sizeof(id));
- SSDProjectile* ent = GetSpecificProjectile(id);
- ent->ReadFromSaveGame(savefile, _game);
- }
- }
- /*
- *****************************************************************************
- * SSDPowerup
- ****************************************************************************
- */
- const char* powerupMaterials[][2] = {
- "game/SSD/powerupHealthClosed", "game/SSD/powerupHealthOpen",
- "game/SSD/powerupSuperBlasterClosed", "game/SSD/powerupSuperBlasterOpen",
- "game/SSD/powerupNukeClosed", "game/SSD/powerupNukeOpen",
- "game/SSD/powerupRescueClosed", "game/SSD/powerupRescueOpen",
- "game/SSD/powerupBonusPointsClosed", "game/SSD/powerupBonusPointsOpen",
- "game/SSD/powerupDamageClosed", "game/SSD/powerupDamageOpen",
- };
- #define POWERUP_MATERIAL_COUNT 6
- SSDPowerup SSDPowerup::powerupPool[MAX_POWERUPS];
- SSDPowerup::SSDPowerup() {
-
- }
- SSDPowerup::~SSDPowerup() {
- }
- void SSDPowerup::WriteToSaveGame( idFile *savefile ) {
- SSDMover::WriteToSaveGame(savefile);
- savefile->Write(&powerupState, sizeof(powerupState));
- savefile->Write(&powerupType, sizeof(powerupType));
- }
- void SSDPowerup::ReadFromSaveGame( idFile *savefile, idGameSSDWindow* _game ) {
- SSDMover::ReadFromSaveGame(savefile, _game);
- savefile->Read(&powerupState, sizeof(powerupState));
- savefile->Read(&powerupType, sizeof(powerupType));
- }
- void SSDPowerup::OnHit(int key) {
- if(powerupState == POWERUP_STATE_CLOSED) {
- //Small explosion to indicate it is opened
- SSDExplosion* explosion = SSDExplosion::GetNewExplosion(game, position, size*2.0f, 300, SSDExplosion::EXPLOSION_NORMAL, this, false, true);
- game->entities.Append(explosion);
-
- powerupState = POWERUP_STATE_OPEN;
- SetMaterial(powerupMaterials[powerupType][powerupState]);
- } else {
- //Destory the powerup with a big explosion
- SSDExplosion* explosion = SSDExplosion::GetNewExplosion(game, position, size*2, 300, SSDExplosion::EXPLOSION_NORMAL, this);
- game->entities.Append(explosion);
- game->PlaySound("arcade_explode");
- noHit = true;
- noPlayerDamage = true;
- }
- }
- void SSDPowerup::OnStrikePlayer() {
-
- if(powerupState == POWERUP_STATE_OPEN) {
- //The powerup was open so activate it
- OnActivatePowerup();
- }
- //Just destroy the powerup
- destroyed = true;
- }
- void SSDPowerup::OnOpenPowerup() {
- }
- void SSDPowerup::OnActivatePowerup() {
- switch(powerupType) {
- case POWERUP_TYPE_HEALTH:
- {
- game->AddHealth(10);
- break;
- }
- case POWERUP_TYPE_SUPER_BLASTER:
- {
- game->OnSuperBlaster();
- break;
- }
- case POWERUP_TYPE_ASTEROID_NUKE:
- {
- game->OnNuke();
- break;
- }
- case POWERUP_TYPE_RESCUE_ALL:
- {
- game->OnRescueAll();
- break;
- }
- case POWERUP_TYPE_BONUS_POINTS:
- {
- int points = (game->random.RandomInt(5)+1) * 100;
- game->AddScore(this, points);
- break;
- }
- case POWERUP_TYPE_DAMAGE:
- {
- game->AddDamage(10);
- game->PlaySound("arcade_explode");
- break;
- }
- }
- }
- void SSDPowerup::Init(idGameSSDWindow* _game, float _speed, float _rotation) {
- EntityInit();
- MoverInit(idVec3(0,0, -_speed), _rotation);
- SetGame(_game);
- SetSize(idVec2(200,200));
- SetRadius(Max(size.x, size.y), 0.3f);
- type = SSD_ENTITY_POWERUP;
-
- idVec3 startPosition;
- startPosition.x = game->random.RandomInt(V_WIDTH)-(V_WIDTH/2.0f);
- startPosition.y = game->random.RandomInt(V_HEIGHT)-(V_HEIGHT/2.0f);
- startPosition.z = ENTITY_START_DIST;
- position = startPosition;
- //SetPosition(startPosition);
- powerupState = POWERUP_STATE_CLOSED;
- powerupType = game->random.RandomInt(POWERUP_TYPE_MAX+1);
- if(powerupType >= POWERUP_TYPE_MAX) {
- powerupType = 0;
- }
- /*OutputDebugString(va("Powerup: %d\n", powerupType));
- if(powerupType == 0) {
- int x = 0;
- }*/
- SetMaterial(powerupMaterials[powerupType][powerupState]);
- }
- SSDPowerup* SSDPowerup::GetNewPowerup(idGameSSDWindow* _game, float _speed, float _rotation) {
- for(int i = 0; i < MAX_POWERUPS; i++) {
- if(!powerupPool[i].inUse) {
- powerupPool[i].Init(_game, _speed, _rotation);
- powerupPool[i].inUse = true;
- return &powerupPool[i];
- }
- }
- return NULL;
- }
- SSDPowerup* SSDPowerup::GetSpecificPowerup(int id) {
- return &powerupPool[id];
- }
- void SSDPowerup::WritePowerups(idFile* savefile) {
- int count = 0;
- for(int i = 0; i < MAX_POWERUPS; i++) {
- if(powerupPool[i].inUse) {
- count++;
- }
- }
- savefile->Write(&count, sizeof(count));
- for(int i = 0; i < MAX_POWERUPS; i++) {
- if(powerupPool[i].inUse) {
- savefile->Write(&(powerupPool[i].id), sizeof(powerupPool[i].id));
- powerupPool[i].WriteToSaveGame(savefile);
- }
- }
- }
- void SSDPowerup::ReadPowerups(idFile* savefile, idGameSSDWindow* _game) {
- int count;
- savefile->Read(&count, sizeof(count));
- for(int i = 0; i < count; i++) {
- int id;
- savefile->Read(&id, sizeof(id));
- SSDPowerup* ent = GetSpecificPowerup(id);
- ent->ReadFromSaveGame(savefile, _game);
- }
- }
- /*
- *****************************************************************************
- * idGameSSDWindow
- ****************************************************************************
- */
- idRandom idGameSSDWindow::random;
- idGameSSDWindow::idGameSSDWindow(idDeviceContext *d, idUserInterfaceLocal *g) : idWindow(d, g) {
- dc = d;
- gui = g;
- CommonInit();
- }
- idGameSSDWindow::idGameSSDWindow(idUserInterfaceLocal *g) : idWindow(g) {
- gui = g;
- CommonInit();
- }
- idGameSSDWindow::~idGameSSDWindow() {
- ResetGameStats();
- }
- void idGameSSDWindow::WriteToSaveGame( idFile *savefile ) {
- idWindow::WriteToSaveGame(savefile);
- savefile->Write(&ssdTime, sizeof(ssdTime));
- beginLevel.WriteToSaveGame(savefile);
- resetGame.WriteToSaveGame(savefile);
- continueGame.WriteToSaveGame(savefile);
- refreshGuiData.WriteToSaveGame(savefile);
- crosshair.WriteToSaveGame(savefile);
- savefile->Write(&screenBounds, sizeof(screenBounds));
- savefile->Write(&levelCount, sizeof(levelCount));
- for(int i = 0; i < levelCount; i++) {
- savefile->Write(&(levelData[i]), sizeof(SSDLevelData_t));
- savefile->Write(&(asteroidData[i]), sizeof(SSDAsteroidData_t));
- savefile->Write(&(astronautData[i]), sizeof(SSDAstronautData_t));
- savefile->Write(&(powerupData[i]), sizeof(SSDPowerupData_t));
- }
- savefile->Write(&weaponCount, sizeof(weaponCount));
- for(int i = 0; i < weaponCount; i++) {
- savefile->Write(&(weaponData[i]), sizeof(SSDWeaponData_t));
- }
- savefile->Write(&superBlasterTimeout, sizeof(superBlasterTimeout));
- savefile->Write(&gameStats, sizeof(SSDGameStats_t));
- //Write All Static Entities
- SSDAsteroid::WriteAsteroids(savefile);
- SSDAstronaut::WriteAstronauts(savefile);
- SSDExplosion::WriteExplosions(savefile);
- SSDPoints::WritePoints(savefile);
- SSDProjectile::WriteProjectiles(savefile);
- SSDPowerup::WritePowerups(savefile);
- int entCount = entities.Num();
- savefile->Write(&entCount, sizeof(entCount));
- for(int i = 0; i < entCount; i++) {
- savefile->Write(&(entities[i]->type), sizeof(entities[i]->type));
- savefile->Write(&(entities[i]->id), sizeof(entities[i]->id));
- }
- }
- void idGameSSDWindow::ReadFromSaveGame( idFile *savefile ) {
- idWindow::ReadFromSaveGame(savefile);
- savefile->Read(&ssdTime, sizeof(ssdTime));
- beginLevel.ReadFromSaveGame(savefile);
- resetGame.ReadFromSaveGame(savefile);
- continueGame.ReadFromSaveGame(savefile);
- refreshGuiData.ReadFromSaveGame(savefile);
- crosshair.ReadFromSaveGame(savefile);
- savefile->Read(&screenBounds, sizeof(screenBounds));
- savefile->Read(&levelCount, sizeof(levelCount));
- for(int i = 0; i < levelCount; i++) {
- SSDLevelData_t newLevel;
- savefile->Read(&newLevel, sizeof(SSDLevelData_t));
- levelData.Append(newLevel);
- SSDAsteroidData_t newAsteroid;
- savefile->Read(&newAsteroid, sizeof(SSDAsteroidData_t));
- asteroidData.Append(newAsteroid);
- SSDAstronautData_t newAstronaut;
- savefile->Read(&newAstronaut, sizeof(SSDAstronautData_t));
- astronautData.Append(newAstronaut);
-
- SSDPowerupData_t newPowerup;
- savefile->Read(&newPowerup, sizeof(SSDPowerupData_t));
- powerupData.Append(newPowerup);
- }
- savefile->Read(&weaponCount, sizeof(weaponCount));
- for(int i = 0; i < weaponCount; i++) {
- SSDWeaponData_t newWeapon;
- savefile->Read(&newWeapon, sizeof(SSDWeaponData_t));
- weaponData.Append(newWeapon);
- }
- savefile->Read(&superBlasterTimeout, sizeof(superBlasterTimeout));
-
- savefile->Read(&gameStats, sizeof(SSDGameStats_t));
- //Reset this because it is no longer valid
- gameStats.levelStats.targetEnt = NULL;
- SSDAsteroid::ReadAsteroids(savefile, this);
- SSDAstronaut::ReadAstronauts(savefile, this);
- SSDExplosion::ReadExplosions(savefile, this);
- SSDPoints::ReadPoints(savefile, this);
- SSDProjectile::ReadProjectiles(savefile, this);
- SSDPowerup::ReadPowerups(savefile, this);
- int entCount;
- savefile->Read(&entCount, sizeof(entCount));
- for(int i = 0; i < entCount; i++) {
- int type, id;
- savefile->Read(&type, sizeof(type));
- savefile->Read(&id, sizeof(id));
- SSDEntity* ent = GetSpecificEntity(type, id);
- if(ent) {
- entities.Append(ent);
- }
- }
- }
- const char *idGameSSDWindow::HandleEvent(const sysEvent_t *event, bool *updateVisuals) {
-
- // need to call this to allow proper focus and capturing on embedded children
- const char *ret = idWindow::HandleEvent(event, updateVisuals);
- if(!gameStats.gameRunning) {
- return ret;
- }
- int key = event->evValue;
- if ( event->evType == SE_KEY ) {
- if ( !event->evValue2 ) {
- return ret;
- }
- if ( key == K_MOUSE1 || key == K_MOUSE2) {
- FireWeapon(key);
- } else {
- return ret;
- }
- }
- return ret;
- }
- idWinVar *idGameSSDWindow::GetWinVarByName (const char *_name, bool winLookup, drawWin_t** owner) {
- idWinVar *retVar = NULL;
- if (idStr::Icmp(_name, "beginLevel") == 0) {
- retVar = &beginLevel;
- }
- if (idStr::Icmp(_name, "resetGame") == 0) {
- retVar = &resetGame;
- }
- if (idStr::Icmp(_name, "continueGame") == 0) {
- retVar = &continueGame;
- }
- if (idStr::Icmp(_name, "refreshGuiData") == 0) {
- retVar = &refreshGuiData;
- }
-
- if(retVar) {
- return retVar;
- }
- return idWindow::GetWinVarByName(_name, winLookup, owner);
- }
- void idGameSSDWindow::Draw(int time, float x, float y) {
- //Update the game every frame before drawing
- UpdateGame();
- RefreshGuiData();
- if(gameStats.gameRunning) {
- ZOrderEntities();
- //Draw from back to front
- for(int i = entities.Num()-1; i >= 0; i--) {
- entities[i]->Draw(dc);
- }
- //The last thing to draw is the crosshair
- idVec2 cursor;
- //GetCursor(cursor);
- cursor.x = gui->CursorX();
- cursor.y = gui->CursorY();
- crosshair.Draw(dc, cursor);
- }
- }
- bool idGameSSDWindow::ParseInternalVar(const char *_name, idParser *src) {
- if (idStr::Icmp(_name, "beginLevel") == 0) {
- beginLevel = src->ParseBool();
- return true;
- }
- if (idStr::Icmp(_name, "resetGame") == 0) {
- resetGame = src->ParseBool();
- return true;
- }
- if (idStr::Icmp(_name, "continueGame") == 0) {
- continueGame = src->ParseBool();
- return true;
- }
- if (idStr::Icmp(_name, "refreshGuiData") == 0) {
- refreshGuiData = src->ParseBool();
- return true;
- }
-
- if(idStr::Icmp(_name, "levelcount") == 0) {
- levelCount = src->ParseInt();
- for(int i = 0; i < levelCount; i++) {
- SSDLevelData_t newLevel;
- memset(&newLevel, 0, sizeof(SSDLevelData_t));
- levelData.Append(newLevel);
- SSDAsteroidData_t newAsteroid;
- memset(&newAsteroid, 0, sizeof(SSDAsteroidData_t));
- asteroidData.Append(newAsteroid);
- SSDAstronautData_t newAstronaut;
- memset(&newAstronaut, 0, sizeof(SSDAstronautData_t));
- astronautData.Append(newAstronaut);
- SSDPowerupData_t newPowerup;
- memset(&newPowerup, 0, sizeof(SSDPowerupData_t));
- powerupData.Append(newPowerup);
- }
- return true;
- }
- if(idStr::Icmp(_name, "weaponCount") == 0) {
- weaponCount = src->ParseInt();
- for(int i = 0; i < weaponCount; i++) {
- SSDWeaponData_t newWeapon;
- memset(&newWeapon, 0, sizeof(SSDWeaponData_t));
- weaponData.Append(newWeapon);
- }
- return true;
- }
- if(idStr::FindText(_name, "leveldata", false) >= 0) {
- idStr tempName = _name;
- int level = atoi(tempName.Right(2))-1;
- idStr levelData;
- ParseString(src, levelData);
- ParseLevelData(level, levelData);
- return true;
- }
- if(idStr::FindText(_name, "asteroiddata", false) >= 0) {
- idStr tempName = _name;
- int level = atoi(tempName.Right(2))-1;
- idStr asteroidData;
- ParseString(src, asteroidData);
- ParseAsteroidData(level, asteroidData);
- return true;
- }
- if(idStr::FindText(_name, "weapondata", false) >= 0) {
- idStr tempName = _name;
- int weapon = atoi(tempName.Right(2))-1;
- idStr weaponData;
- ParseString(src, weaponData);
- ParseWeaponData(weapon, weaponData);
- return true;
- }
- if(idStr::FindText(_name, "astronautdata", false) >= 0) {
- idStr tempName = _name;
- int level = atoi(tempName.Right(2))-1;
- idStr astronautData;
- ParseString(src, astronautData);
- ParseAstronautData(level, astronautData);
- return true;
- }
- if(idStr::FindText(_name, "powerupdata", false) >= 0) {
- idStr tempName = _name;
- int level = atoi(tempName.Right(2))-1;
- idStr powerupData;
- ParseString(src, powerupData);
- ParsePowerupData(level, powerupData);
- return true;
- }
- return idWindow::ParseInternalVar(_name, src);
- }
- void idGameSSDWindow::ParseLevelData(int level, const idStr& levelDataString) {
- idParser parser;
- idToken token;
- parser.LoadMemory(levelDataString.c_str(), levelDataString.Length(), "LevelData");
- levelData[level].spawnBuffer = parser.ParseFloat();
- levelData[level].needToWin = parser.ParseInt(); //Required Destroyed
- }
- void idGameSSDWindow::ParseAsteroidData(int level, const idStr& asteroidDataString) {
- idParser parser;
- idToken token;
- parser.LoadMemory(asteroidDataString.c_str(), asteroidDataString.Length(), "AsteroidData");
- asteroidData[level].speedMin = parser.ParseFloat(); //Speed Min
- asteroidData[level].speedMax = parser.ParseFloat(); //Speed Max
- asteroidData[level].sizeMin = parser.ParseFloat(); //Size Min
- asteroidData[level].sizeMax = parser.ParseFloat(); //Size Max
- asteroidData[level].rotateMin = parser.ParseFloat(); //Rotate Min (rotations per second)
- asteroidData[level].rotateMax = parser.ParseFloat(); //Rotate Max (rotations per second)
- asteroidData[level].spawnMin = parser.ParseInt(); //Spawn Min
- asteroidData[level].spawnMax = parser.ParseInt(); //Spawn Max
- asteroidData[level].asteroidHealth = parser.ParseInt(); //Health of the asteroid
- asteroidData[level].asteroidDamage = parser.ParseInt(); //Asteroid Damage
- asteroidData[level].asteroidPoints = parser.ParseInt(); //Points awarded for destruction
- }
- void idGameSSDWindow::ParsePowerupData(int level, const idStr& powerupDataString) {
-
- idParser parser;
- idToken token;
- parser.LoadMemory(powerupDataString.c_str(), powerupDataString.Length(), "PowerupData");
- powerupData[level].speedMin = parser.ParseFloat(); //Speed Min
- powerupData[level].speedMax = parser.ParseFloat(); //Speed Max
- powerupData[level].rotateMin = parser.ParseFloat(); //Rotate Min (rotations per second)
- powerupData[level].rotateMax = parser.ParseFloat(); //Rotate Max (rotations per second)
- powerupData[level].spawnMin = parser.ParseInt(); //Spawn Min
- powerupData[level].spawnMax = parser.ParseInt(); //Spawn Max
- }
- void idGameSSDWindow::ParseWeaponData(int weapon, const idStr& weaponDataString) {
- idParser parser;
- idToken token;
- parser.LoadMemory(weaponDataString.c_str(), weaponDataString.Length(), "WeaponData");
- weaponData[weapon].speed = parser.ParseFloat();
- weaponData[weapon].damage = parser.ParseFloat();
- weaponData[weapon].size = parser.ParseFloat();
- }
- void idGameSSDWindow::ParseAstronautData(int level, const idStr& astronautDataString) {
-
- idParser parser;
- idToken token;
- parser.LoadMemory(astronautDataString.c_str(), astronautDataString.Length(), "AstronautData");
- astronautData[level].speedMin = parser.ParseFloat(); //Speed Min
- astronautData[level].speedMax = parser.ParseFloat(); //Speed Max
- astronautData[level].rotateMin = parser.ParseFloat(); //Rotate Min (rotations per second)
- astronautData[level].rotateMax = parser.ParseFloat(); //Rotate Max (rotations per second)
- astronautData[level].spawnMin = parser.ParseInt(); //Spawn Min
- astronautData[level].spawnMax = parser.ParseInt(); //Spawn Max
- astronautData[level].health = parser.ParseInt(); //Health of the asteroid
- astronautData[level].points = parser.ParseInt(); //Asteroid Damage
- astronautData[level].penalty = parser.ParseInt(); //Points awarded for destruction
- }
- void idGameSSDWindow::CommonInit() {
- crosshair.InitCrosshairs();
- beginLevel = false;
- resetGame = false;
- continueGame = false;
- refreshGuiData = false;
- ssdTime = 0;
- levelCount = 0;
- weaponCount = 0;
- screenBounds = idBounds(idVec3(-320,-240,0), idVec3(320,240,0));
- superBlasterTimeout = 0;
- currentSound = 0;
- //Precahce all assets that are loaded dynamically
- declManager->FindMaterial(ASTEROID_MATERIAL);
- declManager->FindMaterial(ASTRONAUT_MATERIAL);
- for(int i = 0; i < EXPLOSION_MATERIAL_COUNT; i++) {
- declManager->FindMaterial(explosionMaterials[i]);
- }
- declManager->FindMaterial(PROJECTILE_MATERIAL);
- for(int i = 0; i < POWERUP_MATERIAL_COUNT; i++) {
- declManager->FindMaterial(powerupMaterials[i][0]);
- declManager->FindMaterial(powerupMaterials[i][1]);
- }
-
- // Precache sounds
- declManager->FindSound( "arcade_blaster" );
- declManager->FindSound( "arcade_capture " );
- declManager->FindSound( "arcade_explode" );
- ResetGameStats();
- }
- void idGameSSDWindow::ResetGameStats() {
- ResetEntities();
- //Reset the gamestats structure
- memset(&gameStats, 0, sizeof(gameStats));
- gameStats.health = 100;
- }
- void idGameSSDWindow::ResetLevelStats() {
-
- ResetEntities();
-
- //Reset the level statistics structure
- memset(&gameStats.levelStats, 0, sizeof(gameStats.levelStats));
-
- }
- void idGameSSDWindow::ResetEntities() {
- //Destroy all of the entities
- for(int i = 0; i < entities.Num(); i++) {
- entities[i]->DestroyEntity();
- }
- entities.Clear();
- }
- void idGameSSDWindow::StartGame() {
-
- gameStats.gameRunning = true;
- }
- void idGameSSDWindow::StopGame() {
-
- gameStats.gameRunning = false;
- }
- void idGameSSDWindow::GameOver() {
-
- StopGame();
- gui->HandleNamedEvent("gameOver");
- }
- void idGameSSDWindow::BeginLevel(int level) {
-
- ResetLevelStats();
- gameStats.currentLevel = level;
- StartGame();
- }
- /**
- * Continue game resets the players health
- */
- void idGameSSDWindow::ContinueGame() {
- gameStats.health = 100;
- StartGame();
- }
- void idGameSSDWindow::LevelComplete() {
-
- gameStats.prebonusscore = gameStats.score;
- // Add the bonuses
- int accuracy;
- if( !gameStats.levelStats.shotCount ) {
- accuracy = 0;
- } else {
- accuracy = (int)( ( (float)gameStats.levelStats.hitCount / (float)gameStats.levelStats.shotCount ) * 100.0f );
- }
- int accuracyPoints = Max( 0, accuracy - 50 ) * 20;
- gui->SetStateString("player_accuracy_score", va("%i", accuracyPoints));
- gameStats.score += accuracyPoints;
- int saveAccuracy;
- int totalAst = gameStats.levelStats.savedAstronauts + gameStats.levelStats.killedAstronauts;
- if( !totalAst ) {
- saveAccuracy = 0;
- } else {
- saveAccuracy = (int)( ( (float)gameStats.levelStats.savedAstronauts / (float)totalAst ) * 100.0f );
- }
- accuracyPoints = Max( 0, saveAccuracy - 50 ) * 20;
- gui->SetStateString("save_accuracy_score", va("%i", accuracyPoints));
- gameStats.score += accuracyPoints;
- StopSuperBlaster();
- gameStats.nextLevel++;
- if(gameStats.nextLevel >= levelCount) {
- //Have they beaten the game
- GameComplete();
- } else {
- //Make sure we don't go above the levelcount
- //min(gameStats.nextLevel, levelCount-1);
- StopGame();
- gui->HandleNamedEvent("levelComplete");
- }
- }
- void idGameSSDWindow::GameComplete() {
- StopGame();
- gui->HandleNamedEvent("gameComplete");
- }
- void idGameSSDWindow::UpdateGame() {
- //Check to see if and functions where called by the gui
- if(beginLevel == true) {
- beginLevel = false;
- BeginLevel(gameStats.nextLevel);
- }
- if(resetGame == true) {
- resetGame = false;
- ResetGameStats();
- }
- if(continueGame == true) {
- continueGame = false;
- ContinueGame();
- }
- if(refreshGuiData == true) {
- refreshGuiData = false;
- RefreshGuiData();
- }
- if(gameStats.gameRunning) {
- //We assume an upate every 16 milliseconds
- ssdTime += 16;
- if(superBlasterTimeout && ssdTime > superBlasterTimeout) {
- StopSuperBlaster();
- }
- //Find if we are targeting and enemy
- idVec2 cursor;
- //GetCursor(cursor);
- cursor.x = gui->CursorX();
- cursor.y = gui->CursorY();
- gameStats.levelStats.targetEnt = EntityHitTest(cursor);
- //Update from back to front
- for(int i = entities.Num()-1; i >= 0; i--) {
- entities[i]->Update();
- }
- CheckForHits();
- //Delete entities that need to be deleted
- for(int i = entities.Num()-1; i >= 0; i--) {
- if(entities[i]->destroyed) {
- SSDEntity* ent = entities[i];
- ent->DestroyEntity();
- entities.RemoveIndex(i);
- }
- }
- //Check if we can spawn an asteroid
- SpawnAsteroid();
- //Check if we should spawn an astronaut
- SpawnAstronaut();
- //Check if we should spawn an asteroid
- SpawnPowerup();
- }
- }
- void idGameSSDWindow::CheckForHits() {
-
- //See if the entity has gotten close enough
- for(int i = 0; i < entities.Num(); i++) {
- SSDEntity* ent = entities[i];
- if(ent->position.z <= Z_NEAR) {
- if(!ent->noPlayerDamage) {
- //Is the object still in the screen
- idVec3 entPos = ent->position;
- entPos.z = 0;
- idBounds entBounds(entPos);
- entBounds.ExpandSelf(ent->hitRadius);
- if(screenBounds.IntersectsBounds(entBounds)) {
- ent->OnStrikePlayer();
- //The entity hit the player figure out what is was and act appropriately
- if(ent->type == SSD_ENTITY_ASTEROID) {
- AsteroidStruckPlayer(static_cast<SSDAsteroid*>(ent));
- } else if(ent->type == SSD_ENTITY_ASTRONAUT) {
- AstronautStruckPlayer(static_cast<SSDAstronaut*>(ent));
- }
- } else {
- //Tag for removal later in the frame
- ent->destroyed = true;
- }
- }
- }
- }
- }
- void idGameSSDWindow::ZOrderEntities() {
- //Z-Order the entities
- //Using a simple sorting method
- for (int i = entities.Num()-1; i >= 0; i--) {
- bool flipped = false;
- for (int j = 0; j<i ; j++) {
- if (entities[j]->position.z > entities[j+1]->position.z) {
- SSDEntity* ent = entities[j];
- entities[j] = entities[j+1];
- entities[j+1] = ent;
- flipped = true;
- }
- }
- if (!flipped) {
- //Jump out because it is sorted
- break;
- }
- }
- }
- void idGameSSDWindow::SpawnAsteroid() {
- int currentTime = ssdTime;
- if(currentTime < gameStats.levelStats.nextAsteroidSpawnTime) {
- //Not time yet
- return;
- }
- //Lets spawn it
- idVec3 startPosition;
- float spawnBuffer = levelData[gameStats.currentLevel].spawnBuffer*2.0f;
- startPosition.x = random.RandomInt(V_WIDTH+spawnBuffer)-((V_WIDTH/2.0f)+spawnBuffer);
- startPosition.y = random.RandomInt(V_HEIGHT+spawnBuffer)-((V_HEIGHT/2.0f)+spawnBuffer);
- startPosition.z = ENTITY_START_DIST;
- float speed = random.RandomInt(asteroidData[gameStats.currentLevel].speedMax - asteroidData[gameStats.currentLevel].speedMin) + asteroidData[gameStats.currentLevel].speedMin;
- float size = random.RandomInt(asteroidData[gameStats.currentLevel].sizeMax - asteroidData[gameStats.currentLevel].sizeMin) + asteroidData[gameStats.currentLevel].sizeMin;
- float rotate = (random.RandomFloat() * (asteroidData[gameStats.currentLevel].rotateMax - asteroidData[gameStats.currentLevel].rotateMin)) + asteroidData[gameStats.currentLevel].rotateMin;
-
- SSDAsteroid* asteroid = SSDAsteroid::GetNewAsteroid(this, startPosition, idVec2(size, size), speed, rotate, asteroidData[gameStats.currentLevel].asteroidHealth);
- entities.Append(asteroid);
-
- gameStats.levelStats.nextAsteroidSpawnTime = currentTime + random.RandomInt(asteroidData[gameStats.currentLevel].spawnMax - asteroidData[gameStats.currentLevel].spawnMin) + asteroidData[gameStats.currentLevel].spawnMin;
- }
- void idGameSSDWindow::FireWeapon(int key) {
- idVec2 cursorWorld = GetCursorWorld();
- idVec2 cursor;
- //GetCursor(cursor);
- cursor.x = gui->CursorX();
- cursor.y = gui->CursorY();
- if(key == K_MOUSE1) {
-
- gameStats.levelStats.shotCount++;
-
- if(gameStats.levelStats.targetEnt) {
- //Aim the projectile from the bottom of the screen directly at the ent
- //SSDProjectile* newProj = new SSDProjectile(this, idVec3(320,0,0), gameStats.levelStats.targetEnt->position, weaponData[gameStats.currentWeapon].speed, weaponData[gameStats.currentWeapon].size);
- SSDProjectile* newProj = SSDProjectile::GetNewProjectile(this, idVec3(0,-180,0), gameStats.levelStats.targetEnt->position, weaponData[gameStats.currentWeapon].speed, weaponData[gameStats.currentWeapon].size);
- entities.Append(newProj);
- //newProj = SSDProjectile::GetNewProjectile(this, idVec3(-320,-0,0), gameStats.levelStats.targetEnt->position, weaponData[gameStats.currentWeapon].speed, weaponData[gameStats.currentWeapon].size);
- //entities.Append(newProj);
- //We hit something
- gameStats.levelStats.hitCount++;
- gameStats.levelStats.targetEnt->OnHit(key);
- if(gameStats.levelStats.targetEnt->type == SSD_ENTITY_ASTEROID) {
- HitAsteroid(static_cast<SSDAsteroid*>(gameStats.levelStats.targetEnt), key);
- } else if(gameStats.levelStats.targetEnt->type == SSD_ENTITY_ASTRONAUT) {
- HitAstronaut(static_cast<SSDAstronaut*>(gameStats.levelStats.targetEnt), key);
- } else if(gameStats.levelStats.targetEnt->type == SSD_ENTITY_ASTRONAUT) {
- }
- } else {
- ////Aim the projectile at the cursor position all the way to the far clipping
- //SSDProjectile* newProj = SSDProjectile::GetNewProjectile(this, idVec3(0,-180,0), idVec3(cursorWorld.x, cursorWorld.y, (Z_FAR-Z_NEAR)/2.0f), weaponData[gameStats.currentWeapon].speed, weaponData[gameStats.currentWeapon].size);
- //Aim the projectile so it crosses the cursor 1/4 of screen
- idVec3 vec = idVec3(cursorWorld.x, cursorWorld.y, (Z_FAR-Z_NEAR)/8.0f);
- vec *= 8;
- SSDProjectile* newProj = SSDProjectile::GetNewProjectile(this, idVec3(0,-180,0), vec, weaponData[gameStats.currentWeapon].speed, weaponData[gameStats.currentWeapon].size);
- entities.Append(newProj);
-
- }
- //Play the blaster sound
- PlaySound("arcade_blaster");
- } /*else if (key == K_MOUSE2) {
- if(gameStats.levelStats.targetEnt) {
- if(gameStats.levelStats.targetEnt->type == SSD_ENTITY_ASTRONAUT) {
- HitAstronaut(static_cast<SSDAstronaut*>(gameStats.levelStats.targetEnt), key);
- }
- }
- }*/
- }
- SSDEntity* idGameSSDWindow::EntityHitTest(const idVec2& pt) {
- for(int i = 0; i < entities.Num(); i++) {
- //Since we ZOrder the entities every frame we can stop at the first entity we hit.
- //ToDo: Make sure this assumption is true
- if(entities[i]->HitTest(pt)) {
- return entities[i];
- }
- }
- return NULL;
- }
- void idGameSSDWindow::HitAsteroid(SSDAsteroid* asteroid, int key) {
-
- asteroid->health -= weaponData[gameStats.currentWeapon].damage;
- if(asteroid->health <= 0) {
-
- //The asteroid has been destroyed
- SSDExplosion* explosion = SSDExplosion::GetNewExplosion(this, asteroid->position, asteroid->size*2, 300, SSDExplosion::EXPLOSION_NORMAL, asteroid);
- entities.Append(explosion);
- PlaySound("arcade_explode");
- AddScore(asteroid, asteroidData[gameStats.currentLevel].asteroidPoints);
- //Don't let the player hit it anymore because
- asteroid->noHit = true;
- gameStats.levelStats.destroyedAsteroids++;
- //if(gameStats.levelStats.destroyedAsteroids >= levelData[gameStats.currentLevel].needToWin) {
- // LevelComplete();
- //}
- } else {
- //This was a damage hit so create a real small quick explosion
- SSDExplosion* explosion = SSDExplosion::GetNewExplosion(this, asteroid->position, asteroid->size/2.0f, 200, SSDExplosion::EXPLOSION_NORMAL, asteroid, false, false);
- entities.Append(explosion);
- }
- }
- void idGameSSDWindow::AsteroidStruckPlayer(SSDAsteroid* asteroid) {
- asteroid->noPlayerDamage = true;
- asteroid->noHit = true;
-
- AddDamage(asteroidData[gameStats.currentLevel].asteroidDamage);
- SSDExplosion* explosion = SSDExplosion::GetNewExplosion(this, asteroid->position, asteroid->size*2, 300, SSDExplosion::EXPLOSION_NORMAL, asteroid);
- entities.Append(explosion);
- PlaySound("arcade_explode");
- }
- void idGameSSDWindow::AddScore(SSDEntity* ent, int points) {
- SSDPoints* pointsEnt;
-
- if(points > 0) {
- pointsEnt = SSDPoints::GetNewPoints(this, ent, points, 1000, 50, idVec4(0,1,0,1));
- } else {
- pointsEnt = SSDPoints::GetNewPoints(this, ent, points, 1000, 50, idVec4(1,0,0,1));
- }
- entities.Append(pointsEnt);
- gameStats.score += points;
- gui->SetStateString( "player_score", va("%i", gameStats.score ) );
- }
- void idGameSSDWindow::AddDamage(int damage) {
- gameStats.health -= damage;
- gui->SetStateString( "player_health", va("%i", gameStats.health ) );
- gui->HandleNamedEvent( "playerDamage" );
- if(gameStats.health <= 0) {
- //The player is dead
- GameOver();
- }
- }
- void idGameSSDWindow::AddHealth(int health) {
- gameStats.health += health;
- gameStats.health = Min( 100, gameStats.health );
- }
- void idGameSSDWindow::OnNuke() {
-
- gui->HandleNamedEvent("nuke");
- //Destory All Asteroids
- for(int i = 0 ; i < entities.Num(); i++) {
- if(entities[i]->type == SSD_ENTITY_ASTEROID) {
-
- //The asteroid has been destroyed
- SSDExplosion* explosion = SSDExplosion::GetNewExplosion(this, entities[i]->position, entities[i]->size*2, 300, SSDExplosion::EXPLOSION_NORMAL, entities[i]);
- entities.Append(explosion);
- AddScore(entities[i], asteroidData[gameStats.currentLevel].asteroidPoints);
- //Don't let the player hit it anymore because
- entities[i]->noHit = true;
- gameStats.levelStats.destroyedAsteroids++;
- }
- }
- PlaySound("arcade_explode");
-
- //Check to see if a nuke ends the level
- /*if(gameStats.levelStats.destroyedAsteroids >= levelData[gameStats.currentLevel].needToWin) {
- LevelComplete();
- }*/
- }
- void idGameSSDWindow::OnRescueAll() {
-
- gui->HandleNamedEvent("rescueAll");
- //Rescue All Astronauts
- for(int i = 0 ; i < entities.Num(); i++) {
- if(entities[i]->type == SSD_ENTITY_ASTRONAUT) {
- AstronautStruckPlayer((SSDAstronaut*)entities[i]);
- }
- }
- }
- void idGameSSDWindow::OnSuperBlaster() {
-
- StartSuperBlaster();
- }
- void idGameSSDWindow::RefreshGuiData() {
- gui->SetStateString("nextLevel", va("%i", gameStats.nextLevel+1));
- gui->SetStateString("currentLevel", va("%i", gameStats.currentLevel+1));
- float accuracy;
- if(!gameStats.levelStats.shotCount) {
- accuracy = 0;
- } else {
- accuracy = ((float)gameStats.levelStats.hitCount/(float)gameStats.levelStats.shotCount)*100.0f;
- }
- gui->SetStateString( "player_accuracy", va("%d%%", (int)accuracy));
- float saveAccuracy;
- int totalAst = gameStats.levelStats.savedAstronauts + gameStats.levelStats.killedAstronauts;
- if(!totalAst) {
- saveAccuracy = 0;
- } else {
- saveAccuracy = ((float)gameStats.levelStats.savedAstronauts/(float)totalAst)*100.0f;
- }
- gui->SetStateString( "save_accuracy", va("%d%%", (int)saveAccuracy));
- if(gameStats.levelStats.targetEnt) {
- int dist = (gameStats.levelStats.targetEnt->position.z/100.0f);
- dist *= 100;
- gui->SetStateString("target_info", va("%i meters", dist));
- } else {
- gui->SetStateString("target_info", "No Target");
- }
- gui->SetStateString( "player_health", va("%i", gameStats.health ) );
- gui->SetStateString( "player_score", va("%i", gameStats.score ) );
- gui->SetStateString( "player_prebonusscore", va("%i", gameStats.prebonusscore ) );
- gui->SetStateString( "level_complete", va("%i/%i", gameStats.levelStats.savedAstronauts, levelData[gameStats.currentLevel].needToWin ));
- if(superBlasterTimeout) {
- float timeRemaining = (superBlasterTimeout - ssdTime)/1000.0f;
- gui->SetStateString("super_blaster_time", va("%.2f", timeRemaining));
- }
- }
- idVec2 idGameSSDWindow::GetCursorWorld() {
-
- idVec2 cursor;
- //GetCursor(cursor);
- cursor.x = gui->CursorX();
- cursor.y = gui->CursorY();
- cursor.x = cursor.x - 0.5f * V_WIDTH;
- cursor.y = -(cursor.y - 0.5f * V_HEIGHT);
- return cursor;
- }
- void idGameSSDWindow::SpawnAstronaut() {
-
- int currentTime = ssdTime;
- if(currentTime < gameStats.levelStats.nextAstronautSpawnTime) {
- //Not time yet
- return;
- }
- //Lets spawn it
- idVec3 startPosition;
- startPosition.x = random.RandomInt(V_WIDTH)-(V_WIDTH/2.0f);
- startPosition.y = random.RandomInt(V_HEIGHT)-(V_HEIGHT/2.0f);
- startPosition.z = ENTITY_START_DIST;
- float speed = random.RandomInt(astronautData[gameStats.currentLevel].speedMax - astronautData[gameStats.currentLevel].speedMin) + astronautData[gameStats.currentLevel].speedMin;
- float rotate = (random.RandomFloat() * (astronautData[gameStats.currentLevel].rotateMax - astronautData[gameStats.currentLevel].rotateMin)) + astronautData[gameStats.currentLevel].rotateMin;
- SSDAstronaut* astronaut = SSDAstronaut::GetNewAstronaut(this, startPosition, speed, rotate, astronautData[gameStats.currentLevel].health);
- entities.Append(astronaut);
- gameStats.levelStats.nextAstronautSpawnTime = currentTime + random.RandomInt(astronautData[gameStats.currentLevel].spawnMax - astronautData[gameStats.currentLevel].spawnMin) + astronautData[gameStats.currentLevel].spawnMin;
- }
- void idGameSSDWindow::HitAstronaut(SSDAstronaut* astronaut, int key) {
- if(key == K_MOUSE1) {
- astronaut->health -= weaponData[gameStats.currentWeapon].damage;
- if(astronaut->health <= 0) {
- gameStats.levelStats.killedAstronauts++;
- //The astronaut has been destroyed
- SSDExplosion* explosion = SSDExplosion::GetNewExplosion(this, astronaut->position, astronaut->size*2, 300, SSDExplosion::EXPLOSION_NORMAL, astronaut);
- entities.Append(explosion);
- PlaySound("arcade_explode");
- //Add the penalty for killing the astronaut
- AddScore(astronaut, astronautData[gameStats.currentLevel].penalty);
- //Don't let the player hit it anymore
- astronaut->noHit = true;
- } else {
- //This was a damage hit so create a real small quick explosion
- SSDExplosion* explosion = SSDExplosion::GetNewExplosion(this, astronaut->position, astronaut->size/2.0f, 200, SSDExplosion::EXPLOSION_NORMAL, astronaut, false, false);
- entities.Append(explosion);
- }
- }
- }
- void idGameSSDWindow::AstronautStruckPlayer(SSDAstronaut* astronaut) {
- gameStats.levelStats.savedAstronauts++;
- astronaut->noPlayerDamage = true;
- astronaut->noHit = true;
- //We are saving an astronaut
- SSDExplosion* explosion = SSDExplosion::GetNewExplosion(this, astronaut->position, astronaut->size*2, 300, SSDExplosion::EXPLOSION_TELEPORT, astronaut);
- entities.Append(explosion);
- PlaySound("arcade_capture");
- //Give the player points for saving the astronaut
- AddScore(astronaut, astronautData[gameStats.currentLevel].points);
- if(gameStats.levelStats.savedAstronauts >= levelData[gameStats.currentLevel].needToWin) {
- LevelComplete();
- }
- }
- void idGameSSDWindow::SpawnPowerup() {
- int currentTime = ssdTime;
- if(currentTime < gameStats.levelStats.nextPowerupSpawnTime) {
- //Not time yet
- return;
- }
- float speed = random.RandomInt(powerupData[gameStats.currentLevel].speedMax - powerupData[gameStats.currentLevel].speedMin) + powerupData[gameStats.currentLevel].speedMin;
- float rotate = (random.RandomFloat() * (powerupData[gameStats.currentLevel].rotateMax - powerupData[gameStats.currentLevel].rotateMin)) + powerupData[gameStats.currentLevel].rotateMin;
- SSDPowerup* powerup = SSDPowerup::GetNewPowerup(this, speed, rotate);
- entities.Append(powerup);
- gameStats.levelStats.nextPowerupSpawnTime = currentTime + random.RandomInt(powerupData[gameStats.currentLevel].spawnMax - powerupData[gameStats.currentLevel].spawnMin) + powerupData[gameStats.currentLevel].spawnMin;
- }
- void idGameSSDWindow::StartSuperBlaster() {
-
- gui->HandleNamedEvent("startSuperBlaster");
- gameStats.currentWeapon = 1;
- superBlasterTimeout = ssdTime + 10000;
- }
- void idGameSSDWindow::StopSuperBlaster() {
- gui->HandleNamedEvent("stopSuperBlaster");
- gameStats.currentWeapon = 0;
- superBlasterTimeout = 0;
- }
- SSDEntity* idGameSSDWindow::GetSpecificEntity(int type, int id) {
- SSDEntity* ent = NULL;
- switch(type) {
- case SSD_ENTITY_ASTEROID:
- ent = SSDAsteroid::GetSpecificAsteroid(id);
- break;
- case SSD_ENTITY_ASTRONAUT:
- ent = SSDAstronaut::GetSpecificAstronaut(id);
- break;
- case SSD_ENTITY_EXPLOSION:
- ent = SSDExplosion::GetSpecificExplosion(id);
- break;
- case SSD_ENTITY_POINTS:
- ent = SSDPoints::GetSpecificPoints(id);
- break;
- case SSD_ENTITY_PROJECTILE:
- ent = SSDProjectile::GetSpecificProjectile(id);
- break;
- case SSD_ENTITY_POWERUP:
- ent = SSDPowerup::GetSpecificPowerup(id);
- break;
- }
- return ent;
- }
- #define MAX_SOUND_CHANNEL 8
- void idGameSSDWindow::PlaySound(const char* sound) {
- session->sw->PlayShaderDirectly(sound, currentSound);
- currentSound++;
- if(currentSound >= MAX_SOUND_CHANNEL) {
- currentSound = 0;
- }
- }
|