Lexicon: The Rewrite

Hello all! I’ve started up on the rewrite and after a total of maybe 6-8 hours of programming I’ve got a simple menu, map loading and reading, and a new map that’s very close to finished. I felt like sharing because the system I’m using might help new people with learning how to use AppStates and the likes.

The structure is something like the following:

Main.java - The main class, obviously. All this really does is coordinates the app states and gives them a center to communicate with each other.

MenuAppState.java - Controls the main menu. Everything about the menu is controlled through this class. I enable it when I want the menu to show, and disable it when I don’t.

GameplayAppState.java - Controls the gameplay. When this is initialized, it’s given a map from the selection at the main menu. When the start game button is pressed, it loads the map’s models and textures on a separate thread, and reads through each file’s name for specific details.

PlayerAppState.java - I considered just having player code inside the GameplayAppState, but I decided against it for a cool idea I’ll explain another time. This class controls the player’s movement, weapons, etc. When enabled, the player will spawn at a randomized point (close to his/her base of selection, flag, etc.). When disabled, it de-spawns the player and de-initializes the major parts of the code.

That’s it for now, everyone. I hope explaining this might’ve helped some newer people with app states and some applications for them.

Sounds cool. You can package the whole application project in the SDK (without having to worry to pack the build or dist folder or any versioning info unnecessarily) by just going File->Export->Zip File while having the project selected. Actually its also quite easy to make whole example project templates for the SDK as plugins but I intend to make contributing this kind of plugin even easier in the future, so the ZIP should be fine for now :slight_smile:

@normen That’s interesting. I’ll have to mess with that at some point. I’m starting on player code, which I plan to make highly modular.

The base player code will control only movement and weapons. Adding new stuff such as armor powers will be done via a Module system. You create a new class that extends the Module.java class, and override it’s update method. Each frame, the modules are sent data such as the player’s location, stance, which buttons are being pressed, etc. and you use this data to modify your module. Most of the major modifications will be threaded to help performance.

For example, say I want to add a module that gives my player the ability to cast a shield wall which is slightly transparent and will stop bullets and explosions for a short period of time. All I would do is something like the following:

Check if the player is pressing shield wall (or special attack) button.
-If so, attach model and it’s physics to the scene. Increase player’s susceptibility to damage (as a trade off to having a ginormous shield). Initiate countdown for how long the shield has.
–(Optional) Add a HUD part to display timer and shield state and whatever else you want.
–If the shield is hit by bullets, decrease countdown by a small amount.
–If the shield is hit by an explosion, decrease countdown by an amount inversely related to the distance of the explosion from the shield.
-If not, remove the model and physics if they’re attached.

You could almost add anything. It sounds like a do-able idea so far and I’m sure I’ll find a way to make it work.

@vinexgames, how do you enable, disable and switch between the states? For example I have 2 players, each indicates a state. Where the switching should be done.?
I tried to implement the switching using following code. But it didn’t go giving a lot of exceptions.
[java]
public void startGame(String nextScreen) {

	String swap="swap";
	if(nextScreen.equals(swap)){
		System.out.println("swap worked");
		if(change==1){
			stateManager.detach(bot);
			stateManager.attach(player);
			getStateName(1);
			change=0;	
			System.out.println("bot is here");
		}
		else if(change==0){
			stateManager.detach(player);
			stateManager.attach(bot);
			getStateName(0);
			change=1;
			System.out.println("player is here");
		}
		nifty.gotoScreen("hud");
	}
	else{	
		System.out.println("next screen is here");
		nifty.gotoScreen(nextScreen);
	}
}

[/java]

I don’t see any problem with the code you posted. Is the exception you got a NullPointerException by any chance?

@tsogtoo I swap between appstates in the Main class. In the AppState, override the method setEnabled and do something like the following:

[java]
@Override
public void setEnabled(boolean enabled) {
if(enabled != isEnabled()) { //Check to make sure we’re not enabling already enabled code, or disabling already disabled code.
super.setEnabled(enabled);
if(enabled) {
initializeYourStuffHere();
} else {
deinitializeHere();
}
}
}
[/java]