The recommended method is to pre-compile your game to Java bytecode. See the example Java game which does this and which we will talk about below.
If that is too simple for you, there's a more realistic Kotlin example game too.
It's also possible to write your game in Groovy script, which requires no compilation or IDE, just
a text editor. See games/ButtonMasher/buttonmasher.groovy
for an example.
Now we also support Python 2 (via Jython). See mods/PythonTest/PythonTest.py
for the example.
git clone https://github.com/electronstudio/ButtonMasherGame.git
cd ButtonMasherGame
./gradlew desktop:run
./gradlew desktop:jfxnative
App will be in desktop/build/jfx/native/ folder. (You can also build Android and iOS apps but this hasn'be been tested recently.)
./gradlew jar
This will compile all the Java sourcecode into bytecode class files, and then zip them up into a file called something like core/build/libs/core-1.0.jar
Then copy that file into the same directory as the game's resource (graphic and sound) files
cp core/build/libs/core-1.0.jar core/assets/mods/ButtonMasherGame/
Finally copy that entire directory as a subdirectory of your RetroWar install
core/assets/mods/ButtonMasherGame YOUR_RETRO_STEAM_INSTALL/mods/
Next time you run RetroWar it should be available under the mod menu. If it doesn't work, turn on debug in RetroWar settings and take a look at retrowar-log.txt file in your home directory.
The easiest way is to modify the ButtonMasherGame game. Rename the main class, rename the package, create more classes, etc. (It is possible use the LibGDX creator to create a new project, but I won't cover that here.)
There are lots of comments in the code to explain how it works. If you prefer Kotlin there is also a Kotlin example game which is more in-depth on getting gamepad input.
To import the project into IntelliJ, just 'open' the build.gradle file and it will offer to import the whole project. Accept the defaults.
RetroWar games use LibGDX for graphics and sound, so you will need the LibGDX docs
A RetroWar mini game is just a LibGDX project that uses the retrowar-common library. See retrowar-common docs for API.
The asset files are stored in core/assets/mods/GAMENAME/ so that the file paths will be consistent with the mods directory when running inside RetroWar.
The name of core-1.0.jar doesn't matter, just make sure there is only one jar file in the directory
When the running the game standalone DesktopLauncher creates a SimpleFactory instance. However to run as a plugin, you will need to create your own implementation of AbstractGameFactory which will be used by RetroWar when launcing your game. See ButonMasherGameFactory.java for an example, although yours doesn't need to be complex as that.
build.gradle file contains this info:
jar {
manifest {
attributes(
"RetroWar-Version": "0.19",
"Factory-Class": "com.mygdx.game.ButtonMasherGameFactory"
)
}
}
This info gets stored in the jar files output by gradle.
If you change the name or package of the factory or the version of RetroWar you are targetting you
must change these fields.
The only absolute requirement is that you supply a Game class. (Well that and a Factory to build it). The easiest way to is to subclass SimpleGame.
You must have a constructor which takes a GameSession and passes it to the superclass constructor, e.g.
public MyGame(GameSession session){
super(session, 640, 480, font, font, false);
}
Your game is drawn at a constant virtual resolution no matter what the actual resolution of the user's screen is. In this case we have specified we want 640x480.
The fonts are used for drawing the menus and are LibGDX BitmapFonts.
There are two methods which are called every frame.
Usually when you start the game there will be one Player playing the game, and you can get him with getPlayers(). But RetroWar will automatically add more Players to the list whenever a user presses a button on his keyboard or controller. So if you are making a multiplayer game you should regulary call getPlayers().size() to see if any new players have joined!
Player has a variety of methods you can use or ignore as you wish, e.g. if you have score you can store it with setScore() but the really important ones are
When the game is finished, call gameover(). Before that you can calculate the winner(s) using getSession().findWinners() (assuming the winners are the Players(s) with most score.) You could also print the text of simpleHighScoreTable().