my latest project is a little math-game called BabyGraph.
Your task is easy. Build a way for the baby with math functions and collect all the sweets.
There are two versions-
First written with pure Java
Second written with libgdx to have the same code for desktop and android version
Next steps:
music
publishing
If someone wants to try the current version:
HTML version: Play
Android Libgdx version: Download
Desktop libgdx version: Download
old “pure Java” version: Download
Now the solution will be saved online and you can compare to other players. Now you can see in every level what is the shortest solution and what the the lowest time to solve the level.
And now there are 49 levels and I started the editor.
Now the editor is ready and I polished the game. I am very happy with the result.
You can create your own levels (then you have to solve them) and after solving the level you can upload the level and everybody can play it. =)
Next step is trying to make a little better collision detection. But it works good now.
A question:
I update the function with the time variable only every 100 ms because calculating the values for the polygon needs time (for longer, harder function like ‘((2^((14-x+t)/6))-e^(-(((x-96)/12)^2))32+2^((x-96)/2))(1-1/(1+20))’ ). Then I need ~15ms to calculate all new values. My plan is to update the function every 10 ms.
Do you know a simple libary to solve that (speed)-problem?
I have a string with a function and want the result for x >= -500 and x <= 500 in (0.1 steps). At the moment I tried exp4j, javaluator, my own solver and the javax.script.ScriptEngine . And all solutions needs too much time.
A workmate was a very good rubber duck. I reported my problem with the time and solved the problem on my own. I dont need to calculate from x = -500 to x = 500. My levels are small (and hard enough). The new borders are x = -105 to x = 105. Thats really enough to have fun and its fast enough to solve it every 10 ms.
The next step is the android version. It will be my first libGDX project. I’m looking forward.
The “normal” port was easy for me (except some problems with drawing a filling polygon and other little problems) but I solved them all …
All Problems? No, a little problem “crashed” the whole port.
And that is calculating the values for the function. On a “normal” pc everything works finde but on a smartphone it is way too slow (only with the ‘t’ variable). :’(
I tried so much libs and the best for me is the JEP Java library (the last free version). With that the smartphone version is only 5 times slower than it should … with my solution or other libs the factor is 30 to 100 times slower. And that is frustrating.
Tried it, it brought my phone to the knees weeping and it’s actually quite fast…
Did you try using less samples/bigger steps combined with interpolation?
You could also use some kind of level of detail approach where you do more samples of your function around the baby and way less where the baby cannot touch the function and interpolate between the samples to generate a smooth graph.
Also most phones have multiple processor cores and generating function values can be done in parallel really easy.
define a common “MathExpression” interface with an abstract “double evaluate(double x)” method
Use objectweb’s ASM library to generate a new class that implements MathExpression and evaluate(), by walking the AST and generating bytecode instructions for the math operations
Define the generated class in the JVM
– preferably use sun.misc.Unsafe.defineAnonymousClass() when available (>= 1.7) (same is used to generated classes for Java 8 lambdas implementing the functional interface);
– or use java.lang.ClassLoader.defineClass()
For Android Dalvik VM, code generation and defining in the VM looks a bit different. Here you can use:
objectweb’s ASMDEX library and instantiating a new dalvik.system.DexClassLoader giving it the generated dex file as first constructor argument
Here is a small project (73kb jar size) I assembled from code I had laying around, that should get you a fast math expression evaluation at least on Desktop (tested on HotSpot and OpenJDK). It uses JavaCC to parse and ASM to generate bytecode and HotSpot Anonymous Classes (also works on OpenJDK) to define new classes in the JVM with minimal overhead.
It compiles and evaluates your expression “((2^((14-x+t)/6))-e^(-(((x-96)/12)^2))32+2^((x-96)/2))(1-1/(1+20))” between -500.0 and +500.0 with 0.1 stepping in ~3.2 ms. on my machine (with making sure that HotSpot does not eliminate the evaluation altogether).
Have fun with it!
Now it works fine on my smartphone [onePlus 2].
If you want to try it, you can find it here.
If you want to try the desktop libgdx version, you can find it here.
Thanks for the nice word phil.
The sweet geyser starts in the middle of the game. It has no “source”. It shows only the joy of winning the level. =)
Today I started with a new game mode: Find the function. In that mode you have to find the correct function and only the function, no baby and no sweets. While playing the game I found so many nice looking functions that I have to add that game mode.
Next steps:
more find the function levels
sound/music
publish it to the playstore
current Alpha-Download
Android Libgdx version: Download
Desktop libgdx version: Download
Just one tiny thing: I have the impression that somehow when entering an expression fast on a Desktop keyboard, the game does not recognize all key presses and oftentimes on an Android device, key presses are recognized multiple times in succession, even though the press was just very quick. Do you use event-driven input or do you query the key states on each render cycle?
Thanks for the feedback. It was event driven input (but with a mapping for the desktop key input). Now it is evaluated every render/update cycle and now the problems are gone. =)
And I implemented a new babysprite with a “crawl” animation and some more “find the function” levels (at the moment 20 levels).
Next steps:
more find the function levels (I want 40 or 50 levels)
sound/music
publish it to the playstore
current Alpha-Download
Android Libgdx version: Download
Desktop libgdx version: Download