예제 #1
0
        //**********************************************************
        //** methods:
        //**********************************************************

        public void Render(Skater skater)
        {
            var radius = skater.Mass * .9f;

            _skaterShape.Radius    = radius;
            _skaterShape.Scale     = new Vector2f(.6f, 1f);
            _skaterShape.Rotation  = skater.Angle;
            _skaterShape.Origin    = new Vector2f(radius, radius);
            _skaterShape.Position  = skater.Position;
            _skaterShape.FillColor = Color.Blue;

            _renderTarget.Draw(_skaterShape);
        }
예제 #2
0
        //**********************************************************
        //** methods:
        //**********************************************************

        public void Update(Skater skater)
        {
            if (Keyboard.IsKeyPressed(Keyboard.Key.A))
            {
                skater.Angle -= (360f * Timer.DeltaTimeSeconds);
            }
            if (Keyboard.IsKeyPressed(Keyboard.Key.D))
            {
                skater.Angle += (360f * Timer.DeltaTimeSeconds);
            }

            var rad = MathUtils.DegreeToRadian(skater.Angle - 90);
            var dir = new Vector2f(
                (float)Math.Cos(rad),
                (float)Math.Sin(rad)
                );

            var force = new Vector2f();

            if (Keyboard.IsKeyPressed(Keyboard.Key.W))
            {
                force += dir * skater.Strength;
            }
            if (Keyboard.IsKeyPressed(Keyboard.Key.Space))
            {
                force += dir * 100f;
            }

            force += -(skater.Velocity.Normalize() * 100f);

            var a = (force / skater.Mass);

            skater.Acceleration = a;
            skater.Velocity    += a;
            skater.Position    += skater.Velocity;
        }