Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package graphics.main;
- import javax.swing.JFrame;
- import java.awt.Container;
- import java.awt.event.KeyListener;
- import java.awt.event.ActionListener;
- import javax.swing.JPanel;
- import javax.swing.BoxLayout;
- import javax.swing.JLabel;
- import javax.swing.WindowConstants;
- import java.awt.Dimension;
- import java.awt.Graphics;
- import java.awt.Color;
- import java.awt.FlowLayout;
- import engine.FireEmblemEngine;
- import engine.system.*;
- import engine.system.internal.*;
- import engine.chapterdata.*;
- import graphics.img.fireemblem.*;
- /**
- * This class displays the basic game frame.
- */
- public class GameFrame extends JPanel implements GameConstants,FEImages,InternalCommands {
- protected static final int GAME_WIDTH = 640;
- protected static final int GAME_HEIGHT = 480;
- protected FireEmblemEngine gameEngine;
- //JFrame gFrame;
- protected static JFrame gFrame;
- private static final Dimension preferredSize = new Dimension(GAME_WIDTH,GAME_HEIGHT);
- private static int mapPosX = 0;
- private static int mapPosY = 0;
- //Finds the size of the frame.
- public Dimension getPreferredSize() {
- return preferredSize;
- }
- public static JFrame getCurrentFrame() {
- return gFrame;
- }
- //Whee, constructor.
- public GameFrame(JFrame j) {
- gameEngine = new FireEmblemEngine(this);
- j.addKeyListener(gameEngine);
- }
- public JFrame getFrame() {
- if (gFrame != null)
- {
- return gFrame;
- }
- else
- {
- return null;
- }
- }
- public void addPanelToFrame(Container c) {
- c.add(this);
- }
- public void paintComponent(Graphics g) {
- super.paintComponent(g);
- //Fill the entire screen with white, dummy at the moment
- g.setColor(Color.WHITE);
- g.fillRect(0,0,GAME_WIDTH,GAME_HEIGHT);
- //g.drawImage(gameEngine.getCurrentMap().getImage());
- switch(gameEngine.getCurrentMode())
- {
- case MAP_MODE:
- int mapHeight = gameEngine.getCurrentMap().getHeight();
- int mapWidth = gameEngine.getCurrentMap().getWidth();
- switch(gameEngine.scrollMap())
- {
- case NONE:
- break;
- case UP:
- mapPosY = (((mapPosY == 0) ? mapPosY:(mapPosY + TILE_INCR)));
- break;
- case DOWN:
- mapPosY = (((mapPosY == GAME_HEIGHT - mapHeight) ? mapPosY:(mapPosY - TILE_INCR)));
- break;
- case LEFT:
- mapPosX = (((mapPosX == 0) ? mapPosX:(mapPosX + TILE_INCR)));
- break;
- case RIGHT:
- mapPosX = (((mapPosX == GAME_WIDTH - mapWidth) ? mapPosX:(mapPosX - TILE_INCR)));
- break;
- }
- g.drawImage(gameEngine.getCurrentMap().getImage(),mapPosX,mapPosY,this);
- g.drawImage(Cursor,gameEngine.getCursorX(),gameEngine.getCursorY(),this);
- }
- }
- //Actually display the frame
- public static void main(String[] args) {
- gFrame = new JFrame("Fire Emblem!");
- GameFrame game = new GameFrame(gFrame);
- Container contentPane = gFrame.getContentPane();
- game.addPanelToFrame(contentPane);
- contentPane.setLayout(new FlowLayout());
- //label.setIcon(FELogo);
- //JLabel label = new JLabel(FELogo);
- //contentPane.add(label);
- gFrame.pack();
- //gFrame.setSize(preferredSize);
- gFrame.setResizable(false);
- gFrame.setVisible(true);
- gFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- }
- }
- package graphics.main;
- import javax.swing.JFrame;
- import java.awt.Container;
- import java.awt.event.KeyListener;
- import java.awt.event.ActionListener;
- import javax.swing.JPanel;
- import javax.swing.BoxLayout;
- import javax.swing.JLabel;
- import javax.swing.WindowConstants;
- import java.awt.Dimension;
- import java.awt.Graphics;
- import java.awt.Color;
- import java.awt.FlowLayout;
- import engine.FireEmblemEngine;
- import engine.system.*;
- import engine.system.internal.*;
- import engine.chapterdata.*;
- import graphics.img.fireemblem.*;
- /**
- * This class displays the basic game frame.
- */
- public class GameFrame extends JPanel implements GameConstants,FEImages,InternalCommands {
- protected static final int GAME_WIDTH = 640;
- protected static final int GAME_HEIGHT = 480;
- protected FireEmblemEngine gameEngine;
- //JFrame gFrame;
- protected static JFrame gFrame;
- private static final Dimension preferredSize = new Dimension(GAME_WIDTH,GAME_HEIGHT);
- private static int mapPosX = 0;
- private static int mapPosY = 0;
- //Finds the size of the frame.
- public Dimension getPreferredSize() {
- return preferredSize;
- }
- public static JFrame getCurrentFrame() {
- return gFrame;
- }
- //Whee, constructor.
- public GameFrame(JFrame j) {
- gameEngine = new FireEmblemEngine(this);
- j.addKeyListener(gameEngine);
- }
- public JFrame getFrame() {
- if (gFrame != null)
- {
- return gFrame;
- }
- else
- {
- return null;
- }
- }
- public void addPanelToFrame(Container c) {
- c.add(this);
- }
- public void paintComponent(Graphics g) {
- super.paintComponent(g);
- //Fill the entire screen with white, dummy at the moment
- g.setColor(Color.WHITE);
- g.fillRect(0,0,GAME_WIDTH,GAME_HEIGHT);
- //g.drawImage(gameEngine.getCurrentMap().getImage());
- switch(gameEngine.getCurrentMode())
- {
- case MAP_MODE:
- int mapHeight = gameEngine.getCurrentMap().getHeight();
- int mapWidth = gameEngine.getCurrentMap().getWidth();
- switch(gameEngine.scrollMap())
- {
- case NONE:
- break;
- case UP:
- mapPosY = (((mapPosY == 0) ? mapPosY:(mapPosY + TILE_INCR)));
- break;
- case DOWN:
- mapPosY = (((mapPosY == GAME_HEIGHT - mapHeight) ? mapPosY:(mapPosY - TILE_INCR)));
- break;
- case LEFT:
- mapPosX = (((mapPosX == 0) ? mapPosX:(mapPosX + TILE_INCR)));
- break;
- case RIGHT:
- mapPosX = (((mapPosX == GAME_WIDTH - mapWidth) ? mapPosX:(mapPosX - TILE_INCR)));
- break;
- }
- g.drawImage(gameEngine.getCurrentMap().getImage(),mapPosX,mapPosY,this);
- g.drawImage(Cursor,gameEngine.getCursorX(),gameEngine.getCursorY(),this);
- }
- }
- //Actually display the frame
- public static void main(String[] args) {
- gFrame = new JFrame("Fire Emblem!");
- GameFrame game = new GameFrame(gFrame);
- Container contentPane = gFrame.getContentPane();
- game.addPanelToFrame(contentPane);
- contentPane.setLayout(new FlowLayout());
- //label.setIcon(FELogo);
- //JLabel label = new JLabel(FELogo);
- //contentPane.add(label);
- gFrame.pack();
- //gFrame.setSize(preferredSize);
- gFrame.setResizable(false);
- gFrame.setVisible(true);
- gFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment