⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 velocity.java

📁 J2ME 从入门到精通(程序开发使用案例) 书中代码
💻 JAVA
字号:
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -