📄 velocity.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 + -