示例#1
0
        public void engine_update(abstractKeys keys)
        {
            power = 0;

            if (keys.Right())
            {
                if (rpm < MINRPM)
                {
                    rpm = MINRPM; // in case the player is allready in motion
                }
                else
                if (rpm > MAXRPM)
                {
                    rpm = MAXRPM; // setting boundris
                }
                rpm  += RPMINC;
                power = rpm / MAXRPM * maxpower / 250; // calculating power, (not based on phizics just aproximetly)
                if (speed >= 0)
                {
                    speed = speed - speed * FRICTION + power / (speed + 0.2f);
                }
                else
                {
                    //rpm = MINRPM;
                    speed = speed - speed * FRICTION + Math.Abs(power / (speed + 0.2f)) + 1f;
                }
            }
            if (keys.Left())
            {
                if (rpm > -MINRPM)
                {
                    rpm = -MINRPM; // in case the player is allready in motion
                }
                else if (rpm < -MAXRPM)
                {
                    rpm = -MAXRPM;                                   // setting boundris
                }
                rpm -= RPMINC;                                       // decrising rpm

                power = -Math.Abs(rpm / MAXRPM * maxpower / RPMINC); // calculating power, (not based on phizics)

                // case 1: speed is positie, the player is moving foward
                if (speed <= 0)
                {
                    speed = speed + speed * FRICTION - Math.Abs(power / (speed + 0.2f));
                }
                // case 2: speed is negative, the player is moving backwards
                else
                {
                    //rpm = -MINRPM; // if i wont do this when the speed reaches 0 the rpm would be to big and there wont be any feal of phizics.
                    speed = speed - speed * FRICTION - Math.Abs(power / (speed + 0.2f)) - 1f;
                }
            }


            //setting speed limits
            if (speed > maxspeed)
            {
                speed = maxspeed;
            }
            if (speed < -maxspeed)
            {
                speed = -maxspeed;
            }

            this.velocity = new Vector2(speed, velocity.Y);
            #endregion
        }
示例#2
0
 public void engineupdate(abstractKeys keys, int index, IFocous f)
 {//activates the update function of an engine by his index
     eng[index].engine_update(keys);
 }