Sign in to follow this  
kelicant

Any tutorials on creating start-up menus?

Recommended Posts

Can anyone point me towards some resources to learn about practical programming? I know how to program simple things that will run from a dos window, but I’m really only interested in things with an actual gui. It can be C++ or Java, or even another language if it’s transferable.

My goal is to program my own simple game. I want to run my program and have a menu come up where you select from the game, options, or exit. Clicking the game goes into a character selection menu (like a fighting game) and then you go into the actual game with your character. But I don’t know how to start the menu and character selection for the game. I’ve looked for tutorials for other games, but they focus on the game logic rather than the menus and such. Can anyone point me in the right direction?

Edit* I'd also like to have a book/tutorial/something that would teach me how to make a game with more than just the game loop (that is usually game specific anyways). I want to know how to create the start-up screen, menus, (maybe) networking, etc. as well as the game itself.

Share this post


Link to post
Share on other sites
Don't really know if I will help.

I have done state manager of game. Basic class have abstract methods like update, draw and input. Later extend that class and do Meniu, CharacterChooser and gamePlay states. Every states will have their owns basic methods of game. So, now creating currentState, and always do everything with it. Starting meniu, currentState would be set as MeniuState, pressing character button, currentState will be changed to CharacterChooser.

I done this thing on java, I could give source code if you would try to understand how I done that [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]

Share this post


Link to post
Share on other sites
Tried to simplified it. State, MeniuState, GamePlayState, and in Core updating currentState and doing every switching between states. Every time time I change state, I set that state is used first time, so then variables init would be used only once. And with some event, changing from state to state (MeniuState sets gamePlay if you press Play button). And every time i change states, I hide all panels, and add new (not best choice, because after a lot changing there will be a lot panels added to frame, but just not visible)

[CODE]
package towerdefense;
public abstract class State implements ActionListener {
private boolean firstFrame;
private boolean pause;
private int gameSpeed;
ArrayList<JPanel> panels;
public State() {
firstFrame = true;
pause = false;
panels = new <JPanel>ArrayList();
}
abstract void loadImages();
abstract void init();
abstract void update(long frameDuration);
abstract void draw(Graphics2D g2d);
abstract void input(InputHandler input);

}
[/CODE]

[CODE]
public class Meniu extends State {
private boolean gamePlay;
JButton btnPlay;
@Override
void loadImages() {
}
@Override
void init() {
gamePlay = false;
}
@Override
void update(long frameDuration) {
}
@Override
void draw(Graphics2D g2d) {
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == btnPlay) {
setGamePlay(true);
}
}
@Override
void input(InputHandler input) {
}
public boolean isGamePlay() {
return gamePlay;
}
}
[/CODE]
[CODE]
public class GamePlay extends State {
private boolean gameOver;
private boolean meniu;
private boolean win;
@Override
void loadImages() {

}
@Override
void init() {
}
@Override
void update(long frameDuration) {
}
@Override
void draw(Graphics2D g2d) {

}
@Override
void input(InputHandler input) {
}
@Override
public void actionPerformed(ActionEvent e) {


}

public boolean isGameOver() {
return gameOver;
}
public boolean isMeniu() {
return meniu;
}
public boolean isWin() {
return win;
}
}
[/CODE]

[CODE]
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
public class Core extends Canvas {
GamePlay gamePlay;
Meniu meniu;
GameOver gameOver;
Win win;
State cState;


public Core() {
initCore();
gamePlay = new GamePlay();
meniu = new Meniu();
gameOver = new GameOver();
fps = new FramePerSecond();
win = new Win();
cState = meniu;
}
private void initCore() {
//window settings
frame = new JFrame();
frame.setLocation(200, 100);
frame.setResizable(false);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBackground(backColor);
setForeground(forColor);

running = true;
pause = false;
}
private void addPanel(JPanel panel) {
frame.add(panel);
}
private void secondInit() {

panel = (JPanel) frame.getContentPane();
//player = (JPanel) frame.getContentPane();
// panel.add(button);
panel.setPreferredSize(new Dimension(screenW - 10, screenH - 10));
panel.setLayout(null);
setBounds(0, 0, screenW, screenH);
panel.add(this);
setIgnoreRepaint(true);
frame.pack();
createBufferStrategy(2);
strategy = getBufferStrategy();
g2d = (Graphics2D) strategy.getDrawGraphics();
input = new InputHandler(this);
}
//==========================================================================
//method for whole application starting
//==========================================================================
public void run() {
gameLoop();
}
//==========================================================================
//gameLoop (dont't think that need comment it
//basic parts of it is: input, update and draw (rendering)
//==========================================================================
private void gameLoop() {
while (running) {
//state swapping
stateSwaping();

//pausing game
if (cState.isPause()) {
setPause(true);
} else {
setPause(false);
}
//frameDuration calculation. Used for timeBased movement in game
//or could be used for fps calculating
frameDuration = System.nanoTime() - startingTime;
startingTime = System.nanoTime();

//first input
cState.input(input);
//second is update, but only works if state is not paused
if (!isPause()) {
cState.update(frameDuration * cState.getGameSpeed());
}
//graphics thing
//something with graphichs method, because needed every frame call,
//so mnimized gameLoop by putting it in method
//later use draw, and disposo (just do it, don't know why)
graphics();
cState.draw(g2d);
g2d.dispose();
}
}
//==========================================================================
//state pause methods
//mostly using for gamePlay pausing
//why? because meniu and gameOver states dont need pause function
//==========================================================================
public boolean isPause() {
return pause;
}
public void setPause(boolean pause) {
this.pause = pause;
}
//==========================================================================
//set state as cState, and set that state is new
//==========================================================================
private void changeState(State state) {
this.cState = state;
cState.setFirstFrame(true);
}
//==========================================================================
//hide cState panels
//==========================================================================
private void hidePanels() {
for (int i = 0; i < cState.getPanels().size(); i++) {
cState.panels.get(i).setVisible(false);
}
}
//==========================================================================
//there is going all state swaping, from one state to another and so on
//==========================================================================
private void stateSwaping() {
//from meniu to gamePlay
if (cState == meniu) {
if (meniu.isGamePlay()) {
hidePanels();
changeState(gamePlay);
gamePlay.setChoosenMap(meniu.getMap());
meniu.setGamePlay(false);
}
}
//from gamePlay to meniu
if (cState == gamePlay) {
if (gamePlay.isMeniu()) {
hidePanels();
changeState(meniu);
gamePlay.setMeniu(false);
}
}
//if gamePlay is gameOver (some number of minions reached end of map)
//then is changed to gameOver state.
if (cState == gamePlay) {
if (gamePlay.isGameOver()) {
hidePanels();
changeState(gameOver);
gamePlay.setGameOver(false);
}
}

//if gamePlay is WIN (killed all minions waves)
if (cState == gamePlay) {
if (gamePlay.isWin()) {
hidePanels();
changeState(win);
gamePlay.setWin(false);
}
}

//from gamePlay to meniu (or in other words - program restart, without
//only changing states)
if (cState == gameOver) {
if (gameOver.isMeniu()) {
hidePanels();
changeState(meniu);
gameOver.setMeniu(false);
}
}

//======================================================================
//if cState is launched first time (cState has it first frame)
//when i need to do:
//1. load cState images
//2. init its variables
//3. add cState panels to window (possible adding same panels if swaping
//was done alot)
//4. second init for core, that new panels would be add nicely to frame
//5. set that frame has been used for first time
if (cState.isFirstFrame()) {
cState.loadImages();
cState.init();
for (int i = 0; i < cState.getPanels().size(); i++) {
addPanel(cState.getPanels().get(i));
}
secondInit();

cState.setFirstFrame(false);
}
}

}
[/CODE]

Share this post


Link to post
Share on other sites
Hi Kelicant

i think Lazy Foo tutorials are quite good for beginning game programming. there isnt a specific menu tutorial but he has an article on gamestates that could be quite useful for you. The tutorials use c++ and SDL and are quite simple in the way they are written and at the bottom of every tutorial is the source codes and any needed files. there is also tutorials for setting up SDL to work depending on your operating system and compiler. just search lazyfoo in google should be first one that comes up.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this