public void Execute(McNxtBrick brick, SortRail sortRail, BallPosition position) { int tacho = sortRail.GetTachoToPosition(position); MotorDirection motorDirection = MotorDirection.Forward; if (tacho < 0) { motorDirection = MotorDirection.Backward; } var absTacho = (uint)Math.Abs(tacho); if (absTacho != 0) { Debug.WriteLine("Heading for position {0} with tacho {1}", position, tacho); int resultTacho = MotorHelper.RunAndWaitOnCompletion( (McNxtMotor)brick.MotorA, absTacho, motorDirection); sortRail.CurrentTacho += resultTacho; } }
public static void OnPacket(Client client, BallPosition ballPosition) { PacketId packid = PacketManager.me.typeIdSets[typeof(BallPosition)]; ClientPool.xx[ballPosition.BallIndex] = ballPosition.X; Console.WriteLine("BallId:" + ballPosition.BallIndex + " X:" + ballPosition.X); }
public void SetBallPosition(BallPosition newBallPosition) { ballPosition = newBallPosition; float newAnchoredYPos = (float)ballPosition; GetComponent <RectTransform> ().anchoredPosition = new Vector2(0f, newAnchoredYPos); }
public RobotSwapBallsCommandSequence(SortRobot robot, SortRail sortRail, BallPosition leftBallPosition, BallPosition rightBallPosition) { _robot = robot; _sortRail = sortRail; _leftBallPosition = leftBallPosition; _rightBallPosition = rightBallPosition; }
public void Serialize(BallPosition message) { m_writer.Reset(); m_writer.Write(NetworkMessageType.BallPosition); m_writer.Write(message.m_clientMsgNum); m_writer.Write(message.m_position); m_writer.Write(message.m_velocity); m_writer.Flush(); }
public GamePosition(Field field, TeamPosition firstTeamPosition, TeamPosition secondTeamPosition, BallPosition ballPosition) { Contract.Requires<ArgumentNullException>(firstTeamPosition != null); Contract.Requires<ArgumentNullException>(secondTeamPosition != null); _field = field; _firstTeamPosition = firstTeamPosition; _secondTeamPosition = secondTeamPosition; _ballPosition = ballPosition; }
private void m_btnStart_Click(object sender, System.EventArgs e) { var field = new Field(100, 50, 0.12f); var firstTeamPosition = new TeamPosition(new Dictionary<Player, PlayerPosition>()); var secondTeamPosition = new TeamPosition(new Dictionary<Player, PlayerPosition>()); var ballPosition = new BallPosition(); var gamePosition = new GamePosition(field, firstTeamPosition, secondTeamPosition, ballPosition); m_imgTopView.Image = new BitmapVisualizer(m_imgTopView.Width, m_imgTopView.Height).Draw(gamePosition); }
private void SendBallPosition() { var ball = m_match.GetBall(); var msg = BallPosition.Create(GameServer.ClientInfos[0].LastMsgNum, ball.GetPosition(), ball.GetVelocity()); GameServer.m_netMsgSerializer.Serialize(msg); GameServer.Send(GameServer.m_netMsgSerializer.Data, GameServer.m_netMsgSerializer.DataSize, GameServer.ClientInfos[0].Address); msg = BallPosition.Create(GameServer.ClientInfos[1].LastMsgNum, ball.GetPosition(), ball.GetVelocity()); GameServer.m_netMsgSerializer.Serialize(msg); GameServer.Send(GameServer.m_netMsgSerializer.Data, GameServer.m_netMsgSerializer.DataSize, GameServer.ClientInfos[1].Address); }
public override byte[] GetBytes() { List <byte> result = new List <byte>(); byte[] baseBytes = base.GetBytes(); result.AddRange(baseBytes); result.AddRange(BallPosition.GetBytes()); result.AddRange(Player1Position.GetBytes()); result.AddRange(Player2Position.GetBytes()); result.Add(Player1Score); result.Add(Player2Score); return(result.ToArray()); }
PreciseGameState( Dictionary<Player, PlayerPosition> playerPositions, Dictionary<Player, PlayerSpeed> playerSpeeds, BallPosition ballPosition, BallSpeed ballSpeed) { Contract.Requires<ArgumentNullException>(playerPositions != null); Contract.Requires<ArgumentNullException>(playerSpeeds != null); _playerPositions = playerPositions; _playerSpeeds = playerSpeeds; _ballPosition = ballPosition; _ballSpeed = ballSpeed; }
public void MoveBall(BallPosition position) { }
/// <summary> /// Adds a player to the game, with the specified uniform number, belonging /// to the team with the specified name. /// </summary> /// <param name="teamName">Name of the team.</param> /// <param name="unum">The uniform number.</param> /// <returns></returns> public int AddPlayer(string teamName, int unum) { if (IsGameStarted) { return(-1); } if (unum > Settings.Default.MaxPlayers) { return(-1); } Sides side; if (LeftTeamName == null || teamName == LeftTeamName) { side = Sides.Left; } else if (RightTeamName == null || teamName == RightTeamName) { side = Sides.Right; } else { return(-1); } if (side == Sides.Left && LeftPlayersCount >= Settings.Default.MaxPlayers) { return(-1); } if (side == Sides.Right && RightPlayersCount >= Settings.Default.MaxPlayers) { return(-1); } int homec = ((unum - 1) / Settings.Default.NumRows) + 1; int homer = unum % Settings.Default.NumRows; var homePos = new Position(homer, homec); if (side == Sides.Right) { homePos = homePos.GetRTL(); } for (int i = 0; i < LeftPlayersCount + RightPlayersCount; ++i) { if (Players[i].Side == side) { if (Players[i].PlayerNumber == unum) { return(-1); } if (Players[i].HomePosition == homePos) { return(-1); } } } Players[LeftPlayersCount + RightPlayersCount] = new PlayerInfo(unum, side, homePos.Row, homePos.Col, homePos.Row, homePos.Col); if (side == Sides.Left) { LeftTeamName = teamName; LeftPlayersCount++; } else { RightTeamName = teamName; RightPlayersCount++; } ChooseDefaultPlayers(); if (m_defaultLeftPlayer >= 0) { BallPosition.Set(Players[m_defaultLeftPlayer].HomePosition); } else if (m_defaultRightPlayer >= 0) { BallPosition.Set(Players[m_defaultRightPlayer].HomePosition); } RaiseChangedEvent(); RaiseScoreChangedEvent(); return(LeftPlayersCount + RightPlayersCount - 1); }
public NetworkMessage Deserialize(byte[] data, int size) { var message = new NetworkMessage(); m_reader.Reset(data, size); m_reader.Read(out message.m_type); switch (message.m_type) { case NetworkMessageType.JoinRequest: { var msg = new JoinRequest(); m_reader.Read(out msg.m_clientVersion); m_reader.Read(out msg.m_playerName); message.m_msg = msg; break; } case NetworkMessageType.JoinAccept: { var msg = new JoinAccept(); m_reader.Read(out msg.m_team); message.m_msg = msg; break; } case NetworkMessageType.OpponentFound: { var msg = new OpponentFound(); m_reader.Read(out msg.m_playerName); message.m_msg = msg; break; } case NetworkMessageType.ReadyToStart: break; case NetworkMessageType.StartMatch: break; case NetworkMessageType.PlayerMove: { var msg = new PlayerMove(); m_reader.Read(out msg.m_messageNumber); m_reader.Read(out msg.m_dt); byte direction; m_reader.Read(out direction); msg.m_playerDirection = (PlayerDirection)direction; message.m_msg = msg; break; } case NetworkMessageType.PlayerPosition: { var msg = new PlayerPosition(); m_reader.Read(out msg.m_clientMsgNum); m_reader.Read(out msg.m_team); m_reader.Read(out msg.m_index); m_reader.Read(out msg.m_position); byte direction; m_reader.Read(out direction); msg.m_direction = (PlayerDirection)direction; message.m_msg = msg; break; } case NetworkMessageType.PlayerAction: { var msg = new Action(); m_reader.Read(out msg.m_duration); message.m_msg = msg; break; } case NetworkMessageType.BallPosition: { var msg = new BallPosition(); m_reader.Read(out msg.m_clientMsgNum); m_reader.Read(out msg.m_position); m_reader.Read(out msg.m_velocity); message.m_msg = msg; break; } default: Debug.Log("Unknown network message."); break; } return(message); }
/// <summary> /// Sets the home position for the player with the specified player index. /// </summary> /// <param name="pi">The player index.</param> /// <param name="r">The row.</param> /// <param name="c">The column.</param> /// <returns></returns> public bool SetHomePos(int pi, int r, int c) { // You cannot set a player's home position during play-on if (IsGameStarted) { return(false); } // Change it to right-to-left coordination if the player // is playing for the right-hand-side team var newHomePosition = new Position(r, c); if (Players[pi].Side == Sides.Right) { newHomePosition = newHomePosition.GetRTL(); } // see if there's another player already at the specified home-position int otherPi = FindPlayerWithHomePos(newHomePosition); if (otherPi < 0) { // if there isn't such player then set the newly // added player's home position successfully Players[pi].HomePosition.Set(newHomePosition); Players[pi].Position.Set(newHomePosition); Players[pi].HasHomePos = true; } else { // if there's another player with the same home position if (otherPi != pi) { if (Players[otherPi].HasHomePos) { return(false); } else { Players[otherPi].HomePosition.Set(Players[pi].HomePosition); Players[otherPi].Position.Set(Players[pi].HomePosition); Players[pi].HomePosition.Set(newHomePosition); Players[pi].Position.Set(newHomePosition); Players[pi].HasHomePos = true; } } } ChooseDefaultPlayers(); // Give the ownership of the ball to the default player if (m_defaultLeftPlayer >= 0) { BallPosition.Set(Players[m_defaultLeftPlayer].HomePosition); } else if (m_defaultRightPlayer >= 0) { BallPosition.Set(Players[m_defaultRightPlayer].HomePosition); } RaiseChangedEvent(); return(true); }
// This function is an asynchronous coRoutine because all the animations need to finish before the code resumes public IEnumerator MoveBallAction(GameManager.Player movingPlayer, ActionMarker.ActionSprite action) { float ballAnimationTime = settingController.GetAnimationSpeed(); float moveBy = 2.1f; // Move only if the controlling team is the one moving if (movingPlayer == controllingTeam) { if (movingPlayer == GameManager.Player.A) { ActionMarker actionMarker = GameObject.Find("Player A Areas").GetComponentInChildren <ActionMarker> (); actionMarker.SetMarker(action); if (ballPosition == BallPosition.PlayerAField) { iTween.MoveBy(gameObject, iTween.Hash("y", moveBy, "time", ballAnimationTime, "easeType", "easeInOutQuad")); ballPosition = BallPosition.Middle; yield return(new WaitForSeconds(ballAnimationTime)); } else if (ballPosition == BallPosition.Middle) { iTween.MoveBy(gameObject, iTween.Hash("y", moveBy, "time", ballAnimationTime, "easeType", "easeInOutQuad")); ballPosition = BallPosition.PlayerBField; yield return(new WaitForSeconds(ballAnimationTime)); } else if (ballPosition == BallPosition.PlayerBField) { iTween.MoveBy(gameObject, iTween.Hash("y", moveBy / 2, "time", ballAnimationTime, "easeType", "easeInOutQuad")); ballPosition = BallPosition.PlayerBGoal; yield return(new WaitForSeconds(ballAnimationTime)); } actionMarker.RemoveMarker(); } else // movingPlayer == PlayerB { ActionMarker actionMarker = GameObject.Find("Player B Areas").GetComponentInChildren <ActionMarker> (); actionMarker.SetMarker(action); if (ballPosition == BallPosition.PlayerBField) { iTween.MoveBy(gameObject, iTween.Hash("y", -moveBy, "time", ballAnimationTime, "easeType", "easeInOutQuad")); ballPosition = BallPosition.Middle; yield return(new WaitForSeconds(ballAnimationTime)); } else if (ballPosition == BallPosition.Middle) { iTween.MoveBy(gameObject, iTween.Hash("y", -moveBy, "time", ballAnimationTime, "easeType", "easeInOutQuad")); ballPosition = BallPosition.PlayerAField; yield return(new WaitForSeconds(ballAnimationTime)); } else if (ballPosition == BallPosition.PlayerAField) { iTween.MoveBy(gameObject, iTween.Hash("y", -(moveBy / 2), "time", ballAnimationTime, "easeType", "easeInOutQuad")); ballPosition = BallPosition.PlayerAGoal; yield return(new WaitForSeconds(ballAnimationTime)); } actionMarker.RemoveMarker(); } } else { yield return(SetControllingTeamAnimation(movingPlayer, action)); } }
private void PerformPendingUpdates() { if (this.m_isGoalScored) { if (m_sideReceivingGoal == Sides.Left) { this.RightScore++; } else { this.LeftScore++; } for (int i = 0; i < LeftPlayersCount + RightPlayersCount; ++i) { Players[i].Position.Set(Players[i].HomePosition); } if (m_sideReceivingGoal == Sides.Right) { if (m_defaultRightPlayer >= 0) { BallPosition.Set(Players[m_defaultRightPlayer].HomePosition); } else if (m_defaultLeftPlayer >= 0) { BallPosition.Set(Players[m_defaultLeftPlayer].HomePosition); } } else if (m_sideReceivingGoal == Sides.Left) { if (m_defaultLeftPlayer >= 0) { BallPosition.Set(Players[m_defaultLeftPlayer].HomePosition); } else if (m_defaultRightPlayer >= 0) { BallPosition.Set(Players[m_defaultRightPlayer].HomePosition); } } RaiseScoreChangedEvent(); } else { if (m_ballOwnerIndex < 0) { m_ballOwnerIndex = FindPlayerAtLocation(BallPosition); } bool conflictsFound = false; do { conflictsFound = false; for (int i = 0; i < m_pendingActions.Length; ++i) { if (!m_pendingActions[i].Updated) { m_pendingActions[i].NewPos.Set(Players[i].Position); m_pendingActions[i].DesiredPos.Set(Players[i].Position); } int ci = FindNewPosConflict(m_pendingActions[i].NewPos, i); // short for conflicting index if (ci >= 0) { conflictsFound = true; if (Players[i].Position != m_pendingActions[i].NewPos && Players[ci].Position != m_pendingActions[ci].NewPos) { if (m_randomGenerator.NextDouble() < 0.5) { m_pendingActions[i].NewPos.Set(Players[i].Position); } else { m_pendingActions[ci].NewPos.Set(Players[ci].Position); } } else if (Players[i].Position == m_pendingActions[i].NewPos && Players[ci].Position != m_pendingActions[ci].NewPos) { m_pendingActions[ci].NewPos.Set(Players[ci].Position); } else if (Players[i].Position != m_pendingActions[i].NewPos && Players[ci].Position == m_pendingActions[ci].NewPos) { m_pendingActions[i].NewPos.Set(Players[i].Position); } } } } while (conflictsFound); if (m_ballOwnerIndex >= 0) { // first form the action type ActionTypes at = ActionTypes.Hold; if (m_pendingActions[m_ballOwnerIndex].Updated) { at = m_pendingActions[m_ballOwnerIndex].Action.ActionType; if (at == ActionTypes.Pass) { int passeeIndex = FindPlayerIndex(Players[m_ballOwnerIndex].Side, m_pendingActions[m_ballOwnerIndex].Action.DestinationUnum); if (passeeIndex == m_ballOwnerIndex || passeeIndex < 0) { at = ActionTypes.Hold; } else if (!PlayersAreWithinPassableDistance(m_ballOwnerIndex, passeeIndex)) { at = ActionTypes.Hold; } } } else // i.e. the player was holding { at = ActionTypes.Hold; } int nextBO = m_ballOwnerIndex; // will hold the next ball owner if (at == ActionTypes.Hold) { m_rndCandidChooser.Clear(); m_rndCandidChooser.AddCandidate(m_ballOwnerIndex, 4.0); for (int i = 0; i < m_pendingActions.Length; ++i) { if (i != m_ballOwnerIndex && m_pendingActions[i].Updated && m_pendingActions[i].DesiredPos == BallPosition) { m_rndCandidChooser.AddCandidate(i, 1.0); } } nextBO = m_rndCandidChooser.ChooseRandomly(); } else if (at == ActionTypes.Pass) { int passee = FindPlayerIndex(Players[m_ballOwnerIndex].Side, m_pendingActions[m_ballOwnerIndex].Action.DestinationUnum); Position passerPos = m_pendingActions[m_ballOwnerIndex].NewPos; Position passeePos = m_pendingActions[passee].NewPos; Position curPos; if (PlayersAreInEightMainDirs(m_ballOwnerIndex, passee)) { nextBO = passee; double minDist = MathUtils.GetDistancePointFromPoint(passeePos, passerPos); double curDist; for (int i = 0; i < m_pendingActions.Length; ++i) { curPos = m_pendingActions[i].NewPos; if (i != m_ballOwnerIndex && i != passee && MathUtils.IsPointBetweenTwoPoints(passerPos, passeePos, curPos)) { curDist = MathUtils.GetDistancePointFromPoint(curPos, passerPos); if (curDist < minDist) { minDist = curDist; nextBO = i; } } } } else // if they are not in the eight main directions { double curDist; nextBO = passee; m_rndCandidChooser.Clear(); m_rndCandidChooser.AddCandidate(passee, 4.0); for (int i = 0; i < m_pendingActions.Length; ++i) { curPos = m_pendingActions[i].NewPos; if (i != m_ballOwnerIndex && i != passee && MathUtils.IsPointInRectangle(passerPos, passeePos, curPos)) { curDist = MathUtils.GetDistancePointFromLine(curPos, passerPos, passeePos); if (0 < curDist && curDist < 1.5) { m_rndCandidChooser.AddCandidate(i, 1.0); } else if (curDist == 0.0) { if (MathUtils.GetDistancePointFromPoint(curPos, passerPos) < MathUtils.GetDistancePointFromPoint(m_pendingActions[nextBO].NewPos, passerPos)) { nextBO = i; } } } } if (nextBO == passee) { nextBO = m_rndCandidChooser.ChooseRandomly(); } } } else // One of the Moves { if (m_pendingActions[m_ballOwnerIndex].NewPos != m_pendingActions[m_ballOwnerIndex].DesiredPos) { int plAtDes = FindPlayerAtLocation(m_pendingActions[m_ballOwnerIndex].DesiredPos); if (plAtDes >= 0 && plAtDes != m_ballOwnerIndex && PlayerWasHolding(plAtDes)) { nextBO = plAtDes; } else { m_rndCandidChooser.Clear(); m_rndCandidChooser.AddCandidate(m_ballOwnerIndex, 4.0); for (int i = 0; i < m_pendingActions.Length; ++i) { if (i != m_ballOwnerIndex && m_pendingActions[i].Updated && m_pendingActions[i].DesiredPos == m_pendingActions[m_ballOwnerIndex].DesiredPos) { m_rndCandidChooser.AddCandidate(i, 1.0); } } nextBO = m_rndCandidChooser.ChooseRandomly(); } } } if (nextBO >= 0) { BallPosition.Set(m_pendingActions[nextBO].NewPos); } } // in the end put the players at their new position for (int i = 0; i < LeftPlayersCount + RightPlayersCount; ++i) { if (m_pendingActions[i].Updated) { Players[i].Position.Set(m_pendingActions[i].NewPos); } } } }
public RobotMoveToPosition(SortRobot robot, SortRail sortRail, BallPosition position) { _robot = robot; _sortRail = sortRail; _position = position; }
/// <summary> /// Coords the painting of the portion of the map between the two Coords parameters. /// </summary> public void Paint(Graphics g, Coords topLeft, Coords bottomRight) { // The algorithm is as follows: // 1) AT INIT: Imports and resizes the bitmaps. // 2) AT ZOOM: Resizes bitmaps. // 3) AT PAINT: The Form determines what portion of the map should be painted and calls Painter. // Painter goes through the Tiles and draws them, row by row, from left-to-right from // top-to-bottom. #region Tiles Int32 pixelsX = 0; // We assume the validity check for the two coords has been done in the caller class. for (Int32 i = 0; i < Constants.MapSizeX; ++i) { if (i > 0) { pixelsX += Constants.TileSizesX[i - 1]; } Int32 pixelsY = 0; for (Int32 j = 0; j < Constants.MapSizeY; ++j) { Coords currentCoords = new Coords(i, j); Tile currentTile = this._currentMap.GetTile(i, j); if (j > 0) { pixelsY += Constants.TileSizesY[j - 1]; } this.TileDrawBitmap(g, new Coords(pixelsX, pixelsY), this.Tiles[(sbyte)currentTile.MyBitmap]); foreach (Footballer critter in _currentMap.Roster.Values) { this.AddForPaintingFootballer(critter); } } } #endregion #region Props and Footballers // The tiles have informed the painter about the Footballers he's supposed to draw. foreach (Footballer critter in this._FootballersToDraw) { this.FillPlayerEllipse(g, critter.PositionDouble, 10, 8, critter.Team.TeamColor); this.DrawBitmapAtPixel(g, new Coords((Int32)critter.PositionDouble.X, (Int32)critter.PositionDouble.Y), this.Footballers[(sbyte)critter.MyBitmap]); Vector2d delta = critter.FacingDirection; delta.ScaleToLength(50); this.DrawLine(g, critter.PositionDouble, critter.PositionDouble + delta); } // Draw the labels foreach (Footballer critter in this._FootballersToDraw) { //FIX // draw labels if ((critter.LabelUpper != null) && (critter.LabelUpper.Length > 0)) { this.DrawLabel(g, critter.PositionDouble + new Vector2d(0, -200), critter.LabelUpper); } if ((critter.LabelLower != null) && (critter.LabelLower.Length > 0)) { //this.DrawLabel(g, new Coords(CoordsType.Pixel, critter.PositionPixel.X, critter.PositionPixel.Y + critter.RadiusY), critter.LabelLower); } } for (int i = 0; i < Props.Length; ++i) { DrawProp(g, Constants.PropLocations[i], Props[i]); } #endregion #region Nets, Ball, and Info // DrawGhostBall if option is enabled if (this._ghost != null) { //BallGhost ghost = new BallGhost(this._currentMap.BallReference); for (int i = 0; i < Constants.GhostBallTimeLength; ++i) { for (int j = 0; j < Constants.GhostBallDrawInterval; ++j) { _ghost.UpdateMotion3D(); } this.DrawGhostBall(g, _ghost); } } if (Constants.ShowTrajectory) { if (this._currentMap.BallReference.Projection.Count > 0) { foreach (Vector3d v in this._currentMap.BallReference.Projection) { BallGhost ghost = new BallGhost(this._currentMap.BallReference); //ghost.SpawnAt(v.ProjectionXY()); ghost.Stop(); ghost.Position3d = v; this.DrawGhostBall(g, ghost); } } } BallPosition ballPos = DetermineBallPosition(_currentMap.BallReference); // Nets if (ballPos == BallPosition.BehindGoal) { this.DrawSomeBall(g, _currentMap.BallReference, this.Balls[(sbyte)SpriteBall.Standard]); } DrawNetYAxis(g, Constants.NetsBackLeft); DrawNetYAxis(g, Constants.NetsBackRight); DrawNetXAxis(g, Constants.NetsBackLeft, Constants.GoalTop); DrawNetXAxis(g, Constants.GoalRight, Constants.GoalTop); if (ballPos == BallPosition.InsideGoal) { this.DrawSomeBall(g, _currentMap.BallReference, this.Balls[(sbyte)SpriteBall.Standard]); } DrawNetXAxis(g, Constants.NetsBackLeft, Constants.GoalBottom); DrawNetXAxis(g, Constants.GoalRight, Constants.GoalBottom); DrawNetZAxis(g, Constants.NetsBackLeft); DrawNetZAxis(g, Constants.GoalRight); DrawGoals(g); if (ballPos == BallPosition.Visible) { this.DrawSomeBall(g, _currentMap.BallReference, this.Balls[(sbyte)SpriteBall.Standard]); } DrawBallParameters(g, topLeft); DrawShotParameters(g, topLeft); this.DrawInfluenceMap(g, _currentMap.MatchOnMap.TeamLeft.TeamInfluenceMap, topLeft, _currentMap.MatchOnMap.TeamLeft.TeamColor, true); this.DrawInfluenceMap(g, _currentMap.MatchOnMap.TeamRight.TeamInfluenceMap, topLeft, _currentMap.MatchOnMap.TeamRight.TeamColor, false); #endregion // Clean up the ID list. this._FootballersToDraw.Clear(); }
private static BallPosition GetNewBallPosition(BallPosition currentBallPosition) { return new BallPosition(); }
public void MoveBall(BallPosition position) { ballController.SetPositionAndVelocity(position.xPos, position.zPos, position.xVel, position.zVel); }