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 » Wed May 30, 2018 11:41 pm

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).
0 x

User avatar
djnzx48
Manic Miner
Posts: 553
Joined: Wed Dec 06, 2017 2:13 am
Location: New Zealand

Re: Snake code in need of improvement

Post by djnzx48 » Wed May 30, 2018 11:47 pm

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.
0 x

User avatar
djnzx48
Manic Miner
Posts: 553
Joined: Wed Dec 06, 2017 2:13 am
Location: New Zealand

Re: Snake code in need of improvement

Post by djnzx48 » Thu May 31, 2018 5: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.
0 x

hikoki
Manic Miner
Posts: 400
Joined: Thu Nov 16, 2017 10:54 am

Re: Snake code in need of improvement

Post by hikoki » Thu May 31, 2018 10:32 am

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
0 x

MrPixel
Microbot
Posts: 170
Joined: Sat Mar 24, 2018 7:42 pm

Re: Snake code in need of improvement

Post by MrPixel » Fri Jun 08, 2018 5:24 pm

djnzx48 wrote:
Thu May 31, 2018 5: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.
0 x

User avatar
ZXDunny
Manic Miner
Posts: 241
Joined: Tue Nov 14, 2017 3:45 pm

Re: Snake code in need of improvement

Post by ZXDunny » Fri Jun 08, 2018 5:56 pm

I did one a while ago, uses attributes:

Image

It's not too easy to follow the code, mind.
0 x

hikoki
Manic Miner
Posts: 400
Joined: Thu Nov 16, 2017 10:54 am

Re: Snake code in need of improvement

Post by hikoki » Fri Jun 08, 2018 6:21 pm

MrPixel, you can open those tap/tzx files provided by djnzx48 with BasinC to edit their Basic listings
0 x

Dr beep
Berk
Posts: 2
Joined: Mon Oct 01, 2018 7:53 pm

Re: Snake code in need of improvement

Post by Dr beep » Mon Oct 01, 2018 8:01 pm

0 x

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

Re: Snake code in need of improvement

Post by Gazzapper » Sun Jan 13, 2019 1:27 pm

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

Post Reply