Java 2d RPG Series 2: Getting Started menu

User Tag List

Results 1 to 5 of 5
  1. #1
    Selvyre's Avatar Active Member
    Reputation
    30
    Join Date
    Jul 2013
    Posts
    104
    Thanks G/R
    0/1
    Trade Feedback
    1 (100%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Java 2d RPG Series 2: Getting Started

    Hi my name is Selvyre and in this tutorial we are going to be covering our basic game states and our game class so we can get a window up and running

    OOOOOOKKKKKK so to start we need to right click our src folder in the game project and hit new package (demonstrated HERE) im gonna call mine Main (yes with a cap M please), for those who dont know a package is essentially javas version of a folder, think of them as literally just organization tools. Inside packages are class files that we create and those are in turn compiled together to make a program in our case a 2d game.[/URL]

    Our First Class Files

    Ok so lets begin by right clicking our package now and hitting "New Class"(dont think i need a pic) and we are gonna name it "Game" now you should see a window with some code like this
    Code:
    package Main;
    
    pubic class Game {
    
    }
    Now here is where we are going to test whether or not you guys did the first tutorial correctly, if your StateBasedGame will import. If you would be so kind as to add this simple line of code to your existing code
    Code:
    package Main;
    
    public class Game extends StateBasedGame{
    
    }
    We now need to import our SBG(will only work if TuT1 is done correctly) (pic featured HERE) You should now see some lines added(green) and you are going to need to add a few lines yourself(red)

    Code:
    package Main;
    
    import org.newdawn.slick.GameContainer;
    import org.newdawn.slick.SlickException;
    import org.newdawn.slick.state.StateBasedGame;
    
    
    
    public Game(String name) {
          super(name);
    }
    
    @Override
    public void initStatesList(GameContainer container) throws SlickException {
          this.addState(new MainMenuState());
          this.addState(new PlayState());
    }
    
    public static void main(String[] args) {
          AppGameContainer container = new AppGameContainer(new Game("GAME NAME"));
          container.setDisplayMode(800, 640, false);
          container.setTargetFrameRate(60);
          container.start();
    }
    
    Now at first MainMenuState and PlayState are gonna give an error because we have no created them yet but dont worry we will, essentially what those do is add two states a Main Menu where we will press play or exit and stuff like that and then a PlayState where all the action is gonna happen

    In the main(String[] args) method we created an AppGameContainer which is a class from slick2d that is essentially just a window and that window is gonna be called "GAME NAME" then we set the display mode to 800x640 and non fullscreen(thats what false is for) then we start the window. All this will be done when we first compile or run our game (because its in the main method)

    Now if you would be so kind as to make 2 new class files
    MainMenuState
    Code:
    package Main;
    
    import org.newdawn.slick.GameContainer;
    import org.newdawn.slick.Graphics;
    import org.newdawn.slick.SlickException;
    import org.newdawn.slick.state.BasicGameState;
    import org.newdawn.slick.state.StateBasedGame;
    
    public class MainMenuState extends BasicGameState {
    
    	@Override
    	public void init(GameContainer container, StateBasedGame game) throws SlickException {
    		
    	}
    
    	@Override
    	public void render(GameContainer container, StateBasedGame game, Graphics g) throws SlickException {
    		
    	}
    
    	@Override
    	public void update(GameContainer container, StateBasedGame game, int delta) throws SlickException {
    		
    	}
    
    	@Override
    	public int getID() {
    		return 0;
    	}
    
    }
    PlayState
    Code:
    package Main;
    
    import org.newdawn.slick.GameContainer;
    import org.newdawn.slick.Graphics;
    import org.newdawn.slick.SlickException;
    import org.newdawn.slick.state.BasicGameState;
    import org.newdawn.slick.state.StateBasedGame;
    
    public class PlayState extends BasicGameState {
    
    	@Override
    	public void init(GameContainer container, StateBasedGame game) throws SlickException {
    		
    	}
    
    	@Override
    	public void render(GameContainer container, StateBasedGame game, Graphics g) throws SlickException {
    		
    	}
    
    	@Override
    	public void update(GameContainer container, StateBasedGame game, int delta) throws SlickException {
    		
    	}
    
    	@Override
    	public int getID() {
    		return 1;
    	}
    
    }
    Ok the simplest way to describe each of the methods in these 2 classes is this, init is now where you are going to initialize things, not in the constructor anymore but in the init method now, this is a method made by slick2d and its linked to AppGameContainer so we are gonna use it to achieve greatness, next is render...render is gonna be anything having to do with drawing on the screen, numbers, text, images anything like that goes in render and all our movements, and other logic, and collision will go in update. The id of MainMenuState is 0 and PlayState 1 these can be accessed and changed by doing Game.enterState(0 or 1). Now if you run the game by pressing the green arrow on the top toolbar (under refactor and navigate) you should get a black window that shows 60 fps in the top right corner(or maybe 61) and says GAME NAME at the top of the window, if so good freaking job you were able to stay with me through this tutorial that is so poorly written
    Last edited by Selvyre; 08-12-2013 at 11:15 PM.
    Skype: Argixx
    Coding Experience: Java: 8 years, c++: 4 years, python: lolk, c#: might as well be java, AutoIt: 1 year

    Java 2d RPG Series 2: Getting Started
  2. #2
    Augury13's Avatar Legendary
    Reputation
    884
    Join Date
    Oct 2012
    Posts
    1,736
    Thanks G/R
    424/74
    Trade Feedback
    7 (100%)
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Can you set up screenies of the code in your eclipse? would be easier to visual.

  3. #3
    Selvyre's Avatar Active Member
    Reputation
    30
    Join Date
    Jul 2013
    Posts
    104
    Thanks G/R
    0/1
    Trade Feedback
    1 (100%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Most Def sir i will set that up tomorrow for now im tired and im done, i just wanted to get 2 tutorials out since i was behind a day
    Skype: Argixx
    Coding Experience: Java: 8 years, c++: 4 years, python: lolk, c#: might as well be java, AutoIt: 1 year

  4. #4
    unholyblood's Avatar Member
    Reputation
    1
    Join Date
    Nov 2008
    Posts
    1
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Looking forward to the next one thanks

  5. #5
    Selvyre's Avatar Active Member
    Reputation
    30
    Join Date
    Jul 2013
    Posts
    104
    Thanks G/R
    0/1
    Trade Feedback
    1 (100%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ya its coming pretty slow with school right now, i think im gonna botch the text turorials and just make some videos and put them on youtube then link them here that sounds much easier for you guys to learn with
    Skype: Argixx
    Coding Experience: Java: 8 years, c++: 4 years, python: lolk, c#: might as well be java, AutoIt: 1 year

Similar Threads

  1. [Tutorial] Java 2d RPG Series 1: Installing Required Garbage
    By Selvyre in forum Programming
    Replies: 3
    Last Post: 08-12-2013, 11:11 PM
  2. Boting: Need help getting started
    By grond in forum World of Warcraft General
    Replies: 3
    Last Post: 10-30-2007, 02:19 PM
  3. Getting Started?
    By Dax in forum WoW ME Questions and Requests
    Replies: 2
    Last Post: 06-23-2007, 12:23 AM
  4. Getting Started
    By masonps3 in forum World of Warcraft General
    Replies: 3
    Last Post: 06-15-2007, 02:05 PM
All times are GMT -5. The time now is 12:59 AM. Powered by vBulletin® Version 4.2.3
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Google Authenticator verification provided by Two-Factor Authentication (Free) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search