package com.ideabobo.game.leidian;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Panel;
import java.awt.Toolkit;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.LinkedList;
import java.util.Random;
public class GamePanel extends Panel implements Runnable {
static final int WIDTH = 450;
static final int HEIGHT = 500;
private Thread gameThread;
public static int gameMode;
private Image offImage;
//g_off在背景上面作画的画笔
private Graphics g_off;
public static Image heroImage;
public static Image enemyImageA;
public static Image enemyImageB;
public static Image enemyImageC;
public static Image enemyImageD;
public static Image bossImageA;
public static Image bossImageB;
public static Image bossImageC;
public static Image flagImage;
public static Image zikiBeamImage;
public static Image enemyBeamImage;
public static Image enemyTamaImage;
public static Image burstImage[] = new Image[16];
public static Image largeBurstImage[] = new Image[16];
public static Image splitBulletImage;
public static Image HomingBulletImage;
public static LinkedList list;
public static LinkedList listTmp;
public static final int STARTSCENE = 0;
public static final int STAGE1 = 1;
public static final int Stage1Clear = 4;
public static final int InitSTAGE2 = 8;
public static final int STAGE2 = 2;
public static final int Stage2Start = 5;
public static final int Stage2Clear = 6;
public static final int InitSTAGE3 = 7;
public static final int STAGE3 = 3;
public static final int Stage3Clear = 9;
public static final int Congratulation = 10;
public static final int GAMEOVERSCENE = 11;
public static final int READY = 12;
public static final int APPEARING = 13;
public static final int CREAR = 14;
public static final int DISAPPEARING = 15;
public static final int BOSS_DEATH = 16;
static boolean AppearingFlag = true;
static boolean DeathSeenAFlag = true;
static boolean DeathSeenBFlag = true;
static boolean DeathSeenCFlag = true;
public static Burst burst;
public static BigBurst largeBurst;
public int t_loon_framework;
Battle battle;
Boss boss;
public static int time = 0;
public static int skillCount = 10;
public StageA stageA;
public StageB stageB;
public StageC stageC;
int current;
Start star[];
Random random;
private int stage;
private float heroX;
private float zikiY;
private float bossX;
private float bossY;
private int bossDeathAnimeCount;
public int skillAnimeCount;
private static final long serialVersionUID = 1L;
public GamePanel() {
offImage = null;
current = 0;
//新建Start类型数组大小为20
star = new Start[Start.num_Star];
//调整窗口尺寸
setPreferredSize(new Dimension(450, 500));
Role.app = this;
list = new LinkedList();
listTmp = new LinkedList();
heroImage = loadImage("image/this.gif");
enemyImageA = loadImage("image/enemyA.gif");
enemyImageB = loadImage("image/enemyB.gif");
enemyImageC = loadImage("image/enemyC.gif");
enemyImageD = loadImage("image/enemyD.gif");
bossImageA = loadImage("image/bossA.gif");
bossImageB = loadImage("image/bossB.gif");
bossImageC = loadImage("image/bossC.gif");
flagImage = loadImage("image/ballSilver.gif");
zikiBeamImage = loadImage("image/beam2.gif");
enemyBeamImage = loadImage("image/beam3.gif");
enemyTamaImage = loadImage("image/ballRed.gif");
//爆炸图片数组
for (int i = 0; i < 16; i++)
burstImage[i] = loadImage("image/burst" + i + ".gif");
//蓝色圆形子弹
splitBulletImage = loadImage("image/ballBlue.gif");
//大型爆炸图片数组
for (int i = 0; i < 16; i++)
largeBurstImage[i] = loadImage("image/largeBurst" + i + ".gif");
//绿色圆形子弹
HomingBulletImage = loadImage("image/ballGreen.gif");
gameMode = 0;
stage = 1;
random = new Random();
for (int i = 0; i < Start.num_Star; i++){
//Start(int x, int y, int vy, int width, Color color)
star[i] = new Start(Math.abs(random.nextInt()) * 450, Math
.abs(random.nextInt()) * 500, 5 * Math
.abs(random.nextInt()), 5 * Math.abs(random.nextInt()),
Color.white);
}
addKeyListener(new Key());
setFocusable(true);
requestFocus();
setBackground(Color.black);
setForeground(Color.white);
gameThread = new Thread(this);
gameThread.start();
}
public void run() {
while (gameThread == Thread.currentThread()) {
//画黑色的背景
gameRender();
//g_off在背景上面作画的画笔
if (g_off != null) {
long RefreshTime = System.currentTimeMillis();
try {
Thread.sleep(2L);
} catch (InterruptedException e) {
e.printStackTrace();
}
switch (gameMode) {
case 0:
title();
break;
case 1:
stage1();
break;
case 12:
ready();
break;
case 14:
crear();
break;
case 13:
appearingAnime();
break;
case 2:
stage2();
break;
case 3:
stage3();
break;
case 10:
congratulation();
break;
case 11:
gameOver();
break;
case 15:
disappearing();
break;
case 16:
bossDeathAnime();
break;
}
paintScreen();
current++;
while (System.currentTimeMillis() - RefreshTime < 13L);
}
}
}
private void disappearing() {
g_off.setColor(Color.white);
Font font = new Font("宋体", 1, 28);
g_off.setFont(font);
g_off.drawString("关卡 " + stage + " 完结", 100, 250);
battle.setPower(battle.getPowerMax());
if (zikiY + battle.getHeight() > 0.0F) {
g_off.drawImage(battle.getImage(), (int) heroX, (int) zikiY, null);
} else {
gameMode = 12;
stage++;
}
if (stage == 4) {
gameMode = 10;
}
//**//--///loonframewrk提供
zikiY -= 2.0F;
}
private void crear() {
if (stage == 1) {
gameMode = 16;
} else if (stage == 2) {
gameMode = 16;
} else if (stage == 3) {
gameMode = 16;
}
}
private void bossDeathAnime() {
if (bossY + boss.getHeight() > 0.0F) {
g_off.drawImage(boss.getImage(), (int) bossX, (int) bossY, null);
if (bossDeathAnimeCount % 5 == 0) {
burst = new Burst((float) ((double) bossX + (double) boss
.getWidth()
* Math.random()),
(float) ((double) bossY + (double) boss.getHeight()
* Math.random()));
burst.draw(g_off);
}
g_off.drawImage(battle.getImage(), (int) heroX, (int) zikiY, null);
bossDeathAnimeCount++;
bossY--;
} else {
gameMode = 15;
}
}
public void skillAnime(){
if (skillAnimeCount % 5 == 0) {
burst = new Burst((float) (400* Math.random()),(float) (300* Math.random()));
burst.draw(g_off);
}
skillAnimeCount++;
}
private void stage1() {
StageA.start();
gameMain();
}
private void stage2() {
StageB.start();
gameMain();
}
private void stage3() {
StageC.start();
gameMain();
}
private void congratulation() {
g_off.setColor(Color.white);
g_off.drawString("恭喜", 100, 250);
}
//关卡开始的准备画面
private void ready() {
bossDeathAnimeCount = 0;
skillAnimeCount = 0;
time = 0;
list.clear();
listTmp.clear();
battle = new Battle();
heroX = battle.getX();
zikiY = battle.getY() + battle.getHeight() * 4F;
switch (stage) {
case 1:
stageA = new StageA(battle);
break;
case 2:
stageB = new StageB(battle);
break;
case 3:
stageC = new StageC(battle);
break;
}
addList(battle);
gameMode = 13;
}
private void appearingAnime() {
g_off.setColor(Color.white);
g_off.drawString("STAGE" + stage, 1
没有合适的资源?快使用搜索试试~ 我知道了~
基于Java的雷电游戏的设计与实现
共176个文件
gif:96个
class:39个
java:38个
需积分: 1 0 下载量 189 浏览量
2024-05-16
21:35:24
上传
评论
收藏 328KB ZIP 举报
温馨提示
电脑游戏,是指在计算机上能够运转的游戏软件。这种软件具有较强的娱乐性。电脑游戏的创新和发展与硬件、软件的发展紧密相关。它能够给玩家提供一个虚拟的环境,使游戏带给了人们很多的享受和欢乐。雷电游戏因为操作简单,节奏明快,一直是纵轴射击游戏的经典之作。经常能够在手机或者计算机中见到这款游戏,深得广大玩家的喜爱,可以说是妇孺皆知的一款益智类游戏。 本游戏基于Eclipse开发平台,以java作为编程语言,整个项目开发旨在模拟雷电游戏的飞机射击游戏。游戏界面的下部是玩家的飞机,可以根据按键控制子弹的发射,上部为敌方飞机,在界面中随机出现。在游戏过程当中,用户飞机的移动是被电脑键盘的方向键所控制的,在整个游戏过程当中,如果用户飞机的子弹与敌方飞机发生相撞时,敌方飞机就会有爆炸的效果产生。游戏中使用到的飞机、子弹均采用对应的类实现。
资源推荐
资源详情
资源评论
收起资源包目录
基于Java的雷电游戏的设计与实现 (176个子文件)
GamePanel.class 14KB
Battle.class 6KB
BossC.class 4KB
BossB.class 4KB
BossA.class 4KB
StageC.class 3KB
StageA.class 3KB
StageB.class 3KB
EnemyA.class 2KB
Enemy.class 2KB
SplitBullet.class 2KB
MoveHomingBullet.class 2KB
Boss.class 2KB
EnemyC.class 2KB
Role.class 2KB
EnemyB.class 1KB
RandomNBullet.class 1KB
Key.class 1KB
Hero.class 1KB
NBullets.class 1KB
Power.class 1KB
FireboltRaidenMain.class 1KB
EnemyBeam.class 1KB
Burst.class 1KB
BigBurst.class 1KB
MessBullets.class 1KB
MoveAimingBullet.class 1KB
CircleBullets.class 1KB
Start.class 1KB
BattleBeam.class 1KB
Stage1Start.class 1KB
BattleAppearing.class 962B
EnemyShot.class 869B
FireboltRaidenMain$1.class 799B
DirectionalBullet.class 683B
EnemyTable.class 554B
ScorePanel.class 553B
BattleBasic.class 516B
BattleShot.class 451B
.classpath 301B
baku.gif 28KB
baku.gif 28KB
bossB.gif 12KB
bossB.gif 12KB
bossA.gif 9KB
bossA.gif 9KB
bossC.gif 8KB
bossC.gif 8KB
largeBurst7.gif 3KB
largeBurst7.gif 3KB
largeBurst5.gif 3KB
largeBurst5.gif 3KB
largeBurst6.gif 3KB
largeBurst6.gif 3KB
largeBurst4.gif 3KB
largeBurst4.gif 3KB
largeBurst8.gif 3KB
largeBurst8.gif 3KB
largeBurst3.gif 2KB
largeBurst3.gif 2KB
largeBurst9.gif 2KB
largeBurst9.gif 2KB
largeBurst2.gif 2KB
largeBurst2.gif 2KB
largeBurst10.gif 2KB
largeBurst10.gif 2KB
largeBurst11.gif 2KB
largeBurst11.gif 2KB
largeBurst1.gif 2KB
largeBurst1.gif 2KB
largeBurst12.gif 1KB
largeBurst12.gif 1KB
burst3.gif 1KB
burst4.gif 1KB
burst3.gif 1KB
burst4.gif 1KB
burst2.gif 1KB
burst2.gif 1KB
burst6.gif 1KB
burst6.gif 1KB
burst5.gif 1KB
burst5.gif 1KB
enemyC.gif 1KB
enemyC.gif 1KB
burst7.gif 1KB
burst7.gif 1KB
burst1.gif 1KB
burst1.gif 1KB
largeBurst0.gif 1KB
largeBurst0.gif 1KB
this.gif 1KB
this.gif 1KB
enemyB.gif 1KB
enemyB.gif 1KB
burst8.gif 1KB
burst8.gif 1KB
burst9.gif 1KB
burst9.gif 1KB
burst10.gif 1KB
enemyA.gif 1KB
共 176 条
- 1
- 2
资源评论
ShaZiJ
- 粉丝: 628
- 资源: 48
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功