Snake code in need of improvement

The place for codemasters or beginners to talk about programming any language for the Spectrum.
Post Reply
MrPixel
Microbot
Posts: 170
Joined: Sat Mar 24, 2018 7:42 pm

Snake code in need of improvement

Post by MrPixel »

Image

all i ask is that this code be put to good use. i saw the entry for the crap games competition, and i got an idea, why not make the game for the +3 instead. could be fun. i already mapped out the INKEY$ input (WASD but also want to do arrow keys). i'm thinking of a summer theme).
User avatar
djnzx48
Manic Miner
Posts: 729
Joined: Wed Dec 06, 2017 2:13 am
Location: New Zealand

Re: Snake code in need of improvement

Post by djnzx48 »

I've got a Snake game in BASIC that I made a few years ago as a prototype for a scrapped machine code version, so you could have a look at that. I can't post it right now but I'll do it when I get home.
User avatar
djnzx48
Manic Miner
Posts: 729
Joined: Wed Dec 06, 2017 2:13 am
Location: New Zealand

Re: Snake code in need of improvement

Post by djnzx48 »

So here's a basic prototype. It uses QAOP but could easily be modified to use WASD. One thing to note is that it uses a string array rather than a number array to store the position of the snake segments; this is to save memory as a number uses 5 bytes but a letter only uses a single byte. It also starts the array off small and expands it as you grow, but it would have been easier and better to keep the array at a constant maximum size, as this would eliminate the slowdown whenever you eat food.

If you want to try something simpler, you could do a game where the snake constantly leaves a trail behind and the aim is to stay alive for as long as possible without hitting anything, like Track Trap for example. If you go this route you don't need to bother about arrays or needing to erase the tail.
hikoki
Manic Miner
Posts: 576
Joined: Thu Nov 16, 2017 10:54 am

Re: Snake code in need of improvement

Post by hikoki »

Could it Track Trap be converted into a Miami Vice Boat Race?
Walls would form a river circuit instead, there would be more than two boats..
maybe the circuit lane would be formed by two immortal boats which run in parallel

or maybe do both at once, a race of tron-snakes.. a few snakes which grow when eating apples, there would be a number of numbered apples, apples get eatable as they are eaten in ascending order, snakes are slowed down instead of dying when crashing into each other, apple number 1 gets eatable again whenever the last number has been eaten to start a new lap
MrPixel
Microbot
Posts: 170
Joined: Sat Mar 24, 2018 7:42 pm

Re: Snake code in need of improvement

Post by MrPixel »

djnzx48 wrote: Thu May 31, 2018 6:37 am So here's a basic prototype. It uses QAOP but could easily be modified to use WASD. One thing to note is that it uses a string array rather than a number array to store the position of the snake segments; this is to save memory as a number uses 5 bytes but a letter only uses a single byte. It also starts the array off small and expands it as you grow, but it would have been easier and better to keep the array at a constant maximum size, as this would eliminate the slowdown whenever you eat food.

If you want to try something simpler, you could do a game where the snake constantly leaves a trail behind and the aim is to stay alive for as long as possible without hitting anything, like Track Trap for example. If you go this route you don't need to bother about arrays or needing to erase the tail.
there is no way in hell i am modifying that. now, if it was a machine code program, maybe i would be able to.
User avatar
ZXDunny
Manic Miner
Posts: 498
Joined: Tue Nov 14, 2017 3:45 pm

Re: Snake code in need of improvement

Post by ZXDunny »

I did one a while ago, uses attributes:

Image

It's not too easy to follow the code, mind.
hikoki
Manic Miner
Posts: 576
Joined: Thu Nov 16, 2017 10:54 am

Re: Snake code in need of improvement

Post by hikoki »

MrPixel, you can open those tap/tzx files provided by djnzx48 with BasinC to edit their Basic listings
Dr beep
Manic Miner
Posts: 375
Joined: Mon Oct 01, 2018 8:53 pm

Re: Snake code in need of improvement

Post by Dr beep »

Gazzapper
Drutt
Posts: 10
Joined: Fri Dec 21, 2018 7:45 pm

Re: Snake code in need of improvement

Post by Gazzapper »

You can use I attr to 'eat' the end of the tail following a direction - then when eating apples - skip the tail eating once.
:)
Post Reply