Java-Gaming.org Hi !
 Featured games (91) games approved by the League of Dukes Games in Showcase (804) Games in Android Showcase (237) games submitted by our members Games in WIP (867) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
Pages: [1]
 ignore  |  Print
 BabyGraph  (Read 42690 times) 0 Members and 1 Guest are viewing this topic.
Apo
 « Posted 2016-10-14 17:17:56 »

Hi,

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

Screenshots:

Apo
 « Reply #1 - Posted 2016-10-15 20:50:13 »

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.

Next steps:
- finish the editor with upload function
- better collision detection
- android version
Archive
 « Reply #2 - Posted 2016-10-16 00:52:00 »

Wow this is the coolest thing I've seen in a while, great job!

Apo
 « Reply #3 - Posted 2016-10-17 16:33:22 »

Thx. =)

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.
Apo
 « Reply #4 - Posted 2016-10-18 19:45:15 »

A new version is online. And if there are no bugs, it will be a release candidate.

new:
- I fixed bugs in the editor.
- You can start the game by pressing Enter
- update the function every 10 ms

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.
Apo
 « Reply #5 - Posted 2016-10-22 09:22:39 »

I had to fix several small bugs and I polished some menus.

Now I am really happy with the result and I can say that is the first version that feels "complete" for me.

Now I can really start to port the game to android
Apo
 « Reply #6 - Posted 2016-10-29 15:46:30 »

I tried the libgdx library und what can I say ... i love it. =)

I made a little libgdx project to try out different settings etc. If you want to see my "playground" with 3 different 4k games ported to libgdx, click here.

Next step is porting the BabyGraph game. =)
Apo
 « Reply #7 - Posted 2016-11-06 19:13:30 »

After making the android version of 5 different 4k games with libgdx, I tried to port BabyGraph.

And what I can say ... I am frustrated.

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.

Now I have to find another solution or I cancel the android port.
If you want to try the current slow andoid version, you can get it here and see what I mean.
VaTTeRGeR
 « Reply #8 - Posted 2016-11-06 19:34:14 »

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.
KaiHH

JGO Kernel

Medals: 787

 « Reply #9 - Posted 2016-11-06 20:21:48 »

I agree with what VaTTeRGeR suggested. Definitely reduce the sampling rate at "uninteresting" points.

When you want to go full speed, and get everything out of the JVM/Android VM, read on...

A question:
...
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.

On HotSpot/OpenJDK, my plan for this would be:
- build a simple JavaCC or ANTLR grammar to recognize math expressions (for inspiration, look at the JavaCC example grammars or this stackoverflow thread)
- define simple AST classes (Constant, BinaryOp, UnaryOp, FunctionCall, etc.)
- use grammar actions to instantiate the AST
- 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);

... 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.

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
- use Dexmaker that does the latter of the above for you

What they do is basically generate a new .dex file at runtime and load it into the VM with a new DexClassLoader.

I however did not try the Dalvik code generation approach. It would be very interesting if that would work for you.
KaiHH

JGO Kernel

Medals: 787

 « Reply #10 - Posted 2016-11-07 09:24:28 »

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!

EDIT: Results of this JMH benchmark between sec and exp4j:

# Run complete. Total time: 00:00:12

Benchmark        Mode  Cnt    Score   Error  Units
Bench.evalExp4j  avgt    3  302,794 ± 9,214  ns/op
Bench.evalSec    avgt    3    7,982 ± 0,610  ns/op
Apo
 « Reply #11 - Posted 2016-11-18 16:51:15 »

KaiHH - I am so grateful.

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.

Next steps:
- sound
- find a solution to draw a dashed line with libgdx
- polishing (smartphone version)
Apo
 « Reply #12 - Posted 2016-11-20 20:04:57 »

WIP version:

Whats new
- As you can see now I can draw a dashed line with libgdx. But my algorithm isnt perfect at the moment. I will fix it in the next version.
- And now you can see a 3 seconds preview when the "t" variable is in the function.
- I added the position information in the android version to "always on when the game is not running". That should help to find the correct solution.

Next steps:
- sound
- more polishing
- perhaps achievements
Apo
 « Reply #13 - Posted 2016-11-21 19:45:52 »

Today
- now you can compare yourself with the world (check your best time against the world best time to beat that level)
- I added some "sweet"-particles after solving a level.
- the game looks after your system language, if its german the game is in german else english

Yes, I am on the right way. =)

Apo
 « Reply #14 - Posted 2016-11-23 13:43:24 »

Today I implemented
- an options menu, now you can choose the language and everything is prepared to switch music and sound on and off
- an achievement screen, you can get up to nine achievements
- removed some bugs in the editor

Next steps:
- sound and music
- publish the game to the playstore

Apo
 « Reply #15 - Posted 2016-11-25 08:24:14 »

Today
- I added three new achievements
- some "flying" functions in the background in the menu.
- I removed serveral bugs

Next steps:
- sound/music
- publish it to the playstore

philfrei
 « Reply #16 - Posted 2016-11-26 03:56:16 »

Nice!

Small suggestion: I was wondering about moving the "Congratulations" panel down a bit to allow the player to see the source of the sweets-geyser?

Apo
 « Reply #17 - Posted 2016-11-29 07:47:18 »

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

KaiHH

JGO Kernel

Medals: 787

 « Reply #18 - Posted 2016-11-29 09:18:00 »

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?
Apo
 « Reply #19 - Posted 2016-12-11 12:37:06 »

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

Apo
 « Reply #20 - Posted 2016-12-19 09:45:11 »

I created a website for the game and added some sound effects.

Next steps:
- more find the function levels (I want 30 or 40 levels)
- music
- publish it to the playstore

And I created some gifs to show how the game works.

KaiHH

JGO Kernel

Medals: 787

 « Reply #21 - Posted 2016-12-19 09:52:25 »

Another issue that happened to me when playing on a Nexus 9, was that the time progresses significantly slower than realtime when the baby "falls" and "slides" on the function graph. The seconds elapse at around one third of the realtime. Oddly this does not happen when swiping with the finger all over the viewport whilst the animation runs. As long as I touch and swipe around with the finger, the time progresses normally (faster) equal to realtime. When stopping the swiping, the time again progresses slower.
Apo
 « Reply #22 - Posted 2016-12-20 08:49:02 »

Another issue that happened to me when playing on a Nexus 9, was that the time progresses significantly slower than realtime when the baby "falls" and "slides" on the function graph. The seconds elapse at around one third of the realtime. Oddly this does not happen when swiping with the finger all over the viewport whilst the animation runs. As long as I touch and swipe around with the finger, the time progresses normally (faster) equal to realtime. When stopping the swiping, the time again progresses slower.

Mhh, I updated my nexus 9 and tried it ... and you are right and I have no idea.
When the user presses a button, the input is saved and in the next update/render step it is evaluated. Why the nexus 9 makes such strange things ... I dont know, I have to debug it at home.

Junior Devvie

Medals: 9
Exp: 4 years

 « Reply #23 - Posted 2016-12-20 18:55:48 »

I'm really happy to see it. Great idea, simple but beautiful interface.
Apo
 « Reply #24 - Posted 2017-01-25 09:03:06 »

I removed some bugs and if the render/update cycle needs too long, then the game renders less objects.

Next step is to publish it to the playstore. The native android version is much faster then the browser version.
Aalhex
 « Reply #25 - Posted 2017-01-31 13:16:15 »

Well—it appears as though I have a game to play through!

Are you going to remove the keypad should the game be played from a desktop computer? It seems to me it covers slightly too much of the screen.

It is I, Alexander from the Junivörs.
Apo
 « Reply #26 - Posted 2017-11-17 12:33:46 »