class_camera.java
来自「05年游戏学院一个学生写的项目」· Java 代码 · 共 96 行
JAVA
96 行
public class Class_Camera
{
//目标位置
static short x0,y0;
//当前位置
static short x,y;
//拍摄范围
static short width=176,height=208;
public Class_Camera()
{
}
//处理屏幕跟随坦克的方法
public static void setFollow(Class_Tank ct)
{
if(ct.getRefPixelX()<width/2)
x0=0;
else if(ct.getRefPixelX()>Class_Map.width-width/2)
x0=(short) (Class_Map.width-width);
else
x0=(short) (ct.getRefPixelX()-width/2);
if(ct.getRefPixelY()<height/2)
y0=0;
else if(ct.getRefPixelY()>Class_Map.height-height/2)
y0=(short) (Class_Map.height-height);
else
y0=(short) (ct.getRefPixelY()-height/2);
}
//处理屏幕跟随子弹的方法
public static void setFollow(Class_Bullet cb)
{
if(cb.getRefPixelX()<width/2)
x0=0;
else if(cb.getRefPixelX()>Class_Map.width-width/2)
x0=(short) (Class_Map.width-width);
else
x0=(short) (cb.getRefPixelX()-width/2);
if(cb.getRefPixelY()<=y0+height/4)
{
if(cb.getRefPixelY()<=height/4)
y0=0;
else
y0=(short) (cb.getRefPixelY()-height/4);
}
if(cb.getRefPixelY()>=y0+3*height/4)
{
if(cb.getRefPixelY()>=Class_Map.height-height/4)
y0=(short) (Class_Map.height-height);
else
y0=(short) (cb.getRefPixelY()-3*height/4);
}
}
//判断对象是否处于屏幕中的方法
public static boolean isShow(Class_GameObject go)
{
if(go.getX()>=x-go.getWidth()&&go.getX()<=x+width&&go.getY()>=y-go.getHeight()&&go.getY()<=y+height)
return true;
else return false;
}
//重置摄象机的方法
public static void rePut()
{
if(x>x0)
{
x-=10;
if(x<x0+10)
x=x0;
}else if(x<x0)
{
x+=10;
if(x>x0-10)
x=x0;
}
if(y>y0)
{
y-=10;
if(y<y0+10)
y=y0;
}else if(y<y0)
{
y+=10;
if(y>y0-10)
y=y0;
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?