Hey,
I am thinking much about modeling an efficient game the last time. I'm using Java since six months and making games since about 5 years, but this is the first time I want to realize a whole game in Java. I planned a Space-Shooter MMORPG with Java7, Slick2D and Kryonet.

The only problem that I have right know is that I dont know how to switch between main menu, login screen, option panel, pause screen and The Game. This is some of my current code:
1 2 3
| static HashMap<String, Image> i = new HashMap<String, Image>(); static HashMap<String, AngelCodeFont> f = new HashMap<String, AngelCodeFont>(); static ArrayList<Entity> e = new ArrayList<Entity>(); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| @Override public void init(GameContainer c) throws SlickException { Network.load(); Network.tcp(new Start()); try { for (String n : new File(ClassLoader.getSystemResource("i").toURI()).list()) i.put(n.substring(0, n.indexOf('.')), new Image("i/" + n)); i.put("clickable1", i.get("clickable0").getFlippedCopy(true, false)); } catch (URISyntaxException e) { e.printStackTrace(); }
try { for (String n : new File(ClassLoader.getSystemResource("f").toURI()).list()) { if (n.endsWith("t")) { n = n.substring(0, n.indexOf('.')); f.put(n, new AngelCodeFont("f/" + n + ".fnt", "f/" + n + ".png")); } } } catch (URISyntaxException e) { e.printStackTrace(); }
start(); } |
1 2 3 4 5 6 7 8
| void start() { Interface.create(); Cursor.load(); Player p = new Player(Ship.SHIPID_SHUTTLE, 5, 5); e.add(p); } |
1 2 3 4 5 6 7 8 9
| @Override public void update(GameContainer c, int delta) throws SlickException { Interface.run(); for (ListIterator<Entity> n = e.listIterator(e.size()); n.hasPrevious();) { if (!n.previous().run()) n.remove(); } Cursor.run(); } |
1 2 3 4 5 6 7 8
| @Override public void render(GameContainer c, Graphics g) throws SlickException { for (Entity n : e) { n.render(); } Interface.render(); Cursor.render(); } |
This works fine, but what should I do to only run an instance of a MainMenu class at first?
I could create an
int gamestate and do a switch(gamestate) at render() and update(),
but I would come up with an undynamic clump of bad written code.
I'd be thankful for every approach and every source improvements.