/monoclass2

This small Java project with only one (master) class is a proof-of-concept of an over simplified java program to deliver maximum feature in a minimum number lines of code, and WITHOUT dependencies out of the JDK itself (but only for test purpose, using JUnit and Cucumber). (Note: subclasses were dispatch into package since july 2022)

Primary LanguageJavaMIT LicenseMIT

README

A MonoClass 2 v1.0.6 project test.

The project evolves to a too big number of feature, and debugging a monoclass is annoying; I reach the point of "class splitting", or refactoring. I've also introduced Maven to perform a better build (see pom.xml) As for now, the project small is now standard and need standard tools and classes.

the project is now structured through multiple packages :

[com.demoing.app]
  |_core
  |  |_  behavior
  |  |_  config
  |  |_  entity
  |  |_  gfx
  |  |_  io
  |  |_  math
  |  |_  scene
  |  |_  services
  |  |   |_  collision
  |  |   |_  monitor
  |  |   |_  physic
  |  |   |_  render
  |  |   |_  scene
  |  |_  utils
  |_ demo
       |_ scenes

Root package is com.demoing.app, and sub-packages are

  • core is the game framework,
  • and demo ... the Demo project !

2022 Gitkraken Project Timeline

And a last constrain is to reduce as much as possible the number of LoC, using enhancement from latest JDK.

Have fun discover this beast of code, to learn and take benefits of some latest JDK features (like the pattern matching for switch), and moreover, overuse of lambda and stream each time this was possible.

📘 NOTE 1
If you are curious, just visit the "Java Language Updates" page from Oracle, you will discover across release from 9 to 18, the list of new introduced features.

More Doc sir ?

See the /docs for details

Build

Relying an a custom build script, just execute:

$> mvn clean compile

This will build a jar in target/ directory.

Run it

You can run it by executing the following command line :

$> mvn exec:java

(see Build README for details on build script)

Or if you build it with scripts/build.sh a, you will be able to run it with :

$> java --enable-preview -jar target/monoclass2-{project.version}.jar

You will get the following window

LightAndShadow pre-release preparing the v1.0.5 with Light and Influences

figure 1 - LightAndShadow pre-release preparing the v1.0.5 with Light and Influences

📘 NOTE You can notice the new Time display, limiting the time play.

Keyboard

Here are all the keys and their corresponding action

Key Action
Up Jump / Move up
Down Move down
Left Move left
Right Move right
F3 take screenshot
Z reset current scene
ESC Exit the demo
K Empty energy
D Switch visual debug level from 0 to 5

CLI arguments

Common arguments

You can configure dynamically some internal parameters:

Argument Configuration key Description Default
w, width app.screen.width The width of the game window 320
h, height app.screen.height The height of the game window 240
s, scale app.screen.scale The the pixel scale 2
fps app.screen.fps Frame Per Second 60
f, fullScreen app.window.mode.fullscreen Switch game window to fullscreen mode false2
ww, worldwidth app.world.area.width The width of the world play area 800
wh, worldheight app.world.area.height The height of the world play area 600
wg, worldgravity app.world.gravity The gravity in the world play area 0.981
spmin app.physic.speed.min Physic Engine threshold object minimum speed to 0 0.1
spmax app.physic.speed.max Physic Engine maximum object speed 3.2
accmin app.physic.acceleration.min Physic Engine threshold object minimum acceleration to 0 0.01
accmax app.physic.acceleration.max Physic Engine maximum object acceleration 3.5
cspmin app.collision.speed.min Collision Detector threshold object minimum speed to 0 0.1
cspmax app.collision.speed.max Collision Detector maximum object speed 3.2
scene app.scene.default the default scene to be activated (must be listed in the app.scenes in the app.properties file) N/A
l, language, lang app.language.default select the preferred language (existing values are en_EN, fr_FR, es_ES or de_DE). en_EN

Debug specific arguments

Argument Configuration key Description Default
d, debug app.debug.level Debug level (0=no debug to 5=max debut) 0
of, objectFilter app.debug.objectFilter String coma separated of objects named to activate details debug display information for. ""
ll, logLevel app.logger.level Logger level (0=none, 5=all) 0

Usage example

  1. Change the size of the opened window :
$ java --enable-preview \
 -jar target/monoclass2-{project.version}.jar \
 w=600 h=400
  1. set the preferred language to English at start :
$ java --enable-preview \
 -jar target/monoclass2-{project.version}.jar \
 language=en_EN
  1. set the preferred language to French and change the pixel scale :
$ java --enable-preview \
 -jar target/monoclass2-{project.version}.jar \
 -Dlanguage=fr_FR s=2.0

Contribute

Feel free to add/edit/modify for your own usage and learn. You can fork this small project to play with.

McG. May 1st, 2022.

Footnotes

  1. Icons reference https://gist.github.com/rxaviers/7360908

  2. Supported boolean values to set to true are "1", "on", "ON", "true", "TRUE", "True", and false value are "0", " off", "OFF", "false", "FALSE", "False".