Need help - Strange tile problem

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

User avatar
Super Mario
Coder
Posts: 21
Joined: Mon Jul 21, 2008 8:34 am
Location: My computer

Need help - Strange tile problem

Post by Super Mario » Fri Jul 25, 2008 9:49 am

Hey guys. I can't seem to find the problem with this code. When I run the program, the map is fine. However, when I move, every tile becomes water. Through my own troubleshooting, I suspect it is reading the last piece of data in the map, which is water. Any tips or solutions?

Code: Select all

DIM grass(10, 10), path(10, 10), water(10, 10), tent(10, 10), scout(10, 10), scoutmask(10, 10)

SCREEN 13

scoutx = 5
scouty = 1

FOR y = 1 TO 10
FOR x = 1 TO 10
READ clr
IF clr = 1 THEN PSET (x, y), 10
IF clr = 0 THEN PSET (x, y), 2
NEXT
NEXT

GET (1, 1)-(10, 10), grass

FOR y = 1 TO 10
FOR x = 1 TO 10
READ clr
IF clr = 0 THEN PSET (x, y), 6
IF clr = 1 THEN PSET (x, y), 14
NEXT
NEXT

GET (1, 1)-(10, 10), path

FOR y = 1 TO 10
FOR x = 1 TO 10
READ clr
IF clr = 0 THEN PSET (x, y), 3
IF clr = 1 THEN PSET (x, y), 11
NEXT
NEXT

GET (1, 1)-(10, 10), water

FOR y = 1 TO 10
FOR x = 1 TO 10
READ clr
IF clr = 0 THEN PSET (x, y), 6
IF clr = 1 THEN PSET (x, y), 8
IF clr = 2 THEN PSET (x, y), 0
NEXT
NEXT

GET (1, 1)-(10, 10), tent

FOR y = 1 TO 10
FOR x = 1 TO 10
READ clr
IF clr = 0 THEN PSET (x, y), 0
IF clr = 1 THEN PSET (x, y), 2
IF clr = 2 THEN PSET (x, y), 8
IF clr = 3 THEN PSET (x, y), 14
IF clr = 4 THEN PSET (x, y), 4
NEXT
NEXT

GET (1, 1)-(10, 10), scout

FOR y = 1 TO 10
FOR x = 1 TO 10
READ clr
IF clr = 0 THEN PSET (x, y), 255
IF clr = 1 THEN PSET (x, y), 2
IF clr = 2 THEN PSET (x, y), 8
IF clr = 3 THEN PSET (x, y), 14
IF clr = 4 THEN PSET (x, y), 4
NEXT
NEXT

GET (1, 1)-(10, 10), scoutmask

CLS
FOR y = 1 TO 15
FOR x = 1 TO 30
READ tilenumber

IF tilenumber = 1 THEN PUT (x * 10, y * 10), grass, PSET
IF tilenumber = 2 THEN PUT (x * 10, y * 10), path, PSET
IF tilenumber = 3 THEN PUT (x * 10, y * 10), water, PSET
IF tilenumber = 4 THEN PUT (x * 10, y * 10), tent, PSET
                                           
NEXT
NEXT

PUT (scoutx * 10, scouty * 10), scoutmask, AND
PUT (scoutx * 10, scouty * 10), scout, OR

DO
p$ = INKEY$
oldscoutx = scoutx
oldscouty = scouty

IF p$ = CHR$(0) + CHR$(75) AND scoutx > 1 THEN scoutx = scoutx - 1

IF p$ = CHR$(0) + CHR$(77) AND scoutx < 20 THEN scoutx = scoutx + 1

IF p$ = CHR$(0) + CHR$(72) AND scouty > 1 THEN scouty = scouty - 1

IF p$ = CHR$(0) + CHR$(80) AND scouty < 14 THEN scouty = scouty + 1

IF oldscoutx <> scoutx OR oldscouty <> scouty THEN

FOR y = 1 TO 15
FOR x = 1 TO 30


IF tilenumber = 1 THEN PUT (x * 10, y * 10), grass, PSET
IF tilenumber = 2 THEN PUT (x * 10, y * 10), path, PSET
IF tilenumber = 3 THEN PUT (x * 10, y * 10), water, PSET
IF tilenumber = 4 THEN PUT (x * 10, y * 10), tent, PSET
                                          
NEXT
NEXT

PUT (scoutx * 10, scouty * 10), scoutmask, AND
PUT (scoutx * 10, scouty * 10), scout, OR

END IF
LOOP UNTIL p$ = CHR$(27)

grass:
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,1,0,0,0,0,0,0,0
DATA 0,0,0,0,0,1,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,1,0,0,0
DATA 0,1,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA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,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,3,3,3
DATA 1,1,1,1,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,3,3
DATA 1,1,1,1,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,3

END

My brother says I'm crazy. I personally don't see the problem with programming at the beach.

Ralph
Veteran
Posts: 148
Joined: Fri Feb 09, 2007 3:10 pm
Location: Katy, Texas

Post by Ralph » Fri Jul 25, 2008 4:40 pm

First of all, Super Mario, congratulations on a well-ordered program!

After running your program, I came to the conclusion that:
The last READ statement is on he "tilenumber" DATA block, and that last READ reads the 3 at the bottom-right of the tilenumber DATA statements. So, in your DO/LOOP, when you do the

Code: Select all

FOR y = 1 TO 15 
  FOR x = 1 TO 30 
    IF tilenumber = 1 THEN PUT (x * 10, y * 10), grass, PSET 
    IF tilenumber = 2 THEN PUT (x * 10, y * 10), path, PSE   T 
    IF tilenumber = 3 THEN PUT (x * 10, y * 10), water, PSET 
    IF tilenumber = 4 THEN PUT (x * 10, y * 10), tent, PSET 
  NEXT 
NEXT 
[\code]
the third IF is true, so, you get "water". And, since you do a complete coverage of the screen with your FOR Y = 1 TO 15 ans FORX = 1 TO 30, you will cover the whole screen with whatever number tilenimber has at this time.  So, you have to change the code here to whatever you want.  Also, you are going to have to, somehow, select a tielnumber that is not the leftover 3.
Ralph, with QuickBASIC 4.5, operating under Windows XP, wiht anHP LaserJet 4L Printer. Bilingual in English/Spanish

User avatar
Super Mario
Coder
Posts: 21
Joined: Mon Jul 21, 2008 8:34 am
Location: My computer

Post by Super Mario » Fri Jul 25, 2008 4:59 pm

Yeah Ralph, I came to that same conclusion. It's reading the "3" in the last DATA line of the map. That means that instead of reading the entire map DATA, it is just getting the last part. What is the proper way to go back to a desired place?
My brother says I'm crazy. I personally don't see the problem with programming at the beach.

Ralph
Veteran
Posts: 148
Joined: Fri Feb 09, 2007 3:10 pm
Location: Katy, Texas

Post by Ralph » Fri Jul 25, 2008 5:55 pm

To allow the next READ statement to read the first DATA statement in the tilenumber group, use RESTORE tilenumber. Is this what you mean?
Ralph, with QuickBASIC 4.5, operating under Windows XP, wiht anHP LaserJet 4L Printer. Bilingual in English/Spanish

User avatar
Mentat
Veteran
Posts: 409
Joined: Tue Aug 07, 2007 3:39 pm
Location: NC, US

Post by Mentat » Fri Jul 25, 2008 6:52 pm

What's the old scout for?
For any grievances posted above, I blame whoever is in charge . . .

User avatar
Super Mario
Coder
Posts: 21
Joined: Mon Jul 21, 2008 8:34 am
Location: My computer

Post by Super Mario » Fri Jul 25, 2008 9:04 pm

Mentat, I got most of my initial help from Vic's "RPG" Tutorial in the Game Design section of the tutorials. In the program, oldscout is where the sprites old values were, while scout is the current ones. I check if they changed with the "IF oldscoutx <> scoutx...". That way, the screen only redraws if the sprite moved.
My brother says I'm crazy. I personally don't see the problem with programming at the beach.

User avatar
Mentat
Veteran
Posts: 409
Joined: Tue Aug 07, 2007 3:39 pm
Location: NC, US

Post by Mentat » Fri Jul 25, 2008 9:12 pm

Oh, I think it's for optimization (no point in refreshing a static screen).

And for the water problem, I did a little fiddling, and the program was reading from the variable tileNumber (not the label), which didn't change because the last data statement is 3 (water). The program should read from the map (which needs to be loaded before being drawn).
For any grievances posted above, I blame whoever is in charge . . .

Ralph
Veteran
Posts: 148
Joined: Fri Feb 09, 2007 3:10 pm
Location: Katy, Texas

Post by Ralph » Fri Jul 25, 2008 9:26 pm

Now I understand! If you simply move a sprite, say the scout, you will either have the old scout AND the new one, or you will leave a hole where the old scout was. So, you should GET the area where first scout will be PUTed before it is PUTed, call it, say, OLDAREA. Then, when a move is detected, you will first PUT the OLDAREA where the scout is, currently, GET the new area where the scout is to be moved to as OLDAREA, and PUT the scout in the new location. This is the way to move any sprite in this sort of moving game. Got it?
Last edited by Ralph on Fri Jul 25, 2008 9:31 pm, edited 1 time in total.

User avatar
Super Mario
Coder
Posts: 21
Joined: Mon Jul 21, 2008 8:34 am
Location: My computer

Post by Super Mario » Fri Jul 25, 2008 9:30 pm

Okay! After messing around with the RESTORE command, I've finally gotten things to work! Now, when you move, you don't drown!

Code: Select all

DIM grass(10, 10), path(10, 10), water(10, 10), tent(10, 10), scout(10, 10), scoutmask(10, 10)

SCREEN 13

scoutx = 5
scouty = 1

FOR y = 1 TO 10
FOR x = 1 TO 10
READ clr
IF clr = 1 THEN PSET (x, y), 10
IF clr = 0 THEN PSET (x, y), 2
NEXT
NEXT

GET (1, 1)-(10, 10), grass

FOR y = 1 TO 10
FOR x = 1 TO 10
READ clr
IF clr = 0 THEN PSET (x, y), 6
IF clr = 1 THEN PSET (x, y), 14
NEXT
NEXT

GET (1, 1)-(10, 10), path

FOR y = 1 TO 10
FOR x = 1 TO 10
READ clr
IF clr = 0 THEN PSET (x, y), 3
IF clr = 1 THEN PSET (x, y), 11
NEXT
NEXT

GET (1, 1)-(10, 10), water

FOR y = 1 TO 10
FOR x = 1 TO 10
READ clr
IF clr = 0 THEN PSET (x, y), 6
IF clr = 1 THEN PSET (x, y), 8
IF clr = 2 THEN PSET (x, y), 0
NEXT
NEXT

GET (1, 1)-(10, 10), tent

FOR y = 1 TO 10
FOR x = 1 TO 10
READ clr
IF clr = 0 THEN PSET (x, y), 0
IF clr = 1 THEN PSET (x, y), 2
IF clr = 2 THEN PSET (x, y), 8
IF clr = 3 THEN PSET (x, y), 14
IF clr = 4 THEN PSET (x, y), 4
NEXT
NEXT

GET (1, 1)-(10, 10), scout

FOR y = 1 TO 10
FOR x = 1 TO 10
READ clr
IF clr = 0 THEN PSET (x, y), 255
IF clr = 1 THEN PSET (x, y), 2
IF clr = 2 THEN PSET (x, y), 8
IF clr = 3 THEN PSET (x, y), 14
IF clr = 4 THEN PSET (x, y), 4
NEXT
NEXT

GET (1, 1)-(10, 10), scoutmask

CLS
FOR y = 1 TO 15
FOR x = 1 TO 30
READ tilenumber

IF tilenumber = 1 THEN PUT (x * 10, y * 10), grass, PSET
IF tilenumber = 2 THEN PUT (x * 10, y * 10), path, PSET
IF tilenumber = 3 THEN PUT (x * 10, y * 10), water, PSET
IF tilenumber = 4 THEN PUT (x * 10, y * 10), tent, PSET
                                           
NEXT
NEXT

PUT (scoutx * 10, scouty * 10), scoutmask, AND
PUT (scoutx * 10, scouty * 10), scout, OR

DO
p$ = INKEY$
oldscoutx = scoutx
oldscouty = scouty

IF p$ = CHR$(0) + CHR$(75) AND scoutx > 1 THEN scoutx = scoutx - 1

IF p$ = CHR$(0) + CHR$(77) AND scoutx < 30 THEN scoutx = scoutx + 1

IF p$ = CHR$(0) + CHR$(72) AND scouty > 1 THEN scouty = scouty - 1

IF p$ = CHR$(0) + CHR$(80) AND scouty < 14 THEN scouty = scouty + 1

IF oldscoutx <> scoutx OR oldscouty <> scouty THEN

RESTORE tilenumber
FOR y = 1 TO 15
FOR x = 1 TO 30
READ tilenumber

IF tilenumber = 1 THEN PUT (x * 10, y * 10), grass, PSET
IF tilenumber = 2 THEN PUT (x * 10, y * 10), path, PSET
IF tilenumber = 3 THEN PUT (x * 10, y * 10), water, PSET
IF tilenumber = 4 THEN PUT (x * 10, y * 10), tent, PSET
                                          
NEXT
NEXT

PUT (scoutx * 10, scouty * 10), scoutmask, AND
PUT (scoutx * 10, scouty * 10), scout, OR

END IF
LOOP UNTIL p$ = CHR$(27)

grass:
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,1,0,0,0,0,0,0,0
DATA 0,0,0,0,0,1,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,1,0,0,0
DATA 0,1,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,1,0,0
DATA 0,0,0,0,0,0,0,0,0,0

path:
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,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,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,3

END
It turns out I have to RESTORE the data, then give the FOR x = ... part, then READ the data. Now I just have to make it so you can only walk on the pathway. ('Cause green on green doesn't work...)
My brother says I'm crazy. I personally don't see the problem with programming at the beach.

Ralph
Veteran
Posts: 148
Joined: Fri Feb 09, 2007 3:10 pm
Location: Katy, Texas

Post by Ralph » Fri Jul 25, 2008 9:34 pm

Read my post, just above yours! Then, report back if you are still experiencing problems. Note that you simply have to GET the area where the scout is to be moved to, as it is ALREADY drawn! You do NOT have to RESTORE anything!

Edited by Ralph:
OK, I ran your code as is, and, it does work! Congratulations, again!
I did make one, small change. For the limit on the y value, I changed your 14 to 15, to allow the scout to reach the bottom of the screen.

And, as far as the "green on green doesn't work", why don't you change the green (2) in your scout sprite DATA statements to, say, blue?
Ralph, with QuickBASIC 4.5, operating under Windows XP, wiht anHP LaserJet 4L Printer. Bilingual in English/Spanish

User avatar
Mentat
Veteran
Posts: 409
Joined: Tue Aug 07, 2007 3:39 pm
Location: NC, US

Post by Mentat » Sat Jul 26, 2008 6:10 am

Oh, so that's what the old scout is for. But if you're scrolling, you would still have to update the screen.

So what do you want to do next? Save and load tiles/sprites from files? It's not hard, pretty much like READ. Except that it doesn't fill your program like DATA.
For any grievances posted above, I blame whoever is in charge . . .

User avatar
Super Mario
Coder
Posts: 21
Joined: Mon Jul 21, 2008 8:34 am
Location: My computer

Post by Super Mario » Sat Jul 26, 2008 12:49 pm

Ralph, I may just change the colors. Now I just want it so the scout can't walk on water. Also, thanks for pointing out the error. I probably just a typo.

Mentat, do you mean storing all the tile data in an external file? That sounds like a good idea. How?
My brother says I'm crazy. I personally don't see the problem with programming at the beach.

Ralph
Veteran
Posts: 148
Joined: Fri Feb 09, 2007 3:10 pm
Location: Katy, Texas

Post by Ralph » Sat Jul 26, 2008 1:43 pm

Super Mario:
As far as the scout not being able to get to the water, one way would be to not allow any scoutx, scouty combination to land the scout in the water. Perhaps something like this:

Code: Select all

IF p$ = CHR$(0) + CHR$(77) AND scoutx = 29 AND scouty = 1 THEN scoutx = 29
That would work for the first row. Similar code would have to be added for each instance of scoutx and scouty that would land the scout in the water.
Hopefully, someone else knows more about boundries than I do, and can come up with a much simpler method than my suggested one.! :)
Ralph, with QuickBASIC 4.5, operating under Windows XP, wiht anHP LaserJet 4L Printer. Bilingual in English/Spanish

User avatar
Super Mario
Coder
Posts: 21
Joined: Mon Jul 21, 2008 8:34 am
Location: My computer

Post by Super Mario » Sat Jul 26, 2008 1:59 pm

Yeah, I considered that method, but it seemed a bit inefficient. I think a better method would be to check if the new tile will be water, then either move or don't move the scout.
My brother says I'm crazy. I personally don't see the problem with programming at the beach.

User avatar
Mentat
Veteran
Posts: 409
Joined: Tue Aug 07, 2007 3:39 pm
Location: NC, US

Post by Mentat » Sat Jul 26, 2008 2:28 pm

Boundaries are simple. This is when the map comes into play: Look up the array for where you want to go, and if it's a permissive tile (path, land, etc.), then move otherwise don't.

And file i/o is, well, simple for simple stuff.

Like this:

Code: Select all

input "Enter file: ", fileName$

open fileName$ for input as #1

input #1, someVar$

print someVar

close #1
end
It's sort of like using data statements. But you can also write to files too.

Like this:

Code: Select all

open "someFile.txt" for output as #3

print #3, "Hello world!"

close #3
end
Note:
With output, it overwrites the file if it exists, or makes a new one if it doesn't. With input, it raises an error if the file exists, otherwise it'll just take input. With append, it'll add to a file if it exists, otherwise it'll make one.

It may be a lot to swallow when starting with file i/o, but just think of it as reading from data statements.
For any grievances posted above, I blame whoever is in charge . . .

Ralph
Veteran
Posts: 148
Joined: Fri Feb 09, 2007 3:10 pm
Location: Katy, Texas

Post by Ralph » Sat Jul 26, 2008 2:36 pm

Super Mario:
OK, I agree. To check if the new location will be water, I would create a new array

Code: Select all

DIM tilenumber(30,15)
I would then load it, using

Code: Select all

RESTORE tielnumber
FOR Y = 1 TO 15
  FOR X = 1 TO 30
    READ clr     
    tilenumber(X,y)=clr
  NEXT X
NEXT Y
Now, when I read what arrow has been hit, I can check for water by
IF tilenumber(newX, newY) = 3 THEN add the code to go back for a new arrow key, so, dont move the scout.
Last edited by Ralph on Sat Jul 26, 2008 2:54 pm, edited 2 times in total.
Ralph, with QuickBASIC 4.5, operating under Windows XP, wiht anHP LaserJet 4L Printer. Bilingual in English/Spanish

Ralph
Veteran
Posts: 148
Joined: Fri Feb 09, 2007 3:10 pm
Location: Katy, Texas

Post by Ralph » Sat Jul 26, 2008 2:37 pm

Oops, double entry! I cleard this one out.
Ralph, with QuickBASIC 4.5, operating under Windows XP, wiht anHP LaserJet 4L Printer. Bilingual in English/Spanish

User avatar
burger2227
Veteran
Posts: 2330
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Ralph

Post by burger2227 » Sat Jul 26, 2008 3:28 pm

Go back and edit the double post. Check the box that says Delete Post before it is too late to do so. Click Submit Post.

Ted
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0

User avatar
Super Mario
Coder
Posts: 21
Joined: Mon Jul 21, 2008 8:34 am
Location: My computer

Post by Super Mario » Sat Jul 26, 2008 4:00 pm

Here's what I have in the program loop.

Code: Select all

DO
p$ = INKEY$
oldscoutx = scoutx
oldscouty = scouty
tilenumber = 1

IF p$ = CHR$(0) + CHR$(75) AND tilenumber(scoutx - 1, scouty) <> 3 THEN
IF scoutx > 1 THEN scoutx = scoutx - 1
END IF

IF p$ = CHR$(0) + CHR$(77) AND tilenumber(scoutx + 1, scouty) <> 3 THEN
IF scoutx < 30 THEN scoutx = scoutx + 1
END IF

IF p$ = CHR$(0) + CHR$(72) AND tilenumber(scoutx, scouty - 1) <> 3 THEN
IF scouty > 1 THEN scouty = scouty - 1
END IF

IF p$ = CHR$(0) + CHR$(80) AND tilenumber(scoutx, scouty + 1) <> 3 THEN
IF scouty < 15 THEN scouty = scouty + 1
END IF

IF oldscoutx <> scoutx OR oldscouty <> scouty THEN

RESTORE tilenumber
FOR y = 1 TO 15
FOR x = 1 TO 30
READ tilenumber

IF tilenumber = 1 THEN PUT (x * 10, y * 10), grass, PSET
IF tilenumber = 2 THEN PUT (x * 10, y * 10), path, PSET
IF tilenumber = 3 THEN PUT (x * 10, y * 10), water, PSET
IF tilenumber = 4 THEN PUT (x * 10, y * 10), tent, PSET

NEXT
NEXT

PUT (scoutx * 10, scouty * 10), scoutmask, AND
PUT (scoutx * 10, scouty * 10), scout, OR

END IF
LOOP UNTIL p$ = CHR$(27)

When I go to run this, after I move about 10 spaces, I get a SUBSCRIPT OUT OF RANGE error. Any idea what this means?

Thanks for all your help, by the way.
My brother says I'm crazy. I personally don't see the problem with programming at the beach.

User avatar
Mentat
Veteran
Posts: 409
Joined: Tue Aug 07, 2007 3:39 pm
Location: NC, US

Post by Mentat » Sat Jul 26, 2008 4:30 pm

Alright, I'm pulling out the big guns.

Code: Select all

SCREEN 13

'graphics
DIM grass(10, 10), path(10, 10), water(10, 10) 
dim tent(10, 10), scout(10, 10), scoutmask(10, 10)
dim map(15, 30)

'initialize variables
dim scoutX
dim scouty
dim clr
dim x
dim y
dim key
dim tile
dim vx
dim vy

'player coordinates
scoutX = 5
scoutY = 1

'load grass tile
FOR y = 1 TO 10
    FOR x = 1 TO 10
        READ clr
        IF clr = 1 THEN PSET (x, y), 10
        IF clr = 0 THEN PSET (x, y), 2
    NEXT
NEXT
GET (1, 1)-(10, 10), grass

'load path tile
FOR y = 1 TO 10
    FOR x = 1 TO 10
        READ clr
        IF clr = 0 THEN PSET (x, y), 6
        IF clr = 1 THEN PSET (x, y), 14
    NEXT x
NEXT y
GET (1, 1)-(10, 10), path

'load water tile
FOR y = 1 TO 10
    FOR x = 1 TO 10
        READ clr
        IF clr = 0 THEN PSET (x, y), 3
        IF clr = 1 THEN PSET (x, y), 11
    NEXT x
NEXT y
GET (1, 1)-(10, 10), water

'load tent tile
FOR y = 1 TO 10
    FOR x = 1 TO 10
        READ clr
        IF clr = 0 THEN PSET (x, y), 6
        IF clr = 1 THEN PSET (x, y), 8
        IF clr = 2 THEN PSET (x, y), 0
    NEXT x
NEXT y
GET (1, 1)-(10, 10), tent

'sprite
FOR y = 1 TO 10
    FOR x = 1 TO 10
        READ clr
        IF clr = 0 THEN PSET (x, y), 0
        IF clr = 1 THEN PSET (x, y), &h11
        IF clr = 2 THEN PSET (x, y), 8
        IF clr = 3 THEN PSET (x, y), 14
        IF clr = 4 THEN PSET (x, y), 4
    NEXT x
NEXT y
GET (1, 1)-(10, 10), scout

'load mask
FOR y = 1 TO 10
    FOR x = 1 TO 10
        READ clr
        IF clr = 0 THEN PSET (x, y), 255
        IF clr = 1 THEN PSET (x, y), 2
        IF clr = 2 THEN PSET (x, y), 8
        IF clr = 3 THEN PSET (x, y), 14
        IF clr = 4 THEN PSET (x, y), 4
    NEXT x
NEXT y
GET (1, 1)-(10, 10), scoutmask

'load map
FOR y = 1 TO 15
    FOR x = 1 TO 30

    read tile
    map(y, x) = tile 
    
    NEXT x
NEXT y

cls
vy = -1
DO
    'keyboard input
    key$ = INKEY$
    
    IF key$ = chr(0) + chr(72) THEN vy = vy - 1
    IF key$ = chr(0) + chr(80) THEN vy = vy + 1
    IF key$ = chr(0) + chr(75) THEN vx = vx - 1
    IF key$ = chr(0) + chr(77) THEN vx = vx + 1
    
    scoutX = scoutX + vx
    scoutY = scoutY + vy
    
    if scoutX <0>= 31 or scoutY <0>= 16 then
        'tried to walk past map borders
        scoutX = scoutX - vx
        scoutY = scoutY - vy
    else
        if map(scoutY, scoutX) = 3 then
            scoutX = scoutX - vx
            scouty = scouty - vy
        end if
    end if
    
    if vx or vy then
        FOR y = 1 TO 15
            FOR x = 1 TO 30
                
            IF map(y, x) = 1 THEN PUT (x * 10, y * 10), grass, PSET
            IF map(y, x) = 2 THEN PUT (x * 10, y * 10), path, PSET
            IF map(y, x) = 3 THEN PUT (x * 10, y * 10), water, PSET
            IF map(y, x) = 4 THEN PUT (x * 10, y * 10), tent, PSET
                                             
            NEXT x
        NEXT y
        
        PUT (scoutX * 10, scoutY * 10), scoutmask, AND
        PUT (scoutX * 10, scoutY * 10), scout, OR
    end if
    
    vx = 0
    vy = 0
LOOP UNTIL key$ = CHR$(27)

'grass:
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,1,0,0,0,0,0,0,0
DATA 0,0,0,0,0,1,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,1,0,0,0
DATA 0,1,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,1,0,0
DATA 0,0,0,0,0,0,0,0,0,0

'path:
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0

'water:
DATA 0,0,0,0,0,0,0,0,0,0
DATA 1,1,1,1,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,1,1,1,1,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 1,1,1,1,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,1,1,1,1,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 1,1,1,1,0,0,0,0,0,0

'tent:
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,1,1,0,0,0,0
DATA 0,0,0,1,1,1,1,0,0,0
DATA 0,0,0,1,2,2,1,0,0,0
DATA 0,0,1,1,2,2,1,1,0,0
DATA 0,0,1,1,2,2,1,1,0,0
D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