ALTk is a Java implementation of the exercises in Daniel Shiffman's book The Nature of Code.
It is assumed you have git, maven, and Java8 installed on your computer. If you don't, do that then come back.
To build, you should only need to do a maven install from the project root directory thusly:
mvn clean install
Open a terminal window, and from the project root directory type:
java -jar altk/target/altK-0.0.1-SNAPSHOT-jar-with-dependencies.jar -Dsun.java2d.opengl=true
There is a simple Swing interface, but interaction with ALTk is currently limited to BeanShell scripts. All commands must be suffixed with ();
. To run any of the demos, type {name of demo}();
.
- vectorBall -- Balls that bounce around the window. Not managed by JBox2D.
- gravityBall -- 'Planet' ball in the center of the screen to which all other elements are attracted. 'Planet' ball is movable via mouse. Not managed by JBox2D.
- spacewar -- Simple (and incomplete) asteroids-like simulation. No collision detection. Ship can fly around via arrow keys (up for thrust, right/left to turn). Ship thruster effect made using a particle system. Not managed by JBox2D.
- bounce2 -- Click mouse anywhere in the window to create a stream of randomly generated bouncy balls. First demo managed by JBox2D so collision detection is present.
There is an MVC framework that hooks into JBox2D. To make new simulations, simply extend the Managed Element, Runner, Controller, View, and Model classes. Note also that the JBox2D testbed library is included, which is enormously helpful in working out the 'physics' of your world before integrating your demo into the application. Enable/disable the testbed in ALTk's main method.
JBox2D comes with a nifty sandbox mode that provides a pre-baked view and controller. This makes it easier to sort out physics logic without having to also contend with application logic. To run, type:
java -jar altk/target/altK-0.0.1-SNAPSHOT-jar-with-dependencies.jar debug -Dsun.java2d.opengl=true
- JBox2D JavaDoc
- Box2D Manual (JBox2D is a port of Box2D and is similar enough to where the Box2D manual is applicable)
- JBox2D wiki