Advertisement
Guest User

Untitled

a guest
Jan 5th, 2017
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.82 KB | None | 0 0
  1. using System;
  2. using Microsoft.Xna.Framework;
  3. using Microsoft.Xna.Framework.Graphics;
  4. using Microsoft.Xna.Framework.Input.Touch;
  5. using Microsoft.Xna.Framework.Media;
  6.  
  7. namespace SaccoGame
  8. {
  9.     public class Jogador
  10.     {
  11.         static Texture2D characterSheetTexture;
  12.          Texture2D _quadradoChutar;
  13.         bool _IsTouched;
  14.         Rectangle _posicao;
  15.         GraphicsDevice _graphicsDevice;
  16.  
  17.         public Jogador(GraphicsDevice graphicsDevice, Rectangle posicaoJogador)
  18.         {
  19.             _graphicsDevice = graphicsDevice;
  20.             _posicao = posicaoJogador;
  21.  
  22.             if (characterSheetTexture == null)
  23.             {
  24.                 using (var stream = TitleContainer.OpenStream("Content/Jogador_Azul.png"))
  25.                     characterSheetTexture = Texture2D.FromStream(graphicsDevice, stream);
  26.             }
  27.  
  28.        
  29.         }
  30.  
  31.  
  32.         public void Update(GameTime gameTime)
  33.         {
  34.             _IsTouched = CheckRectangleTouch(_posicao);
  35.         }
  36.  
  37.          bool CheckRectangleTouch(Rectangle target)
  38.         {
  39.             TouchCollection touchCollection = TouchPanel.GetState();
  40.             if (touchCollection.Count > 0)
  41.                 foreach (var touch in touchCollection)
  42.                     if (target.Contains(touch.Position))
  43.                         return true;
  44.                    
  45.                
  46.  
  47.             return false;
  48.         }
  49.         public void Draw(SpriteBatch spriteBatch)
  50.         {
  51.             if (_IsTouched)
  52.             {
  53.        
  54.                 spriteBatch.Draw(characterSheetTexture, new Vector2(_posicao.X,_posicao.Y), null,
  55.                                  Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f);
  56.                
  57.                 if (_quadradoChutar!=null)
  58.                 {
  59.                     spriteBatch.Draw(_quadradoChutar, new Vector2(_posicao.X-100, _posicao.Y+100), null,
  60.                  Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f);
  61.                 }
  62.             }
  63.             else
  64.                 spriteBatch.Draw(characterSheetTexture, new Rectangle(_posicao.X, _posicao.Y,_posicao.Width, _posicao.Height), Color.White);
  65.         }
  66.  
  67.         public void SetQuadradoChutar(Texture2D quadrado)
  68.         {
  69.             _quadradoChutar = quadrado;
  70.         }
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement