123
-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|100|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
Socoder -> Retro Coding -> Snake Games are the Best Games

Sun, 06 Nov 2022, 03:07
AndyH

Snake Games are the Best Games



Unexpanded Vic 20

This is just a simple snake game, with some unique features and twists. Main reason for writing this is I've been stuck in a bit of mindset recently that has made it physically and mentally exhausting to think programming things in my spare time, and I wanted to do something simple to get over that hump.

The game:

- Four difficulty levels
- plays in waves of increasing difficulty
- a combo bonus (green jelly)
- mushroom bonus for completing a wave
- wrap around play area
- tight, instantaneous controls
- zero bytes free!

I'll be pushing out for free on itch.io as usual, and hopefully will get a tape realese too.

-=-=-
Andy H
8-bit games at www.hewco.uk
Cartoons at awful.ovine.net
Ovine at ovine.net
Sun, 06 Nov 2022, 03:17
Jayenkai
I let out an audible "ooh!" when he screen-wrapped!

-=-=-
''Load, Next List!''
Sun, 06 Nov 2022, 04:35
rockford
Looks good Love the eating effect where the food item stays put until the tail reaches it

I would not have attempted to go through the top/bottom/sides - looks like there's a wall surrounding the playfield; they're normally deadly.

Snake games are generally pretty good, but unfortunately become tedious quickly. I did one mamy. many, many years ago in The Games Factory. Each level altered after all foods were eaten - columns and walls expanded, leaving less and less of the area free to move around; it added some longevity and made progress trickier.
Sun, 06 Nov 2022, 15:30
AndyH
Yea snake games can be a trundle that never ends. Yours sounds like a good idea. My first 68000 game on the Atari St was a snake game with mazes, although not like nibbler maxes, more open.

This one has distinct rounds which makes it feel like you're progressing. And the wrap around is because it uses fewer bytes and I don't have to lose screen space with wall characters. It doesn't make it easier when there are more mushrooms about.

-=-=-
Andy H
8-bit games at www.hewco.uk
Cartoons at awful.ovine.net
Ovine at ovine.net
Sun, 18 Dec 2022, 12:36
AndyH
You can now download a copy to play on your Real Vic 20 ... what? you don't have a Vic 20? How can that be? Well I guess you can play it fine in VICE too.

hewco64.itch.io/vic-20-sgatbg-unexpanded

-=-=-
Andy H
8-bit games at www.hewco.uk
Cartoons at awful.ovine.net
Ovine at ovine.net
Sun, 18 Dec 2022, 12:40
Jayenkai
Awesome!!
Sun, 18 Dec 2022, 20:15
Jayenkai
Runs nicely. A decent fast-paced game, too, which is nice to see on the Vic. (albeit an emulated one)
Good stuff

-=-=-
''Load, Next List!''
Mon, 19 Dec 2022, 05:03
AndyH
Thanks for having a play.

Snake games from back in the day, and I guess many other types of games from the 80's in particular, can often suffer from their controls. Feeling unresponsive or unfair.

I first started looking into making the best of the controls after my first vic 20 game Nibbler was released. It was also a snake game and did initially have some annoyances. One was a bug, but the other was the perception of changing direction and the timing of doing this. The games are (or can be) very fast, so you want it to respond as you think it will.


I have found a method that works for me which I thought worth sharing if any help to us lot here on SoCoder. I'm thinking about writing this up in a bit more detail as a devlog on itch.io later, but for now here's the solution I settled on.



About the problem

The way a lot of old 8-bit games work is tied to the screen refresh cycle of 50 or 60 frame per second (TV Hz - frequency). If you try to modify RAM used to dictate what is on the screen while the TV is refreshing (going from top left to bottom right, one row at a time, very fast) you can end up with annoying flicker, or worst, stuff just not appearing. To get a good stable display you have to make sure you only change things on the screen (RAM) when the TV beam is not in the area you are updating. The vertical blank, or even where te bottom border starts on the Vic, are good places to do this but you can also implement "chasing the beam" techniques too.

In Snake Games are the Best Games, updating the snake, checkiong collisions, getting keyboard or joystick input takes very few cycles. Most of the time it is waiting for the next vertical blank. Then on top of this I have a counter to slow down the movement of the snake. If I moved the snake every screen refresh, that would be moving 50 or 60 times in a second and impossible to react to and control, so instead I use a counter to move the snake every 'n' screen refreshes.

So on harder levels the snake might move every fourth refresh which is still super fast, or on easy every sixteenth refresh. So there is quite a delay, still in milliseconds, between the user pressing a key or pushing the joystick to change direction. This input might happen at any time, it will most often happen while the program is waiting for the next move cycle. The longer the wait between move cycles, the more unresponsive it feels. Easy levels being the worst for this, you're waiting up to a 1/5 of a second.


Possible solutions

There are more methods, but lets just look at three. The first is the most basic, second what I used in Nibbler and the third what I have gone with in this game.


Basic

At the most basic, yout snake code does the following:

1. Wait for the Vertical Blank.
2. Get key or joystick input
3. Move the snake and handle the collisions

When the game is in easy mode, step 2 and 3 would occur less frequently, let's say every 15th or 16th screen refresh. Without buffering, the current state of the key or joystick is read at that time only and responded to. The player could have pressed and released UP (for example) between the last read and this read and thus, because the key/joystick is released the snake does not go up. The controls are unresponsive.

Other issues that can come up is over compensating and holding UP for too long. Maybe you need to go UP and then RIGHT immediately after to get the food and avoid a mushroom? Holding UP for too long you make the RIGHT movement too late and BANG, mushroom pie!

If you play a lot of (bad) snake games, this is what you might find.


Nibbler

On Nibbler I ended up with a buffered or cached input. This worked well for the nature of the screen which was a maze. I would not wait for the counter to expire before checking for the keyboard or joystick. I would instead constantly check while waiting for the next move cycle. If the user pushed a direction while waiting, I would record that and keep it for when the snake did move on its next cycle. The player could change their mind if fast enough, pressing UP and then RIGHT before the next move cycle would action the RIGHT input. For the maze this works well because your freedom of movment is restricted by the walls and essentially you have more time by design to navigate around right bends and junctions.


Snake Games are the Best Games

In the latest game where you have an open playfield, the Nibbler method worked but was frustrating. You have free movement and need more precise control of the snake.

Take the following example:



Here the snake is the --->, M a mushroom that kills you and F the food.

You are about to collide with a mushroom. To avoid it you want to push UP to move up, then RIGHT to avoid the mushroom above and instead collect the food.

The Nibbler approach makes it harder to to get the quick succession of UP and then RIGHT, sometimes only registering the RIGHT input. The basic approach can sometimes work better but still the same problem and missing a change of direction because you overcompensate or just get the timing wrong.

The solution I finalised on was to use the move cycle counter as a kind of heart beat.

If you pushed UP, it would respond right away and immediately move you up, still constrained to the VBL though, which is faster than you can press & release a direction.

Then when you pressed RIGHT, it would again respond right away and move you right, avoiding the mushroom and getting the food. Not key/joystick movements missed.

Left like this, the game speeds up and I often found I got disorientated, leading to making mistakes most of the time as my brain could not process everything at this speed, even though it was temporary, it would occur frequently as you make lots of changes to your snakes direction. The answer was the heart beat.

Moving immediately is like missing a beat.

The simple solution was to keep the heart beat of the game roughly the same, despite the instant changes of direction. I incremented another counter with the time that would have remained after changing direction and use this to adjust the next move cycle (a bit like delta timing, but not quite). I placed an upper limit on this value, otherwise with many key presses/joystick movements it would have an unnatural pause to catch up. But with the limit, the heart beat or pace of the game is controlled and you are able to process what you are seeing on the screen.

If you play the game now you might be able to spot that happening but otherwise, without knowing about it it doesn't stand out. The controls respond to every turn and the game moves roughly at the pace you expect it to.


Summary

In modern games you can get around a lot of these issues using delta timing. You could use that on old 8 bit games too, but having less flexibility with the display refresh timings, you will end up compromising on how good the display looks to how well a small 2D game character responds and moves.

Hope this is useful to someone, or at least interesting to read my approach to solving this problem.

Have you come up against a problem like this? How did you resolve it?

-=-=-
Andy H
8-bit games at www.hewco.uk
Cartoons at awful.ovine.net
Ovine at ovine.net
Tue, 20 Dec 2022, 19:06
Kuron
Thank you Andy. Saved for future reference!
Tue, 20 Dec 2022, 19:27
steve_ancell
I'm usually OK with coding Snake type games but not sure if I could do it on a Vic 20.
Nice effort Andy.
Tue, 20 Dec 2022, 19:37
steve_ancell
This was my attempt about 4 years ago, a very much unfinished AppGameKit project.


View on YouTube
Tue, 20 Dec 2022, 19:43
steve_ancell
@AndyH
Seeing your project has given me the urge to finish mine.
Tue, 20 Dec 2022, 19:47
Kuron
Steve: How did you like AppGameKit?
Tue, 20 Dec 2022, 20:49
steve_ancell
It's easy enough to learn and does what I need it to.
Wed, 21 Dec 2022, 05:30
AndyH
Steve, that looks great, love how the worm moves. You should definitely finish it.

I have agk too. Its pretty good generally.

-=-=-
Andy H
8-bit games at www.hewco.uk
Cartoons at awful.ovine.net
Ovine at ovine.net