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:
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:
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:
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:
Minor Changes
- Draw lines for the grid instead of polygons → faster rendering.
- Fill a black polygon as background on each face instead of filling black polygons for each empty tile → faster rendering.
- Store the highscores of each gamemode/level in one file instead of distributing them across multiple files.
- Use Graphics2D.translate() for better readability in Graphics3D.paint(). This is distributed across 2 commits because I forgot something in the first one.
- Use Vector(a new class) instead of int-array for the positioning of Snake and Object. → more readable code
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
Thank you for your contribution! Excellent/creative idea to bring the classic snake game to 3D.
move()
a lot if you use a double-ended queue to represent the body, in your case, theseg
. Read more details at: How to Design a Snake Game? i.e. you don't move the tails, you pop one from tail, and add a new one to the front.Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.
To view those questions and the relevant answers related to your post, click here.
Need help? Chat with us on Discord.
[utopian-moderator]
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Thanks for your review.
move()
where the main problem are all those checks when the head changes to another area of the cube. But thanks anyway. I'll implement it the next time I work on Snake3D.Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Thank you for your review, @justyy! Keep up the good work!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Hey, @quantumdeveloper!
Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!
Get higher incentives and support Utopian.io!
Simply set @utopian.pay as a 5% (or higher) payout beneficiary on your contribution post (via SteemPlus or Steeditor).
Want to chat? Join us on Discord https://discord.gg/h52nFrV.
Vote for Utopian Witness!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Hi, as a ONECENT player, you have won a random upvote on this post.
Please read about it here: ONECENT Daily Report - Fund Adjustment and a Rant - Day 14
Thanks for participating in the ONECENT strategic game!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Congratulations @quantumdeveloper! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :
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
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit