2020-05-24
I’ve managed to solve a number picking algorithm that I’m happy with the performance of in NextBASIC. It’s a Fisher Yates sort, then picking the first 4 items (actually I cut the sort at the fourth iteration).
#autoline 10,10
%N=20: ; select from 0-20 (excluding 20)
%P=4: ; pick 4 numbers
; init the 0-N array
REPEAT
%S(i)=%i
%i=%i+1
REPEAT UNTIL %i=N
REPEAT
%T=% RND i
%W(N-i)=%S(T)
%i=%i-1
%S(T)=%S(i)
REPEAT UNTIL %i=(N-P)
; the picked results are stored in W
Now I need to check this array when the tomb is surrounded. I could check the whole of this array each time the tomb is surrounded, but it makes more sense to add which are the “winning” tombs to the tomb array(20) I already have.
The tomb array itself holds it’s state in bit values. As such, the current line of code for marking one side of a tomb as “completed” looks like this (horribly):
IF %k THEN %T[g]=%T[g]&@11111101:%T[h]=%T[h]&@11110111: ; new line for readability
ELSE %T[g]=%T[g]&@11111011:%T[h]=%T[h]&@11111110
The low nibble represent the side of the tomb that has been completed, and the high nibble for whether the tomb has been unlocked already:
0x01=top
0x02=right
0x04=bottom
0x08=left
0xF0=tomb has been unlocked
So the IF
statement from earlier is always run and always applies the logical &
but this is to create consistent timings. Normally, in modern coding, I’d avoid unnecessary code execution, but with NextBASIC to get the game to run at a consistent speed, I’m making sure that each loop does roughly the same amount of work.
Thus far I’m only using 8 bits of the value to indicate the status of the tomb and I need to be able to flag the tomb to say what’s contained inside of it, either a scroll, a mummy, a key, a tomb or nothing at all. I could keep all this data inside a single byte, but the integers in NextBASIC as 16bit so I could also expand out to the high byte to store the value of the tomb.
Meh. I prefer to be efficient, so how about this:
0x00-0x04=tomb contents
0x08=tomb has been unlocked
0x10=top
0x20=right
0x40=bottom
0x80=left
This shifts around where the data is stored, but I put the wall status on the high nibble for simplicity, so that I can then do something like %T = %T + INT (key)
and set key = 3
somewhere as a constant (though in reality I’ll stick to integer expressions).
Originally published on Remy Sharp’s b:log
Get Go Mummy! (ZX Spectrum Next)
Go Mummy! (ZX Spectrum Next)
ZX Spectrum Next clone/reimagination/upgrade of Amsoft's Oh Mummy from the CPC 464
Status | Released |
Author | rem |
Genre | Survival |
Tags | nextbasic, Retro, specnext, spectrum-next, zx-next, zxnext, ZX Spectrum, zx-spectrum-next |
More posts
- Fin - 2020-08-25Aug 25, 2020
- 2020-08-09Aug 09, 2020
- 2020-07-28Jul 28, 2020
- 2020-07-20Jul 20, 2020
- 2020-07-07Jul 07, 2020
- 2020-06-25Jun 29, 2020
- 2020-06-15Jun 15, 2020
- 2020-06-07Jun 08, 2020
- 2020-06-03Jun 08, 2020
- 2020-06-01Jun 01, 2020
Leave a comment
Log in with itch.io to leave a comment.