|
|
|
|
|
|
public class HitWall : MonoBehaviour |
|
|
|
{ |
|
|
|
public GameObject areaObject; |
|
|
|
public int lastAgentHit; |
|
|
|
int m_LastAgentHit; |
|
|
|
|
|
|
|
public enum FloorHit |
|
|
|
{ |
|
|
|
|
|
|
FloorBHit |
|
|
|
} |
|
|
|
|
|
|
|
public FloorHit lastFloorHit; |
|
|
|
FloorHit m_LastFloorHit; |
|
|
|
|
|
|
|
TennisArea m_Area; |
|
|
|
TennisAgent m_AgentA; |
|
|
|
|
|
|
m_Area = areaObject.GetComponent<TennisArea>(); |
|
|
|
m_AgentA = m_Area.agentA.GetComponent<TennisAgent>(); |
|
|
|
m_AgentB = m_Area.agentB.GetComponent<TennisAgent>(); |
|
|
|
} |
|
|
|
|
|
|
|
public void ResetPoint() |
|
|
|
{ |
|
|
|
m_LastFloorHit = FloorHit.Service; |
|
|
|
m_LastAgentHit = -1; |
|
|
|
} |
|
|
|
|
|
|
|
void Reset() |
|
|
|
|
|
|
m_Area.MatchReset(); |
|
|
|
lastFloorHit = FloorHit.Service; |
|
|
|
lastAgentHit = -1; |
|
|
|
m_AgentA.SetReward(1); |
|
|
|
m_AgentA.SetReward(1 + m_AgentA.timePenalty); |
|
|
|
m_AgentB.SetReward(-1); |
|
|
|
m_AgentA.score += 1; |
|
|
|
Reset(); |
|
|
|
|
|
|
void AgentBWins() |
|
|
|
{ |
|
|
|
m_AgentA.SetReward(-1); |
|
|
|
m_AgentB.SetReward(1); |
|
|
|
m_AgentB.SetReward(1 + m_AgentB.timePenalty); |
|
|
|
m_AgentB.score += 1; |
|
|
|
Reset(); |
|
|
|
|
|
|
|
|
|
|
if (collision.gameObject.name == "wallA") |
|
|
|
{ |
|
|
|
// Agent A hits into wall or agent B hit a winner
|
|
|
|
if (lastAgentHit == 0 || lastFloorHit == FloorHit.FloorAHit) |
|
|
|
if (m_LastAgentHit == 0 || m_LastFloorHit == FloorHit.FloorAHit) |
|
|
|
{ |
|
|
|
AgentBWins(); |
|
|
|
} |
|
|
|
|
|
|
else if (collision.gameObject.name == "wallB") |
|
|
|
{ |
|
|
|
// Agent B hits into wall or agent A hit a winner
|
|
|
|
if (lastAgentHit == 1 || lastFloorHit == FloorHit.FloorBHit) |
|
|
|
if (m_LastAgentHit == 1 || m_LastFloorHit == FloorHit.FloorBHit) |
|
|
|
{ |
|
|
|
AgentAWins(); |
|
|
|
} |
|
|
|
|
|
|
else if (collision.gameObject.name == "floorA") |
|
|
|
{ |
|
|
|
// Agent A hits into floor, double bounce or service
|
|
|
|
if (lastAgentHit == 0 || lastFloorHit == FloorHit.FloorAHit || lastFloorHit == FloorHit.Service) |
|
|
|
if (m_LastAgentHit == 0 || m_LastFloorHit == FloorHit.FloorAHit || m_LastFloorHit == FloorHit.Service) |
|
|
|
lastFloorHit = FloorHit.FloorAHit; |
|
|
|
m_LastFloorHit = FloorHit.FloorAHit; |
|
|
|
if (lastAgentHit == 1 || lastFloorHit == FloorHit.FloorBHit || lastFloorHit == FloorHit.Service) |
|
|
|
if (m_LastAgentHit == 1 || m_LastFloorHit == FloorHit.FloorBHit || m_LastFloorHit == FloorHit.Service) |
|
|
|
lastFloorHit = FloorHit.FloorBHit; |
|
|
|
m_LastFloorHit = FloorHit.FloorBHit; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
if (lastAgentHit == 0) |
|
|
|
if (m_LastAgentHit == 0) |
|
|
|
{ |
|
|
|
AgentBWins(); |
|
|
|
} |
|
|
|
|
|
|
lastAgentHit = 0; |
|
|
|
lastFloorHit = FloorHit.FloorHitUnset; |
|
|
|
m_LastAgentHit = 0; |
|
|
|
m_LastFloorHit = FloorHit.FloorHitUnset; |
|
|
|
if (lastAgentHit == 1) |
|
|
|
if (m_LastAgentHit == 1) |
|
|
|
lastAgentHit = 1; |
|
|
|
lastFloorHit = FloorHit.FloorHitUnset; |
|
|
|
m_LastAgentHit = 1; |
|
|
|
m_LastFloorHit = FloorHit.FloorHitUnset; |
|
|
|
} |
|
|
|
} |
|
|
|
} |