//////////////////////////////////////// // Collision Methods //////////////////////////////////////// bool Entity::CheckCollision(Entity* other) { if (GetCollisionRect().Intersects(other->GetCollisionRect()) ) { CollideWith(other); other->CollideWith(this); return true; } return false; }
void CEntityPhysics::Update(float ElapsedTime,int index, int top, vector<CEntityPhysics>* physics, vector<CEntityTransform>* transforms, vector<CEntity>* entities) { for (int i = 0; i < top; i++) { if (i != index && (*entities)[i].GetFaction() != "neutral" && (*entities)[index].GetFaction() != "neutral" ) { if (CollideWith((*physics)[i],(*transforms)[index],(*transforms)[i]) && (*entities)[index].GetFaction() != (*entities)[i].GetFaction()) (*entities)[index].HurtMe((*entities)[i].GetHitpoints()); } (*transforms)[index].Translate(m_Velocity * ElapsedTime); (*transforms)[index].Rotate(m_RotationalVelocity * ElapsedTime); } }
bool T_Sprite::MoveTo(IN POINT mousePT, IN POINT desPT, IN T_Map* map) { int xRatio, yRatio; if(active == true) { SIZE ratioFrameSize = GetRatioSize(); RECT HotRect; HotRect.left = (long)(desPT.x-5); HotRect.top = (long)(desPT.y-5); HotRect.right = (long)(desPT.x+5); HotRect.bottom = (long)(desPT.y+5); T_Util::GetBevelSpeed(desPT, mousePT, speed, xRatio, yRatio); BOOL ToDesPos = PtInRect(&HotRect, mousePT); if(ToDesPos == TRUE) { return true; } if(ToDesPos == FALSE) { int nextStepX = (int)xRatio; int nextStepY = (int)yRatio; int x =0; int y = 0; if(!CollideWith(map)) { x = GetX(); y = GetY(); Move(nextStepX, nextStepY); } if(CollideWith(map)) { SetPosition(x, y); } return false; } } return true; }