package com.beancore.ui;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.image.ImageObserver;
import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException;
import javax.swing.JPanel;
import com.beancore.config.CatchableWeaponType;
import com.beancore.config.Config;
import com.beancore.config.EnemyPlaneType;
import com.beancore.config.ImageConstants;
import com.beancore.entity.Bomb;
import com.beancore.entity.Bullet;
import com.beancore.entity.CatchableWeapon;
import com.beancore.entity.EnemyPlane;
import com.beancore.entity.MyPlane;
import com.beancore.factory.CatchableWeaponFactory;
import com.beancore.factory.EnemyPlaneFactory;
import com.beancore.listener.BulletListener;
import com.beancore.listener.CatchableWeaponListener;
import com.beancore.listener.EnemyPlaneListener;
import com.beancore.util.Images;
import com.beancore.util.SoundPlayer;
public class GamePlayingPanel extends JPanel implements MouseListener, MouseMotionListener, BulletListener,
EnemyPlaneListener, CatchableWeaponListener, ImageObserver {
private static final long serialVersionUID = 1L;
private static int ANIMATION_STEP_1 = 1;
private static int ANIMATION_STEP_2 = 2;
private volatile List<Bullet> bullets;
private volatile List<EnemyPlane> enemyPlanes;
private int score;
private MyPlane myPlane;
private CatchableWeapon popBomb;
private CatchableWeapon popDoubleLaser;
private Thread paintThread;
private int remainTimeToPopSmallPlane;
private int remainTimeToPopBigPlane;
private int remainTimeToPopBossPlane;
private int remainTimeToPopBomb;
private int remainTimeToPopDoubleLaser;
private int remainTimeDoubleLaserRunOut;
private int bombAnomationStep;
private int doubleLaserAnimationStep;
private SoundPlayer smallPlaneKilledSoundPlayer;
private SoundPlayer bigPlaneKilledSoundPlayer;
private SoundPlayer bossPlaneKilledSoundPlayer;
private SoundPlayer bossPlaneFlyingSoundPlayer;
private SoundPlayer popWeaponSoundPlayer;
private SoundPlayer fireBulletSoundPlayer;
private SoundPlayer useBombSoundPlayer;
private SoundPlayer getDoubleLaserSoundPlayer;
private SoundPlayer getBombSoundPlayer;
private SoundPlayer gameMusicSoundPlayer;
private SoundPlayer gameOverSoundPlayer;
public GamePlayingPanel() throws LineUnavailableException, UnsupportedAudioFileException, IOException {
this.initSoundPlayer();
this.initComponents();
}
private void initComponents() {
this.addMouseMotionListener(this);
this.addMouseListener(this);
this.setSize(Config.MAIN_FRAME_WIDTH, Config.MAIN_FRAME_HEIGHT);
this.setDoubleBuffered(true);
this.setOpaque(false);
}
private void initSoundPlayer() throws LineUnavailableException, UnsupportedAudioFileException, IOException {
smallPlaneKilledSoundPlayer = new SoundPlayer(Config.SMALL_PLANE_KILLED_AUDIO);
bigPlaneKilledSoundPlayer = new SoundPlayer(Config.BIG_PLANE_KILLED_AUDIO);
bossPlaneKilledSoundPlayer = new SoundPlayer(Config.BOSS_PLANE_KILLED_AUDIO);
bossPlaneFlyingSoundPlayer = new SoundPlayer(Config.BOSS_PLANE_FLYING_AUDIO);
popWeaponSoundPlayer = new SoundPlayer(Config.POP_WEAPON_AUDIO);
fireBulletSoundPlayer = new SoundPlayer(Config.FIRE_BULLET_AUDIO);
useBombSoundPlayer = new SoundPlayer(Config.USER_BOMB_AUDIO);
getDoubleLaserSoundPlayer = new SoundPlayer(Config.GET_DOUBLE_LASER_AUDIO);
getBombSoundPlayer = new SoundPlayer(Config.GET_BOMB_AUDIO);
gameMusicSoundPlayer = new SoundPlayer(Config.GAME_MUSIC_AUDIO);
gameOverSoundPlayer = new SoundPlayer(Config.GAME_OVER_AUDIO);
}
@Override
public void onBulletLocationChanged(Bullet b) {
if (b != null) {
b.setPosY(b.getPosY() - b.getSpeed());
if (b.getPosY() <= 0) {
synchronized (this.bullets) {
this.bullets.remove(b);
}
}
EnemyPlane enemyPlane = b.hitEnemyPlanes();
if (enemyPlane != null) {
enemyPlane.drawFighting(this.getComponentGraphics(this.getGraphics()));
if (enemyPlane.isKilled()) {
switch (enemyPlane.getEnemyType()) {
case SMALL_ENEMY_PLANE:
this.smallPlaneKilledSoundPlayer.play();
break;
case BIG_ENEMY_PLANE:
this.bigPlaneKilledSoundPlayer.play();
break;
case BOSS_ENEMY_PLANE:
this.bossPlaneFlyingSoundPlayer.stop();
this.bossPlaneKilledSoundPlayer.play();
break;
}
synchronized (this) {
this.score += enemyPlane.getKilledScore();
}
synchronized (this.enemyPlanes) {
this.enemyPlanes.remove(enemyPlane);
}
synchronized (this.bullets) {
this.bullets.remove(b);
}
enemyPlane.drawKilled(this.getComponentGraphics(this.getGraphics()));
}
}
}
}
@Override
public void onEnemyPlaneLocationChanged(EnemyPlane p) {
if (p != null && !p.isKilled()) {
p.setPosY(p.getPosY() + p.getSpeed());
if (p.getPosY() >= this.getHeight()) {
if (p.getEnemyType().equals(EnemyPlaneType.BOSS_ENEMY_PLANE)) {
this.bossPlaneFlyingSoundPlayer.stop();
}
synchronized (this.enemyPlanes) {
enemyPlanes.remove(p);
}
} else {
if (p.getRectangle().intersects(myPlane.getRectange())) {
// game ends
synchronized (myPlane) {
if (myPlane.isAlive()) {
this.stopGame();
}
}
}
}
}
}
@Override
public void onCatchableWeaponLocationChanged(CatchableWeapon weapon) {
if (weapon != null) {
synchronized (weapon) {
int posY = weapon.getPosY();
if (weapon.isUseAnimation()) {
switch (weapon.getWeaponType()) {
case BOMB:
if (this.bombAnomationStep == ANIMATION_STEP_1) {
posY += Config.POP_WEAPON_ANIMATION_MOVE_FORWARD_SPEED;
this.bombAnomationStep++;
} else if (this.bombAnomationStep == ANIMATION_STEP_2) {
posY -= Config.POP_WEAPON_ANIMATION_MOV_BACK_SPEED;
this.bombAnomationStep = 0;
weapon.setUseAnimation(false);
weapon.setUseAnimationDone(true);
}
break;
case DOUBLE_LASER:
if (this.doubleLaserAnimationStep == ANIMATION_STEP_1) {
posY += Config.POP_WEAPON_ANIMATION_MOVE_FORWARD_SPEED;
this.doubleLaserAnimationStep++;
} else if (this.doubleLaserAnimationStep == ANIMATION_STEP_2) {
posY -= Config.POP_WEAPON_ANIMATION_MOV_BACK_SPEED;
this.doubleLaserAnimationStep = 0;
weapon.setUseAnimation(false);
weapon.setUseAnimationDone(true);
}
break;
}
} else {
posY += weapon.getSpeed();
}
weapon.setPosY(posY);
if (!weapon.isUseAnimationDone() && weapon.getPosY() >= this.getHeight() / 5) {
weapon.setUseAnimation(true);
switch (weapon.getWeaponType()) {
case BOMB:
if (this.bombAnomationStep == 0) {
this.bombAnomationStep++;
}
break;
case DOUBLE_LASER:
if (this.doubleLaserAnimationStep == 0) {
this.doubleLaserAnimationStep++;
}
break;
}
}
if (weapon.getPosY() >= this.getHeight()) {
weapon.setWeaponDisappear(true);
} else {
if (weapon.getRectangle().intersects(myPlane.getRectange())) {
switch (weapon.getWeaponType()) {
case BOMB:
if (myPlane.getHoldBombCount() < Config.BOMB_MAX_HOLD_COUNT) {
myPlane.getHoldBombList().add((Bomb) weapon);
this.getBombSoundPlayer.play();
}
break;
case DOUBLE_LASER:
myPlane.setHitDoubleLaser(true);
this.getDoubleLaserSoundPlayer.play();
break;
}
weapon.setWeaponDisappear(true);
}
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源详情
资源评论
资源推荐
收起资源包目录
plane.zip (98个子文件)
plane
bin
com
beancore
config
ImageConstants.class 7KB
CatchableWeaponType.class 1KB
Config.class 4KB
EnemyPlaneType.class 1KB
BulletType.class 1KB
factory
BulletFactory.class 2KB
CatchableWeaponFactory.class 2KB
EnemyPlaneFactory.class 3KB
Main.class 713B
ui
GamePlayingPanel$PaintThread.class 5KB
PopupMenuPanel.class 3KB
MainFrame.class 11KB
MainFrame$StartGameActionClass.class 771B
HelpDialog.class 2KB
GameLoadingPanel.class 2KB
GameButton.class 4KB
GamePlayingPanel.class 15KB
Top10ScorePanel.class 3KB
entity
BigPlane$DrawKilled.class 731B
EnemyPlane.class 4KB
MyPlane$LauchBulletThread.class 916B
MyPlane.class 5KB
SmallPlane$DrawFighting.class 719B
SmallPlane$DrawKilled.class 713B
BossPlane.class 2KB
Bullet.class 5KB
BigPlane.class 2KB
BigPlane$DrawFighting.class 739B
BossPlane$DrawFighting.class 745B
SmallPlane.class 2KB
Bomb.class 510B
CatchableWeapon.class 3KB
Score.class 2KB
BossPlane$DrawKilled.class 737B
DoubleLaser.class 531B
util
FileUtil.class 3KB
ImageLoader.class 1KB
SoundPlayer.class 1KB
Images.class 1KB
listener
EnemyPlaneListener.class 215B
CatchableWeaponListener.class 235B
BulletListener.class 199B
images
shoot_background.png 96KB
button_bg.png 2KB
font.png 5KB
shoot.png 453KB
logo.png 12KB
button_hover_bg.png 2KB
sound
boss_plane_flying.wav 144KB
achievement.wav 153KB
button.wav 45KB
small_plane_killed.wav 67KB
get_bomb.wav 90KB
game_music.wav 1.99MB
pop_weapon.wav 99KB
use_bomb.wav 189KB
big_plane_killed.wav 225KB
game_over.wav 126KB
boss_plane_killed.wav 116KB
fire_bullet.wav 36KB
get_double_laser.wav 41KB
.settings
org.eclipse.jdt.core.prefs 629B
score.dat 473B
src
com
beancore
config
BulletType.java 88B
CatchableWeaponType.java 89B
EnemyPlaneType.java 118B
Config.java 5KB
ImageConstants.java 9KB
factory
EnemyPlaneFactory.java 2KB
BulletFactory.java 1KB
CatchableWeaponFactory.java 1KB
ui
GamePlayingPanel.java 19KB
HelpDialog.java 1KB
GameLoadingPanel.java 2KB
MainFrame.java 16KB
GameButton.java 3KB
PopupMenuPanel.java 3KB
Top10ScorePanel.java 2KB
entity
CatchableWeapon.java 3KB
Bomb.java 297B
EnemyPlane.java 3KB
BigPlane.java 2KB
Bullet.java 3KB
SmallPlane.java 2KB
MyPlane.java 4KB
BossPlane.java 3KB
Score.java 1KB
DoubleLaser.java 311B
util
Images.java 2KB
FileUtil.java 2KB
ImageLoader.java 694B
SoundPlayer.java 844B
listener
EnemyPlaneListener.java 165B
CatchableWeaponListener.java 203B
BulletListener.java 148B
Main.java 304B
.project 383B
.classpath 301B
共 98 条
- 1
白日焰火
- 粉丝: 327
- 资源: 19
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论18