Qbasicnews.com
Why isn't this creating a random map? - Printable Version

+- Qbasicnews.com (http://qbasicnews.com/newforum)
+-- Forum: Qbasic "like" compilers/interpreters (http://qbasicnews.com/newforum/forum-5.html)
+--- Forum: FB Discussion & Programming Help (http://qbasicnews.com/newforum/forum-15.html)
+--- Thread: Why isn't this creating a random map? (/thread-7564.html)

Pages: 1 2


Why isn't this creating a random map? - TheDarkJay - 06-19-2005

Well, why isn't it. I am trying my hand at scrolling, this is just tsting that the map works first

Code:
SCREENRES 200,200
DIM map(1000,800)

'1000 is the maximum cell x co-ordinate
'800 is the maximum cell y co-ordinate

FOR y = 1 TO 800
    FOR x = 1 TO 1000
        map(x,y) = int((RND * 16) + 1)
    NEXT
NEXT

playerx = 500 'where in the cell the player is
playery = 400

cameraminx = playerx - 100 'The size of the camera box
cameraminy = playery - 100 'and
cameramaxx = playerx + 100 'the location of the
cameramaxy = playery + 100 'camera

FOR y = cameraminy to cameramaxy
    FOR x = cameraminx to cameramaxx
        PSET (x,y), map(x,y)
    NEXT
NEXT

px = 100
py = 100
LINE (px, py)-(px + 10, py + 10), 15, BF

SLEEP



Why isn't this creating a random map? - whitetiger0990 - 06-19-2005

put RANDOMIZE TIMER near the beginning of the program

RND by itself will always return the same sequence whenever the program is run


RANDOMIZE TIMER sets the seed to the time something blah blah


Why isn't this creating a random map? - Moneo - 06-20-2005

Here's the complete "blah, blah" regarding the RANDOMIZE statement from the QB Online Help.

RANDOMIZE [expression]
When you use the argument expression, QuickBASIC uses the value to initialize the random-number generator.

If the random-number generator is not reseeded, the RND function returns the same sequence of random numbers each time the program is run. To change the sequence of random numbers every time the program is run, place a RANDOMIZE statement at the beginning of the program and change the argument with each run.

A convenient way to initialize the random-number generator is to use the TIMER function. Using TIMER ensures a new series of random numbers each time you use the program.
*****


Why isn't this creating a random map? - TheDarkJay - 06-20-2005

HOW DID I FORGET RANDOMIZE TIMER?

Hang on, i add one to the result, so shoudn't the screen still be just one colour even if rnd returns a value of 0?

I've noticed the problem, x is between cameraminx and cameramaxx

cameraminx = 400 (larger then the screen size)
cameramaxx = 600 (larger than the screen size)

FB is trying to plot the co-odinates at areas outside the screen. FB really needs to learn to catch that, maybe a error message that doesn't stop the program from compiling...


Why isn't this creating a random map? - MystikShadows - 06-20-2005

NOt necessarily....but it will have the same sequence of "random" colors...in the same order :-)


Why isn't this creating a random map? - DrV - 06-20-2005

Quote:HOW DID I FORGET RANDOMIZE TIMER?

Hang on, i add one to the result, so shoudn't the screen still be just one colour even if rnd returns a value of 0?

I've noticed the problem, x is between cameraminx and cameramaxx

cameraminx = 400 (larger then the screen size)
cameramaxx = 600 (larger than the screen size)

FB is trying to plot the co-odinates at areas outside the screen. FB really needs to learn to catch that, maybe a error message that doesn't stop the program from compiling...
That can't be a compile-time warning; a run-time warning would be possible, but that would slow things down and bloat gfxlib... just be careful not to use coordinates outside the resolution of the screen.


Why isn't this creating a random map? - TheDarkJay - 06-20-2005

I haven't tested it (i'm not at my computer at the moment) but this should work

Code:
RANDOMIZE TIMER
SCREENRES 200,200
DIM map(1000,800)

'1000 is the maximum cell x co-ordinate
'800 is the maximum cell y co-ordinate

FOR y = 1 TO 800
    FOR x = 1 TO 1000
        map(x,y) = int((RND * 16) + 1)
    NEXT
NEXT

playerx = 500 'where in the cell the player is (start camera)
playery = 400

camerax = playerx - 100 'The Top corner of the camerabox compared to the player
cameray = playery - 100

FOR y = 1 TO 200
FOR x = 1 TO 200
cx = camerax + x
cy = cameray + y
PSET (x,y), map(cx,cy)
NEXT
NEXT

px = 100
py = 100
LINE (px, py)-(px + 10, py + 10), 15, BF
SLEEP



Why isn't this creating a random map? - SotSvart - 06-21-2005

Code:
This function plots a single pixel on the screen. The x and y coordinates are
affected by the last call to the VIEW and WINDOW statements, and respect the
current clipping region as set by the VIEW statement. If you do not specify
color, current foreground color is used.

Pset dosent do anything if its out of the clipping box, the same goes for put, line etc...


Why isn't this creating a random map? - TheDarkJay - 06-21-2005

Quote:
Code:
This function plots a single pixel on the screen. The x and y coordinates are
affected by the last call to the VIEW and WINDOW statements, and respect the
current clipping region as set by the VIEW statement. If you do not specify
color, current foreground color is used.

Pset dosent do anything if its out of the clipping box, the same goes for put, line etc...

I'm aware it clips, it's just anoying when you accidently place something outside the screen and are blissfully unaware.

And the code i posted doesn't work, this should, though someone pointing out any errors would be nice...
Code:
SCREENRES 200,200
DIM map(1000,800)

'1000 is the maximum cell x co-ordinate
'800 is the maximum cell y co-ordinate

FOR y = 1 TO 800
    FOR x = 1 TO 1000
        map(x,y) = int((RND * 16) + 1)
    NEXT
NEXT

playerx = 500 'where in the cell the player is
playery = 400

camerax = playerx - 100 'The size of the camera box
cameray = playery - 100 'and

cx = camerax
cy = cameray
FOR y = 0 to 200
    cy = cy + 1
    FOR x = 0 to 200
        cx = cx + 1
        PSET (x,y), map(cx,cy)
    NEXT
    cx = camerax
NEXT

px = 100
py = 100
LINE (px, py)-(px + 10, py + 10), 15, BF

SLEEP



Why isn't this creating a random map? - Anonymous - 06-21-2005

fb must clip. end of story :o

ill arm wrestle you for it


edit: not exactly sure what that last code u posted is supposed to do....