Beispiel #1
0
        public void Update(float gameTime)
        {
            if (respawnTimer > 0)
            {
                respawnTimer -= gameTime;
                velocity      = Vector2.Zero;
            }
            else
            {
                currentState.Update(this);

                if (isHit)
                {
                    shotCooldown -= gameTime;

                    if (shotCooldown <= 0)
                    {
                        isHit = false;
                    }
                }

                if (acceleration.Length() > 60)
                {
                    acceleration = acceleration.Scale(60);
                }

                acceleration += WallAvoid();

                velocity.X += acceleration.X * gameTime * 5;
                velocity.Y += acceleration.Y * gameTime * 5;

                if (velocity.Length() > 100)
                {
                    velocity = velocity.Scale(100);
                }

                rotation = Math.Atan2(velocity.Y, velocity.X);

                circle.Position.X += velocity.X * gameTime;
                circle.Position.Y += velocity.Y * gameTime;

                foreach (Rectangle rect in staticMap.rectangles)
                {
                    if (staticMap.IntersectsRect(rect, circle))
                    {
                        circle.Position.X -= velocity.X * gameTime;
                        circle.Position.Y -= velocity.Y * gameTime;
                        velocity           = Vector2.Zero;
                    }
                }
            }
        }
Beispiel #2
0
        public void Update(StaticMap map, float gameTime)
        {
            Position += (unit * 500f) * gameTime;

            if (Position.X < -100 || Position.X > 1300 || Position.Y < -100 || Position.Y > 1300)
            {
                IsActive = false;
            }

            foreach (var rect in map.rectangles)
            {
                if (map.IntersectsRect(rect, Position))
                {
                    IsActive = false;
                }
            }
        }