Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rnd help please
#1
heres my code

Code:
POKE Uinteger 23675, @MyUdgBlock
randomize
BORDER 7 : PAPER 7 : INK 0 : CLS
  PRINT AT 3,13 ; PAPER 1 ; INK 7 ; "BattleField"
  PRINT AT 5,9 ; PAPER 7 ; INK 0 ; "Q - Up"
  PRINT AT 6,9 ; PAPER 7 ; INK 0 ; "A - Down"
  PRINT AT 7,9 ; PAPER 7 ; INK 0 ; "O - Left"
  PRINT AT 8,9 ; PAPER 7 ; INK 0 ; "P - Right"
  PRINT AT 9,9 ; PAPER 7 ; INK 0 ; "M - Select"

  PRINT AT 10,3 ; PAPER 7 ; INK 0 ; "You have to select units"
  PRINT AT 11,3 ; PAPER 7 ; INK 0 ; "to fight the enemy units"
  PRINT AT 15,3 ; PAPER 7 ; INK 0 ; "Press any key to start"

60  LET j$ = INKEY$
  IF j$ = "" THEN GOTO 60: END IF

  Function byterndrange (first As uByte, last As uByte) As uByte
    return Rnd * (last - first) + first
End Function
paper 4
cls
  BORDER 4: INK 0
  
for x=0 to 200
plot  byterndrange(0,255),byterndrange(0,192)
next



Dim BlueFactoryX (6) as uByte
Dim BlueFactoryY (6) as uByte
For x =0 to 5
BlueFactoryX(x)  = byterndrange(1,9)
BlueFactoryY(x)  = byterndrange(1,24)
Next

dim RedFactoryX (6) as uByte
dim RedFactoryY (6) as uByte

For x =0 to 5
RedFactoryX(x)  = byterndrange(28,32)
RedFactoryY(x)  = byterndrange(1,24)
Next


drawFactories()

sub drawFactories()
for x =0 to 5
ink 1
print at BlueFactoryX(x), BlueFactoryY(x); CHR$(144)
ink 2
print at RedFactoryX(x), RedFactoryY(x); CHR$(144)

next
End sub


STOP : REM Avoid execution to enter this zone
MyUdgBlock: REM a simple Label; @Label returns it's memory address
ASM
incbin "factory.BIN"
END ASM

When I draw random dots the rnd function works fine,
but when I draw factories at random positions it doesnt turn out right

I am trying to draw the red ones on the right side of the screen but they end up on the left
the blue ones are all over the screen
Reply
#2
You're overflowing your screen: SINCLAIR Basic PRINT AT uses Y, X coordinates (row, column) Idea
I've reversed them in your listing and it seems to be working ok. Since this is a compiled program, by default it won't check your screen overflows (e.g. "OUT of Screen error"), but with the flag (NOT YET IMPLEMENTED) --debug-screen it will stop when this happens.

There are more checkers already done:
--debug-array Will raise a "Subscript out of range" if you access an non-existing array-cell
--debug-memory Will raise an "Out of memory error" in case the program run out of mem.

The idea is: If you suspect your program has an error, enable the checkers and tests it. Once your program runs ok, compile again without your check flags (faster and less memory required)

Idea Tip: PRINT ... ; is faster than PRINT ... , because the former doesn't need to print a newline. So use PRINT ... ; whenever possible. Also for legibility, you can use PRINT "\A" instead of PRINT CHRS$(144) (the compiled code is the same, though);
Reply
#3
thanks for the fix


Quote: PRINT ... ; is faster than PRINT ... ,

im not sure what this means,

like this?
Print y,x;
print y,x,
Reply
#4
slenkar Wrote:thanks for the fix


Quote: PRINT ... ; is faster than PRINT ... ,

im not sure what this means,

like this?
Print y,x;
print y,x,
No, this way:
Code:
PRINT a$; : REM Faster than PRINT a$
When you use PRINT, by default it prints a NEW LINE (carriage return) if no semicolon is used. So use semicolon (Wink as it's slightly faster (specially during in-game prints)
Reply
#5
ok thanks for that
Reply
#6
I've just uploaded a new revision 1.2.7-r2096. Please download and test! It has some bugfixes so the --debug-array and the --debug-memory works ok again. If you run your program with --debug-array it seems to work ok, but sometimes an "OUT of Screen" is returned. So check screen boundaries.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)