Jump to content
IGNORED

Thoughts on improving this code?


SIO2

Recommended Posts

This is a routine from Frogus (a Frogger type game) that I am working on (in 7800 basic).

 

There are five lanes of traffic with up to three cars in each lane. Within each lane there are seven slots where a car could potentially be placed.

 

This routine randomly places cars into the slots in each lane.  It works but is rather long.  I am interested to know if anyone has ideas that might make it more compact?

 

 

build_cars.txt

Link to comment
Share on other sites

The biggest improvement I can see is in how you're reducing your random values to the range of 1-7.

Instead of running through each of those checks you can store your random value to a temp variable, then use a bitwise AND of 7 to cut it down to a range of 0-7, and then check that if it's zero you can try randomising it again or set it to something specific. Once that's done, store it back to your array and then move on to the next one.

 

Doing the above then let's you easily loop through all of your lanes by incrementing which index in the array you're storing to when you get a valid random value.

 

Thirdly, I'm not sure how good 7800basic is at 'remembering' which array entry you're working with, so essentially every time you mention an array entry it has to reload memory. You can avoid that by reading the array once into a temp variable and working with that.

 

Lastly, this is the sort of thing that assembly would be really good at optimising if you want to give it a go.

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...