tailieunhanh - Beginning XNA 2.0 Game Programming From Novice to Professional phần 4

Bạn có thể kiểm tra mã mới bằng cách thực hiện lại các bước bạn sử dụng trong các phần trước để tham gia một phiên đồng bộ, ngoại trừ việc bạn nhấn phím F4 thay vì F3. Trên máy client, bạn sẽ thấy thông báo sau "không đồng bộ tìm kiếm bắt đầu!", | CHAPTER 4 IMPROVING YOUR FIRST 2-D GAME 109 Game Stuff protected int score protected int power private const int INITIALPOWER 100 public Player Game game ref Texture2D theTexture PlayerIndex playerID Rectangle rectangle base game texture theTexture position new Vector2 playerIndex playerID Create the source rectangle. This represents where the sprite picture is in the surface spriteRectangle rectangle if XBOX360 On the 360 we need to take care about the TV safe area. screenBounds new Rectangle int int - int - int else screenBounds new Rectangle 0 0 endif summary Put the ship in your start position in screen summary public void Reset if playerIndex 3 else 110 CHAPTER 4 IMPROVING YOUR FIRST 2-D GAME int - score 0 power INITIALPOWER summary Total Points of the Player summary public int Score get return score set if value 0 score 0 else score value summary Remaining Power summary public int Power get return power set power value summary Update the ship position points and power summary public override void Update GameTime gameTime Move the ship with the Xbox controller CHAPTER 4 IMPROVING YOUR FIRST 2-D GAME 111 GamePadState gamepadstatus playerlndex int 3 -2 int 3 2 Move the ship with the keyboard if playerIndex HandlePlayer1KeyBoard else HandlePlayer2KeyBoard Keep the player inside the screen KeepInBound Update score elapsedTime if elapsedTime 1 elapsedTime - 1 score power-- .

TỪ KHÓA LIÊN QUAN