public void Register(RectCollider collider, string layer) { int chunkIndex = Peaks(collider.rect.center.x); Chunk chunk = GetChunk(chunkIndex); chunk.Add(collider, layer); }
public override void Init() { Sprite sprite = new Sprite(); gameObject.AddComponent(sprite); gameObject.GetComponent <Sprite>().Load("Sprites/MainGuySpriteSheet_0"); gameObject.GetComponent <Sprite>().scale = 1; gameObject.GetComponent <Sprite>().rect = new Rectangle(46, 0, 32, 36); Transform transform = new Transform(); gameObject.AddComponent(transform); // gameObject.GetComponent<Transform>().position = new Vector2(Screen.width / 2 - gameObject.GetComponent<Sprite>().rect.Width, Screen.height / 2 - gameObject.GetComponent<Sprite>().rect.Height); gameObject.GetComponent <Transform>().position = new Vector2(pos_X, pos_Y - 32 * (gameObject.GetComponent <Sprite>().scale - 1)); RectCollider collider = new RectCollider(); gameObject.AddComponent(collider); gameObject.GetComponent <RectCollider>().Set(gameObject.GetComponent <Sprite>(), gameObject.GetComponent <Transform>()); SpriteRenderer render = new SpriteRenderer(); gameObject.AddComponent(render); gameObject.GetComponent <SpriteRenderer>().layer = 1; gameObject.GetComponent <SpriteRenderer>().Set(gameObject.GetComponent <Sprite>()); }
bool IsCollided(out RectCollider collider, Vector2 endPoint) { Vector2 outsidePointTarget; if (!MathHelper.LineIntersectRect(out outsidePointTarget, _gunRoot.position, endPoint, GameCamera.instance.viewport)) { Debug.LogWarning("No collision with the viewport and the aiming line"); } Rect boundingBox = MathHelper.ConstructRect(outsidePointTarget, _gunRoot.position); #if UNITY_EDITOR _boundingBox = boundingBox; #endif List <RectCollider> found = ColliderManager.instance.FindCollisions(boundingBox, "interactable"); Vector2 intersection; for (int i = 0; i < found.Count; i++) { if (MathHelper.LineIntersectRect(out intersection, _gunRoot.position, endPoint, found[i].rect)) { collider = found[i]; return(true); } } collider = null; return(false); }
public SongButton(Rectangle rect, String folder) { String[] songfiles = Directory.GetFiles(folder, "*.wav", SearchOption.TopDirectoryOnly); String[] dmlfiles = Directory.GetFiles(folder, "*.dml", SearchOption.TopDirectoryOnly); if (dmlfiles.Count() > 0) { dmlfile = dmlfiles[0]; } String[] pngs = Directory.GetFiles(folder, "*.png", SearchOption.TopDirectoryOnly);//gets images from folder String[] jpgs = Directory.GetFiles(folder, "*.jpg", SearchOption.TopDirectoryOnly); String[] images = new String[pngs.Length + jpgs.Length]; pngs.CopyTo(images, 0); jpgs.CopyTo(images, pngs.Length); if (images.Count() > 0) { String image = images[0]; texture = Texture2D.FromStream(Globals.graphics.GraphicsDevice, File.OpenRead(image));//reads images from stream(non content) } else { texture = new Texture2D(Globals.graphics.GraphicsDevice, 1, 1, false, SurfaceFormat.Color); texture.SetData <Color>(new Color[] { Color.White }); } this.song = songfiles[0]; if (songfiles.Length > 0) { this.music = new Wave(songfiles[0]); } this.title = songfiles[0]; this.rect = rect; CollisionMask = new RectCollider(rect); }
public override void Init() { Sprite sprite = new Sprite(); gameObject.AddComponent(sprite); gameObject.GetComponent <Sprite>().Load("Sprites/tomatoes01"); gameObject.GetComponent <Sprite>().scale = 1; gameObject.GetComponent <Sprite>().rect = new Rectangle(0, 50, 50, 45); Transform transform = new Transform(); gameObject.AddComponent(transform); gameObject.GetComponent <Transform>().position = new Vector2(Screen.width / 2 - gameObject.GetComponent <Sprite>().rect.Width, Screen.height / 2 - gameObject.GetComponent <Sprite>().rect.Height); RectCollider collider = new RectCollider(); gameObject.AddComponent(collider); gameObject.GetComponent <RectCollider>().Set(gameObject.GetComponent <Sprite>(), gameObject.GetComponent <Transform>()); SpriteRenderer render = new SpriteRenderer(); gameObject.AddComponent(render); gameObject.GetComponent <SpriteRenderer>().layer = 5; gameObject.GetComponent <SpriteRenderer>().Set(gameObject.GetComponent <Sprite>()); }
void FilterCollisions(List <RectCollider> colliders, Rect rect) { int removeIndex = -1; int removeCount = 0; for (int i = 0; i < colliders.Count; i++) { RectCollider c = colliders[i]; if (!c.rect.Overlaps(rect)) { removeCount++; if (removeIndex == -1) { removeIndex = i; } } else { if (removeIndex != -1) { // swap with the first remove item colliders[removeIndex] = c; removeIndex++; } } } if (removeIndex > -1) { colliders.RemoveRange(removeIndex, removeCount); } }
protected virtual void Awake() { if (__collider == null) { __collider = GetComponent <RectCollider>(); } }
public CollisionInfo(bool hitBottom, bool hitTop, bool hitRight, bool hitLeft, RectCollider obj) { this.hitBottom = hitBottom; this.hitTop = hitTop; this.hitRight = hitRight; this.hitLeft = hitLeft; this.obj = obj; }
public static void RegisterCollider(RectCollider collider) { if (colliders == null) { colliders = new List <RectCollider>(); } colliders.Add(collider); }
public SceneButton(string n, string texture_name, Vector2 topleft, Rectangle rect) { name = n; locked = false; selected = false; texture = Globals.content.Load <Texture2D>(texture_name); CollisionMask = new RectCollider(rect); }
public void Actualize(float dt) { RectCollider playerCollider = Player.instance.collider; List <RectCollider> colliders = ColliderManager.instance.FindCollisions(playerCollider.rect, _colliderLayer); for (int i = 0; i < colliders.Count; i++) { colliders[i].triggerZone.OnTrigger(); } }
public SceneButton(string n, string texture_name, Vector2 topleft) { // Constructor edited by: Michael Ala name = n; locked = false; selected = false; // Initialize RectCollider texture = Globals.content.Load <Texture2D>(texture_name); CollisionMask = new RectCollider(topleft.X, topleft.Y, texture.Width, texture.Height); }
public void Add(RectCollider collider, string layer) { if (!_quadTreeDict.ContainsKey(layer)) { QuadTrees qt = new QuadTrees(_bounds); _quadTreeDict.Add(layer, qt); _quadTreeList.Add(qt); } _quadTreeDict[layer].Insert(collider); }
public override void Initialize() { D3D9Manager.Instance.OnMouseClickEvent += OnClick; if (rectCollider == null) { rectCollider = new RectCollider() { Range = new Rectangle(0, 0, ButtonTexture.Width, ButtonTexture.Height) }; } }
public bool CheckCollision(CircleCollider circle, RectCollider rect) { var closestX = MathHelper.Clamp(circle.X, rect.X, rect.X + rect.Widht); var closestY = MathHelper.Clamp(circle.Y, rect.Y, rect.Y + rect.Height); // Calculate the distance between the circle's center and this closest point var distanceX = circle.X - closestX; var distanceY = circle.Y - closestY; // If the distance is less than the circle's radius, an intersection occurs var distanceSquared = (distanceX * distanceX) + (distanceY * distanceY); return(distanceSquared < (circle.Radius * circle.Radius)); }
public bool CollisionCheck(RectCollider area, out List <Entity> e) { var collidedWith = new List <Entity>(); e = collidedWith; foreach (var entity in Entities) { if (!entity.destroy && entity.Collider.Active && entity.Collider.Collide(area)) { collidedWith.Add(entity); } } return(collidedWith.Count > 0); }
private void OnCollisionEnter2D(Collision2D other) { RectCollider rect = other.gameObject.GetComponent <RectCollider>(); if (rect != null) { if (rect.blockType == BlockType.breakable) { Destroy(other.gameObject); } if (rect.blockType == BlockType.coinblock) { other.gameObject.GetComponent <SpriteRenderer>().sprite = aout; } } }
public void Initialize(GameServiceContainer gameServices, ContentManager content, PropertyMap propMap, Vector2 position) { Health = propMap.GetInt("Health"); Tag = propMap["Tag"]; _spriteSheet = content.Load <Texture2D>(SPRITE_SHEET_PATH); Sprite = new Sprite(0, 0, SPRITE_SIZE, SPRITE_SIZE, _spriteSheet); Position = position; IPhysicsManager physicsManager = gameServices.GetService <IPhysicsManager>(); this.Collider = physicsManager.CreateRectCollider(this, new Vector2(ROCK_SIZE), false); _debugTexture = content.Load <Texture2D>(DEBUG_TEXTURE_PATH); }
public override void Initialize() { D3D9Manager.Instance.AddMessageHandler(MsgProc); D3D9Manager.Instance.OnMouseClickEvent += OnMouseClick; if (Range == null) { if (FieldTexture != null) { Range = new RectCollider(new Rectangle(0, 0, FieldTexture.Width, FieldTexture.Height)); } else { Range = new RectCollider(new Rectangle(0, 0, 50, 50 * MaxLength)); } } }
public void Insert(RectCollider collider) { QuadTree <RectCollider> quadTree = collider.isDynamic ? dynamicQT : staticQT; quadTree.Insert(collider, collider.rect); }
public static void DeleteCollider(RectCollider collider) { colliders.Remove(collider); }
private bool IntersectsWith(BoxCollider boxCollider) { return(RectCollider.IntersectsWith(boxCollider.RectCollider)); }
public bool CheckCollision(RectCollider rect1, RectCollider rect2) { return(rect1.Rect.Intersects(rect2.Rect)); }
public void Update() { CollisionMask = new RectCollider(rect); }