button problem
Author |
Message |
nin
|
Posted: 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 |
|
|
|
|
|
Sponsor Sponsor
|
|
|
CodeMonkey2000
|
Posted: Fri Dec 29, 2006 5:53 pm Post subject: (No subject) |
|
|
Ok first you need to figure out the distance betwen two point you can do that with:
code: | fcn Distance (x, y, x2, y2 : int) : real
result sqrt ((x2 - x) ** 2 + (y2 - y) ** 2)
end Distance |
Next you need to know the radius of the circle. to do that you can do:
code: | Radius := Distance (50, 150, 30 + 50, 30 + 150) | where 50, 150 is the mid point of your circle, and 30 + 50, 30 + 150 is the end point.
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: code: | if Distance (rangex, rangey, 50, 150) < Radius then
locate (16, 1)
put "Light blue"
else |
|
|
|
|
|
|
CodeMonkey2000
|
Posted: Fri Dec 29, 2006 5:58 pm Post subject: (No subject) |
|
|
spearmonkey2000 wrote:
code: | Radius := Distance (50, 150, 30 + 50, 30 +150) |
ok thats wrong, (i cant edit my posts for some reason :S) anyway it should be: code: | Radius := Distance (50, 150, 30 + 50, 150) |
|
|
|
|
|
|
nin
|
Posted: Sat Dec 30, 2006 5:16 pm Post subject: (No 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? |
|
|
|
|
|
CodeMonkey2000
|
Posted: Sat Dec 30, 2006 9:21 pm Post subject: (No subject) |
|
|
Then you need to first understand how a retangular collision works and how it is different from a circular detecion. |
|
|
|
|
|
nin
|
Posted: Sun Dec 31, 2006 2:04 pm Post subject: (No subject) |
|
|
actually nvm i understand it now .. tnx anyway =) |
|
|
|
|
|
|
|