Snake3D: Released Version 1.0 containing more features and bug fixes.

Snake3D 1.0 released

github: https://github.com/IntegratedQuantum/Snake3D

Bug Fixes

1. Issue

At certain angles one of the 3 faces of the cube disappeared like this:
Screenshot from 2019-07-12 17-31-00.png
In the graphics part I sort the areas and take the 3 areas closest to the screen(which have the smallest z-coordinate) to paint only those. My theory is that I made a mistake at some point there or my assumption that the 3 closest areas to the screen are also the 3 areas that are visible is wrong. Since I was unable to find any evidence for both of these cases, I decided to remake that part of the code.
I just took the corner-point closest to the screen and now painted the areas that are touching this point. That worked, so I decided to no longer bother about the why.

Prologue to 2./3. Issue

In the main update function I first decided to restrict the frame rate of the Graphics3D update function to 50 fps, but a quick test revealed that that update only needs a few microseconds → I removed that restriction.
That revealed two bugs I previously wasn't aware of.

2. Issue

Suddenly the cube took much longer to rotate.
For the rotation I used a structure like this:

ax += (System.nanoTime() - lastTime)*constant;
…
Some other code involving the few microsecond function
…
lastTime = System.nanoTime();

The obvious error here was that I used different times for the two lines. Due to that error when I removed the restriction for the function in between I created a higher difference between the values leading to an overall lower value for Δax.
The solution to this is quite simple using the same time for both:

long newTime = System.nanoTime();
ax += (newTime - lastTime)*constant;
…
lastTime = newTime;

3. Issue

I also detected a graphics bug that now appeared pretty often and which you can see in the following video/gif:
s3d.gif
Luckily I already came across a similar bug years ago in another 3D-game and already solved it back then(after weeks of hard work):
When I call repaint() of a javax.swing.Component like JFrame/JPanel, java automatically creates a separate Thread that then does the work. That is really great and can increase the overall speed of the program, but there is a small problem:
For the new Thread to work it first needs to get all the needed data from cache to the relevant processor core. This takes a little time in which the other Thread already progresses. There is a high chance that the other Thread changes those chunks of data the graphics thread didn't yet copy. In my case there is an array that contains the numbers 0, 1 or 2 and a while later that array holds indices for the 3 areas that are painted. If the copy is made at the moment where the array contains 0, 1 or 2, the graphics Thread will paint the areas of index 0, 1 and 2, which are not necessary the areas that should be painted.
→ So under certain conditions the wrong areas are painted
→ The graphic on screen starts to flicker as seen above.

How can this be solved?

The simplest way to solve this is to just add a delay between the creation of the new Thread and the next function call.
In speed sensitive programs this should be done with a volatile boolean that stops the main process and that is inverted from the beginning of the graphics thread, but in the case of snake, which naturally contains a pretty long delay, I decided to add a 1 ms delay which also serves to spare power of whoever uses the computer.

Here is where I fixed the two issues above: https://github.com/IntegratedQuantum/Snake3D/commit/2fcfe45e28c09c9206feddfbe714516f2615b92d

Features

I made the cubes size dependent to only one variable(main.size) everywhere its numerical value was plugged into the code.
This allowed me to change that value from anywhere. I ended creating a new gamemode/level(big cube) which has a size of 16×16×16, but generally there is no real limit(to those who are able to change the source code) apart from your CPU. Even 60×60×60(above that it gets really hard to see the snake/the food and it just takes ages to get around the cube) is still playable:
Screenshot from 2019-07-12 15-39-15.png
Playing a custom level(TODO) should be really fun on such a big cube!
Previously the snakes length was limited to 50 due to my bad coding. I changed that and gave that array containing all segments of the snake a simplified list-like functionality. Here you can see a little showcase of a long snake:
Screenshot from 2019-07-12 16-56-19.png

Minor Changes

The commits of the minor changes often also contain other changes, so don't think I added the wrong link or something. And sometimes they are distributed across 2 commits because I forgot a crucial part.

1.0 Release

https://github.com/IntegratedQuantum/Snake3D/releases

My username

https://github.com/IntegratedQuantum

Sort:  

Interesting. Will it be made available on Google Play Store?

Interesting. Will
It be made available
On Google Play Store?

                 - xyzashu


I'm a bot. I detect haiku.

Yes, that is one of the long-term goals.
But there are a few problems:
First of all publishing anything on google play costs 25$ and I only want to invest that money if I can be sure a at least some people would be interested(based on your comment I would say that's true).
Then I need to port the current version of the game to android(on github there is only a version for the PC). This is not that hard, but I'd like to add some more features to the PC-version before I do that.
If you want I could give you an unofficial version of the app which is missing some features, but the main gamemodes can be played without a problem.

Congratulations @quantumdeveloper! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

You received more than 50 as payout for your posts. Your next target is to reach a total payout of 100

You can view your badges on your Steem Board and compare to others on the Steem Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP

You can upvote this notification to help all Steem users. Learn how here!

Coin Marketplace

STEEM 0.30
TRX 0.12
JST 0.033
BTC 64534.17
ETH 3150.15
USDT 1.00
SBD 4.01