Exemple #1
0
 public override void Update(GameTime gametime)
 {
     base.Update(gametime);
     physic.UpdateVelocity(space.GetGravity(), 1, 0.01f);
     physic.UpdatePosition(1);
     shp.Update(trsf);
     ChipmunkSharp.cpVect vec = physic.GetPosition();
     Position = new Vector2(vec.x, vec.y);
     angle    = (physic.GetAngle() % 360) / 57.2958f;
     if (Position.Y > 200)
     {
         physic.ApplyImpulse(new ChipmunkSharp.cpVect(1, -100), new ChipmunkSharp.cpVect(0.1f, 0.1f));
     }
 }
Exemple #2
0
        public override void Tick(World world, GameTime gameTime)
        {
            Console.WriteLine(this.transform.Position);

            //PhysicalBody.Body.UpdatePosition((float)gameTime.ElapsedGameTime.TotalSeconds);


            //Tick the input controller
            inputController.TickInput(gameTime);


            float zoomLerpSpeed = 0.1f;



            //Move the player in the direction
            if (MoveDirection.Length() != 0)
            {
                playerAcceleration = MathHelper.Lerp(playerAcceleration, Speed, Acceleration * ((float)gameTime.ElapsedGameTime.TotalMilliseconds / 1000.0f));

                Vector2 result = (MoveDirection * playerAcceleration * (float)gameTime.ElapsedGameTime.TotalMilliseconds);

                MoveDirection.Normalize();
                PhysicalBody.Body.SetVelocity(new ChipmunkSharp.cpVect(result.X, PhysicalBody.Body.GetVelocity().y));
                //this.transform.Position += (MoveDirection * playerAcceleration * (float)gameTime.ElapsedGameTime.TotalMilliseconds);

                //Handle flipping our animation based on our move direction
                float dot = Vector2.Dot(MoveDirection, new Vector2(1, 0));
                if (dot < 0)
                {
                    animation.ShouldFlipAnimation = true;
                }
                else if (dot != 0)
                {
                    animation.ShouldFlipAnimation = false;
                }
                else
                {
                    runType = "run_sideways";
                }

                if (dot != 0)
                {
                    runType = "run";
                }

                //Clear move direction
                MoveDirection = Vector2.Zero;
            }
            else
            {
                PhysicalBody.Body.SetVelocity(new ChipmunkSharp.cpVect(0, PhysicalBody.Body.GetVelocity().y));
                playerAcceleration = MathHelper.Lerp(playerAcceleration, 0, Acceleration * ((float)gameTime.ElapsedGameTime.TotalMilliseconds / 1000.0f));
                zoomLerpSpeed      = 0.2f;
            }

            base.Tick(world, gameTime);

            //Animation switching
            if (playerAcceleration > 0.1 && currentAnimation != runType)
            {
                animation.SetAnimationFrames(animations[runType]);
                currentAnimation = runType;
                animation.Reset();
            }

            if (playerAcceleration < 0.1 && currentAnimation != "idle")
            {
                animation.SetAnimationFrames(animations["idle"]);
                currentAnimation = "idle";
            }

            //Update camera to follow player?

            PlayerCamera.transform.Position = Vector2.Lerp(PlayerCamera.transform.Position, this.transform.Position, 2 * (float)gameTime.ElapsedGameTime.TotalMilliseconds / 1000.0f);
            PlayerCamera.transform.Rotation = (float)Math.Sin(gameTime.TotalGameTime.TotalMilliseconds / 800) / 64.0f;

            ChipmunkSharp.cpVect vel = PhysicalBody.Body.GetVelocity();

            float zoom = MathHelper.Lerp(0.2f, 1f, (float)Math.Clamp(((vel.x * vel.x) + (vel.y * vel.y)) / Speed, 0, 1.0f));

            camZoom = MathHelper.Lerp(camZoom, zoom, zoomLerpSpeed * ((float)gameTime.ElapsedGameTime.TotalMilliseconds / 1000.0f));
            PlayerCamera.transform.Scale = new Vector2(camZoom * 1000, camZoom * 1000);
        }