Advertisement
Guest User

Untitled

a guest
Jan 21st, 2018
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1. using Microsoft.Xna.Framework;
  2. using Microsoft.Xna.Framework.Graphics;
  3. using PingPong.Models;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9.  
  10. namespace PingPong.Sprites
  11. {
  12. public class Sprite
  13. {
  14. public Texture2D _texture;
  15.  
  16. public Vector2 Position;
  17. public Vector2 Velocity;
  18. public bool _visible { get; set; }
  19. public float Speed;
  20. private Input TextInputEventArgs;
  21. public int _type;
  22. public int _life;
  23.  
  24. public Rectangle Rectangle
  25. {
  26. get
  27. {
  28. return new Rectangle((int)Position.X, (int)Position.Y, _texture.Width, _texture.Height);
  29. }
  30. }
  31.  
  32. public Sprite(Texture2D texture,int type,bool Visible)
  33. {
  34. _texture = texture;
  35. _type = type;
  36. _visible = Visible;
  37.  
  38. }
  39. public Sprite(Texture2D texture, int type, bool Visible,int life)
  40. {
  41. _texture = texture;
  42. _type = type;
  43. _visible = Visible;
  44. _life = life;
  45. }
  46.  
  47. public virtual void Update(GameTime gameTime, List<Sprite> sprites)
  48. {
  49. }
  50.  
  51. public virtual void Draw(SpriteBatch spriteBatch)
  52. {
  53. spriteBatch.Draw(_texture, Position, Color.White);
  54. }
  55.  
  56.  
  57. //tu zaczyna się kolizja
  58. #region Collision
  59. protected bool isTouchingLeft(Sprite sprite)
  60. {
  61. return this.Rectangle.Right + this.Velocity.X > sprite.Rectangle.Left &&
  62. this.Rectangle.Left < sprite.Rectangle.Left &&
  63. this.Rectangle.Bottom > sprite.Rectangle.Top &&
  64. this.Rectangle.Top < sprite.Rectangle.Bottom;
  65. }
  66. protected bool isTouchingRight(Sprite sprite)
  67. {
  68. return this.Rectangle.Left + this.Velocity.X < sprite.Rectangle.Right &&
  69. this.Rectangle.Right > sprite.Rectangle.Right &&
  70. this.Rectangle.Bottom > sprite.Rectangle.Top &&
  71. this.Rectangle.Top < sprite.Rectangle.Bottom;
  72. }
  73. protected bool isTouchingTop(Sprite sprite)
  74. {
  75. return this.Rectangle.Bottom+ this.Velocity.Y > sprite.Rectangle.Top &&
  76. this.Rectangle.Top < sprite.Rectangle.Top &&
  77. this.Rectangle.Right > sprite.Rectangle.Left &&
  78. this.Rectangle.Left < sprite.Rectangle.Right;
  79. }
  80. protected bool isTouchingBottom(Sprite sprite)
  81. {
  82. return this.Rectangle.Top + this.Velocity.Y < sprite.Rectangle.Bottom &&
  83. this.Rectangle.Bottom > sprite.Rectangle.Bottom &&
  84. this.Rectangle.Right > sprite.Rectangle.Left &&
  85. this.Rectangle.Left < sprite.Rectangle.Right;
  86. }
  87.  
  88.  
  89.  
  90. #endregion
  91.  
  92. }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement