Taking a look at your code, I have a few questions for you:
1) Why make keystate so hard to comprehend, when what it's doing is really very simple:
keystate(k) = 1 'keystate(k) = -((k AND 128) = 0)
The code you're using is running the formula from 0 to 255, and placing the value of 1 in the first 128 elements of the array (0 to 127), and then placing 0 in the next 128 elements. It works, but it's some of the best code obfuscation I've seen in ages. You can see how much simpler, and easier to read and understand, the changes I'd make are, above.
2) Same question with the DATA array. Why read it as a single line for "B", "X", "V" and such, and then have to break it down with MID$ to get the numeric values you want from that data -- after running it through a value conversion routine?
Isn't it much simpler to just change the DATA so that it represents what you're actually using?
DATA "±±±±±±±±±±±±±±±±±±±±" DATA "±°°°±±°°° OO ±°OOO°±" DATA "±°±±±°°O° °° ±°°°°°±" DATA "±°O°O°±±±±±±± °°°Û" DATA "±O°°°°±±± ±OO± O°°±" DATA "±°°°°°°°± ±O± °OO±" DATA "±°°O°O°°± ±±O±± °°°±" DATA "±°O°O°O°± °°°°° °O°±" DATA "±±±±±±±±±±Û±±±±±±±±±"
Note that the above doesn't display all pretty for me here on the forums, but it works just fine in QB64's IDE which supports the extended ASCII characters.
Also note, with the above, all we need to read that DATA and use it is the following little routine:
readlev:
IF b
= 1 THEN mx%
= j: my%
= i
screenmem%(j, i) = b
Doesn't that seem a wee bit simpler?
Or, even better, I prefer to break the DATA down to the ASC values and store them independent as the following:
DATA 177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177 DATA 177,79,79,4,177,234,32,32,32,32,32,32,32,177,79,4,79,4,79,177 DATA 177,176,176,176,177,177,176,176,176,32,79,79,32,177,176,79,79,79,176,177 DATA 177,176,177,177,177,176,176,79,176,32,176,176,32,177,176,176,176,176,176,177 DATA 177,176,176,176,176,176,79,176,79,32,32,32,32,32,32,32,176,79,176,177 DATA 177,176,79,176,79,176,177,4,177,1,177,177,177,177,177,32,176,176,176,219 DATA 177,79,176,176,176,176,177,177,177,32,177,79,4,79,177,32,79,176,176,177 DATA 177,176,176,176,176,176,176,176,177,32,177,4,79,4,177,32,176,79,79,177 DATA 177,176,176,79,176,79,176,176,177,32,177,177,79,177,177,32,176,176,176,177 DATA 177,176,79,176,79,176,79,176,177,32,176,176,176,176,176,32,176,79,176,177 DATA 177,176,79,4,176,4,79,176,177,32,32,32,235,32,32,32,176,79,4,177 DATA 177,177,177,177,177,177,177,177,177,177,219,177,177,177,177,177,177,177,177,177
And, with the DATA stored as we actually need it, all we have to do is the following to use it in our program:
readlev:
IF screenmem
(j
, i
) = 1 THEN mx%
= j: my%
= i
It doesn't get any simpler -- or faster -- than that! ;)
My overall changes to your last set of code that you shared would end up looking like the following:
DIM screenmem%
(22, 12), kbd
(255), keystate
(255)
'Why complicate the following with hard to understand math, when a much simpler method exists which is way easier to understand?
keystate(k) = 1 'keystate(k) = -((k AND 128) = 0)
score = 0
screenmem%(mx%, my%) = 1
k
= INP(&H60): kbd
(k
AND 127) = keystate
(k
) xv = kbd(77) - kbd(75)
yv = kbd(80) - kbd(72)
screenmem%(mx%, my%) = 32
IF xv
= -1 AND screenmem%
(mx%
- 1, my%
) = 32 THEN mx%
= mx%
- 1 IF xv
= 1 AND screenmem%
(mx%
+ 1, my%
) = 32 THEN mx%
= mx%
+ 1 IF yv
= -1 AND screenmem%
(mx%
, my%
- 1) = 32 THEN my%
= my%
- 1 IF yv
= 1 AND screenmem%
(mx%
, my%
+ 1) = 32 THEN my%
= my%
+ 1 IF xv
= -1 AND screenmem%
(mx%
- 1, my%
) = 176 THEN mx%
= mx%
- 1:
GOTO skp
IF xv
= 1 AND screenmem%
(mx%
+ 1, my%
) = 176 THEN mx%
= mx%
+ 1:
GOTO skp
IF yv
= -1 AND screenmem%
(mx%
, my%
- 1) = 176 THEN my%
= my%
- 1:
GOTO skp
IF yv
= 1 AND screenmem%
(mx%
, my%
+ 1) = 176 THEN my%
= my%
+ 1:
GOTO skp
IF xv
= -1 AND screenmem%
(mx%
- 1, my%
) = 79 AND screenmem%
(mx%
- 2, my%
) = 32 THEN screenmem%
(mx%
- 2, my%
) = 79: screenmem%
(mx%
- 1, my%
) = 32: mx%
= mx%
- 1 IF xv
= 1 AND screenmem%
(mx%
+ 1, my%
) = 79 AND screenmem%
(mx%
+ 2, my%
) = 32 THEN screenmem%
(mx%
+ 2, my%
) = 79: screenmem%
(mx%
+ 1, my%
) = 32: mx%
= mx%
+ 1 IF xv
= -1 AND screenmem%
(mx%
- 1, my%
) = 4 THEN mx%
= mx%
- 1: score
= score
+ 1 IF xv
= 1 AND screenmem%
(mx%
+ 1, my%
) = 4 THEN mx%
= mx%
+ 1: score
= score
+ 1 IF yv
= 1 AND screenmem%
(mx%
, my%
+ 1) = 4 THEN my%
= my%
+ 1: score
= score
+ 1 skp:
animate:
IF screenmem%
(i
, j
) = 79 AND screenmem%
(i
, j
+ 1) = 32 THEN screenmem%
(i
, j
) = 32: screenmem%
(i
, j
+ 1) = 79 IF screenmem%
(i
, j
) = 4 AND screenmem%
(i
, j
+ 1) = 32 THEN screenmem%
(i
, j
) = 32: screenmem%
(i
, j
+ 1) = 4
displaymap:
b = screenmem%(j, i)
readlev:
IF screenmem
(j
, i
) = 1 THEN mx%
= j: my%
= i
DATA 177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177 DATA 177,79,79,4,177,234,32,32,32,32,32,32,32,177,79,4,79,4,79,177 DATA 177,176,176,176,177,177,176,176,176,32,79,79,32,177,176,79,79,79,176,177 DATA 177,176,177,177,177,176,176,79,176,32,176,176,32,177,176,176,176,176,176,177 DATA 177,176,176,176,176,176,79,176,79,32,32,32,32,32,32,32,176,79,176,177 DATA 177,176,79,176,79,176,177,4,177,1,177,177,177,177,177,32,176,176,176,219 DATA 177,79,176,176,176,176,177,177,177,32,177,79,4,79,177,32,79,176,176,177 DATA 177,176,176,176,176,176,176,176,177,32,177,4,79,4,177,32,176,79,79,177 DATA 177,176,176,79,176,79,176,176,177,32,177,177,79,177,177,32,176,176,176,177 DATA 177,176,79,176,79,176,79,176,177,32,176,176,176,176,176,32,176,79,176,177 DATA 177,176,79,4,176,4,79,176,177,32,32,32,235,32,32,32,176,79,4,177 DATA 177,177,177,177,177,177,177,177,177,177,219,177,177,177,177,177,177,177,177,177
'The above DATA statements correspond directly to the ASCII values of each spot on the grid below
'DATA "±±±±±±±±±±±±±±±±±±±±"
'DATA "±OO±ê ±OOO±"
'DATA "±°°°±±°°° OO ±°OOO°±"
'DATA "±°±±±°°O° °° ±°°°°°±"
'DATA "±°°°°°O°O °O°±"
'DATA "±°O°O°±±±±±±± °°°Û"
'DATA "±O°°°°±±± ±OO± O°°±"
'DATA "±°°°°°°°± ±O± °OO±"
'DATA "±°°O°O°°± ±±O±± °°°±"
'DATA "±°O°O°O°± °°°°° °O°±"
'DATA "±°O°O°± ë °O±"
'DATA "±±±±±±±±±±Û±±±±±±±±±"