Snake revisit.

General games-related topics
Post Reply
Whitey
Posts: 22
Joined: Sat Jan 21, 2023 10:28 pm

Snake revisit.

Post by Whitey »

So it's been an interesting journey to this point. My new to me physical zx81 needs an adjustment to the composite video mod as it's currently showing both a grey rather than white screen and the text is distorted so I'm still on the emulator currently whilst I wait on a new composite video mod board.

After 40 years away I'm rediscovering sinclair basic but have also found mcoder2 which is a game changer albeit with it's idiosyncrasies around random number generation!
I never understood machine code as a kid and that is a project for later.

My initial project has been a snake style clone written in basic adapted for and then compiled with mcoder 2
This is week one.
Currently produces a game play area, moving snake, four direction control, both snake and walls have crash detection. Each move increase the score and every 50 points the snake grows by two segments.
Hopefully the youtube link works

Next will be random placed food item to grow the snake by one segments and 'hazard' mushrooms to avoid.
If I can get that far then I'll 'pretty it up'πŸ˜‚

https://youtu.be/HYnEcKUBkPM
dr beep
Posts: 2060
Joined: Thu Jun 16, 2011 8:35 am
Location: Boxmeer

Re: Snake revisit.

Post by dr beep »

Hello,

my suggestion after 40 years:

Skip MCODER2 and start machinecode. Your code will not only be shorter, but it will be faster as well.

If you think it is too hard, start simple.
Make it BASIC first and then convert it step by step into machinecode.

Enough knowledge here to help you out when you get stuck.
Whitey
Posts: 22
Joined: Sat Jan 21, 2023 10:28 pm

Re: Snake revisit.

Post by Whitey »

Thanks for the advice. It's certainly something I'd like to learn. I was very Concious that other than messing around with an arduino and c++ a couple of years ago I hadn't done any programming since I was a kid so baby steps are going to be needed. πŸ€¦β€β™‚οΈπŸ˜‚
Whitey
Posts: 22
Joined: Sat Jan 21, 2023 10:28 pm

Re: Snake revisit.

Post by Whitey »

Thanks to the help with mcoder2 random number generation my snake clone now sports poisonous mushrooms that kill you on contact and sporadically increase in number and food to make your tail grow.
it's far from pretty or efficient programming but it's mine and the first one I've produced in fourty years πŸ˜‚

https://youtu.be/wbb29PZ3EDc
User avatar
mrtinb
Posts: 1906
Joined: Fri Nov 06, 2015 5:44 pm
Location: Denmark
Contact:

Re: Snake revisit.

Post by mrtinb »

dr beep wrote: ↑Sun Feb 05, 2023 5:01 pm Skip MCODER2 and start machinecode. Your code will not only be shorter, but it will be faster as well.

If you think it is too hard, start simple.
Make it BASIC first and then convert it step by step into machinecode.
Another approach is to make small sub-routines in machine code. The idea is to break down the problem, and test the small routines, before they are combined with the rest of the code. Then combine the program with

Code: Select all

CALL subrutine1
CALL subrutine2
CALL subrutine3
If you then need to add an IF-statement to your code, it could be

Code: Select all

CALL subrutine4
CALL testConditionForIFandSetZflag
CALL Z subrutineIFflagZisSet
CALL subrutine7
A good idea is also to have a subrutine, that displays the current status of registers and program counter, and stack pointer - without modifying them.

Then you can add

Code: Select all

CALL showregisters
multiple times in your code, when you are trying to find an error.
Martin
https://zx.rtin.be
ZX81, Lambda 8300, Commodore 64, Mac G4 Cube
dr beep
Posts: 2060
Joined: Thu Jun 16, 2011 8:35 am
Location: Boxmeer

Re: Snake revisit.

Post by dr beep »

mrtinb wrote: ↑Wed Feb 08, 2023 8:22 pm
A good idea is also to have a subrutine, that displays the current status of registers and program counter, and stack pointer - without modifying them.

Then you can add

Code: Select all

CALL showregisters
multiple times in your code, when you are trying to find an error.
Even easier is setting a breakpoint in EughtyOne and do step execution.
It will give all the info Mrtinnb mentioned.
Whitey
Posts: 22
Joined: Sat Jan 21, 2023 10:28 pm

Re: Snake revisit.

Post by Whitey »

Thanks guys. I'm definitely going to look to progress the machine code thing.
Now that I know I can sort of remember how to program in basic I figure I'll probably look to try the machine code subroutine thing first.
I may use snake as my test bed or I might try some thing a bit simpler to start with.

I've got a small bouncing ball thing I wrote to test out using mcoder a couple of weeks back that might make a useful test project.
Whitey
Posts: 22
Joined: Sat Jan 21, 2023 10:28 pm

Re: Snake revisit.

Post by Whitey »

Whilst waiting for my interface parts to arrive i spent a bit of time on this.

Dr Beep will be horrified that it's compiled with mcoder 2 but I'm still at the point of crashing my machine just trying to print simple characters on the screen in machine code πŸ™„πŸ˜‚
D7CFD77E-FFD1-43FA-96AA-A9E98AF1EDEB.jpeg
The video of it running is here
https://youtu.be/Sk3UDBQXuio

Even compiled from basic it needs significantly slowing down to be playable.
I'm looking forward to being able to code this sort of thing myself without the need of a compiler.
salvacam
Posts: 50
Joined: Wed Jul 21, 2021 4:50 pm

Re: Snake revisit.

Post by salvacam »

I just saw this contest, in case you are interested in presenting the game
https://itch.io/jam/retro-snake-game-jam
My games

ZX81 hoy Blog (in Spanish) of new games and applications for the ZX81
JohnsBargs
Posts: 169
Joined: Fri Oct 19, 2018 2:22 am

Re: Snake revisit.

Post by JohnsBargs »

Whitey wrote: ↑Mon Feb 27, 2023 5:15 pm Whilst waiting for my interface parts to arrive i spent a bit of time on this.

Dr Beep will be horrified that it's compiled with mcoder 2 but I'm still at the point of crashing my machine just trying to print simple characters on the screen in machine code πŸ™„πŸ˜‚
D7CFD77E-FFD1-43FA-96AA-A9E98AF1EDEB.jpeg

The video of it running is here
https://youtu.be/Sk3UDBQXuio

Even compiled from basic it needs significantly slowing down to be playable.
I'm looking forward to being able to code this sort of thing myself without the need of a compiler.

I love the look of this! Any news on it?
Post Reply