📄 t3d.java
字号:
import java.awt.*;
public class T3D{
public int health;
public int kills;
private surface Surface;
public cuboid body;
public cuboid tower;
public boolean rotateLeft, rotateRight, moveUp, moveDown, aimLeft, aimRight, aimUp, aimDown;
private double speed, rSpeedB, rSpeedT, rSpeedG;
private vector[] gun;
private double gunLength;
public vector gunCentre;
private double MaxAimAngle, MinAimAngle, currentAimAngle;
public int fireInterval;
private Color colour;
private explosion Explosion;
public T3D(surface Surface, int xpos, int ypos, int w, int l, int h, Color colour){
health = 100;
this.Surface = Surface;
this.colour = colour;
speed = 1;
rSpeedB = Math.PI/96;
rSpeedT = Math.PI/48;
rSpeedG = 0.1;
body = new cuboid(Surface, xpos, ypos, 0, 0, w, l, h, 1);
tower = new cuboid(Surface, xpos, ypos, h, 3,w-6, l-8, h-3, 2);
gun = new vector[6];
defindGunPosition();
gunLength = 20;
MaxAimAngle = gunLength*Math.sin(Math.PI/6);
MinAimAngle = -gunLength*Math.sin(Math.PI/100);
currentAimAngle = 4;
}
public void move(){
if(rotateLeft){
body.rotate(rSpeedB);
tower.rotate(rSpeedB);
}
if(rotateRight){
body.rotate(-rSpeedB);
tower.rotate(-rSpeedB);
}
if(moveUp){
body.move(speed);
tower.x = body.x;
tower.y = body.y;
tower.defindStatus();
}
if(moveDown){
body.move(-speed);
tower.x = body.x;
tower.y = body.y;
tower.defindStatus();
}
if(aimLeft)
tower.rotate(rSpeedT);
if(aimRight)
tower.rotate(-rSpeedT);
if(aimUp){
if(currentAimAngle <MaxAimAngle)
currentAimAngle+=rSpeedG;
}
if(aimDown){
if(currentAimAngle > MinAimAngle)
currentAimAngle-=rSpeedG;
}
defindGunPosition();
if(fireInterval >0)
fireInterval--;
if(Explosion != null){
Explosion.changeShape();
if(Explosion.over())
Explosion = null;
}
}
public void draw(Graphics g){
if(Explosion != null && Explosion.Outer !=null){
Explosion.draw(g);
if(Explosion.over())
Explosion = null;
}
body.draw(g, colour);
tower.draw(g, colour);
g.setColor(Color.black);
for(int i = 0; i < gun.length; i++){
for(int j = 0; j < gun.length; j++)
g.drawLine(gun[i].getX(), gun[i].getY(), gun[j].add(gunCentre).getX(), gun[j].add(gunCentre).getY());
}
if(fireInterval < 34 && fireInterval > 30){
g.setColor(Color.orange);
g.fillOval(gun[0].add(gunCentre).getX()- 2, gun[0].add(gunCentre).getY()- 2, 5, 5);
}
}
public void defindGunPosition(){
gun[0] = tower.centre.add(tower.direction3D.scale(tower.length/2)).add(tower.normal.scale(-tower.height/2));
gun[1] = gun[0].add(tower.normal.scale(-1));
gun[2] = gun[0].add(tower.direction3DCrossNor);
gun[3] = gun[1].add(tower.direction3DCrossNor);
gun[4] = gun[0].add(tower.direction3DCrossNor.scale(-1));
gun[5] = gun[1].add(tower.direction3DCrossNor.scale(-1));
gunCentre = tower.direction3D.scale(gunLength).add(tower.normal.scale(-currentAimAngle));
}
public ammunition fireAmmo(){
fireInterval = 35;
return new ammunition(Surface, gunCentre, gun[0].add(gunCentre), tower.direction3DCrossNor, 18);
}
public Point getPosition(){
return new Point(body.centre.getX(), body.centre.getY());
}
public void damage(T3D opposer){
if(health >0)
health-=(int)(Math.random()*10);
if(health <=0){
Explosion = new explosion(body.centre, body.gradient);
opposer.killsPLUSPLUS();
health = 100;
body.x = Math.random()*300;
body.y = Math.random()*300;
tower.x = body.x;
tower.y = body.y;
tower.defindStatus();
body.defindStatus();
}
}
public void killsPLUSPLUS(){
kills++;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -