08-19-2025, 11:27 PM
My goal in this program I am attempting to write is to tally up how much time the ball spends inside of the square area I have set aside in the screen. I thought I would be able to subtract the time it exited from the time it entered the square to get the time spent inside. But it seems that the constant update of the variable being used to hold result of the 'TIMER' command into is constantly updating due to the loop, so I can't seem to figure out how to get a single value for the time the circle's center actually crossed into the green square. I was thinking something like endTime! - beginTime! would give me the number of seconds that the circle spent in the square.
Code: (Select All)
CONST BALLRADIUS = 30
DIM ballx! 'ball x coordinate
DIM bally! 'ball y coordinate
DIM ballvecx! 'ball x vector
DIM ballvecy! 'ball y vector
SCREEN _NEWIMAGE(400, 400, 32)
ballx! = 50
bally! = 50
ballvecx! = .25
ballvecy! = .50
DO
_LIMIT 60
CLS
LINE (100, 300)-(300, 100), _RGB32(0, 300, 0), BF
ballx! = ballx! + ballvecx!
bally! = bally! + ballvecy!
IF ballx! > 370 OR ballx! < 30 THEN
ballvecx! = -ballvecx!
END IF
IF bally! > 370 OR bally! < 30 THEN
ballvecy! = -ballvecy!
END IF
IF bally! > 100 AND bally! < 300 AND ballx! > 100 AND ballx! < 300 THEN
PRINT TIMER
END IF
CIRCLE (ballx!, bally!), BALLRADIUS
PAINT (ballx!, bally!), _RGB32(255, 255, 255)
_DISPLAY
LOOP UNTIL _KEYDOWN(27)
SYSTEM

