Beispiel #1
0
 public PlayerObject(string name, IInputDevice inputDevice, Viewport viewport,
     Vector2 startPosition, Color color, Texture2D texture, int size)
 {
     this.viewport = viewport;
     this.name = name;
     this.inputDevice = inputDevice;
     //pos = startPosition;
     this.color = color;
     this.texture = texture;
     this.size = size;
     velocity = new Vector2(0, 0);
     rect = new Rectangle((int)startPosition.X, (int)startPosition.Y,
         size, size);
     currentState = new PlayerState()
     {
         name = this.name,
         size = this.size,
         posX = (int)this.Rect.X,
         posY = (int)this.Rect.Y,
         velX = (int)this.velocity.X,
         velY = (int)this.velocity.Y
     };
 }
Beispiel #2
0
 public void UpdateState(PlayerState state)
 {
     this.size = state.size;
     this.rect.X = state.posX;
     this.rect.Y = state.posY;
     this.velocity.X = state.velX;
     this.velocity.Y = state.velY;
 }
Beispiel #3
0
 /// <summary>
 /// Update the list of networked players with updated states.
 /// </summary>
 /// <param name="newPlayer"></param>
 private void UpdatePlayerList(PlayerState newPlayer)
 {
     //Console.WriteLine("Updating playerlist for: " + newPlayer.name);
     foreach(PlayerState player in PlayerList)
     {
         if(player.name == newPlayer.name)
         {
             player.posX = newPlayer.posX;
             player.posY = newPlayer.posY;
             player.size = newPlayer.size;
             player.velX = newPlayer.velX;
             player.velY = newPlayer.velY;
             return;
         }
     }
     PlayerList.Add(newPlayer);
 }