Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Audio;
- using Microsoft.Xna.Framework.Content;
- using Microsoft.Xna.Framework.GamerServices;
- using Microsoft.Xna.Framework.Graphics;
- using Microsoft.Xna.Framework.Input;
- using Microsoft.Xna.Framework.Media;
- namespace GrafikaRuchoma_01a
- {
- public class Tile
- {
- public Texture2D Sprite { get; set; }
- public Rectangle Position { get; set; }
- public double Rotation { get; set; }
- public Color TintColor { get; set; }
- public Rectangle? Source { get; set; }
- public float Scale { get; set; }
- public int Width { get { return Position.Width; } }
- public int Height { get { return Position.Height; } }
- public bool IsVisible { get; set; }
- public Tile(Texture2D sprite, Rectangle position, int rotation, Rectangle? source = null)
- {
- Sprite = sprite;
- Position = position;
- Rotation = rotation;
- Source = source;
- TintColor = Color.White;
- IsVisible = true;
- Scale = 1;
- }
- public void Rotate(int degrees)
- {
- Rotation += (Math.PI / 180) * degrees;
- if (Rotation >= 360)
- Rotation -= 360;
- else if (Rotation < 0)
- Rotation += 360;
- }
- public bool IsOn(Point mousePosition)
- {
- var position = Position;
- position.X -= Position.Width / 2;
- position.Y -= Position.Height / 2;
- return position.Contains(mousePosition);
- }
- public void Draw(SpriteBatch spriteBatch, bool center = true)
- {
- if (IsVisible)
- {
- var source = Source.HasValue ? Source : new Rectangle(0, 0, Sprite.Width, Sprite.Height);
- Vector2 origin = new Vector2(0, 0);
- if (center)
- origin = Source.HasValue ? new Vector2(Source.Value.Width / 2, Source.Value.Height / 2) : new Vector2(Sprite.Width / 2, Sprite.Height / 2);
- var position = new Rectangle(Position.X, Position.Y, (int)(Position.Width * Scale), (int)(Position.Height * Scale));
- spriteBatch.Draw(Sprite, position, source, TintColor, (float)Rotation, origin, SpriteEffects.None, 0);
- }
- }
- public void Resize(int width, int height)
- {
- Position = new Rectangle(Position.X, Position.Y, width, height);
- }
- public void SetPosition(int x, int y)
- {
- Position = new Rectangle(x, y, Position.Width, Position.Height);
- }
- public void SetScale(float scale)
- {
- Scale = scale;
- }
- public void SetColor(Color color)
- {
- TintColor = color;
- }
- public void SetVisibility(bool visible)
- {
- IsVisible = visible;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement