|
From: julien r. <jul...@us...> - 2004-11-13 23:38:18
|
Update of /cvsroot/epfl/tggame In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv920 Modified Files: game.cc game.h playercontroller.cc playercontroller.h Added Files: weapon.cc weapon.h Log Message: decals + classe weapon Index: game.cc =================================================================== RCS file: /cvsroot/epfl/tggame/game.cc,v retrieving revision 1.30 retrieving revision 1.31 diff -C2 -d -r1.30 -r1.31 *** game.cc 12 Nov 2004 12:13:17 -0000 1.30 --- game.cc 13 Nov 2004 23:38:08 -0000 1.31 *************** *** 112,121 **** //creation de l'arme ! MD5Instance* pModel = Engine::pMeshManager->LoadInstance("machinegun"); pModel->SetAnimation("idle"); pModel->bCamera = true; pModel->SetRotation(Quaternion(90, Vector3(0,0,1))); pModel->SetPosition(Vector3(5,0,-5)); ! pSceneManager->AddWorldObject(pModel); //creation du joueur --- 112,121 ---- //creation de l'arme ! /*MD5Instance* pModel = Engine::pMeshManager->LoadInstance("machinegun"); pModel->SetAnimation("idle"); pModel->bCamera = true; pModel->SetRotation(Quaternion(90, Vector3(0,0,1))); pModel->SetPosition(Vector3(5,0,-5)); ! pSceneManager->AddWorldObject(pModel);*/ //creation du joueur Index: playercontroller.h =================================================================== RCS file: /cvsroot/epfl/tggame/playercontroller.h,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** playercontroller.h 12 Nov 2004 12:13:17 -0000 1.7 --- playercontroller.h 13 Nov 2004 23:38:08 -0000 1.8 *************** *** 5,8 **** --- 5,9 ---- #include "controller.h" + #include "weapon.h" using namespace tg; *************** *** 19,23 **** static int STRAFERIGHT; ! DebugSphere* pSphere; public: PlayerController (Pawn*); --- 20,26 ---- static int STRAFERIGHT; ! Weapon* pWeapon; ! bool bFire; ! //DebugSphere* pSphere; public: PlayerController (Pawn*); Index: playercontroller.cc =================================================================== RCS file: /cvsroot/epfl/tggame/playercontroller.cc,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** playercontroller.cc 12 Nov 2004 12:13:17 -0000 1.14 --- playercontroller.cc 13 Nov 2004 23:38:08 -0000 1.15 *************** *** 13,33 **** { Game::pSelf->GetConsole()->Register("clip", this, CLIP); ! pSphere = new DebugSphere (); ! Game::pSelf->GetSceneManager()->AddDebugSphere(pSphere); } void PlayerController::Think (float eTime) { //Test des tirs { Vector3 vTarget = pPawn->GetRotation().GetZAxis(); Vector3 vPosition = pPawn->GetPosition()+vViewOffset; ! vTarget = vPosition - vTarget*1000000; CollisionResult cR = Game::pSelf->Trace(vPosition, vTarget, pPawn); pSphere->vPosition = cR.EndPoint; if (cR.pNode != NULL && cR.pNode->GetPhysicCallBack() != NULL) ! cR.pNode->GetPhysicCallBack()->Collide(NULL, cR.EndPoint, cR.Normal); } --- 13,41 ---- { Game::pSelf->GetConsole()->Register("clip", this, CLIP); ! /*pSphere = new DebugSphere (); ! Game::pSelf->GetSceneManager()->AddDebugSphere(pSphere);*/ ! pWeapon = new Weapon (); ! bFire = false; } void PlayerController::Think (float eTime) { + pWeapon->Think(eTime); //Test des tirs + if (bFire) { Vector3 vTarget = pPawn->GetRotation().GetZAxis(); Vector3 vPosition = pPawn->GetPosition()+vViewOffset; ! pWeapon->Fire (vPosition, vTarget, pPawn); ! /* vTarget = vPosition - vTarget*1000000; CollisionResult cR = Game::pSelf->Trace(vPosition, vTarget, pPawn); pSphere->vPosition = cR.EndPoint; + if (cR.pNode == NULL) //on a touche la map + Game::pSelf->GetSceneManager()->GetDecalManager()->AddDecal(cR.EndPoint, cR.Normal, 1.0f, 1.0f, Engine::pTextureManager->LoadTexture("data/textures/decals/mgun.bmp", TG_TEXTURE_2D), 10.0f); + if (cR.pNode != NULL && cR.pNode->GetPhysicCallBack() != NULL) ! cR.pNode->GetPhysicCallBack()->Collide(NULL, cR.EndPoint, cR.Normal);*/ } *************** *** 75,78 **** --- 83,97 ---- void PlayerController::EventHandler (tgEvent& e) { + //souris + if (e.type == evMouseButtonDown) + { + bFire = true; + } + else if (e.type == evMouseButtonUp) + { + bFire = false; + } + + //clavier if (e.type == evKeyDown) { Index: game.h =================================================================== RCS file: /cvsroot/epfl/tggame/game.h,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** game.h 12 Nov 2004 12:13:17 -0000 1.10 --- game.h 13 Nov 2004 23:38:08 -0000 1.11 *************** *** 60,63 **** --- 60,64 ---- inline PhysicEngine* GetPhysicEngine () { return pPhysicEngine; } inline Console* GetConsole () { return pConsole; } + inline Timer* GetTimer() { return pTimer; } /** --- NEW FILE: weapon.h --- #ifndef _TGWEAPON_H #define _TGWEAPON_H #include "pawn.h" #include "controller.h" #include <vector3.h> #include <md5instance.h> using namespace tg; class Weapon { public: Weapon (); ~Weapon (); void Fire (const Vector3& vPosition, const Vector3& vTarget, Pawn* p); void Think (float eTime); protected: MD5Instance* pModel; float fCoolDown; float fFireRate; }; #endif --- NEW FILE: weapon.cc --- #include "weapon.h" #include "game.h" Weapon::Weapon () { pModel = Engine::pMeshManager->LoadInstance("machinegun"); pModel->SetAnimation("idle"); pModel->bCamera = true; pModel->SetRotation(Quaternion(90, Vector3(0,0,1))); pModel->SetPosition(Vector3(5,0,-5)); Game::pSelf->GetSceneManager()->AddWorldObject(pModel); fFireRate = 0.1f; fCoolDown = fFireRate; } Weapon::~Weapon () { Game::pSelf->GetSceneManager()->RemoveWorldObject(pModel); delete pModel; } void Weapon::Think (float eTime) { if (fCoolDown > 0) fCoolDown -= eTime; else fCoolDown = 0.0f; } void Weapon::Fire (const Vector3& vPosition, const Vector3& vTarget, Pawn* p) { if (fCoolDown > 0.0f) return; fCoolDown = fFireRate; Vector3 target = vPosition - vTarget*10000; CollisionResult cR = Game::pSelf->Trace(vPosition, target, p); if (cR.pNode == NULL) //on a touche la map Game::pSelf->GetSceneManager()->GetDecalManager()->AddDecal(cR.EndPoint, cR.Normal, 1.0f, 1.0f, Engine::pTextureManager->LoadTexture("data/textures/decals/mgun.bmp", TG_TEXTURE_2D), 10.0f); if (cR.pNode != NULL && cR.pNode->GetPhysicCallBack() != NULL) //on a touche un objet cR.pNode->GetPhysicCallBack()->Collide(NULL, cR.EndPoint, cR.Normal); } |