summaryrefslogtreecommitdiffstats
path: root/MatchBloxEngine/MatchBloxEngine/C_MatchBloxEngine.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'MatchBloxEngine/MatchBloxEngine/C_MatchBloxEngine.cpp')
-rw-r--r--MatchBloxEngine/MatchBloxEngine/C_MatchBloxEngine.cpp186
1 files changed, 160 insertions, 26 deletions
diff --git a/MatchBloxEngine/MatchBloxEngine/C_MatchBloxEngine.cpp b/MatchBloxEngine/MatchBloxEngine/C_MatchBloxEngine.cpp
index 7e17b1b..80767b8 100644
--- a/MatchBloxEngine/MatchBloxEngine/C_MatchBloxEngine.cpp
+++ b/MatchBloxEngine/MatchBloxEngine/C_MatchBloxEngine.cpp
@@ -15,7 +15,9 @@
#include "bitmap.h"
C_MatchBloxEngine::C_MatchBloxEngine(const char *f_strModelPath,
- const char *f_strLogFile)
+ const char *f_strLogFile,
+ GameSettings f_GameSettings)
+: m_GameSettings(f_GameSettings)
{
//create logger
@@ -37,19 +39,10 @@ C_MatchBloxEngine::C_MatchBloxEngine(const char *f_strModelPath,
//init vars
m_CurrentBox = BS_SMALL;
- //debug
- m_pBox[0]->SetPos(0.0, -5.0, -15.0);
- m_pBox[0]->SetRot(45.0, 0.0, 0.0);
- m_pBox[0]->RandomizeTiles();
-
- m_pBlock[0]->SetPos(-6.0, 1.0, -10.0);
- m_pBlock[0]->SetRot(90.0, 0.0, 0.0);
- m_pBlock[1]->SetPos(-2.0, 1.0, -10.0);
- m_pBlock[1]->SetRot(90.0, 0.0, 0.0);
- m_pBlock[2]->SetPos(2.0, 1.0, -10.0);
- m_pBlock[2]->SetRot(90.0, 0.0, 0.0);
- m_pBlock[3]->SetPos(6.0, 1.0, -10.0);
- m_pBlock[3]->SetRot(90.0, 0.0, 0.0);
+ //init the world bounding box
+ m_WorldBox.m_Min = Vect3D_t(-50.0, -50.0, -50.0);
+ m_WorldBox.m_Max = Vect3D_t(50.0, 50.0, 0.0);
+
}
C_MatchBloxEngine::~C_MatchBloxEngine()
@@ -60,10 +53,28 @@ C_MatchBloxEngine::~C_MatchBloxEngine()
DeleteModels();
}
-GameResult C_MatchBloxEngine::GameStep(msgQueue &f_Queue)
+GameResult C_MatchBloxEngine::ProcessMsgs(msgQueue &f_Queue)
{
+ msgStruct l_msg;
+
//process message queue
- return GR_ERROR;
+ while (!f_Queue.empty())
+ {
+ //get the first msg
+ l_msg = f_Queue.front();
+ f_Queue.pop();
+
+ switch (l_msg.m_MessageType)
+ {
+ case WII_CURSOR_MOVE:
+
+ break;
+
+ case WII_BUTTON_PRESS:
+ break;
+ }
+ }
+ return GR_BUSY;
}
void C_MatchBloxEngine::Render_Basics(unsigned int f_uiElapsedTime)
@@ -71,10 +82,13 @@ void C_MatchBloxEngine::Render_Basics(unsigned int f_uiElapsedTime)
//render the environment
m_pEnvMap->Render();
- m_pBox[(intptr_t)m_CurrentBox]->Render();
- for (int i=0; i<4; i++)
- m_pBlock[i]->Render(f_uiElapsedTime);
-// m_pHand->Render(f_uiElapsedTime);
+ if (m_pCurrentSession)
+ {
+ m_pBox[(int)m_pCurrentSession->m_BoxSize]->Render();
+ for (int i=0; i<4; i++)
+ m_pBlock[i]->Render(f_uiElapsedTime);
+ // m_pHand->Render(f_uiElapsedTime);
+ }
}
void C_MatchBloxEngine::Render(unsigned int f_uiElapsedTime)
@@ -148,15 +162,17 @@ bool C_MatchBloxEngine::NewGame(int f_iUserID, int f_iGameId, BoxSize f_BS)
{
//log new game
- //prepare a fresh box
- m_CurrentBox = f_BS;
- m_pBox[(int)m_CurrentBox]->RandomizeTiles();
+ //prepare a session struct for administration
+ m_pCurrentSession = new GameSession(8, f_BS);
+
+ //randomize the box tiles
+ m_pBox[(int)m_pCurrentSession->m_BoxSize]->RandomizeTiles();
+ //init box's position
+ m_pBox[(int)m_pCurrentSession->m_BoxSize]->SetPos(0.0, -6.0, -15.0);
//set state to GET READY
m_State = ES_GET_READY;
- //init object positions
- m_pBox[(int)m_CurrentBox]->SetPos(0.0, -6.0, -15.0);
return true;
}
@@ -165,6 +181,20 @@ bool C_MatchBloxEngine::NewGame(int f_iUserID, int f_iGameId, BoxSize f_BS)
bool C_MatchBloxEngine::StartGame()
{
+ if (m_State == ES_GET_READY)
+ {
+ BlockType l_Block;
+
+ //start the session timer
+ l_Block = m_pCurrentSession->StartSession();
+
+ //move a block into the sky
+ m_pBlock[(int)l_Block]->SetPos(0.0, 0.0, 15.0);
+
+ m_State = ES_PLAYING_GRAB_BLOCK;
+
+ return true;
+ }
return false;
}
@@ -178,7 +208,7 @@ bool C_MatchBloxEngine::Pause()
m_SavedState = m_State;
//probably do something with a time variable
-
+
//set current state to paused
m_State = ES_PAUSED;
@@ -346,3 +376,107 @@ void C_MatchBloxEngine::LoadTexture(const char* f_BmpName, GLuint &f_uiTexHandle
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
}
+void C_MatchBloxEngine::CursorMove(Vect3D_t f_NewCursorPos)
+{
+ //check the state to see what 3d object currently has to be considered to
+ //be the cursor currently is and which bounding box we need to check for overlap
+ BoundingBox_t l_CursBBox;
+ bool l_bCollision = false; //indicates a collission has happend
+
+ switch (m_State)
+ {
+ case ES_PLAYING_PUT_BLOCK:
+ //cursor is the current block figure (that is being held by the player)
+ //translate the bounding box of the block with the cursor position
+ l_CursBBox = m_pBlock[m_CurrentBlock]->GetBoundingBox() + f_NewCursorPos;
+ break;
+
+ default:
+ //cursor is the hand object
+ l_CursBBox = m_pHand->GetBoundingBox() + f_NewCursorPos;
+ break;
+ }
+
+ //now we have the bounding box of the cursor which we use to do some simple hit tests
+
+ //make sure the cursor is still completely contained in the world bounding box
+ if (!m_WorldBox.Contains(l_CursBBox))
+ {
+ //restore the previous cursor position, because the new one is invalid
+ //... nothing to do actually
+ //maybe generate some vibration event and collision animation???
+ l_bCollision = true;
+ }
+ else
+ {
+ //check for bounding box overlap with the static elements in the scene
+ //actually only the block box
+ if (m_pBox[m_CurrentBox]->GetAbsBoundBox().Overlap(l_CursBBox))
+ {
+ //overlap with the block box, a collision is very likely so set
+ //collision to true and reset to false when the player is putting
+ //the block in the right hole (if the player is holding a block
+ //that is, if the player isn't then there is certainly a collision)
+ l_bCollision = true;
+
+ //check if we are holding a block that has to be put in the box
+ if (m_State == ES_PLAYING_PUT_BLOCK)
+ {
+
+
+ }
+ else
+ {
+ //we are not holding a block so every contact with the
+ //block box is a collision
+ l_bCollision = true;
+ }
+ }
+ }
+
+}
+
+GameResult_t C_MatchBloxEngine::CursorMove_PutBlock(Vect3D_t &f_CursPos, BoundingBox_t &f_CusrBBox)
+{
+ //check if the block is being put in the right hole
+ //by testing whether the position of the cursor is close
+ //enough to the center of the correct hole
+ //note that the hole positions are relative to the position
+ //of the box
+ Vect3D_t l_AbsHolePos = m_pBox[m_CurrentBox]->GetPos() +
+ m_pTiles[m_CurrentBlock]->GetPos();
+ Vect3D_t l_PosDif = l_AbsHolePos - f_CursPos;
+ double l_dXZProximity = l_PosDif.x * l_PosDif.x +
+ l_PosDif.y * l_PosDif.y;
+
+ if (l_dXZProximity < m_GameSettings.m_dMinProximity)
+ {
+ //the block the player is holding is considered to be in the right hole
+ //l_bCollision = false;
+
+ //?? would it not be better to check for bounding box intersection with hole?
+ l_bCollision = !(m_pTiles[m_CurrentBlock]->GetAbsBoundBox() +
+ m_pBox[m_CurrentBox]->GetPos())->Overlap(f_CursBBox);
+
+ //now check if the block is far enough in the hole to count as a point
+ if (l_PosDif.z > m_GameSettings.m_dHoleDepth)
+ {
+ //yipee!! we have got a winner!!
+ m_CurrentBlock = m_pGameSession->NewTurn();
+
+ m_GameState
+ }
+
+
+ }
+}
+
+GameResult_t C_MatchBloxEngine::CursorMove_GrabBlock(Vect3D_t &f_CursPos, BoundingBox_t &f_CusrBBox)
+{
+ //grabbing a block: just check for bounding box intersection
+ if (m_pBlock[(int)m_CurrentBlock)->GetAbsBoundBox().Overlap(f_CursBBox))
+ {
+
+ }
+}
+