velocity.java

来自「基于JAVA编程的手机游戏--赛车游戏」· Java 代码 · 共 42 行

JAVA
42
字号
package game.entities;

//汽车的物理系统类(速度控制)
public class Velocity {

   float speed = 0;
   float bottom = 0.05f;

  public Velocity() {
  }
  
  public  float accelerate(){
	    if (speed == 0.0f)
	      speed = bottom;
	    else
	      speed = speed + ((top - speed) / 40);
	    if (speed > top)
	      speed = top;
	    return speed;
	  }

	  public  float brake(){
	      speed = speed - ((top-speed) / 10);
	      if (speed < bottom) speed = 0;
	    return speed;
	  }

	  public  float brake( int drag ){
	      speed = speed - ((top-speed) / drag);
	      if (speed < bottom) speed = 0;
	    return speed;
	  }
	  
	  static float top = 0.5f; // m/s

	  public float getSpeed()
	  {
		return speed;
	  }

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?