public void Initialize(ContentManager content, PlayerColour colour) { // Load the player resources Animation playerAnimation = new Animation(); Texture2D playerTexture = content.Load <Texture2D>("shipAnimation"); playerAnimation.Initialize(playerTexture, Vector2.Zero, 0, Width, Height, 8, 30, new Color(colour.R, colour.G, colour.B), 1f, true); PlayerAnimation = playerAnimation; }
public PlayerColour MakePlayerColour(int r, int g, int b) { PlayerColour colour = new PlayerColour { R = r, G = g, B = b }; return(colour); }
public void Draw(SpriteBatch spriteBatch) { int xDistanceBetweenEach = 150; int textWidth = 50; int currentXpos = (_width / 2) - (_playerCount / 2 * (xDistanceBetweenEach + textWidth)); // Calculate starting xpos foreach (KeyValuePair <string, string> player in _playerNames) { PlayerColour colour = _playerColours[player.Key]; // DRAW NAME spriteBatch.DrawString(_font, player.Value, new Vector2(currentXpos, 0), new Color(colour.R, colour.G, colour.B)); // DRAW SCORE spriteBatch.DrawString(_font, _playerScores[player.Key].ToString(), new Vector2(currentXpos + ((xDistanceBetweenEach) / 2), textWidth / 2), new Color(colour.R, colour.G, colour.B)); currentXpos += (textWidth + xDistanceBetweenEach); } }
private void CheckGameOver() { foreach (KeyValuePair <string, int> player in _playerScores) { if (player.Value >= Application.SCORE_TO_WIN) { Logger.Instance.Info(_playerNames[player.Key] + " has reached the score limit"); int playerCount = ComponentClients.Count; int[] playerScores = new int[playerCount]; string[] playerNames = new string[playerCount]; int index = 0; foreach (KeyValuePair <string, int> playerScore in _playerScores) { playerScores[index] = playerScore.Value; playerNames[index] = _playerNames[playerScore.Key]; index++; } PlayerColour[] playerColours = new PlayerColour[_playerColours.Count]; index = 0; foreach (KeyValuePair <string, Color> playerColour in _playerColours) { playerColours[index] = NetworkPacketFactory.Instance.MakePlayerColour(playerColour.Value.R, playerColour.Value.G, playerColour.Value.B); index++; } LeaderboardPacket packet = NetworkPacketFactory.Instance.MakeLeaderboardPacket(playerCount, playerNames, playerScores, playerColours); for (int iClient = 0; iClient < ComponentClients.Count; iClient++) { ComponentClients[iClient].SendPacketToClient(packet, MessageType.GI_ServerSend_GameOver); } OnGameCompleted(packet); return; } } }
public void FireRemoteLaserClient(Vector2 position, float rotation, string playerID, DateTime originalTimeFired, string laserID, PlayerColour colour) { var timeDifference = (originalTimeFired - DateTime.UtcNow).TotalSeconds; var laser = AddLaser(position, rotation, laserID, playerID, colour); laser.Update((float)timeDifference); // Update it to match the true position if (!_playerLasers.ContainsKey(playerID)) { _playerLasers.Add(playerID, new List <Laser>()); } _playerLasers[playerID].Add(laser); }
public Laser FireLocalLaserClient(GameTime gameTime, Vector2 position, float rotation, PlayerColour colour) { // Govern the rate of fire for our lasers if (gameTime.TotalGameTime - _previousLaserSpawnTime > _laserSpawnTime) { _previousLaserSpawnTime = gameTime.TotalGameTime; // Add the laer to our list. return(AddLaser(position, rotation, "", "", colour)); } return(null); }
public Laser AddLaser(Vector2 position, float rotation, string laserID, string playerFiredID, PlayerColour colour) { Animation laserAnimation = new Animation(); // Initlize the laser animation laserAnimation.Initialize(_laserTexture, position, rotation, 46, 16, 1, 30, new Color(colour.R, colour.G, colour.B), 1f, true); Laser laser; if (string.IsNullOrEmpty(laserID)) { laser = new Laser(); } else { laser = new Laser(laserID, playerFiredID); } Vector2 direction = new Vector2((float)Math.Cos(rotation), (float)Math.Sin(rotation)); direction.Normalize(); // Move the starting position to be slightly in front of the cannon var laserPostion = position; laserPostion += direction * LASER_SPAWN_DISTANCE; // Init the laser laser.Initialize(laserAnimation, laserPostion, rotation); _laserBeams.Add(laser); return(laser); }