package com.sylva.tank;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.KeyEvent;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Timer;
import org.w3c.dom.css.Rect;
public class Tank implements Idestructible {
protected Point tankCenter = new Point(300, 300);
public int getDamage() {
return damage;
}
public void setDamage(int damage) {
this.damage = damage;
}
protected int speed = 2;
protected Color pedrail = Color.GRAY;
protected Color plant = new Color(60, 120, 25);
protected Color cab = new Color(40, 90, 40);
protected Color cannon = Color.BLACK;
protected int damage = 1;
protected camp tankCamp;
protected direction curDir = direction.U;
protected boolean alter = true;
protected int pedrailW = 5 + 2;
protected int pedrailH = 25 + 4;
protected int plantW = 15 + 2;
protected int plantH = 18 + 2;
protected int cabW = 9 + 2;
protected int attackRate=10;
protected int specialShot=0;
public int getSpecialShot() {
return specialShot;
}
public void setSpecialShot(int specialShot) {
this.specialShot = specialShot;
}
public int getLife() {
return life;
}
public int getSpeed() {
return speed;
}
public void setSpeed(int speed) {
this.speed = speed;
if(this.speed>8)this.speed=8;
}
public void setLife(int life) {
this.life = life;
}
protected int cabH = 12;
protected int cannonW = 3;
protected int cannonH = 17;
protected int pedrailint = 4;
protected int shotSpeed = 4;
protected boolean coolDown = false;
protected int CDint = 1000;
protected Freezer f = new Freezer();
protected boolean left = false, right = false, up = false, down = false;
protected BattleField bf;
protected boolean live=true;
protected Point oldCenter;
protected int autoCD=0;
protected int life=1;
public boolean isLive() {
return live;
}
public void setLive(boolean live) {
this.live = live;
}
enum direction {
L, R, U, D
};
enum camp{FRIEND,FOE};
protected boolean engine = false;
public Tank(Point tankCenter, camp tankCamp,BattleField bf) {
this.tankCenter = tankCenter;
this.bf = bf;
this.tankCamp =tankCamp;
f.start();
}
public Tank(int x, int y, camp tankCamp,BattleField bf) {
this(new Point(x, y),tankCamp, bf);
}
public Tank(int x, int y, camp tankCamp,BattleField bf, Color pedrail, Color plant,
Color cab, Color cannon) {
this(new Point(x, y),tankCamp, bf);
this.pedrail = pedrail;
this.plant = plant;
this.cab = cab;
this.cannon = cannon;
}
public Tank(int x, int y,camp tankCamp, BattleField bf, Color pedrail, Color plant,
Color cab, Color cannon, direction oriDir) {
this(x, y,tankCamp, bf, pedrail, plant, cab, cannon);
this.curDir = oriDir;
}
public Tank(int x, int y,camp tankCamp, BattleField bf, Color pedrail, Color plant,
Color cab, Color cannon, direction oriDir,boolean boss) {
this(x, y,tankCamp, bf, pedrail, plant, cab, cannon);
this.curDir = oriDir;
this.pedrailH*=2;
this.pedrailW*=2;
this.plantH*=2;
this.plantW*=2;
this.cabH*=2;
this.cabW*=2;
this.cannonH*=2;
this.cannonW*=2;
this.pedrailint+=2;
}
public Missile fire() {
coolDown = true;
Point mc = null;
switch (curDir) {
case U:
mc = new Point(tankCenter.x, specialShot==0?(tankCenter.y - cannonH):(tankCenter.y - cannonH-(damage*3+30)));
break;
case D:
mc = new Point(tankCenter.x, specialShot==0?(tankCenter.y + cannonH):(tankCenter.y + cannonH+(damage*3+30)));
break;
case L:
mc = new Point(specialShot==0?(tankCenter.x - cannonH):(tankCenter.x - cannonH-(damage*3+30)), tankCenter.y);
break;
case R:
mc = new Point(specialShot==0?(tankCenter.x + cannonH):(tankCenter.x + cannonH+(damage*3+30)), tankCenter.y);
break;
}
if(specialShot!=0){
specialShot--;
return new Laser(this, mc, curDir, shotSpeed, bf, Color.RED);
}
return new Missile(this,mc, curDir, shotSpeed,bf,this.tankCamp==camp.FRIEND?Color.RED:Color.BLUE);
}
public void draw(Graphics g) {
if(!live){
bf.tanks.remove(this);
return;
}
if(tankCamp==camp.FOE&&(autoCD++)%20==0)autoDrive();
if(autoCD==1000)autoCD=0;
Color oriForeCol = g.getColor();
move();
if (curDir == direction.U || curDir == direction.D) {
g.setColor(pedrail);
g.draw3DRect(tankCenter.x - pedrailW - (plantW / 2), tankCenter.y
- (pedrailH / 2), pedrailW, pedrailH, true);
g.draw3DRect(tankCenter.x + (plantW / 2), tankCenter.y
- (pedrailH / 2), pedrailW, pedrailH, true);
if (alter) {
for (int i = tankCenter.y - (pedrailH / 2); i <= tankCenter.y
+ (pedrailH / 2); i += pedrailint) {
g.drawLine(tankCenter.x - pedrailW - (plantW / 2), i,
tankCenter.x - plantW / 2, i);
g.drawLine(tankCenter.x + (plantW / 2), i, tankCenter.x
+ plantW / 2 + pedrailW, i);
}
} else {
for (int i = tankCenter.y - (pedrailH / 2) + pedrailint / 2; i <= tankCenter.y
+ (pedrailH / 2); i += pedrailint) {
g.drawLine(tankCenter.x - pedrailW - (plantW / 2), i,
tankCenter.x - plantW / 2, i);
g.drawLine(tankCenter.x + (plantW / 2), i, tankCenter.x
+ plantW / 2 + pedrailW, i);
}
}
g.setColor(plant);
g.fill3DRect(tankCenter.x - plantW / 2, tankCenter.y - plantH / 2,
plantW, plantH, true);
g.setColor(cab);
g.fill3DRect(tankCenter.x - cabW / 2, tankCenter.y - cabH / 2,
cabW, cabH, true);
g.setColor(cannon);
if (curDir == direction.U) {
g.fill3DRect(tankCenter.x - cannonW / 2,
tankCenter.y - cannonH, cannonW, cannonH, true);
} else {
g.fill3DRect(tankCenter.x - cannonW / 2, tankCenter.y, cannonW,
cannonH, true);
}
} else if (curDir == direction.L || curDir == direction.R) {
g.setColor(pedrail);
g.draw3DRect(tankCenter.x - pedrailH / 2, tankCenter.y - pedrailW
- plantW / 2, pedrailH, pedrailW, true);
g.draw3DRect(tankCenter.x - pedrailH / 2,
tankCenter.y + plantW / 2, pedrailH, pedrailW, true);
if (alter) {
for (int i = tankCenter.x - (pedrailH / 2); i <= tankCenter.x
+ (pedrailH / 2); i += pedrailint) {
g.drawLine(i, tankCenter.y - pedrailW - plantW / 2, i,
tankCenter.y - plantW / 2);
g.drawLine(i, tankCenter.y + (plantW / 2), i, tankCenter.y
+ plantW / 2 + pedrailW);
}
} else {
for (int i = tankCenter.x - (pedrailH / 2) + pedrailint / 2; i <= tankCenter.x
+ (pedrailH / 2); i += pedrailint) {
g.drawLine(i, tankCenter.y - pedrailW - plantW / 2, i,
tankCenter.y - plantW / 2);
g.drawLine(i, tankCenter.y + (plantW / 2), i, tankCenter.y
+ plantW / 2 + pedrailW);
}
}
g.setColor(plant);
g.fill3DRect(tankCenter.x - plantH / 2, tankCenter.y - plantW / 2,
plantH, plantW, true);
g.setColor(cab);
g.fill3DRect(tankCenter.x - cabH / 2, tankCenter.y - cabW / 2,
cabH, cabW, true);
g.setColor(cannon);
if (curDir == direction.L) {
g.fill3DRect(tankCenter.x - cannonH,
tankCenter.y - cannonW / 2, cannonH, cannonW, true);
} else {
g.fill3DRect(tankCenter.x, tankCenter.y - cannonW / 2, cannonH,
cannonW, true);
}
}
if (engine)
alter = !alter;
g.setColor(oriForeCol);
}
public void move() {
if (engine) {
oldCenter=new Point(tankCenter.x,tankCenter.y);
switch (curDir) {
case U:
tankCenter = new Point(tankCenter.x, tankCenter.y - speed);
break;
case D:
tankCenter = new Point(tankCenter.x, tankCenter.y + speed);
break;
case L:
tankCenter = new Point(tankCenter.x - speed, tankCenter.y);
break;
case R:
tankCenter = new Point(tankCenter.x + speed, tankCenter.y);
break;
}
}
if(tankCenter.x<cannonH)
tankCenter.x=cannonH;
if(tankCenter.x>bf.initSiz.width-cannonH)
tankCenter.x=bf.initSiz.width-cannonH;
if(tankCenter.y<cannonH+30)
tankCenter.y=cannonH+30;
if(tankCenter.y>bf.initSiz.height-cannonH)
tankCenter.y=bf.initSiz.height-cannonH;
barrier(bf.tanks)
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
很久以前初学java的时候写的小游戏.zip (49个子文件)
SylvanTank-master
LICENSE.md 11KB
SylvanTank
src
META-INF
MANIFEST.MF 62B
com
sylva
tank
SteelWall.java 844B
BattleField.java 8KB
Base.java 2KB
Explode.java 887B
Missile.java 5KB
DeathCross.java 2KB
Tank.java 11KB
BrickWall.java 2KB
CrazyLaser.java 4KB
Wall.java 948B
PowerUp.java 2KB
Idestructible.java 128B
Laser.java 3KB
SylvanTank.iml 423B
out
artifacts
SylvanTank_jar
SylvanTank.jar 32KB
production
SylvanTank
META-INF
MANIFEST.MF 62B
com
sylva
tank
Laser$1.class 801B
CrazyLaser.class 4KB
Tank$direction.class 1KB
Missile.class 6KB
BattleField$1.class 746B
Tank$camp.class 1010B
BattleField.class 9KB
SteelWall.class 2KB
Wall.class 1KB
Missile$1.class 807B
Idestructible.class 165B
PowerUp.class 3KB
Tank.class 12KB
Explode.class 2KB
Tank$1.class 773B
Tank$Freezer.class 982B
BattleField$TankPainter.class 1KB
CrazyLaser$1.class 816B
Base.class 2KB
BrickWall.class 2KB
Laser.class 4KB
BattleField$keyMonitor.class 1KB
DeathCross.class 4KB
.idea
.name 10B
artifacts
SylvanTank_jar.xml 294B
workspace.xml 40KB
misc.xml 1KB
compiler.xml 686B
modules.xml 260B
encodings.xml 159B
copyright
profiles_settings.xml 74B
共 49 条
- 1
资源评论
马coder
- 粉丝: 1200
- 资源: 6602
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功