Logo Glusoft

How to make a game with libGDX

In this tutorial we will make a simple logic puzzle game: Take Ten (number game) with libGDX.

Take Ten

You can play the game online on Kongregate
You need to be familiar with Object-oriented programming, if not the tutorial will probably be too difficult. :(

Setting up libGDX

You can follow the libGDX wiki to configure and create a project for libGDX:

Rules of the game

The rules of the games are simple we will put these instrctions in the How To page of the game:

The goal is to cross every number. You may cross two adjacent numbers by following at least one of these rules:
	- The two numbers are identical
	- The sum of the two numbers is ten
	
	- Two numbers separated with crossed numbers are adjacent
	- The first and the last number are adjacent
	
When there are no more solutions, the game adds new numbers from the previous lines.
The game may not be solvable.

The main class: Numbers.java

This class will stores every numbers on the screen and implement the rules of the games.

First let's see the attributes of the class:

private Array<Integer> numbers; // Array of number
private Texture numTex; // Texture atlas of numbers
private int size; // size of a number in pixel (numbers are square images)
private float x ,y; // position of the screen
private Array<TextureRegion> rects; // sprites
private int indexSelected; // index of the selected number
private Vector2 posSelected, posSelected2; // position fo the selected numbers
private boolean solutionFound; // if a solution has been found (for the solver)
private Viewport viewport; // viewport to keep the same ratio display on multiple screen
private boolean selected; // if a first number is selected
private boolean selected2; // if a number is drop on another number
private boolean easy; // easy mode enabled
private int iSol; // index of the solution


And now let's see the list of the methods whe have to implements:
// Constructor and destructor
public Numbers(float x, float y, String filename, Viewport viewport, boolean easy)
public void dispose()

// Main methods
public boolean checkSolution2() // find a solution 
public boolean sumOrEquals(int i1, int i2) // check if the number can be crossed (see rules)
public boolean computeDistanceIndex(int i1, int i2) // Compute the distance between two numbers
public void setTouchDown(int x, int y, int pointer, int button) // call after a mouse button is pressed 
								   when nothing is selected
public void setTouchDown2(int x, int y, int pointer, int button) // call after a mouse button is pressed 
			  					    when a number is selected 
public void checkBlackLine() // Check when there are a line with every numbers crossed
public void setTouchUp(int x, int y) // call when a mouse button is released
public void generateNewLine() // generate a new line of numbers
private int getIndexCollision(int xP, int yP) // get the index of the number collided
public void addNumber(Integer i) // add number to the array
public void render(SpriteBatch batch) // rendering method

// Getter and Setter methods
public boolean isNumSelected()
public Vector2 getPosSel2()
public float getX()
public float getY()
public boolean isSelected()
public boolean isSelected2()
public void setPositionSel(int x, int y)
public void setPositionSel2(int x, int y)
public void setPosition(float x, float y)

This seem like a lot of works but every method is short so it's not very complicated :).

Constructor and destructor

In construction

Download the project

You can download the srouce of the project on gamejolt!

Too much white, I can't see blue