public static Image zd=PUtils.getImage(“images/zd.png”);//枪弹图片资源
public ImageIcon bz2=new
ImageIcon(PUtils.getImage(“images/dd2.png”));
public FightPlane(){
x=300;
y=300;
width=120;
height=120;
new CreateBullet().start();//创造画出枪弹的线程
}
@Override
public void drawMe(Graphics g) {
g.drawImage(image,x,y,width,height,null);
//画出枪弹;
for(int i=0;i<arrayList.size();i++){
//检验和测定枪弹能否与敌机相撞
for(int j=0;j<GamePanel.EnemyPlaneArrayList.size();j++){
if(GamePanel.EnemyPlaneArrayList.get(j).getRect().intersects(arrayList.get(i).getRect())){
/* int x=GamePanel.EnemyPlaneArrayList.get(j).x;
int y=GamePanel.EnemyPlaneArrayList.get(j).y;
GamePanel.EnemyPlaneArrayList.remove(j);
g.drawImage(bz2.getImage(),500,500,150,150,null);*/
GamePanel.EnemyPlaneArrayList.get(j).flat=1;
}
}
if(arrayList.get(i).y<20){
arrayList.remove(i);//优化枪弹类,当枪弹到达确定场所时让其消逝
}
arrayList.get(i).drawMe(g);
}
}
@Override
public Rectangle getRect() {
return new Rectangle(x,y,width,height);
}
//创造枪弹里面类
class Bullet extends GameObject{
public Bullet(){
width=60;
height=120;
}
@Override
public void drawMe(Graphics g) {//在面板上画出枪弹
g.drawImage(zd,x,y,width,height,null);
y-=3;
}
@Override
public Rectangle getRect() {
return new Rectangle(x,y,width,height);
}
}
/**
* 创造一个连接画出枪弹的线程
*/
class CreateBullet extends Thread{
@Override
public void run() {
while(true){
try {
Bullet bullet=new Bullet();
bullet.x=x+32;
bullet.y=y+20;
arrayList.add(bullet);
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
}
2.3敌机类
package com.eneity;
import com.utils.P;
import com.utils.PUtils;
import java.awt.*;
import java.util.LinkedList;
import java.util.List;
/**
* 敌机类
*/
public class EnemyPlane extends GameObject {
public int flat=0;//检验和测定枪弹能否与敌机相撞
public static Image dj =PUtils.getImage(“images/wugui.png”);//铁鸟图像资源
/* public static Image zd=PUtils.getImage(“images/zd.png”);//枪弹图片资源*/
public EnemyPlane(){
x=300;
y=300;
width=120;
height=120;
// new CreateBullet().start();//创造画出枪弹的线程
}
@Override
public void drawMe(Graphics g) {
g.drawImage(dj,x,y,width,height,null);
y+=3;//历次画完革新y坐标
if(y> P.HEIGHT){//俭朴资源反复运用每架铁鸟
y=-150;
}
/* //画出枪弹
for(int i=0;i<arrayList.size();i++){
arrayList.get(i).drawMe(g);
}*/
}
@Override
public Rectangle getRect() {
return new Rectangle(x,y,width,height);
}
/* //创造枪弹里面类
class Bullet extends GameObject{
public Bullet(){
width=60;
height=120;
}
@Override
public void drawMe(Graphics g) {//在面板上画出枪弹
g.drawImage(zd,x,y,width,height,null);
y-=3;
}
@Override
public Rectangle getRect() {
return null;
}
}
*//**
* 创造一个连接画出枪弹的线程
*//*
class CreateBullet extends Thread{
@Override
public void run() {
while(true){
try {
Bullet bullet=new Bullet();
bullet.x=x+32;
bullet.y=y+20;
arrayList.add(bullet);
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}*/
}
2.4战机连接展示类
package com.eneity;
import com.view.GamePanel;
import java.util.Random;
/**
* 源源不绝的创造敌机
*/
public class CreateEnemy extends Thread{
Random random =new Random();//创造随机数保护历次展示的敌机x坐标随机展示
@Override
public void run() {
while(true){
try {
EnemyPlane e= new EnemyPlane();
e.x=random.nextInt(650)+50;
e.y=-150;
GamePanel.EnemyPlaneArrayList.add(e);
Thread.sleep(300);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
3.controller遏制铁鸟挪动层
3.1PlaneController类
package com.controller;
import com.eneity.FightPlane;
import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
推荐阅读
- 长途飞机怎么舒服 如何在长途飞行中保持舒适
- ug4轴编程步骤 操作技巧如下
- 午餐肉可以带上飞机吗 你现在知道了吗
- 爽肤水可以带上飞机吗爽肤水能不能带上飞机
- 飞机备降是什么意思? 飞机备降是什么意思
- 天津特产可以带上飞机吗 天津能带上飞机的特产
- 飞机每小时飞行800什么 飞机每小时飞行800千米
- 飞机上的东西多少钱 成人用品飞机被卖多少钱一个
- 飞机坐在什么位置比较舒适 坐飞机哪些位置比较舒适
- 飞机托运水乳能带多少毫升 飞机托运水乳可以带多少