Quote: "The problem is that I don't know what conditions I should check for in my IF statements."
I see. Here is a small program that demonstrates what I think you want. It is mainly the concept of zones to check so don't worry about how the circle moves. In order for you to understand it you will probably have to sit down with pen and paper to work out why I check for the bounds that I do check for. I have tried to comment it but they aren't the best explanations. Good luck
Rem ***** Main Source File *****
sync on : sync rate 60
// variables
global circlex as integer = 60
global circley as integer = 80
global circlexspeed as integer = 3
global circleyspeed as integer = 3
global radius as integer = 10
global collided as boolean = 0
// screen widths and heights
global sw as integer
sw = screen width()
global sh as integer
sh = screen height()
// main loop
do
// clear screen
cls
// functions
draw_big_box()
draw_small_box()
move_circle()
bounce_off_big_box()
bounce_off_small_box()
// draw circle
circle circlex, circley, radius
// screen fps
text 0, 0, str$(screen fps())
// update screen
sync
loop
// draw a large box
function draw_big_box()
line 20, 20, 20, sh - 20
line 20, 20, sw - 20, 20
line sw - 20, 20, sw - 20, sh - 20
line sw - 20, sh - 20, 20, sh - 20
endfunction
// draw a smaller box
function draw_small_box()
// left
line 150, 150, 150, sh - 150
// top
line 150, 150, sw - 150, 150
// right
line sw - 150, 150, sw - 150, sh - 150
// bottom
line sw - 150, sh - 150, 150, sh - 150
endfunction
// move circle function
function move_circle()
inc circlex, circlexspeed
inc circley, circleyspeed
endfunction
// bounce off big box
function bounce_off_big_box()
if circlex < 20 + radius then circlexspeed = circlexspeed * -1
if circlex > sw - 20 - radius then circlexspeed = circlexspeed * -1
if circley < 20 + radius then circleyspeed = circleyspeed * -1
if circley > sh - 20 - radius then circleyspeed = circleyspeed * -1
endfunction
// bounce off the small box
function bounce_off_small_box()
// top and bottom
// if the circle x position is in between the two vertical lines of the
// smaller box, then detect if it is coming from the top or the bottom
if circlex > 150 and circlex < sw - 150
// if circle is coming from the top hence:
// circley is too large (past bounds) but on top half of screen bounce
if circley + radius > 150 and circley < sh / 2
// if it hasn't already "collided" then allow direction change
if collided = 0
// change the direction, hence bounce
circleyspeed = circleyspeed * -1
collided = 1
endif
endif
// if circle is coming from the bottom of the screen hence:
// circley is too small but on bottom half of screen bounce
if circley - radius < sh - 150 and circley > sh / 2
// if it hasn't already "collided" then allow direction change
if collided = 0
// change direction
circleyspeed = circleyspeed * -1
collided = 1
endif
endif
endif
// same concept as explained above
// left and right
if circley > 150 and circley < sh - 150
// left
//if the circle x is large enough but on left side of screen, bounce in correct direction
if circlex + radius > 150 and circlex < sw / 2
// if it hasn't already "collided" then allow direction change
if collided = 0
circlexspeed = circlexspeed * -1
collided = 1
endif
endif
// if the circlex is small enought but on right side of the screen, bounce
if circlex - radius < sw - 150 and circlex > sw / 2
if collided = 0
circlexspeed = circlexspeed * -1
collided = 1
endif
endif
endif
// if the circle has left the zones for detection then allow collision
if circlex < 140 then collided = 0
if circlex > (sw - 150 + 10) then collided = 0
if circley < 140 then collided = 0
if circley > (sh - 150 + 10) then collided = 0
endfunction
Quote: "Sorry about bumping too soon as well."
Don't worry about it, I know how eager people can be to get an answer, especially when it is a show stopper problem like this.