Documente Academic
Documente Profesional
Documente Cultură
/**
*
* @author n.fletcher
*/
public class Directions {
public static final int STOP = 0;
public static final int NORTH = 1;
public static final int NORTH_WEST = 2;
public static final int WEST = 3;
public static final int SOUTH_WEST = 4;
public static final int SOUTH = 5;
public static final int SOUTH_EAST = 6;
public static final int EAST = 7;
public static final int NORTH_EAST = 8;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package space.monster.shoot.em.up;
/**
*
* @author n.fletcher
*/
public class Coordinates {
public int x, y, width, height, top, bottom, left, right, direction, amount;
public Coordinates() {
dispose();
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package space.monster.shoot.em.up;
import javax.swing.JLabel;
/**
*
* @author n.fletcher
*/
public class GameObject {
protected Coordinates coordinates;
public JLabel image;
private boolean isAlive;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package space.monster.shoot.em.up;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JLabel;
import javax.swing.Timer;
/**
*
* @author n.fletcher
*/
public abstract class GameCharacter extends GameObject {
private int delay;
private ActionListener listener;
public Timer timer;
@Override
public void spawn() {
super.spawn();
super.image.setVisible(true);
// this.coordinates.direction = Directions.STOP;
timer.start();
}
@Override
public void kill() {
super.kill();
super.image.setVisible(false);
timer.stop();
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package space.monster.shoot.em.up;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
/**
*
* @author n.fletcher
*/
public class Background extends GameObject{
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package space.monster.shoot.em.up;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
/**
*
* @author Nicholas
*/
public class CShot extends GameCharacter{
private final Wall[] walls;
private final Wachs hero;
private final Cruiser cruiser;
@Override
public void action() {
super.checkDirection();
checkWalls();
checkHero();
super.redraw();
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package space.monster.shoot.em.up;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.Timer;
/**
*
* @author Nicholas
*/
public class Cruiser extends GameCharacter{
@Override
public void action() {
super.checkDirection();
shoot();
checkWalls();
super.redraw();
}
@Override
public void spawn() {
super.spawn();
coordinates.x = -170;
coordinates.y = 150;
coordinates.width = 170;
coordinates.height = 105;
Icon background = new ImageIcon("F:\\My Pictures\\SMSEU Enemies\\"
+ "Bird of Prey.png");
this.image.setIcon(background);
super.coordinates.direction = randomDirection();
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package space.monster.shoot.em.up;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.Timer;
/**
*
* @author Nicholas
*/
public class DiveBomber extends GameCharacter{
@Override
public void action() {
super.checkDirection();
checkWalls();
checkHero();
super.redraw();
}
@Override
public void spawn() {
super.spawn();
int random = (int)((2-1+1)*Math.random()+1);
if (random == 1)
{
Icon background1 = new ImageIcon("F:\\My Pictures\\SMSEU Enemies\\"
+ "Space War 1.png");
this.image.setIcon(background1);
coordinates.x = setX();
coordinates.y = setY();
coordinates.width = 52;
coordinates.height = 100;
}
else
{
Icon background2 = new ImageIcon("F:\\My Pictures\\SMSEU Enemies\\"
+ "Space War 2.png");
this.image.setIcon(background2);
coordinates.x = setX();
coordinates.y = setY();
coordinates.width = 30;
coordinates.height = 135;
}
super.coordinates.direction = Directions.SOUTH;
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package space.monster.shoot.em.up;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
/**
*
* @author n.fletcher
*/
public class FShot extends GameCharacter {
@Override
public void action() {
super.checkDirection();
checkWalls();
checkHero();
super.redraw();
}
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.Timer;
/**
*
* @author n.fletcher
*/
public class Fighter extends GameCharacter{
@Override
public void action() {
super.checkDirection();
shoot();
checkWalls();
checkHero();
super.redraw();
}
@Override
public void spawn() {
super.spawn();
coordinates.x = setX();
coordinates.y = setY();
Icon background = new ImageIcon("F:\\My Pictures\\SMSEU Enemies\\"
+ "TIE Fighter.png");
this.image.setIcon(background);
coordinates.width = 100;
coordinates.height = 86;
super.coordinates.direction = randomDirection();
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package space.monster.shoot.em.up;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.Timer;
/**
*
* @author Nicholas
*/
public class GameTime {
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package space.monster.shoot.em.up;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
/**
*
* @author Nicholas
*/
public class HShot extends GameCharacter {
@Override
public void action() {
super.checkDirection();
checkWalls();
checkFighters();
checkBombers();
checkCruisers();
super.redraw();
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package space.monster.shoot.em.up;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
/**
*
* @author Nicholas
*/
public class HeroLife extends GameObject{
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package space.monster.shoot.em.up;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.Timer;
/**
*
* @author n.fletcher
*/
public class Wachs extends GameCharacter{
@Override
public void action() {
super.checkDirection();
checkWalls();
super.redraw();
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package space.monster.shoot.em.up;
import java.awt.Color;
import javax.swing.JLabel;
/**
*
* @author n.fletcher
*/
public class Wall extends GameObject{
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package space.monster.shoot.em.up;
import java.awt.event.KeyEvent;
import javax.swing.JFrame;
import javax.swing.JLabel;
/**
*
* @author n.fletcher
*/
public class GameEngine {
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package space.monster.shoot.em.up;
/**
*
* @author n.fletcher
*/
public class SpaceMonsterShootEmUp {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
GUI gui = new GUI();
}
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package space.monster.shoot.em.up;
import javax.swing.JLabel;
/**
*
* @author n.fletcher
*/
public class GUI extends javax.swing.JFrame {
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setPreferredSize(new java.awt.Dimension(1000, 750));
addKeyListener(new java.awt.event.KeyAdapter() {
public void keyPressed(java.awt.event.KeyEvent evt) {
formKeyPressed(evt);
}
});
jPanel1.setOpaque(false);
jPanel1.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyPressed(java.awt.event.KeyEvent evt) {
jPanel1KeyPressed(evt);
}
});
jPanel1.setLayout(null);
jPanel1.add(wall1);
wall1.setBounds(0, 0, 0, 750);
jPanel1.add(wall2);
wall2.setBounds(1000, 0, 0, 750);
jPanel1.add(wall3);
wall3.setBounds(0, 0, 1000, 0);
jPanel1.add(wall4);
wall4.setBounds(0, 750, 1000, 0);
jPanel1.add(wachs);
wachs.setBounds(450, 535, 95, 162);
jPanel1.add(fighter1);
fighter1.setBounds(340, 100, 100, 86);
jPanel1.add(fighter2);
fighter2.setBounds(581, 79, 100, 86);
jPanel1.add(fShot1);
fShot1.setBounds(800, 180, 30, 30);
jPanel1.add(fShot2);
fShot2.setBounds(701, 179, 30, 30);
jPanel1.add(bomber1);
bomber1.setBounds(240, 140, 52, 100);
jPanel1.add(bomber2);
bomber2.setBounds(240, 140, 52, 100);
jPanel1.add(hShot1);
hShot1.setBounds(130, 30, 10, 30);
jPanel1.add(cruiser1);
cruiser1.setBounds(0, 0, 170, 105);
cShot1.setToolTipText("");
jPanel1.add(cShot1);
cShot1.setBounds(0, 0, 10, 30);
jPanel1.add(lives);
lives.setBounds(0, 670, 141, 80);
jPanel1.add(background);
background.setBounds(0, 0, 1040, 750);
pack();
}// </editor-fold>
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info :
javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(GUI.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(GUI.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(GUI.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(GUI.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
}
//</editor-fold>