
-----------------------------------
MichaelM
Sun Aug 05, 2007 11:10 am

Mouse Question
-----------------------------------
Im making a game where you click of boxes that do things depending on their colours etc... However im not sure what I should be using for the mouse. I tried Mouse.Where but I dont know the parameters, any help?!?

--edit--

okay, no answer yet, but i tried out the Mouse.Where and experimented with whatdotcolour. test it out, for now it just puts out 12 random boxes, blue or orange. to test the mouse, it'll say if the box is blue or orange, but shouldn't it only check when the mouse has been clicked? Also, is there a way to prevent the error of "oustside clipping range" ? Another question, i put GUI stuff at the start and end, is that necessary for Mouse.Where? heres the code...



import GUI in "%oot/lib/GUI"
setscreen("graphics:800;600")
procedure boxblue(x,y:int)
    drawfillbox(x,y,x+50,y+50,9)
    drawbox(x,y,x+50,y+50,black)
    drawbox(x+1,y+1,x+49,y+49,55)
    drawbox(x+2,y+2,x+48,y+48,55)
    drawbox(x+3,y+3,x+47,y+47,55)
end boxblue

procedure boxorange(x,y:int)
    drawfillbox(x,y,x+50,y+50,42)
    drawbox(x,y,x+50,y+50,black)
    drawbox(x+1,y+1,x+49,y+49,43)
    drawbox(x+2,y+2,x+48,y+48,43)
    drawbox(x+3,y+3,x+47,y+47,43)
end boxorange

procedure boxerase(x,y:int)
    drawfillbox(x,y,x+50,y+50,white)
end boxerase

var xposition:int:=0
var difficulty:int:=1
var boxcolour:int

for z:1..12
    if difficulty=1 then
        randint(boxcolour,1,2)
        if boxcolour=1 then
            boxblue(xposition,50)
        elsif boxcolour=2 then
            boxorange(xposition,50)
        end if
        xposition:=xposition+50
    elsif difficulty=2 then
    elsif difficulty=3 then
    end if
end for

var x,y,c:int
loop
Mouse.Where(x,y,c)
    if whatdotcolour(x,y)=9 then
        locatexy(0,500)
        put "it is blue"
    elsif whatdotcolour(x,y)=42 then
        locatexy(0,500)
        put "it is orange"
    end if
end loop

loop
    exit when GUI.ProcessEvent
end loop  


-----------------------------------
Aziz
Mon Aug 06, 2007 10:13 am

RE:Mouse Question
-----------------------------------
First off, no you don't need the GUI module. You don't use anything from the GUI module (GUI.something).

Second, check out some of these tutorials:

http://www.compsci.ca/v2/viewtopic.php?t=3275
http://www.compsci.ca/v2/viewtopic.php?t=6

This code is correct:

var x,y,c:int
loop
Mouse.Where(x,y,c)
    if whatdotcolour(x,y)=9 then
        locatexy(0,500)
        put "it is blue"
    elsif whatdotcolour(x,y)=42 then
        locatexy(0,500)
        put "it is orange"
    end if
end loop

That is a simple loop. You could replace the whatdotcolour check with check to the boundaries of the box. Say the box is at (10,10) to (30, 30). The check would be:

if x >= 10 and x = 10 and y 