Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Graphics;
- using PingPong.Models;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace PingPong.Sprites
- {
- public class Sprite
- {
- public Texture2D _texture;
- public Vector2 Position;
- public Vector2 Velocity;
- public bool _visible { get; set; }
- public float Speed;
- private Input TextInputEventArgs;
- public int _type;
- public int _life;
- public Rectangle Rectangle
- {
- get
- {
- return new Rectangle((int)Position.X, (int)Position.Y, _texture.Width, _texture.Height);
- }
- }
- public Sprite(Texture2D texture,int type,bool Visible)
- {
- _texture = texture;
- _type = type;
- _visible = Visible;
- }
- public Sprite(Texture2D texture, int type, bool Visible,int life)
- {
- _texture = texture;
- _type = type;
- _visible = Visible;
- _life = life;
- }
- public virtual void Update(GameTime gameTime, List<Sprite> sprites)
- {
- }
- public virtual void Draw(SpriteBatch spriteBatch)
- {
- spriteBatch.Draw(_texture, Position, Color.White);
- }
- //tu zaczyna się kolizja
- #region Collision
- protected bool isTouchingLeft(Sprite sprite)
- {
- return this.Rectangle.Right + this.Velocity.X > sprite.Rectangle.Left &&
- this.Rectangle.Left < sprite.Rectangle.Left &&
- this.Rectangle.Bottom > sprite.Rectangle.Top &&
- this.Rectangle.Top < sprite.Rectangle.Bottom;
- }
- protected bool isTouchingRight(Sprite sprite)
- {
- return this.Rectangle.Left + this.Velocity.X < sprite.Rectangle.Right &&
- this.Rectangle.Right > sprite.Rectangle.Right &&
- this.Rectangle.Bottom > sprite.Rectangle.Top &&
- this.Rectangle.Top < sprite.Rectangle.Bottom;
- }
- protected bool isTouchingTop(Sprite sprite)
- {
- return this.Rectangle.Bottom+ this.Velocity.Y > sprite.Rectangle.Top &&
- this.Rectangle.Top < sprite.Rectangle.Top &&
- this.Rectangle.Right > sprite.Rectangle.Left &&
- this.Rectangle.Left < sprite.Rectangle.Right;
- }
- protected bool isTouchingBottom(Sprite sprite)
- {
- return this.Rectangle.Top + this.Velocity.Y < sprite.Rectangle.Bottom &&
- this.Rectangle.Bottom > sprite.Rectangle.Bottom &&
- this.Rectangle.Right > sprite.Rectangle.Left &&
- this.Rectangle.Left < sprite.Rectangle.Right;
- }
- #endregion
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement