Example #1
0
        public void UpdateFireballs(GameTime gameTime)
        {
            fireballs.RemoveAll((Fireball f) => GetDistance(new Point(f.X, f.Y), player.Position.ToPoint()) > 3200);
            if (gameTime.TotalGameTime - lastFireballStepUpdate > fireballStepFreq)
            {
                foreach (var fireball in fireballs)
                {
                    if (fireball.Step < 3)
                    {
                        fireball.Step++;
                    }
                    else
                    {
                        fireball.Step = 0;
                    }
                }
                lastFireballStepUpdate = gameTime.TotalGameTime;
            }

            if (gameTime.TotalGameTime - lastFireballMoveUpdate > fireballMoveFreq)
            {
                List <Fireball> td = new List <Fireball>();
                foreach (var fireball in fireballs)
                {
                    Vector2 newPos = new Vector2(fireball.X, fireball.Y);
                    switch (fireball.Direction)
                    {
                    case 0:
                        newPos.Y += fireball.Speed;
                        break;

                    case 1:
                        newPos.X -= fireball.Speed;
                        break;

                    case 2:
                        newPos.X += fireball.Speed;
                        break;

                    case 3:
                        newPos.Y -= fireball.Speed;
                        break;
                    }

                    Rectangle pr = new Rectangle((int)newPos.X + 4, (int)newPos.Y + 4, 32 - 8, 32 - 8);
                    if (currentLocation.IsFree(pr))
                    {
                        fireball.X = (int)newPos.X;
                        fireball.Y = (int)newPos.Y;
                        particleController.FireballFlySparks(newPos + new Vector2(0, 5));
                    }
                    else
                    {
                        td.Add(fireball);
                    }
                }
                for (int i = 0; i < fireballs.Count; i++)
                {
                    if (td.IndexOf(fireballs[i]) != -1)
                    {
                        particleController.FireballDestroySparks(new Vector2(fireballs[i].X, fireballs[i].Y));
                        fireballs.RemoveAt(i);
                        i--;
                        continue;
                    }
                }
                //fireballs.RemoveAll((Fireball f) => td.IndexOf(f) != -1);


                lastFireballMoveUpdate = gameTime.TotalGameTime;
            }

            currentLocation.Update(gameRegistry, gameTime);
        }