You are browsing as a guest. Sign up (or log in) to start making projects!

Snake!

  • 5 Devlogs
  • 5 Total hours

A recreation of the traditional Snake in Java! I made this to practice my Java skills and get ready for making a bigger game over the coming months.

Ship #1 ✨ Blessed

I started learning Java at the beginning of June, and to test my skills I recreated Snake in Java. You can control the snake using WASD/arrow keys, and reset the game using R. It features modifiers that let you adjust the snake’s speed and board size, and you can enable other modifiers as well.

During development, I faced a lot of minor challenges caused by me writing something incorrectly and then battling with the bug for 5-10 minutes or so. Since it’s my first project made using Java, I tried to do most things on my own but I did reference a video if I got too stuck on one thing. However, I’m super proud of achieving this, for two main reasons:

  1. It’s my first project made in Java, and it’s actually usable and fun to play.
  2. It’s a functional game that people can play. This is especially important because I’m planning to make a platformer in C++ soon, so this was a nice warmup for game development.

Anyway, I hope you enjoy my Snake game! :)

  • 5 devlogs
  • 5h
  • 13.26x multiplier
  • 79 Stardust
Try project → See source code →
Open comments for this post

25m 22s logged

I just fixed two bugs/issues:

  • Made it so you can no longer click a button while the game is running
  • Fixed a bug where if you mashed two inputs in the same frame, your snake could crash (e.g. moving down and mashing the right and up inputs). I fixed this by adding a check to make sure you can only switch directions once per frame.

How I did it: I made a boolean called hasMoved, set it to false, and made it check for if hasMoved was false. It also sets hasMoved to true after you change direction and sets it back to false at the end of the frame.

0
0
5
Open comments for this post

2h 8m 8s logged

It’s been a hot minute since I posted a devlog, but I think I’ve more or less finished the game. Here’s what I’ve added:

  • Interactive buttons that let you toggle/change the snake’s speed, size of the board, and different modifiers such as disabled collisions and mines that spawn randomly on the map
  • Fixed a bunch of pre-existing bugs (like with score tracking) and new bugs (working out the mines was so annoying holy)

yeah that’s pretty much it I think.
Next steps:

  • I’ll look into making it resizable/of different dimensions. Honestly, I might not do this one because a lot of my positions/coordinates were hard coded so it might be a pain to rework, but I’ll think about it.
  • I’ll fix any remaining bugs that I can catch. I know there’s one that crashes the snake if you try to mash two directions together.

And last but not least, I’m gonna start preparing to ship!

0
0
4
Open comments for this post

43m 39s logged

Ok so I went and fixed all the bugs, there were a LOT of bugs. here’s a couple:

  • Snake movement and apple generation were happening incorrectly; I use a system where different variables like appleX, appleY, and an array for x and y values of each snake segment are stored as values between 1 and the length of the board (boardDim). They’re then multiplied by the dimension of each cell(cellDim). I initially forgot to multiply by cellDim so the snake was moving at a 1 pixel/second speed and the apple was confined to the top left corner.
  • The borders of the cells were not being generated
  • I didn’t initialize the arrays that contain the positions for each of the snake’s segments, causing the game to not run at all initially
  • Up and down controls were reversed; borders did not work
  • If you mash 2 directions, you can crash: e.g. if you’re going up, then mash left and down, the program interprets your down input as the latest one and essentially pushes you into yourself

There are probably some more I haven’t explored yet, but for now I’m gonna work on the main menu.

0
0
4
Open comments for this post

1h 6m 56s logged

This time I completed pretty much all the basic gameplay mechanics and the game should technically work once I fix up any bugs. However, there are still bugs: quite a few of them, actually, since I kinda just brute forced my way through this stage of development with code that I thought should work.

Anyway, once I get any bugs that stop me from running the game sorted out, I’ll refine the bugs that are impacting gameplay (there are def gonna be a couple of bugs there too). Then I’ll probably get started on designing a main menu.

0
0
3
Open comments for this post

35m 10s logged

I started learning Java at the beginning of June, and to test my skills I’ making a guided project in Java. I decided to recreate Snake, using the video attached in the README file to help guide me. I’ll try to use it as minimally as possible, but if I get stuck I’ll watch the video to learn where to go next.
So far I’ve just set up files and classes/functions as mentioned in the video, and I also set up a couple of variables and some code for a few functions on my own. Next time I’ll work on gameplay aspects, then I’ll move on to coding a death screen completely on my own.

0
0
3

Delete project?

Are you sure you want to permanently delete this project? This action cannot be undone.

All devlogs, followers, and associated data will be removed.

Followers

Loading…