⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 missile.java

📁 一个基于JAVA的小游戏
💻 JAVA
字号:
package com.bjsxt.tank.core;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.util.List;


public abstract class Missile extends GameObject{
	protected int offx;
	protected int offy;
	int SPEED = 10;
	protected static int WIDTH=10;
	protected static int HEIGHT=10;
	boolean good = true;
	Rectangle rect = new Rectangle(x,y,Missile.WIDTH,Missile.HEIGHT);
	static int count;
	public Missile(int x, int y, int offx, int offy,boolean good) {
		this.x = x;
		this.y = y;
		this.good = good;
		if(offx==0){
			this.offx=0;
		}else if(offx<0){
			this.offx = -SPEED;
		}else if(offx>0){
			this.offx = SPEED;
		}
		this.offx = offx==0?0:offx<0?-SPEED:SPEED;
		
		if(offy==0){
			this.offy=0;
		}else if(offy<0){
			this.offy = -SPEED;
		}else if(offy>0){
			this.offy = SPEED;
		}
		this.offy = offy==0?0:offy<0?-SPEED:SPEED;
		
		count ++;
		
	}
	public abstract void draw (Graphics g);
	protected void checkBounds() {
		if (x<0 || y<0 || x>TankClient.GAME_WIDTH || y>TankClient.GAME_HEIGHT) {
			die();
		}
	}
	public void die(){
		setLive(false);
		GameMediator.getInstance().removeGameObject(this);
		count--;
	}
	public boolean hitTank(Tank t) {
		if(this.good==t.good){
			return false;
		}
		if(t.good){
			return false;
		}
		
		if(!this.isLive()){
			return false;
		}
		if(!t.isLive()){
			return false;
		}
		
		if(this.getRect().intersects(t.getRect())){
			this.die();
			t.die();
			GameMediator.getInstance().addGameObject(GameFactoryMgr.getFactory().createExplode(t.x,t.y));
			return true;
		}
		return false;
		
	}
	public Rectangle getRect(){
		rect.x = this.x;
		rect.y = this.y;
		return this.rect;
	}
	public void hitTanks(List<Tank> tanks) {
		for (int i = 0; i < tanks.size(); i++) {
			Tank t = tanks.get(i);
			hitTank(t);
		}
		
	}
	public void hitWalls(List<Wall> walls) {
		for (int i = 0; i < walls.size(); i++) {
			Wall w = walls.get(i);
			hitWall(w);
		}
		
	}
	boolean hitWall(Wall w) {
		if(!this.isLive()){
			return false;
		}
		if(this.good){
			return false;
		}
		if(this.getRect().intersects(w.getRect())){
			this.die();
			return true;
		}
		return false;
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -