Category Archives: Programming

Rugby game, AS3 – CE – haXe versions

Two weeks ago at school we made a simple rugby game with graphics provided.
I take this opportunity to compare how I develop the game if I use different framewok :

– in AS3 with linked list and object pooling (refers to this previous tutorial). Obviously it is a little game, and we don’t need complex optimization, but that was a good implementation exercice. Moreover I’ve updated my class πŸ˜‰

– with the Citrus Engine, managing Box2D. It was not easy to handle physics to have the same result that the basic AS3 version, and actually it is not the same (there is some inertia), but I really like how Box2d handle collision. We can manage before collision, the beginning and the ending. It is really more precise than a hitTestObject. Moreover we can separate art from physic body, and so change easily the “collision box”.

– last night, with lbineau we made a programming evening around haXe (and some beers πŸ™‚ ). The idea was really simple : make the same game, using existing AS3 classes with haXe. I have already given a chance to haXe previously and saw how powerful it is. This time, I see how easy it is to use previous AS3 code. I didn’t rewrite my Opponent and Player class! And I used the fla to link graphics without any trouble! However I’m a bit disappointed : I used most of the time original AS3 objects instead of haXe primary objects. What I need right now is FDT5 with its full haXe support! Can’t wait for it… Oh! If you’re interesting by haXe, you should take a look on NME, it seems to be amazing.

The zip with the three versions.

Doubly linked list and object pooling

After holidays, it’s time to get back to work πŸ™‚
I was really busy last month, so this is some news on what I did and what is going on :

– I’ve made some experiments with the Citrus Engine on the Hero adding some functionality. But what appears is the Hero class becomes more and more complex… So I asked its creator if he knows a system/model which has a modular way to add features to the hero. And he gives me some information about the Entity/Component model. Woah, it is awesome! It’s really a new way of thinking about programming. No more OOP. This is 3 useful links/resources if you are interested : Gamasutra the Entity Component Model, Entity Systems are the future of MMOG development, Entity Systems. This links are very interesting, but there isn’t any implementation. You can find implementations with the PushButton Engine (flash), Artemis (java). However it is really complex, so I was not able to create a Component/Entity System for the CE due to my lack of experience… but if its creator has time, he will do!

– I was in holidays at Praha (Czech Republic), amazing city/country! And beer is really cheap πŸ™‚

– I’m currently reading the book of Jesse Schell, The Art of Game Design it’s a masterpiece! Really, really interesting, lots of awesome advices. Approved & Recommended!

– I’m working/designing my next portfolio. It will be nice… πŸ˜‰

– On Thursday 15 September, I go back to the Gobelins school! And I will make a point with Tiffany about Kinessia. We are thinking to create the game for mobile. I hope we will have enough time (there are already lots of project at school…), so stay tuned!

– Mobile, tablet and game design/programming is interesting me more and even more. This is two good links on mobile game programming : Starting with AIR for Android and iOS – building one app for both platforms, and Building mobile games in Adobe AIR – optimization techniques.

– And finally I’m also waiting FDT5 to invest more time in haXe and WebGL!

I think it’s enough for the news at the moment! Now it’s time to speak about the topic, this week I wanted to make some algorithms, doubly linked list and object pooling are a good exercice. Previously I made an oral in my school to introduce recurisivity and data structures (pdf link in french). Doubly linked list and object pooling are techniques optimizations used in game development and especially on mobile devices.

Continue reading Doubly linked list and object pooling

Starting with haXe

I heard a lot about haXe recently, so I made ​​the leap. This is a short introduction with demo to the haXe language.

haXe is a multiplatform language. You can use it to target Flash, JavaScript, C++, Php, and soon C# and Java. What does it mean ? You write your program in haXe and you chose on which platform you will export it. It is compiled on its target platform : .swf .php .js …

“The idea behind haXe is to let the developer choose the best platform for a given job. In general, this is not easy to do, because every new platform comes with its own programming language. What haXe provides you with is:
– a standardized language with many good features
– a standard library (including Date, Xml, Math…) that works the same on all platforms
– platform-specific libraries : the full APIs for a given platform are accessible from haXe”

In this short tutorial, I will target on two platforms .swf and binaries file (cpp) with the same code!

Continue reading Starting with haXe

Greedy algorithm

According to Wikipedia, a greedy algorithm is any algorithm that follows the problem solving heuristic of making the locally optimal choice at each stage with the hope of finding the global optimum. In general, greedy algorithms are used for optimization problems.

An example of a Greedy algorithm is a charging machine. Assume that it give you your change with € currency, you will have coin of : 200, 100, 50, 20, 10, 5, 2, 1. Your change will be really easy to calculate with a greedy algorithm :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
var moneySystem:Array = [200, 100, 50, 20, 10, 5, 2, 1];
var giveBack:uint = 263;
var solution:Array = [];
 
trace(greedyMethod(moneySystem, giveBack, solution));
 
function greedyMethod($moneySystem:Array, $giveBack:uint, $solution:Array):Array {
 
	if ($giveBack == 0) {
		return $solution;
	}
 
	while ($giveBack >= $moneySystem[0]) {
		$giveBack -= $moneySystem[0];
		$solution.push($moneySystem[0]);
	}
 
	$moneySystem.shift();
 
	return greedyMethod($moneySystem, $giveBack, $solution);
}

For 263, the algorithm will output : 200,50,10,2,1. It is the best solution. Thanks to the € currency, greedy algorithm will always give the best results.
However if we have an other money with only 4, 3, 1 coins and the change is 6 the greedy algorithm outputs 4, 1, 1 instead of 3, 3. That’s a fail !

Another typical example is the knapsack problem : given a set of items, each with a weight and a value, determine the number of each item to include in a collection so that the total weight is less than or equal to a given limit and the total value is as large as possible.
According that our values are sorted in decreasing order we have :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
var objects:Array = [["A", 12, 10], ["B", 10, 7], ["C", 8, 5], ["D", 7, 4], 
		 ["E", 7, 4],  ["F", 6, 4], ["G", 5, 2], ["H", 4, 2],
		 ["I", 4, 1], ["J", 3, 2], ["K", 3, 2], ["L", 3, 1],
		 ["M", 2, 2], ["N", 1, 1]];
var totalWeight:uint = 25;
 
trace(knapSack(totalWeight, objects));
 
function knapSack($totalWeight:uint, $objects:Array):Array {
 
	var currentWeight:uint = 0;
	var subSet:Array = [];
 
	for (var counter:uint;counter< $objects.length; ++counter) {
 
		if (currentWeight + $objects[counter][2] <= $totalWeight) {
			currentWeight += $objects[counter][2];
			subSet.push($objects[counter]);
		}
	}
 
    return subSet;
}

The output is [A,12,10],[B,10,7],[C,8,5],[G,5,2],[I,4,1]. It’s ok, but we aren’t sure that it is the best result. The problem with a greedy algorith : it will always try to select the first parameter even if it is not the better.
For instance, our max weight is 40, our objects are [“A”, 30, 39], [“B”, 12, 10], [“C”, 12, 10], [“D”, 12, 10], [“E”, 12, 10],[“F”, 4, 1]. The greedy algorithm choose A and F for a value of 34 whereas B, C, D, E is obviously the best value : 48. That’s an other example where it fails.

So to conclude greedy algorithms depends of datas if they are balanced or not. More data are balanced, more it will be powerful. For a perfect result, you can use dynamic programming method. It is more complex and requires more resources. So it’s up to us to find the best solution for our problem.

Create a breakout game with the Citrus Engine

Today this is a new tutorial on the great Citrus Engine framework. Before starting my school project, I wanted to try using box2D inside the Citrus Engine, so I will show you how create a breakout game !

Click here to play the game, don’t forget to click in the swf to enable keyboard.

Continue reading Create a breakout game with the Citrus Engine

The Settlers of UTBM

This is my last project at the UTBM. It is based on the Settlers of Catan‘s game. I made this project with two schoolmates, we did it in Java with Swing’s library.

I retain of this project a hard utilization of the Swing’s library : it is really another way of conception than ActionScript 3, you manage all as you want, but that’s not easy to see out of the box.

This is the link of the game, you can find all packages and a .jar to run the game ! We tried to respect the MVC model ! I hope you enjoy !

I will add some news soon πŸ˜‰

Recursion with factorial

A recursive function is a procedure or subroutine, implemented in a programming language, whose implementation references itself.
It is really useful, try to make a program like Tower of Hanoi with an iterative algorithm… good luck !

So I will give you an easy method to create a recursive algorithm, I choose the example of factorial because of it simplicity.
Mathematical’s reminder : 4! = 4 * 3 * 2 * 1 = 24.

There are 3 steps :
– parameter(s) : identify all the parameters that you need to resolve the problem. They will decrease at each call of the function. In the factorial’s case, it is the factorial’s number.

function factorialCalculation(factorial:uint):uint

– exception’s case : this is when the procedure stops to call itself.

if (factorial == 1) { return 1; }

– recursive’s case : where recursive call is implemented, don’t forget to decrease (generally) parameter(s).

return factorial * factorialCalculation(factorial - 1);

Now all the code :

var factorial:uint = 4;
var resul:uint = 0;
 
resul = factorialCalculation(factorial);
 
function factorialCalculation(factorial:uint):uint {
 
	if (factorial == 1) {
		return 1;
	} else {
		return factorial*factorialCalculation(factorial-1);
	}
}

Be careful : recursive function are really heavy. Factorial’s case is just an easy example, it should be implemented as an interative function !

And for the fun with a ternary operation :

function factorialCalculation(factorial:uint):uint {
 
	return (factorial == 1) ? 1 : factorial * factorialCalculation(factorial - 1);
}

πŸ˜€