It works but CLS is killing it

by (Login burger2227)
R

The array only needs to be 100 to get it to work. Remove the two FOR loops too. ON Error should be done before the loop. The checking that you added inside of the function does nothing as the variables are not passed to it. Change the 1's to 3's in the paddle moves. Then it will run, but badly...

What you want to do is just erase the previous positions of the ball and paddles instead of the entire screen. Only redraw the paddles when the position is changed. First use black to draw over the old position.

You can GET the background area of the area before you PUT the ball and use that to erase it. The code below shows that concept using the previous coordinates while moving a box.



DEFINT A-Z
DIM BG(300), Box(300), SC(127) ' BG holds background images. Box holds the Box image.
SCREEN 13 ' graphic coordinate minimums are 0 to 319 column or 199 row maximums.
' set up screen background
COLOR 4: LOCATE 10, 5: PRINT "Multikey Keyboard input routine"
COLOR 10: LOCATE 12, 4: PRINT "Use the arrow keys to move the box."
LOCATE 13, 4: PRINT "Note that you can press two or more"
LOCATE 14, 4: PRINT "keys at once for diagonal movement!"
COLOR 14: LOCATE 16, 4: PRINT " Also demonstrates how GET and PUT "
LOCATE 17, 4: PRINT "are used to preserve the background."
COLOR 11: LOCATE 20, 11: PRINT "Press [Esc] to quit"
x = 150: y = 50: PX = x: PY = y ' actual box starting position

GET (x, y)-(x + 15, y + 15), BG ' GET original BG at start box position
LINE (x, y)-(x + 15, y + 15), 9, BF ' the plain blue box to move
GET (x, y)-(x + 15, y + 15), Box ' GET to Box Array

DO 'main loop
t! = TIMER + .05
DO ' 1 Tick (1/18th second) keypress scancode read loop
a$ = INKEY$ ' So the keyboard buffer won't get full
code% = INP(&H60) ' Get keyboard scan code from port 96
IF code% < 128 THEN SC(code%) = 1 ELSE SC(code% - 128) = 0 'true/false values to array
LOOP UNTIL TIMER > t!' loop until one tick has passed

PX = x: PY = y ' previous coordinates
IF SC(75) = 1 THEN x = x - 5: IF x < 0 THEN x = 0
IF SC(77) = 1 THEN x = x + 5: IF x > 304 THEN x = 304
IF SC(72) = 1 THEN y = y - 5: IF y < 0 THEN y = 0
IF SC(80) = 1 THEN y = y + 5: IF y > 184 THEN y = 184
IF x <> PX OR y <> PY THEN ' look for a changed coordinate value
WAIT 936, 8: PUT(PX, PY), BG, PSET ' replace previous BG first
GET (x, y)-(x + 15, y + 15), BG ' GET BG at new position before box is set
PUT(x, y), Box, PSET ' PUT box image at new position
END IF
LOOP UNTIL SC(1) = 1 ' main loop until [Esc] key (scan code 1) is pressed



    
This message has been edited by burger2227 on Sep 6, 2011 12:17 PM
This message has been edited by burger2227 on Sep 6, 2011 12:12 PM
This message has been edited by burger2227 on Sep 6, 2011 12:10 PM
This message has been edited by burger2227 on Sep 6, 2011 12:10 PM

Posted on Sep 6, 2011, 12:04 PM

Respond to this message   

Return to Index


Response TitleAuthor and Date
Re: It works but CLS is killing it on Sep 6
 The function works. The drawing doesn'tClippy on Sep 6
  Re: The function works. The drawing doesn't on Sep 6
   Try using _DISPLAY at bottom of loop too! on Sep 6
    Re: Try using _DISPLAY at bottom of loop too! on Sep 7
     Use the code I posted above. on Sep 8
      Re: Use the code I posted above. on Sep 8
       No wonder! It was trying to zero out the function array every loop on Sep 8
        It works! on Sep 10
         Apparently on Sep 11
          Re: Apparently on Sep 11
    Re: Try using _DISPLAY at bottom of loop too! on Sep 7
    Re: Try using _DISPLAY at bottom of loop too! on Sep 7
    I also have a problem with another program on Sep 7
     Re: I also have a problem with another program on Sep 11
      Re: I also have a problem with another program on Sep 11
       well... on Sep 11
        Re: well... on Sep 11