Monday, March 17, 2014

Block Bunny

This is a tutorial game for getting familiar with Box2D basics and LibGDX's Tiled API.



The point of the game is to get the bunny to the end by jumping and switching block colors. You can only run over blocks that are the same color you currently have selected in the top left.
Press Z to jump, and X to change color.
I only put 5 maps in there, but you can make your own. To make maps, you need three tile layers named "red", "green", and "blue" and two object layers named "crystals" and "spikes". Put all your red/green/blocks in the appropriate layer. You can simply place any object in the crystals and spikes layer to add them. The only thing I grab from these objects is their position.

You can watch the tutorial if you want:
https://www.youtube.com/watch?v=85A1w1iD2oA

Game:
https://dl.dropboxusercontent.com/u/59779278/libgdxtutorials/Block%20Bunny/Block%20Bunny%20Game.rar

Source code:
https://dl.dropboxusercontent.com/u/59779278/libgdxtutorials/Block%20Bunny/Block%20Bunny%20Full.rar

6 comments:

  1. This tutorial is great! Thanks for sharing!

    ReplyDelete
  2. Thanks dude for letting me put this on the Amazon app store!

    ReplyDelete
  3. Hi, Nice tutorials.

    Have one question. After looking at your final source codes, i have noticed that you have remove the while loop (while(accum >= STEP)) in the render method of the Game.java class file.
    Is there any paticular reason for this?

    Thanks,
    Alan

    ReplyDelete
  4. Im getting an Error:(183, 65) java: inconvertible types
    required: int
    found: java.lang.Object

    Play.java :

    tileMapWidth = (int) tileMap.getProperties().get("width");
    tileMapHeight = (int) tileMap.getProperties().get("height");
    tileSize = (int) tileMap.getProperties().get("tilewidth");

    get() returns an Object

    ReplyDelete
    Replies
    1. hi Sebestian, because you get an Object in return, you need to convert the Object into String like this: String str = layer.getObjects().get(0).getProperties().get("width").toString();

      From there you can make it e.g. a float value like this:
      float height = Float.parseFloat(str);

      good luck with your project!

      Delete
  5. btw GREAT JOB on the tutorial and the app Mike! It has helped me a lot and it's an amazing guide for getting introduced to Libgdx programming! Thank you!

    ReplyDelete