Race games - how is it done?

The place for codemasters or beginners to talk about programming any language for the Spectrum.
Post Reply
User avatar
R-Tape
Site Admin
Posts: 6353
Joined: Thu Nov 09, 2017 11:46 am

Race games - how is it done?

Post by R-Tape »

What are the principles of the winding road in games like Enduro Racer and Chevy Chase? I'm not after code examples but the principle of how the road is stored and moves.

Image

I'll have a look at the code for 4KRace but I'm not sure I'll make headway without understanding the principle.
User avatar
ZXDunny
Manic Miner
Posts: 498
Joined: Tue Nov 14, 2017 3:45 pm

Re: Race games - how is it done?

Post by ZXDunny »

Everything you need to know is in this article:

http://www.extentofthejam.com/pseudo/
Ralf
Rick Dangerous
Posts: 2279
Joined: Mon Nov 13, 2017 11:59 am
Location: Poland

Re: Race games - how is it done?

Post by Ralf »

Thanks for the thread! It's an interesting topic for me too.

I did a little bit research once on it myself but not too much. And I think 4KRace is not a best thing to start with - a lot of crazy optimalisations and dirty programming tricks are probably in there.

Maybe start from this link. It's not directly Zx Spectrum related but tells quite a lot abouth algorithms. Reading it requires some effort though:

http://www.extentofthejam.com/pseudo/
Image
Ralf
Rick Dangerous
Posts: 2279
Joined: Mon Nov 13, 2017 11:59 am
Location: Poland

Re: Race games - how is it done?

Post by Ralf »

Oops, looks like Dunny was faster with the same link as mine ;)

This links seems good but the author mixes here basic and more advanced techniques. Would be good to see something really simple and working.
llewelyn
Manic Miner
Posts: 205
Joined: Thu Feb 22, 2018 3:27 pm
Location: virginias eastern shore
Contact:

Re: Race games - how is it done?

Post by llewelyn »

Fascinating! That article is beyond my comprehension math wise but the basic concept I can understand. What keeps me coming back to read posts like these is not because I kid myself I have the remotest chance of using any of it but because of the ways in which a problem can be approached.

This business about the distant pixels moving or scrolling slower then the foreground? I think the earliest and best example of that which made me smile at the cleverness of the solution was in 'Tir Na Nog' one of my all time favourite games though its long since been topped nine ways to Sunday.

Well worth taking the time to study Lou's very clearly explained examples. Highly recommended reading, thanks Dunny and Ralf and R-Tape for posing the question. I learned a lot from this.
User avatar
Rorthron
Dynamite Dan
Posts: 1644
Joined: Sun Nov 12, 2017 10:35 pm

Re: Race games - how is it done?

Post by Rorthron »

Actually, what was the first Spectrum game to use parallax scrolling? Moon Alert?
User avatar
Joefish
Rick Dangerous
Posts: 2041
Joined: Tue Nov 14, 2017 10:26 am

Re: Race games - how is it done?

Post by Joefish »

The thing is though, when you turn in real life, there is no parallax effect! It shouldn't be there. It's only when you move parallel to distant things that you get parallax!

The basic trick with the road is you start in the bottom-left corner and draw a line of road across to the bottom-right corner. You now move up a pixel, step in one pixel, and draw another line of road but two pixels shorter. So as you go up the road tapers. This is your basic road image.

Now for a turn, you shift rows of this image right or left. But you need to be able to count fractions.

You need two variables now - one is the offset position (how far to shift each row left/right), and another is the value you add to it as you go up each row. If you just keep adding a constant value, you can make the road slant left/right as a perspective view. But if you add a little to that added value each time, you get an x^2 curve shape.
llewelyn
Manic Miner
Posts: 205
Joined: Thu Feb 22, 2018 3:27 pm
Location: virginias eastern shore
Contact:

Re: Race games - how is it done?

Post by llewelyn »

Ralf wrote: Sun Jul 01, 2018 12:41 pm

This links seems good but the author mixes here basic and more advanced techniques. Would be good to see something really simple and working.
Whilst I agree with you from a would be programmers point of view, the important thing is the way or ways in which the same basic problem has been approached and I'm sure there are others!

For me it was a sort of 'lightbulb over the head' revelation as in "Oh! That's how they did it!" because once you've got the general idea you can code it - or attempt to code it (in my case!) - using whichever means seems best to you and according to your abilities.

In other words, what I'm trying to say is that in my opinion the value of the article mainly lies in its explanations of different approaches to the same problem.
spectron
Drutt
Posts: 25
Joined: Thu Mar 29, 2018 3:27 pm

Re: Race games - how is it done?

Post by spectron »

Ralf wrote: Sun Jul 01, 2018 10:21 am

Maybe start from this link. It's not directly Zx Spectrum related but tells quite a lot abouth algorithms. Reading it requires some effort though:

http://www.extentofthejam.com/pseudo/
Image
This is sort of how it was done for Gameboy road rash. That initially started life as an experiment messing with x and y scroll registers and the sudden realisation that on the GB you could display any line of VRAM at any physical screen position just by altering them on the hblank. That lead to an attempt to do stunt car racer for the Gameboy but that then morphed into Road Rash when Gary Bracey from Ocean saw the demo.

Overall though, the basic maths behind how wide the road was at any screen y position and what x position the centre of the road was on that line was more or less the same as in that article.

I still have the source code and looked at it recently but on first glance have absolutely no idea how it worked! :D
User avatar
Ersh
Manic Miner
Posts: 480
Joined: Mon Nov 13, 2017 1:06 pm

Re: Race games - how is it done?

Post by Ersh »

spectron wrote: Thu Jul 05, 2018 2:57 pm This is sort of how it was done for Gameboy road rash. That initially started life as an experiment messing with x and y scroll registers and the sudden realisation that on the GB you could display any line of VRAM at any physical screen position just by altering them on the hblank. That lead to an attempt to do stunt car racer for the Gameboy but that then morphed into Road Rash when Gary Bracey from Ocean saw the demo.
Yeah the Gameboy SCY register is pretty great, it's the backbone of lots of different effects. :)

The NES works in a similar manner but it lacks the different raster interrupts of the GB (outside the use of additional hardware like the MBC3). Rad Racer for the NES is pretty impressive-looking especially considering it only uses 'sprite zero hits' and not 'proper' raster interrupts.
Bizzley
Microbot
Posts: 124
Joined: Thu Nov 16, 2017 10:47 am

Re: Race games - how is it done?

Post by Bizzley »

spectron wrote: Thu Jul 05, 2018 2:57 pm This is sort of how it was done for Gameboy road rash.
I coded a similar thing for a Gameboy version of Formula 1 for Psygnosis that never progressed past the proof of concept stage. They wanted to see a working 3D road so I used the HBLANK method to slide individual lines into curves etc. I've got a compiled version on a development cart somewhere as well as the source code and it is a really quick and easy way to get an into-the-screen road up and running. To save on in-game processing time I pre-calculated a selection of straights, curves, chicanes etc. at varying degress and built a complete track out of those sections held in tables.

I told Psygnosis that if they wanted to see more details like dips, hills, trackside objects, other cars etc. then they'd have to pay actual money but it never got any further - for "political" reasons it didn't get a green light - but it was a fun thing to code up I remember.
"He made eloquent speeches to an audience consisting of a few depressed daffodil roots, and sometimes the cat from next door."
spectron
Drutt
Posts: 25
Joined: Thu Mar 29, 2018 3:27 pm

Re: Race games - how is it done?

Post by spectron »

Bizzley wrote: Thu Jul 05, 2018 5:29 pm
I told Psygnosis that if they wanted to see more details like dips, hills, trackside objects, other cars etc. then they'd have to pay actual money but it never got any further - for "political" reasons it didn't get a green light - but it was a fun thing to code up I remember.
It was indeed fun and hills were just a case of taking that extra step of altering VBLANK as well as HBLANK to give the impression of going up and down. It's the sort of thing most of us would have stumbled upon back then given the freedom of experimenting; luckily we were given that time to mess.
Ralf
Rick Dangerous
Posts: 2279
Joined: Mon Nov 13, 2017 11:59 am
Location: Poland

Re: Race games - how is it done?

Post by Ralf »

[mention]R-Tape[/mention] , did you made any progress with racing game engines? ;)
User avatar
Joefish
Rick Dangerous
Posts: 2041
Joined: Tue Nov 14, 2017 10:26 am

Re: Race games - how is it done?

Post by Joefish »

If you've ever seen Electraglide on an 8-bit Atari it looks absolutely stunning, with a colourful fast-running road leading to the horizon.
But really it's just a flat picture of a triangular road. The road moving is done by colour-swapping on alternate lines, and the curves are done by scroll-shifting individual pixel rows left and right. And that' all it can do. When objects appear you can see they're crude geometric shapes made of hugely upscaled sprite pixels; it's simply impossible to make it do a racing game with rival detailed vehicle graphics on the track with anything like that slick frame rate.

To do the same on the Spectrum means the hard graft and pre-shifted data to re-draw all the lines of the screen scrolled to different positions horizontally, and re-distributed vertically to make hills, but then you can draw it however you like and add whatever sprites you want. It would be neat to combine a racing game with a multicolour engine to do the roadside strips in colour, but it would take some very clever coding to use the processing time in the wait-periods productively.
User avatar
R-Tape
Site Admin
Posts: 6353
Joined: Thu Nov 09, 2017 11:46 am

Re: Race games - how is it done?

Post by R-Tape »

Ralf wrote: Tue Aug 07, 2018 11:05 am @R-Tape , did you made any progress with racing game engines? ;)
Not yet, I find this quite hard to understand but I just need to set a some time aside with a cold flannel on my head to think it through.

However, current priorities are a laptop free holiday and then finish Bean Brothers!
User avatar
Vampyre
Manic Miner
Posts: 833
Joined: Wed Nov 15, 2017 2:51 pm
Contact:

Re: Race games - how is it done?

Post by Vampyre »

Joefish wrote: Tue Aug 07, 2018 12:00 pm If you've ever seen Electraglide on an 8-bit Atari it looks absolutely stunning, with a colourful fast-running road leading to the horizon.
But really it's just a flat picture of a triangular road. The road moving is done by colour-swapping on alternate lines, and the curves are done by scroll-shifting individual pixel rows left and right. And that' all it can do. When objects appear you can see they're crude geometric shapes made of hugely upscaled sprite pixels; it's simply impossible to make it do a racing game with rival detailed vehicle graphics on the track with anything like that slick frame rate.

To do the same on the Spectrum means the hard graft and pre-shifted data to re-draw all the lines of the screen scrolled to different positions horizontally, and re-distributed vertically to make hills, but then you can draw it however you like and add whatever sprites you want. It would be neat to combine a racing game with a multicolour engine to do the roadside strips in colour, but it would take some very clever coding to use the processing time in the wait-periods productively.
I'd never heard of Electraglide before but just seen a vid on YT. That is superbly smooth for an 8-bit game.
ZX Spectrum Reviews REST API: http://zxspectrumreviews.co.uk/
Ralf
Rick Dangerous
Posts: 2279
Joined: Mon Nov 13, 2017 11:59 am
Location: Poland

Re: Race games - how is it done?

Post by Ralf »

I've just had a look on Electraglide too.

Yes, very smooth movement but ultimately boring. No other cars, no hills, very sparse scenery.

Now, Chase H.Q. on Spectrum on the other hand... ;)
Dr beep
Manic Miner
Posts: 375
Joined: Mon Oct 01, 2018 8:53 pm

Re: Race games - how is it done?

Post by Dr beep »

Here is a pseudo 3D racing game coded for the ZX81 in just 1K and a hires way.

https://m.youtube.com/watch?v=uSPMIidgA18

The game is based on the same track coded for the ZX Spectrum in Grandpr1x, also just 1K of code, but on the ZX Spectrum you have more memory available.
Post Reply