Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Text;
- using System.Threading.Tasks;
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Graphics;
- using Microsoft.Xna.Framework.Input;
- namespace EngineTest
- {
- public class Entity : ICloneable
- {
- protected Texture2D _texture;
- protected float _rotation;
- public Vector2 Position;
- public Vector2 Origin;
- public Vector2 Velocity;
- public Vector2 Speed;
- public Color Color = Color.White;
- public Rectangle Rectangle
- {
- get
- {
- return new Rectangle((int)Position.X, (int)Position.Y, _texture.Width, _texture.Height);
- }
- }
- public Entity (Texture2D texture)
- {
- _texture = texture;
- //Origin = new Vector2(_texture.Width / 2, _texture.Height / 2);
- }
- public virtual void Update(GameTime gameTime, List<Entity> entities)
- {
- }
- public virtual void Draw (SpriteBatch spriteBatch)
- {
- spriteBatch.Draw(_texture, Position, null, Color.White, _rotation, Origin, 1, SpriteEffects.None, 0);
- }
- public object Clone()
- {
- return this.MemberwiseClone();
- }
- #region Collision
- protected bool IsTouchingLeft(Vector2 pos, Entity entity)
- {
- return pos.X + _texture.Width >= entity.Rectangle.Left &&
- pos.X <= entity.Rectangle.Left &&
- pos.Y + _texture.Height >= entity.Rectangle.Top &&
- pos.Y <= entity.Rectangle.Bottom;
- }
- protected bool IsTouchingRight(Vector2 pos, Entity entity)
- {
- return pos.X >= entity.Rectangle.Right &&
- pos.X + _texture.Width >= entity.Rectangle.Right &&
- pos.Y + _texture.Height >= entity.Rectangle.Top &&
- pos.Y <= entity.Rectangle.Bottom;
- }
- protected bool IsTouchingTop(Vector2 pos, Entity entity)
- {
- return pos.X <= entity.Rectangle.Right &&
- pos.X + _texture.Width >= entity.Rectangle.Left &&
- pos.Y + _texture.Height >= entity.Rectangle.Top &&
- pos.Y <= entity.Rectangle.Top;
- }
- protected bool IsTouchingBottom(Vector2 pos, Entity entity)
- {
- return pos.X <= entity.Rectangle.Right &&
- pos.X + _texture.Width >= entity.Rectangle.Left &&
- pos.Y <= entity.Rectangle.Bottom &&
- pos.Y + _texture.Height >= entity.Rectangle.Bottom;
- }
- protected bool PlaceMeeting(Vector2 pos, Entity entity)
- {
- return IsTouchingLeft(pos, entity) ||
- IsTouchingRight(pos, entity) ||
- IsTouchingTop(pos, entity) ||
- IsTouchingBottom(pos, entity);
- }
- #endregion
- }
- }
Advertisement
RAW Paste Data
Copied
Advertisement