private void AICollision(Quadtree quadtree, float elapsed, int numThread) { canJump = false; Vector2 newpos = new Vector2(); newpos = pos + speed * elapsed; Rectangle collisionrect = new Rectangle( orgcollisionrect.X + (int)pos.X + orgcollisionrect.Width/2, orgcollisionrect.Y + (int)pos.Y+ orgcollisionrect.Height / 2, orgcollisionrect.Width - orgcollisionrect.Width / 2, orgcollisionrect.Height - orgcollisionrect.Height / 2); Rectangle newcollisionrect = new Rectangle( orgcollisionrect.X + (int)newpos.X, orgcollisionrect.Y + (int)newpos.Y, orgcollisionrect.Width, orgcollisionrect.Height); List<Tile> leveltiles; leveltiles = quadtree.GetEnemyCollision(newcollisionrect, numThread); foreach (Tile tile in leveltiles) { if (tile.TileColission_Type != TileCollision.Event) { //newpos = pos + speed * elapsed; //BottomCollision if (collisionrect.Bottom <= tile.get_rect.Y && newcollisionrect.Bottom >= tile.get_rect.Y) { if (newcollisionrect.Right >= tile.get_rect.X && (int)(newcollisionrect.Left) <= tile.get_rect.Right) { animations.CurrentAnimation = Anims.Walk; newpos.Y -= speed.Y * elapsed; speed.Y = 0; gravity = new Vector2(); jumping = false; jumpSpeed = new Vector2(); canJump = true; break; } } if (tile.TileColission_Type == TileCollision.Impassable) { //RightCollision if (tile.get_rect.X >= collisionrect.Right && newcollisionrect.Right > tile.get_rect.X) { if (newcollisionrect.Bottom > tile.get_rect.Y && newcollisionrect.Top < tile.get_rect.Bottom) { if (!pathfound) rundirection = StandardDirection.Left; speed.X = 0; //continue; } } //LeftCollision else if (collisionrect.Left > tile.get_rect.Right && newcollisionrect.Left <= tile.get_rect.Right) { if (newcollisionrect.Bottom >= tile.get_rect.Y && newcollisionrect.Top <= tile.get_rect.Bottom) { if (!pathfound) rundirection = StandardDirection.Right; speed.X = 0; //continue; } } //UpCollision else if (collisionrect.Y >= tile.get_rect.Bottom && newcollisionrect.Top < tile.get_rect.Bottom) { if (newcollisionrect.Right >= tile.get_rect.X && newcollisionrect.Left <= tile.get_rect.Right) { speed.Y *= -1; jumping = false; jumpSpeed = new Vector2(); continue; } } } } } }
/// <summary> /// Initializes the KillAnimation /// </summary> public void Kill(Quadtree quadtree,Matrix matrix) { alive = false; particleManager.SpawnPos = pos; //particleManager.UseTimedAlpha = true; //particleManager.Alpha = 1; DebugManager.AddItem("Enemy #" + myNumber + " killed", this.ToString(), new System.Diagnostics.StackTrace()); particleManager.UseMinSpeed = true; particleManager.MinSpeed = new Vector2(300); if (speed.X < 0) particleManager.MaxSpeed = new Vector2(500, 500); else particleManager.MaxSpeed = new Vector2(-500, 500); Rectangle particlerect = new Rectangle((int)pos.X - 150, (int)pos.Y - 150, (int)pos.X + 300, (int)pos.Y + 300); List<Tile> collisions = quadtree.GetEnemyCollision(particlerect, numThread); Collisions = collisions; foreach (Tile collision in collisions) if (collision.TileColission_Type != TileCollision.Passable && collision.Standable) particleManager.AddCollisionRect(collision.get_rect); particleManager.StartExplosion(); wave.Enabled = true; wave.StartResetEffect(); wave.CenterCoord = Vector2.Transform(pos, matrix); wave.Disortion = 0.1f; wave.DistortionChange = -0.2f; wave.RadiusChange = 0.5f; wave.SizeChange = 0f; wave.MaxRadius = 0.2f; wave.Size = 0.02f; }