// Constructor that defines the sprite as a rectangle public Sprite(int x, int y, int w, int h) { this.position = new Vector(x, y); this.size = new Vector(w, h); this.velocity = new Vector(0, 0); this.shape = true; }
// Constructor that defines the sprite as a rectangle using vectors public Sprite(Vector pos, Vector size) { this.position = pos; this.size = size; this.velocity = new Vector(0, 0); this.shape = true; }
// Constructor that defines the sprite as an image public Sprite(Bitmap img, int x, int y) { this.img = img; this.position = new Vector(x, y); this.size = new Vector(img.Width, img.Height); this.velocity = new Vector(0, 0); }
private bool visible = true; // Boolean to define if the sprite is visible #endregion Fields #region Constructors // Constructor that defines the sprite as an image using vector public Sprite(Bitmap img, Vector pos) { this.img = img; this.position = pos; this.size = new Vector(img.Width, img.Height); this.velocity = new Vector(0, 0); }
private List<Sprite> sprites = new List<Sprite>(); // List of sprites to draw #endregion Fields #region Constructors // Initialise the renderer public Renderer(Vector res, Vector screen) { // Figure out the ratio this.Resolution = res; this.ScreenSize = screen; double ratioX = (double)Resolution.x / (double)ScreenSize.y; double ratioY = (double)Resolution.y / (double)ScreenSize.y; // use whichever multiplier is smaller ratio = ratioX < ratioY ? ratioX : ratioY; // Create the Game Canvas for drawing sprites onto. canvas = new Bitmap(Convert.ToInt32(ScreenSize.x * ratio), Convert.ToInt32(ScreenSize.y * ratio)); // Set up the graphic configs for the renderer fg = Graphics.FromImage(canvas); fg.InterpolationMode = InterpolationMode.HighQualityBicubic; fg.SmoothingMode = SmoothingMode.HighQuality; fg.PixelOffsetMode = PixelOffsetMode.HighQuality; fg.CompositingQuality = CompositingQuality.HighQuality; }
// Update the screen size public void UpdateScreenSize(Vector s) { this.ScreenSize = s; }
// Constructor that defines the sprite as a piece of text public Sprite(string t, int x, int y, int w, int h) { this.content = t; this.position = new Vector(x, y); this.size = new Vector(w, h); this.velocity = new Vector(0, 0); this.text = true; }
// Boolean to check if sprite clicked public bool IsClicked(Vector v) { if(v.x > position.x && v.x < (position.x+size.x) && v.y > position.y && v.y < (position.y + size.y)) { return true; } else { return false; } }
// Set the Resolution public static void SetResolution(Vector r) { Resolution = r; }