Computer Science Canada button problem |
Author: | nin [ Fri Dec 29, 2006 5:31 pm ] |
Post subject: | button problem |
hey can you people help me please. The program that i did below is suppose to tell the user the color of the circle that they click, but when i clicked it, it didnt work at all.. 0.o? so can anyone help me please and thank you soo much =) ------------------------------------------------------------------------------------- %Declaration section var finished : boolean := false var rangex, rangey, button : int %set screen mode and size setscreen ("graphics:300;300") %Program Title procedure title cls locate (1, 16) put "Colours" end title %Program introduction procedure introduction title locate (3, 1) put "Click a circle." locate (5, 1) put "If you want to exit, click exit." end introduction procedure display %circles drawfilloval (50, 150, 30, 30, 100) drawfilloval (150, 150, 30, 30, yellow) drawfilloval (250, 150, 30, 30, 29) mousewhere (rangex, rangey, button) if button = 1 then if rangex >= 50 and rangex <= 30 and rangey >= 50 and rangey <= 30 then locate (16, 1) put "Light blue" finished := true else locate (10, 1) put "You clicked at: ", rangex, " ", rangey end if end if end display %Main Program introduction loop display exit when finished end loop %End program |
Author: | CodeMonkey2000 [ Fri Dec 29, 2006 5:53 pm ] | ||||||
Post subject: | |||||||
Ok first you need to figure out the distance betwen two point you can do that with:
Next you need to know the radius of the circle. to do that you can do:
Next you check if the distance from where your mouse is reletive to the mid point of the circle is less than or equal to the circle's radius. Do that with:
|
Author: | CodeMonkey2000 [ Fri Dec 29, 2006 5:58 pm ] | ||||
Post subject: | |||||
spearmonkey2000 wrote:
ok thats wrong, (i cant edit my posts for some reason :S) anyway it should be:
|
Author: | nin [ Sat Dec 30, 2006 5:16 pm ] |
Post subject: | |
i dont get it 0.o? when the button was square we used this: procedure display %draw a red box on the screen drawfillbox (100, 100, 200, 200, red) mousewhere (rangex, rangey, button) if button = 1 then if rangex >= 100 and rangex <= 200 and rangey >= 100 and rangey <= 200 then locate (16, 1) put "Wow-you clicked in the box." finished := true else locate (10, 1) put "You clicked at: ", rangex, " ", rangey end if end if ------------------------------------------------------------------------------------- as a code.... but wen we use circles as a button we use a whole new different code 0.o? |
Author: | CodeMonkey2000 [ Sat Dec 30, 2006 9:21 pm ] |
Post subject: | |
Then you need to first understand how a retangular collision works and how it is different from a circular detecion. |
Author: | nin [ Sun Dec 31, 2006 2:04 pm ] |
Post subject: | |
actually nvm i understand it now .. tnx anyway =) |