protected override void Collision(BaseEntity col, Direction dir) { base.Collision(col, dir); CollisionEffect effect = new CollisionEffect(col, dir); collisionEffects.Add(effect); Game.AddEntity(effect); }
public CollisionEffect(BaseEntity col, Direction dir) { Layer = 5; Width = col.Width; Height = col.Height; switch (dir) { case Direction.Left: SetTexture(GameTextures.ArrowRight); X = col.X - col.Width; Y = col.Y; break; case Direction.Right: SetTexture(GameTextures.ArrowRight); Mirrored = true; X = col.X + col.Width; Y = col.Y; break; case Direction.Up: break; case Direction.Down: SetTexture(GameTextures.ArrowUp); X = col.X; Y = col.Y + col.Height; break; default: break; } }
protected override void CheckCollision(BaseEntity col) { if (this.Hitbox.Bottom > col.Hitbox.Top && this.Hitbox.Top < col.Hitbox.Bottom) { if (this.Hitbox.Right >= col.Hitbox.Left && this.Hitbox.Left < col.Hitbox.Left) { this.SpeedX = -speed; //col.drawHitbox = true; } else if (this.Hitbox.Left <= col.Hitbox.Right && this.Hitbox.Right > col.Hitbox.Right) { this.SpeedX = speed; //col.drawHitbox = true; } } }
/// <summary> /// Insert the object into the quadtree. if the node /// exceeds the capacity, it will split and add all /// objects to their corresponding nodes. /// </summary> /// <param name="ent"></param> public void Insert(BaseEntity ent) { if(Nodes[0] != null) { int index = GetIndex(ent.Hitbox); if(index != -1) { Nodes[index].Insert(ent); return; } } Objects.Add(ent); if(Objects.Count > MAX_OBJECTS && Level < MAX_LEVELS) { if(Nodes[0] == null) { Split(); } int i = 0; while(i < Objects.Count) { int index = GetIndex(Objects[i].Hitbox); if(index != -1) { Nodes[index].Insert(Objects[i]); Objects.RemoveAt(i); } else { i++; } } } }
public static void RemoveEntity(BaseEntity entity) { Entities.Remove(entity); CollidableEntities.Remove(entity); }
/// <summary> /// Adds an entity to the game's render and update loop /// </summary> /// <param name="entity">The Entity to add</param> public static void AddEntity(BaseEntity entity) { Entities.Add(entity); }
/// <summary> /// Adds an entity which needs to check for collision tot he game's render and update loop, /// By using this method it is not neccessary to use AddEntity too. /// </summary> /// <param name="entity">The entity to add.</param> public static void AddCollidableEntity(BaseEntity entity) { Entities.Add(entity); CollidableEntities.Add(entity); }
protected virtual void CheckCollision(BaseEntity col) { }