Rear Gunner XL – Part 6 – SLOW DOWN!!!!

So, have you played it yet?  Yep, it’s complete impossible to control, and there are bugs!  I’m going to cover all the ones I’ve found now, but not initially give you any code to fix them – try to fix them yourself first…

It’s a bit quick eh?!  This is a very graphic demonstration of the difference between BASIC and machine code.  In BASIC if you press a key to move the player it does so after roughly half a second or so?  In machine code, you can move multiple places in that same space of time – so much so that your first attempt at moving is likely to fling the sights completely off the edge of the screen!

To resolve this we need to slow the game down a bit, and add a delay into the main game loop.  We wrote a function for line 5 to pause for a second, and so can use that same method before we start drawing at line 50, or before we jump back at line 140, to slow things down a bit.  A second is probably too long though – perhaps try a five-frame delay at first?

We already fix one bug with the code where it wasn’t correctly checking to see if the player was aligned with the enemy, but actually there’s another to do with that.  The two positions are compared exactly – that’s good – but if you try to place the player exactly where the enemy is, it’s actually shown as being one place to the right, as the enemy graphic is shown at column C, but the player’s ‘+’ graphic is actually shown at column B+1.  So there’s another little bug to be fixed – either by drawing the enemy graphic one column across (C+1) or draw all three rows of the player graphic one column back – so the two are aligned once more.

Converting the game to machine code has introduced two problems.  Firstly, the BASIC ‘RUN’ command at line 200 would clear the screen as it restarted the code.  Our game doesn’t do that however, but should.  We can either do that at that start of the game – line 5 – or before we jump back to it at the end.  We’ll need to fill at 32 columns in all 24 rows with space characters.

The second problem with the machine code, although it was also partially a problem with the BASIC version as well, is that the player can move the sights off-screen.  In BASIC that’s not a problem – it will validate and check everything during the PRINT command – but we don’t do any of that, so when the sight is off-screen it’ll actually still be drawing, but to other areas in memory, and so if you move it around enough you’ll eventually corrupt either the game code, or something in the system variables or display memory which causes a crash.  There are two solutions to this – either prevent any of our printing from being off-screen – i.e. restrict the movement of the player  to the screen – or write a nice print routine to handle the issue.  In a game like this you probably want to keep the sights visible all the time, so clamping could be the best solution, but remember that the player’s sight graphic is surrounded by 8 spaces, and so would have to be stopped from ever reaching the first or last row or column.

Another problem with the BASIC version is that the enemy is drawn, and then the sights with those 8 spaces around it.  The spaces are there to remove the ‘old’ sight graphic as you move.  It’s a lazy method, but it works.  It does mean however that if you are one space away from the enemy then it is removed from the screen by one of those spaces – making things a little more difficult. The quick solution to this is to draw the enemy after the sights.  The better solution is to never draw all those spaces around the sights, and remember to replace the sight with a space before you move in any direction, so erasing the graphic at the previous position.

 

After all that, you actually have the groundings for quite a fun little game.  Add a menu to the start, a HUD to show a score or lives, have the enemy change position every five seconds or so instead being still, have multiple enemies attacking at once….

Advertisements

5 thoughts on “Rear Gunner XL – Part 6 – SLOW DOWN!!!!

  1. I noticed another bug in the BASIC program. both C and D can take the value 0 (since RND can generates 0). In that case, there will be an error on line after the player hits 0 and the program tries to print the blowing of the target. For that reason, both the gunsight and the target should stay within the range (1,30) for the column, and (1,20) for the raw.
    In BASIC, I suggest the following for B and C:
    LET B = 1 + INT (RND*29)
    LET C = 1 + INT (RND*19)

    Like

  2. I now have an improved version of the game in assembly, including score and lives. One last thing i struggle with is the display of a number on the screen (indeed, to disply the score and the lives). If the value is between 0 and 9, this is quite easy, I add 28 to the value to get the character value, and display. But if the number if two or more digits, I have an issue. I have seen a routine to display floating numbers in the ROM, but there might be an easier hand-made solution for 16 bits integers. Any advice?

    Like

    1. There’s two methods for that – one to display the value in a 8 or 16-bit register, and another to use a different way to store values which make it easier to print. I’ll try and put together a blog post on them shortly…

      Liked by 1 person

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s