Need help - Strange tile problem
- Super Mario
- Coder
- Posts: 21
- Joined: Mon Jul 21, 2008 8:34 am
- Location: My computer
Yeah.
Here's I would do the whole thing if it were my project. Except that I would draw my tiles and sprite in Paint, then BLOAD them. This code runs fast enough so you can redraw every frame, without flicker. It takes care of collision detection with water and the sides of the map.
Here's I would do the whole thing if it were my project. Except that I would draw my tiles and sprite in Paint, then BLOAD them. This code runs fast enough so you can redraw every frame, without flicker. It takes care of collision detection with water and the sides of the map.
Code: Select all
screenres 640, 480, 8
'graphics images
dim grass as integer ptr = imageCreate(10, 10)
dim path as integer ptr = imageCreate(10, 10)
dim water as integer ptr = imageCreate(10, 10)
dim tent as integer ptr = imageCreate(10, 10)
dim scout as integer ptr = imageCreate(10, 10)
dim map(15, 30) as integer
'initialize variables
dim scoutX as integer = 5
dim scouty as integer = 1
dim clr as integer
dim x as integer
dim y as integer
dim key as string
dim vy as integer
dim vx as integer
'load grass tile
FOR y = 1 TO 10
FOR x = 1 TO 10
READ clr
pset (x, y), clr
NEXT
NEXT
GET (1, 1)-(10, 10), grass
'load path tile
FOR y = 1 TO 10
FOR x = 1 TO 10
READ clr
pset (x, y), clr
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
pset (x, y), clr
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
pset (x, y), clr
NEXT x
NEXT y
GET (1, 1)-(10, 10), tent
'sprite
FOR y = 1 TO 10
FOR x = 1 TO 10
READ clr
pset (x, y), clr
NEXT x
NEXT y
GET (1, 1)-(10, 10), scout
'load map
FOR y = 1 TO 15
FOR x = 1 TO 30
read clr
map(y, x) = clr
NEXT x
NEXT y
DO
'Prevent flicker
screenunlock
screenlock
cls
'keyboard input
key = INKEY$
vy = 0
vx = 0
'move
IF key = chr(255) + chr(72) THEN vy = -1
IF key = chr(255) + chr(80) THEN vy = 1
IF key = chr(255) + chr(75) THEN vx = -1
IF key = chr(255) + chr(77) THEN vx = 1
'Check against borders and water
if scoutX + vx > 0 and scoutX + vx <31> 0 and scoutY + vy < 16 then
if map(scouty + vy, scoutx + vx) <> 3 then
scoutX += vx
scouty += vy
end if
end if
end if
'draw map
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
'Draw the little dude
PUT (scoutX * 10, scoutY * 10), scout, trans
LOOP UNTIL multikey(1)
'release images
imageDestroy(grass)
imageDestroy(path)
imageDestroy(water)
imageDestroy(tent)
imageDestroy(scout)
end
'grass
DATA 2, 2, 2, 2, 2, 2, 2, 2, 2, 2
DATA 2, 2,10, 2, 2, 2, 2, 2, 2, 2
DATA 2, 2, 2, 2, 2,10, 2, 2, 2, 2
DATA 2, 2, 2, 2, 2, 2, 2, 2, 2, 2
DATA 2, 2, 2, 2, 2, 2, 2, 2, 2, 2
DATA 2, 2, 2, 2, 2, 2,10, 2, 2, 2
DATA 2,10, 2, 2, 2, 2, 2, 2, 2, 2
DATA 2, 2, 2, 2, 2, 2, 2, 2, 2, 2
DATA 2, 2, 2, 2, 2, 2, 2,10, 2, 2
DATA 2, 2, 2, 2, 2, 2, 2, 2, 2, 2
'path
DATA 6,6,6,6,6,6,6,6,6,6
DATA 6,6,6,6,6,6,6,6,6,6
DATA 6,6,6,6,6,6,6,6,6,6
DATA 6,6,6,6,6,6,6,6,6,6
DATA 6,6,6,6,6,6,6,6,6,6
DATA 6,6,6,6,6,6,6,6,6,6
DATA 6,6,6,6,6,6,6,6,6,6
DATA 6,6,6,6,6,6,6,6,6,6
DATA 6,6,6,6,6,6,6,6,6,6
DATA 6,6,6,6,6,6,6,6,6,6
'water
DATA 3, 3, 3, 3, 3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,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,2,2,2,2,2,2,2,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,2,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,2,2,2,2,2,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,2,4,1,1,1,1,1,1,1,1,3,3,3,3
DATA 1,1,1,1,2,2,1,1,1,1,1,1,1,1,1,1,2,1,1,1,1,1,1,1,1,1,3,3,3,3
DATA 1,1,1,1,2,2,1,1,1,4,1,1,1,1,1,1,2,1,1,1,1,1,1,1,1,1,3,3,3,3
DATA 1,1,1,1,2,2,1,1,1,2,1,1,1,1,1,1,2,2,2,2,2,2,1,1,1,1,3,3,3,3
DATA 1,1,1,1,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,2,1,1,1,1,3,3,3,3
DATA 1,1,1,1,2,2,1,1,1,1,1,4,1,1,1,1,1,1,1,1,1,4,1,1,1,1,3,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,3,3,3,3
DATA 2,2,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
For any grievances posted above, I blame whoever is in charge . . .
Super Mario:
This code DOES work! I've also added the "don't allow scout to get in the water". Please STUDY what I've done, and ask questions. Otherwise, this will be my last post on this thread.
This code DOES work! I've also added the "don't allow scout to get in the water". Please STUDY what I've done, and ask questions. Otherwise, this will be my last post on this thread.
Code: Select all
'''Changes or additions by Ralph are identified with three apostrophes '''
DIM grass(10, 10), path(10, 10), water(10, 10), tent(10, 10), scout(10, 10), scoutmask(10, 10)
DIM oldscoutarea(10, 10), map(30, 15)'''
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), 5 '''was 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
map(x, y) = 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
'''Before PUTing the scout, GET the area where it will go
GET (scoutx * 10, scouty * 10)-(scoutx * 10 + 10, scouty * 10 + 10), oldscoutarea
PUT (scoutx * 10, scouty * 10), scoutmask, AND
PUT (scoutx * 10, scouty * 10), scout, OR
'''********************************************************************
DO
again1: '''
p$ = "": WHILE p$ = "": p$ = INKEY$: WEND '''
p$ = RIGHT$(p$, 1) '''
'''Check that an arrow key was pressed; if not, go to label again1:
IF p$ <> "H" AND p$ <> "K" AND p$ <> "M" AND p$ <> "P" THEN GOTO again1 '''
oldscoutx = scoutx
oldscouty = scouty
IF p$ = "H" AND scouty > 1 THEN scouty = scouty - 1
IF p$ = "K" AND scoutx > 1 THEN scoutx = scoutx - 1
IF p$ = "M" AND scoutx < 30 THEN scoutx = scoutx + 1
IF p$ = "P" AND scouty < 15 THEN scouty = scouty + 1
'''Check for water area in next jump; if water, don't allow jump
IF map(scoutx, scouty) = 3 THEN
scoutx = oldscoutx
scouty = oldscouty
GOTO again1
END IF
IF oldscoutx <> scoutx OR oldscouty <> scouty THEN
'''RESTORE tilenumber '''REMarked out
GOTO skip1 '''
'''Following code disabled by above GOTO
FOR y = 1 TO 15
FOR x = 1 TO 30
'READ tilenumber '''REMarked out by Ralph
tilenumber = map(x, y) '''new, by Ralph
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
skip1:
'''Restore oldscout's location with proper background
PUT (oldscoutx * 10, oldscouty * 10), oldscoutarea, PSET '''
'''GET the new scout location area
GET (scoutx * 10, scouty * 10)-(scoutx * 10 + 10, scouty * 10 + 10), oldscoutarea '''
PUT (scoutx * 10, scouty * 10), scoutmask, AND
PUT (scoutx * 10, scouty * 10), scout, OR
END IF
LOOP UNTIL p$ = CHR$(27)
'''********************************************************************
SYSTEM
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
DATA 0,1,1,1,2,2,1,1,1,0
DATA 0,1,1,2,2,2,2,1,1,0
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1,1,1,2,1,1,1,1,1,1,1,1,1,3,3,3,3
DATA 1,1,1,1,2,2,1,1,1,2,1,1,1,1,1,1,2,2,2,2,2,2,1,1,1,1,3,3,3,3
DATA 1,1,1,1,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,2,1,1,1,1,3,3,3,3
DATA 1,1,1,1,2,2,1,1,1,1,1,4,1,1,1,1,1,1,1,1,1,4,1,1,1,1,3,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,3,3,3,3
DATA 2,2,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
Ralph, with QuickBASIC 4.5, operating under Windows XP, wiht anHP LaserJet 4L Printer. Bilingual in English/Spanish
Mentat: I respect your personal opinio, but, I would like to see unbiased and logical PROOF that my use of GOTO is wrong, and that you are ustified in your emotional condemnation, and not just that that is your opinion or strong belief. People using the best and recommended programming methods and procedures can and do still produce code that is very difficult to understand. Is it justifiable to rant and rave against such people? Each person has a personal opinon and preference. Let us be!
THERE IS NOTHING WRONG with a proper use of GOTO. Of course, we can always use a DO/LOOP instead of a GOTO. And, the angry rage against the use of the GOTO goes on and on. Why can't everybody simply accept a PROPERLY used GOTO?
Oh, and, 9 + 9 = 12 is wrong! 9 + 9 = 18! And, when I turn it upside down, I get 6 + 6 = 21, which is also wrong! Yes, yes, I thought your signature is humorous, I'm just pulling your leg, ha, ha. No criticism intended!
THERE IS NOTHING WRONG with a proper use of GOTO. Of course, we can always use a DO/LOOP instead of a GOTO. And, the angry rage against the use of the GOTO goes on and on. Why can't everybody simply accept a PROPERLY used GOTO?
Oh, and, 9 + 9 = 12 is wrong! 9 + 9 = 18! And, when I turn it upside down, I get 6 + 6 = 21, which is also wrong! Yes, yes, I thought your signature is humorous, I'm just pulling your leg, ha, ha. No criticism intended!
Ralph, it isn't just my personal opinion. You don't ever, ever teach programming with goto. If you were just sharing your own code about your own project with experienced members, then I wouldn't care.
Why do I care? Because newer coders write longer and longer programs as they develop. Goto makes it harder to write larger programs. See the problem? You make like Dr. Pepper just like I do, but don't water a tree with it.
Now I sound all grouchy.
9+9 is 12, in hex.
Why do I care? Because newer coders write longer and longer programs as they develop. Goto makes it harder to write larger programs. See the problem? You make like Dr. Pepper just like I do, but don't water a tree with it.
Now I sound all grouchy.
9+9 is 12, in hex.
For any grievances posted above, I blame whoever is in charge . . .
Mentat:
I accept your good explanation, namely, not to teach using GOTOs, to avoid the possibility of difficult-to-follow, spagetti code. It's a good reason for me to avoid it in public and, cetainly, in teaching. I use it, with care and for short jumps, because I learned programming (I consider myself an amateur programmer with a smidgen of understanding) with the GOTO and the WHILE/WEND. I think the DO/LOOP came out later, and, I never took it up. But, I see your point, and will try to change my habits in this respect.
Thank you for your kind and considerate explanations.
I accept your good explanation, namely, not to teach using GOTOs, to avoid the possibility of difficult-to-follow, spagetti code. It's a good reason for me to avoid it in public and, cetainly, in teaching. I use it, with care and for short jumps, because I learned programming (I consider myself an amateur programmer with a smidgen of understanding) with the GOTO and the WHILE/WEND. I think the DO/LOOP came out later, and, I never took it up. But, I see your point, and will try to change my habits in this respect.
Thank you for your kind and considerate explanations.
Ralph, with QuickBASIC 4.5, operating under Windows XP, wiht anHP LaserJet 4L Printer. Bilingual in English/Spanish
Suber Mario:
After considering Mentat's postings, I have accepted eliminating GOTOs, and present the code with the necessary DO/LOOPs substituted.
After considering Mentat's postings, I have accepted eliminating GOTOs, and present the code with the necessary DO/LOOPs substituted.
Code: Select all
'''July 28, 2008: Changed GOTOs to DO/LOOPs
'''July 27, 2008: Changes or additions by Ralph are identified with three
'apostrophes, as in '''
DIM grass(10, 10), path(10, 10), water(10, 10), tent(10, 10), scout(10, 10), scoutmask(10, 10)
DIM oldscoutarea(10, 10), map(30, 15)'''
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), 5 '''was 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
map(x, y) = 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
'''Before PUTing the scout, GET the area where it will go
GET (scoutx * 10, scouty * 10)-(scoutx * 10 + 10, scouty * 10 + 10), oldscoutarea
PUT (scoutx * 10, scouty * 10), scoutmask, AND
PUT (scoutx * 10, scouty * 10), scout, OR
'''********************************************************************
DO
DO '''Changed GOTOs to DO/LOOPs, on Mentat's good advice
DO '''Changed GOTOs to DO/LOOPs, on Mentat's good advice
p$ = "": WHILE p$ = "": p$ = INKEY$: WEND '''
p$ = RIGHT$(p$, 1) '''
LOOP UNTIL p$ = "H" OR p$ = "K" OR p$ = "M" OR p$ = "P" '''
oldscoutx = scoutx
oldscouty = scouty
IF p$ = "H" AND scouty > 1 THEN scouty = scouty - 1
IF p$ = "K" AND scoutx > 1 THEN scoutx = scoutx - 1
IF p$ = "M" AND scoutx < 30 THEN scoutx = scoutx + 1
IF p$ = "P" AND scouty < 15 THEN scouty = scouty + 1
'''Check for water area in next jump; if water, don't allow move
IF map(scoutx, scouty) = 3 THEN scoutx = oldscoutx: scouty = oldscouty
LOOP WHILE map(scoutx, scouty) = 3 '''
IF oldscoutx <> scoutx OR oldscouty <> scouty THEN
'''RESTORE tilenumber '''REMarked out
GOTO skip1 '''
'''Following code disabled by above GOTO
FOR y = 1 TO 15
FOR x = 1 TO 30
'READ tilenumber '''REMarked out by Ralph
tilenumber = map(x, y) '''new, by Ralph
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
skip1:
'''Restore oldscout's location with proper background
PUT (oldscoutx * 10, oldscouty * 10), oldscoutarea, PSET '''
'''GET the new scout location area
GET (scoutx * 10, scouty * 10)-(scoutx * 10 + 10, scouty * 10 + 10), oldscoutarea '''
PUT (scoutx * 10, scouty * 10), scoutmask, AND
PUT (scoutx * 10, scouty * 10), scout, OR
END IF
LOOP UNTIL p$ = CHR$(27)
'''********************************************************************
SYSTEM
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
DATA 0,1,1,1,2,2,1,1,1,0
DATA 0,1,1,2,2,2,2,1,1,0
DATA 1,1,1,2,2,2,2,1,1,1
DATA 1,1,1,2,2,2,2,1,1,1
scout:
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1,1,2,1,1,1,1,1,1,2,2,2,2,2,2,1,1,1,1,3,3,3,3
DATA 1,1,1,1,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,2,1,1,1,1,3,3,3,3
DATA 1,1,1,1,2,2,1,1,1,1,1,4,1,1,1,1,1,1,1,1,1,4,1,1,1,1,3,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,3,3,3,3
DATA 2,2,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
Ralph, with QuickBASIC 4.5, operating under Windows XP, wiht anHP LaserJet 4L Printer. Bilingual in English/Spanish
- burger2227
- Veteran
- Posts: 2466
- Joined: Mon Aug 21, 2006 12:40 am
- Location: Pittsburgh, PA
SEE GOTO GO
GOTO is only necessary for ON ERROR GOTO.
New programmers often get in a bad habit using GOTO. They don't even bother making loops. Troubleshooting the code often becomes a confusing Task.
GOTO is almost as useless as LET, but those are often the two first things that POOR teachers throw at them! I'm glad most of them are moving onto NET nowadays. They can screw that up all they want!
As you demonstrated Ralph, what was so hard about NOT using GOTO?
Ted
New programmers often get in a bad habit using GOTO. They don't even bother making loops. Troubleshooting the code often becomes a confusing Task.
GOTO is almost as useless as LET, but those are often the two first things that POOR teachers throw at them! I'm glad most of them are moving onto NET nowadays. They can screw that up all they want!
As you demonstrated Ralph, what was so hard about NOT using GOTO?
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
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
Well, burger, the difficult thing about not using GOTOs is that I have never used DO/LOOPs for all my normal, small jumps, only GOTOs. So, I never got a good grip on the DO/LOOP method.
Now, with my understanding that it's best not to show the new, future programmers how to make spagetti code, I am making it a point not to do so, and make the ?DO/LOOPs "second nature" to me.
Finally, after all this time, I got a very good and reasonable answer from Menat. In the past, I only saw flaming accusations if anyone used a GOTO, and conclusions that, if a programmer chose to use GOTO in a reasonable and easy-to-follow manner, it was alright. As I've said in this thread, Menat has given me the first GOOD reason for me to forget the use of GOTOs. Thanks again, Menat.
Now, with my understanding that it's best not to show the new, future programmers how to make spagetti code, I am making it a point not to do so, and make the ?DO/LOOPs "second nature" to me.
Finally, after all this time, I got a very good and reasonable answer from Menat. In the past, I only saw flaming accusations if anyone used a GOTO, and conclusions that, if a programmer chose to use GOTO in a reasonable and easy-to-follow manner, it was alright. As I've said in this thread, Menat has given me the first GOOD reason for me to forget the use of GOTOs. Thanks again, Menat.
Ralph, with QuickBASIC 4.5, operating under Windows XP, wiht anHP LaserJet 4L Printer. Bilingual in English/Spanish
Mentat, you already gave a very good reason NOT to use the GOTO. You are spoiling that by adding trivial reasons, as UNTIL can be substituted - and this is what I have used for years - with a WHILE/WEND. Just let your first, convincing reason why not to use GOTOs in public stand as THE reason, since most, if not all, other "reasons" can be stepped around by existing other coding commands, statements, or methods.
Ralph, with QuickBASIC 4.5, operating under Windows XP, wiht anHP LaserJet 4L Printer. Bilingual in English/Spanish
Oh, sorry. I was just talking to TmEE about the difference between do/loop and while/wend.Ralph wrote:Mentat, you already gave a very good reason NOT to use the GOTO. You are spoiling that by adding trivial reasons, as UNTIL can be substituted - and this is what I have used for years - with a WHILE/WEND. Just let your first, convincing reason why not to use GOTOs in public stand as THE reason, since most, if not all, other "reasons" can be stepped around by existing other coding commands, statements, or methods.
For any grievances posted above, I blame whoever is in charge . . .
- burger2227
- Veteran
- Posts: 2466
- Joined: Mon Aug 21, 2006 12:40 am
- Location: Pittsburgh, PA
I seldom use WHILE WEND loops. WHILE is not used in many other programming languages. Thus you have to rewrite them when converting from QB.
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
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