/* */ package com.softeem.shoot;
/* */
/* */ import java.awt.Color;
/* */ import java.awt.Font;
/* */ import java.awt.Graphics;
/* */ import java.awt.event.MouseAdapter;
/* */ import java.awt.event.MouseEvent;
/* */ import java.awt.image.BufferedImage;
/* */ import java.util.Arrays;
/* */ import java.util.Random;
/* */ import java.util.Timer;
/* */ import java.util.TimerTask;
/* */ import javax.imageio.ImageIO;
/* */ import javax.swing.ImageIcon;
/* */ import javax.swing.JFrame;
/* */ import javax.swing.JPanel;
/* */
/* */
/* */
/* */ public class ShootGame
/* */ extends JPanel
/* */ {
/* */ public static final int WIDTH = 400;
/* */ public static final int HEIGHT = 600;
/* */ private int state;
/* */ public static final int START = 0;
/* */ public static final int RUNNING = 1;
/* */ public static final int PAUSE = 2;
/* */ public static final int GAME_OVER = 3;
/* 30 */ private int score = 0;
/* */ private Timer timer;
/* 32 */ private int intervel = 10;
/* */
/* */ public static BufferedImage background;
/* */ public static BufferedImage start;
/* */ public static BufferedImage pause;
/* */ public static BufferedImage gameover;
/* */ public static BufferedImage bullet;
/* */ public static BufferedImage airplane;
/* 40 */ public static BufferedImage[] airplaneEmber = new BufferedImage[4];
/* */ public static BufferedImage bee;
/* 42 */ public static BufferedImage[] beeEmber = new BufferedImage[4];
/* */ public static BufferedImage hero0;
/* */ public static BufferedImage hero1;
/* 45 */ public static BufferedImage[] heroEmber = new BufferedImage[4];
/* */ public static BufferedImage bigPlane;
/* 47 */ public static BufferedImage[] bigPlaneEmber = new BufferedImage[4];
/* */
/* 49 */ private FlyingObject[] flyings = new FlyingObject[0];
/* 50 */ private Bullet[] bullets = new Bullet[0];
/* 51 */ private Hero hero = new Hero();
/* 52 */ private Ember[] embers = new Ember[0];
/* */
/* */ static {
/* */ try {
/* 56 */ background = ImageIO.read(ShootGame.class
/* 57 */ .getResource("background.png"));
/* 58 */ bigPlane =
/* 59 */ ImageIO.read(ShootGame.class.getResource("bigplane.png"));
/* 60 */ airplane =
/* 61 */ ImageIO.read(ShootGame.class.getResource("airplane.png"));
/* 62 */ bee = ImageIO.read(ShootGame.class.getResource("bee.png"));
/* 63 */ bullet = ImageIO.read(ShootGame.class.getResource("bullet.png"));
/* 64 */ hero0 = ImageIO.read(ShootGame.class.getResource("hero0.png"));
/* 65 */ hero1 = ImageIO.read(ShootGame.class.getResource("hero1.png"));
/* 66 */ pause = ImageIO.read(ShootGame.class.getResource("pause.png"));
/* 67 */ gameover =
/* 68 */ ImageIO.read(ShootGame.class.getResource("gameover.png"));
/* 69 */ start =
/* 70 */ ImageIO.read(ShootGame.class.getResource("start.png"));
/* 71 */ for (int i = 0; i < 4; i++) {
/* 72 */ beeEmber[i] = ImageIO.read(
/* 73 */ ShootGame.class.getResource("bee_ember" + i + ".png"));
/* 74 */ airplaneEmber[i] = ImageIO.read(
/* 75 */ ShootGame.class.getResource("airplane_ember" + i + ".png"));
/* 76 */ bigPlaneEmber[i] = ImageIO.read(
/* 77 */ ShootGame.class.getResource("bigplane_ember" + i + ".png"));
/* 78 */ heroEmber[i] = ImageIO.read(
/* 79 */ ShootGame.class.getResource("hero_ember" + i + ".png"));
/* */ }
/* 81 */ } catch (Exception e) {
/* 82 */ e.printStackTrace();
/* */ }
/* */ }
/* */
/* */
/* */ public void paint(Graphics g) {
/* 88 */ g.drawImage(background, 0, 0, null);
/* 89 */ paintEmber(g);
/* 90 */ paintHero(g);
/* 91 */ paintBullets(g);
/* 92 */ paintFlyingObjects(g);
/* 93 */ paintScore(g);
/* 94 */ paintState(g);
/* */ }
/* */
/* */
/* */
/* 99 */ public void paintHero(Graphics g) { g.drawImage(this.hero.getImage(), this.hero.getX(), this.hero.getY(), null); }
/* */
/* */
/* */ public void paintEmber(Graphics g) {
/* 103 */ for (int i = 0; i < this.embers.length; i++) {
/* 104 */ Ember e = this.embers[i];
/* 105 */ g.drawImage(e.getImage(), e.getX(), e.getY(), null);
/* */ }
/* */ }
/* */
/* */
/* */ public void paintBullets(Graphics g) {
/* 111 */ for (int i = 0; i < this.bullets.length; i++) {
/* 112 */ Bullet b = this.bullets[i];
/* 113 */ if (!b.isBomb()) {
/* 114 */ g.drawImage(b.getImage(), b.getX() - b.getWidth() / 2, b.getY(),
/* 115 */ null);
/* */ }
/* */ }
/* */ }
/* */
/* */ public void paintFlyingObjects(Graphics g) {
/* 121 */ for (int i = 0; i < this.flyings.length; i++) {
/* 122 */ FlyingObject f = this.flyings[i];
/* 123 */ g.drawImage(f.getImage(), f.getX(), f.getY(), null);
/* */ }
/* */ }
/* 126 */ Object a = new Object();
/* */
/* */ public void paintScore(Graphics g) {
/* 129 */ int x = 10;
/* 130 */ int y = 25;
/* 131 */ Font font = new Font("SansSerif", 1, 14);
/* 132 */ g.setColor(new Color(3816251));
/* 133 */ g.setFont(font);
/* 134 */ g.drawString("SCORE:" + this.score, x, y);
/* 135 */ y += 20;
/* 136 */ g.drawString("LIFE:" + this.hero.getLife(), x, y);
/* */ }
/* */
/* */ public void paintState(Graphics g) {
/* 140 */ switch (this.state) {
/* */ case 0:
/* 142 */ g.drawImage(start, 0, 0, null);
/* */ break;
/* */ case 2:
/* 145 */ g.drawImage(pause, 0, 0, null);
/* */ break;
/* */ case 3:
/* 148 */ g.drawImage(gameover, 0, 0, null);
/* */ break;
/* */ }
/* */ }
/* */
/* */ public static void main(String[] args) {
/* 154 */ JFrame frame = new JFrame("Shoot Game");
/* 155 */ ShootGame game = new ShootGame();
/* 156 */ frame.add(game);
/* 157 */ frame.setSize(400, 600);
/* 158 */ frame.setAlwaysOnTop(true);
/* 159 */ frame.setDefaultCloseOperation(3);
/* 160 */ frame.setIconImage((new ImageIcon("images/icon.jpg")).getImage());
/* 161 */ frame.setLocationRelativeTo(null);
/* 162 */ frame.setVisible(true);
/* */
/* 164 */ game.action();
/* */ }
/* */
/* */
/* */ public void action() {
/* 169 */ MouseAdapter l = new MouseAdapter()
/* */ {
/* */ public void mouseMoved(MouseEvent e) {
/* 172 */ if (ShootGame.this.state == 1) {
/* 173 */ int x = e.getX();
/* 174 */ int y = e.getY();
/* 175 */ ShootGame.this.hero.moveTo(x, y);
/* */ }
/* */ }
/* */
/* */
/* */ public void mouseEntered(MouseEvent e) {
/* 181 */ if (ShootGame.this.state == 2) {
/* 182 */ ShootGame.this.state = 1;
/* */ }
/* */ }
/* */
/* */
/* */ public void mouseExited(MouseEvent e) {
/* 188 */ if (ShootGame.this.state != 3) {
/* 189 */ ShootGame.this.state = 2;
/* */ }
/* */ }
/* */
/* */
/* */ public void mouseClicked(MouseEvent e) {
/* 195 */ switch (ShootGame.this.state) {
/* */ case 0:
/* 197 */ ShootGame.this.state = 1;
/* */ break;
/* */ case 3:
/* 200 */ ShootGame.this.flyings = new FlyingObject[0];
/* 201 */ ShootGame.this.bullets = new Bullet[0];
/* 202 */ ShootGame.this.hero