Giter Club home page Giter Club logo

jme-dyn4j's Introduction

#jMonkeyEngine 2D using Dyn4J.

###Basic Shapes screenshot

Player control

screenshot

##Rationale. jMonkeyengine has an excellent 3D physics engine bundled - Bullet. I've recently been trying to make a 2D game with physics using all the standard stuff in jME, with mixed luck. I came close by forcing Z=0f using physics tick listeners. But when stuff moved fast (projectiles or really hard/fast collisions) stuff started moving behind each other (Z axis) and I figured trying to switch to a pure 2D physics engine was the right way to go.

##Solution. Attempt to mimic the familiar API you use when using standard bullet.

Dyn4JAppState, trying to be like BullettAppState

		dyn4JAppState = new Dyn4JAppState()
		stateManager.attach(dyn4JAppState)

Dyn4JShapeControl - Tries to behave like RigidBodyControl

	private createBox(Vector2f location, Dyn4JAppState dyn4JAppState) {
		Double boxSize = 0.5f;
		
		// jME Geometry:
		Geometry boxGeom = new Geometry("Box", new Box(new Float(boxSize), new Float(boxSize), 0.1f))
		Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md")
		mat.getAdditionalRenderState().setWireframe(true);
		mat.setColor("Color", new ColorRGBA(new Float(255/255f),new Float(228/255f),new Float(225/255f), 1f))
		boxGeom.setLocalTranslation(location.x, location.y, 0f)
		boxGeom.setMaterial(mat)
		rootNode.attachChild(boxGeom)
		
		// The Control:
		Dyn4JShapeControl physics = new Dyn4JShapeControl(
			new Rectangle(new Float(boxSize*2), new Float(boxSize*2)), MassType.NORMAL,
			100, //100 kg
			0.8, // quite high friction
			0)   // not slippery
			
		// Glue jME with Dyn4J:
		boxGeom.addControl(physics) // <-- Let Dyn4JShapeControl handle the jme Geometry from now on.
		dyn4JAppState.add(boxGeom)
	}

##Current state. Got solid item working (floor) and a couple of squares and circles bouncing on it. The controller is leaky, forcing you to use dyn4j internal classes. Player control seems working but primitive.

Run the tests in src/test/groovy to see what's up.

##Get it Check out the code and run the tests.

or add it to your project. The packaging may be bad, so feedback is apprichiated.

  repositories {
    maven {
      url 'http://dl.bintray.com/johnsen/maven'
    }
  }
  /*
  ...
  */
  dependencies {
    compile 'jme-dyn4j:jme-dyn4j:0.1'
  }

jme-dyn4j's People

Contributors

finnjohnsen avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.