Book Image

JMonkeyEngine 3.0 Cookbook

By : Rickard Eden
Book Image

JMonkeyEngine 3.0 Cookbook

By: Rickard Eden

Overview of this book

Table of Contents (17 chapters)
jMonkeyEngine 3.0 Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

The principles of a bridge-building game


Variants of bridge-building games have been around for a long time. The classical Bridge Builder is a 2D physics game where the player is required connect beams to create a bridge strong enough for a train (or some other moving object) to pass.

This recipe will describe most of the core functionalities needed to create such a game, including making the objects stay 2D and not wander off on the z axis.

We'll have some basic controls for the game:

  • Left-click will select a previously built node in the bridge

  • Right-click will add a new node or connect two previously built ones

  • The Space bar will turn on the physics

The following figure shows a bridge:

Getting ready

Before we begin with more physics-related functions, we should set up the basic application.

First of all, we create a new class that extends SimpleApplication.

Later on, we're going to use the following two lists:

private List<Geometry> segments;
private List<Point2PointJoint> joints;

We also...