예제 #1
0
        public void Update(int iterations)
        {
            input.Update(iterations, world, this);

            if (!acceleration.IsValid())
                acceleration = new Vector(0, 0);

            Velocity += acceleration * factor1;

            Velocity *= 0.97;

            oldPosition = Position.Clone();
            Position += Velocity * factor2;

            Cell currentCell = GetCurrentCell();

            if (currentCell.CellType == CellType.Attractor && Collide(currentCell))
            {
                Score += 50;
                currentCell.CellType = CellType.Normal;
            }

            foreach (Bumpership b in world.Bumperships.Where(b => b != this && Collide(b)))
            {
                Position = oldPosition;

                Vector oldVelocityA = Velocity.Clone();
                Vector oldVelocityB = b.Velocity.Clone();

                Velocity = Reflect(Velocity, Normalize(Position - b.Position));
                b.Velocity = Reflect(b.Velocity, Normalize(b.Position - Position));

                lastcollider = b;
                b.lastcollider = this;

                if (Velocity.Length > b.Velocity.Length)
                {
                    b.Velocity += oldVelocityA * 0.8;
                    Velocity *= 0.2;
                    Score += 5;
                    b.Score -= 5;
                }
                else
                {
                    b.Velocity += oldVelocityB * 0.8;
                    Velocity *= 0.2;
                    b.Score += 5;
                    Score -= 5;
                }
            }

            if (currentCell.CellType == CellType.None)
            {
                if (lastcollider != null)
                {
                    lastcollider.Score += 50;
                    lastcollider = null;
                }
                if (IsSpawnable())
                {
                    Score -= 50;
                    Spawn();
                }
            }

            foreach (Cell cell in GetTouchingCells().Where(Collide))
            {
                if (cell.CellType == CellType.Blocked && Collide(cell.Position, 0.5))
                {
                    Position = oldPosition;
                    Velocity = Reflect(Velocity, Normalize(Position - cell.Position));
                }
                else if (cell.CellType == CellType.Boost)
                    Velocity *= 1.1;
                else if (cell.CellType == CellType.SlowDown)
                    Velocity *= 0.9;
            }
        }