diff options
| author | oy <Tom_Adams@web.de> | 2011-04-13 20:37:12 +0200 |
|---|---|---|
| committer | oy <Tom_Adams@web.de> | 2011-04-13 20:37:12 +0200 |
| commit | 06115dd49dca2f8eb5f14606437e8fd20037cc4d (patch) | |
| tree | 5ec4bca6158319b3f5285d7689c5f94ae8da8c93 /src/game/collision.cpp | |
| parent | 63e059b8fff6498e42b765a1dca000e53005ea77 (diff) | |
| download | zcatch-06115dd49dca2f8eb5f14606437e8fd20037cc4d.tar.gz zcatch-06115dd49dca2f8eb5f14606437e8fd20037cc4d.zip | |
added "Whitespace and line Endings cleanup" by GreYFoX
Diffstat (limited to 'src/game/collision.cpp')
| -rw-r--r-- | src/game/collision.cpp | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/src/game/collision.cpp b/src/game/collision.cpp index 8acddc6e..ca932d9b 100644 --- a/src/game/collision.cpp +++ b/src/game/collision.cpp @@ -26,14 +26,14 @@ void CCollision::Init(class CLayers *pLayers) m_Width = m_pLayers->GameLayer()->m_Width; m_Height = m_pLayers->GameLayer()->m_Height; m_pTiles = static_cast<CTile *>(m_pLayers->Map()->GetData(m_pLayers->GameLayer()->m_Data)); - + for(int i = 0; i < m_Width*m_Height; i++) { int Index = m_pTiles[i].m_Index; - + if(Index > 128) continue; - + switch(Index) { case TILE_DEATH: @@ -55,7 +55,7 @@ int CCollision::GetTile(int x, int y) { int Nx = clamp(x/32, 0, m_Width-1); int Ny = clamp(y/32, 0, m_Height-1); - + return m_pTiles[Ny*m_Width+Nx].m_Index > 128 ? 0 : m_pTiles[Ny*m_Width+Nx].m_Index; } @@ -70,7 +70,7 @@ int CCollision::IntersectLine(vec2 Pos0, vec2 Pos1, vec2 *pOutCollision, vec2 *p float Distance = distance(Pos0, Pos1); int End(Distance+1); vec2 Last = Pos0; - + for(int i = 0; i < End; i++) { float a = i/Distance; @@ -97,7 +97,7 @@ void CCollision::MovePoint(vec2 *pInoutPos, vec2 *pInoutVel, float Elasticity, i { if(pBounces) *pBounces = 0; - + vec2 Pos = *pInoutPos; vec2 Vel = *pInoutVel; if(CheckPoint(Pos + Vel)) @@ -107,7 +107,7 @@ void CCollision::MovePoint(vec2 *pInoutPos, vec2 *pInoutVel, float Elasticity, i { pInoutVel->x *= -Elasticity; if(pBounces) - (*pBounces)++; + (*pBounces)++; Affected++; } @@ -115,10 +115,10 @@ void CCollision::MovePoint(vec2 *pInoutPos, vec2 *pInoutVel, float Elasticity, i { pInoutVel->y *= -Elasticity; if(pBounces) - (*pBounces)++; + (*pBounces)++; Affected++; } - + if(Affected == 0) { pInoutVel->x *= -Elasticity; @@ -150,10 +150,10 @@ void CCollision::MoveBox(vec2 *pInoutPos, vec2 *pInoutVel, vec2 Size, float Elas // do the move vec2 Pos = *pInoutPos; vec2 Vel = *pInoutVel; - + float Distance = length(Vel); int Max = (int)Distance; - + if(Distance > 0.00001f) { //vec2 old_pos = pos; @@ -163,27 +163,27 @@ void CCollision::MoveBox(vec2 *pInoutPos, vec2 *pInoutVel, vec2 Size, float Elas //float amount = i/(float)max; //if(max == 0) //amount = 0; - + vec2 NewPos = Pos + Vel*Fraction; // TODO: this row is not nice - + if(TestBox(vec2(NewPos.x, NewPos.y), Size)) { int Hits = 0; - + if(TestBox(vec2(Pos.x, NewPos.y), Size)) { NewPos.y = Pos.y; Vel.y *= -Elasticity; Hits++; } - + if(TestBox(vec2(NewPos.x, Pos.y), Size)) { NewPos.x = Pos.x; Vel.x *= -Elasticity; Hits++; } - + // neither of the tests got a collision. // this is a real _corner case_! if(Hits == 0) @@ -194,11 +194,11 @@ void CCollision::MoveBox(vec2 *pInoutPos, vec2 *pInoutVel, vec2 Size, float Elas Vel.x *= -Elasticity; } } - + Pos = NewPos; } } - + *pInoutPos = Pos; *pInoutVel = Vel; } |