问题描述
我的游戏对象 Cat 工作得很好,但我正在尝试包含更多图形。所以我想使用图像,而不是像猫一样的点。
import java.awt.Color;
import java.awt.Graphics;
public class Cat extends GameObject{
private float _acc=1f;
private float _dcc=0.5f;
private KeyInput input;
public Cat(int x,int y,ID id,KeyInput input )
{
super(x,y,id);
this.input=input;
}
@Override
public void tick()
{
y-=velY;
//Vertical movement
if(input.keys[2]) velY -= _acc;
if(input.keys[3]) velY += _acc;
else if(!input.keys[3] && !input.keys[2])
{
velY=2;
}
velY = clamp(velY,3,1);
}
@Override
public void render(Graphics g)
{
//this part draws a dot that resembles a Cat
g.setColor(Color.red);
g.fillRect((int)x,(int)y,40,40);
}
private float clamp(float vel,float max,float min )
{
if(vel>max)return max;
if(vel<min)return min;
return vel;
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)