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.Graphics;
- namespace CMFRGReworked
- {
- class Object
- {
- public Rectangle position; //standard varibel for 2D Objects
- protected Texture2D sprite; //standard varibel for 2D Objects
- protected SpriteBatch spriteBatch; //standard varibel for 2D Objects
- public Color[] textureData; // arrey of color varibels
- // just load in all data needed when a new object is made
- public Object(Texture2D sprite, SpriteBatch spriteBatch, int x, int y)
- {
- this.sprite = sprite;
- this.spriteBatch = spriteBatch;
- position = new Rectangle(x, y, sprite.Width , sprite.Height );
- textureData = new Color[sprite.Width * sprite.Height];
- sprite.GetData(textureData);
- }
- // all the suffs needed for pixel collition
- public bool Intersects(Rectangle rectangleIn, Color[] textureDataIn)
- {
- int top = Math.Max(position.Top, rectangleIn.Top);
- int bottom = Math.Min(position.Bottom, rectangleIn.Bottom);
- int left = Math.Max(position.Left, rectangleIn.Left);
- int right = Math.Min(position.Right, rectangleIn.Right);
- for (int y = top; y < bottom; y++)
- {
- for (int x = left; x < right; x++)
- {
- Color color1 = textureData[(x - position.Left) + (y - position.Top) * position.Width];
- Color color2 = textureDataIn[(x - rectangleIn.Left) + (y - rectangleIn.Top) * rectangleIn.Width];
- if (color1.A != 0 && color2.A != 0)
- {
- return true;
- }
- }
- }
- return false;
- }
- // simple draw method
- public void Draw()
- {
- spriteBatch.Draw(sprite, position, Color.White);
- }
- // method overloading
- // same thing but if u send a color with it will use that color as filter.
- public void Draw(Color color)
- {
- spriteBatch.Draw(sprite, position, color);
- }
- }
- }
- // to use the pixel collition
- // ObjectName.Intersects(otherObject.Position, otherObject.TextureData)
- // all objects that is going to intersect needs to have this data
- // so the smartest wey to use it is to make allt classes douthers classes to this one
- // so u allweys have the right data
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement