Permalink
Browse files

Variable position platforms

The Platform class now takes x and y positions as parameters, meaning
the chunk generation in LevelControl is free to place more than one
platform in the same chunk without worrying about moving platforms
according to physics (or moving the entire chunk to place the platform,
as previously). Current version has two platforms per chunk.
  • Loading branch information...
1 parent a609166 commit 3bc399da79586495cfb3c7ee7a62dbf883909ea7 @JonatanKilhamn JonatanKilhamn committed Mar 15, 2013
@@ -72,7 +72,7 @@ public void setSpatial(Spatial spatial) {
*/
public void update(float tpf) {
if (this.player.getLocalTranslation().getX() >
- chunks.getFirst().getLocalTranslation().getX() + 60) {
+ chunks.getFirst().getLocalTranslation().getX() + P.chunkLength + 60) {
deleteChunk(chunks.removeFirst());
generateNextChunk();
}
@@ -110,21 +110,26 @@ private Node generateNextChunk() {
} else {
xPos = this.chunks.getLast().getLocalTranslation().getX() + P.chunkLength;
}
-
// generate a new chunk position
- Random random = new Random();
- int randomNumber = (random.nextInt(6) - 3);
Vector3f newChunkPosition =
- new Vector3f(xPos, randomNumber, 0f);
+ new Vector3f(xPos, 0f, 0f);
+
+ // generate platform positions
+ Random random = new Random();
+ int rand1 = random.nextInt(6) - 3;
+ int rand2 = rand1 + random.nextInt(6) - 3;
+
+ // generate two platforms
+ Platform platform1 = new Platform(this.assetManager, 0f, rand1);
+ Platform platform2 = new Platform(this.assetManager, P.platformLength+P.platformDistance, rand2);
- // generate one platform
- Platform platform = new Platform(this.assetManager);
// generate the background wall
Wall wall = new Wall(this.assetManager);
// attach everything physical to the node
- chunk.attachChild(platform);
+ chunk.attachChild(platform1);
+ chunk.attachChild(platform2);
addChunkToPhysicsSpace(chunk);
// attach everything else to the node
chunk.attachChild(wall);
@@ -23,12 +23,12 @@
* @param assetManager is used to load the geometry and
* texture of the <code>Platform</code>.
*/
- public Platform(AssetManager assetManager){
+ public Platform(AssetManager assetManager, float x, float y){
super("Platform");
Box model =
new Box(Vector3f.ZERO, P.platformLength/2, P.platformHeight/2, P.platformWidth/2);
this.mesh = model;
- this.setLocalTranslation(P.platformLength/2,0,0);
+ this.setLocalTranslation(P.platformLength/2 + x,y,0);
Material material = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
material.setTexture("DiffuseMap", assetManager.loadTexture("Textures/BrickWall.jpg"));
@@ -40,6 +40,10 @@ public Platform(AssetManager assetManager){
this.setShadowMode(ShadowMode.Receive);
}
+ public Platform(AssetManager assetManager) {
+ this(assetManager, 0f, 0f);
+ }
+
/**
* Returns the x-coordinate of this platform
* relative to it's parent <code>Node</code>.
@@ -23,5 +23,5 @@
public static final float run_speed = 0.15f;
public static final float jump_speed = 20f;
- public static final float chunkLength = 15.0f;
+ public static final float chunkLength = 30.0f;
}

0 comments on commit 3bc399d

Please sign in to comment.