
-----------------------------------
nightfeng2
Mon Jan 10, 2011 9:49 pm

mousewhere in a target shooting game
-----------------------------------


%By: Nightfeng2 
setscreen ("graphics:640;480,offscreenonly") 
var targetx, targety, Mx, My, button, CC : int 
var score := 0 
score := 0 
CC := 7 %crosshair color 
for count : 1 .. 50 
    randint (targetx, 50, 590) %%%targets x coor 
    randint (targety, 50, 430) %targets y coor 
    loop 

        put "Your score: ", score 
        %%%%the target 
        drawfilloval (targetx, targety, 50, 50, 12) 
        drawfilloval (targetx, targety, 35, 35, 31) 
        drawfilloval (targetx, targety, 20, 20, 12) 
        drawfilloval (targetx, targety, 5, 5, 31) 
        delay (10) 
        %%%crosshair 
        mousewhere (Mx, My, button) 
        drawoval (Mx, My, 100, 100, CC) 
        drawline (Mx, My, Mx, My + 100, CC) 
        drawline (Mx, My, Mx + 100, My, CC) 
        drawline (Mx, My, Mx - 100, My, CC) 
        drawline (Mx, My, Mx, My - 100, CC) 
        drawoval (Mx, My, 50, 50, CC) 
        drawfilloval (Mx, My, 3, 3, 4) 
        View.Update 
        cls 
        if Mx > targetx + 50 and button = 1 then 
            score -= 1 
        elsif Mx < targetx - 50 and button = 1 then 
            score -= 1 
        elsif My > targety + 50 and button = 1 then 
            score -= 1 
        elsif My < targety - 50 and button = 1 then 
            score -= 1 
        end if 
        exit when Mx = targetx - 50 and My = targety - 50 and button = 1 %end the loop if the cc hits inside the target 

    end loop 
    if Mx = targetx - 50 and My = targety - 50 and button = 1 then %if the cc hit the target, score+1 
        score += 1 

    end if 
end for 
put score 
 




if you tried the game, you will notice that when the mouse is clicked, the score will go crazy because of the button=1, which when the mouse is down the score will be changed. How can i fix this so that the mouse can only be checked once or something like that. thanks.

-----------------------------------
Tony
Mon Jan 10, 2011 9:53 pm

RE:mousewhere in a target shooting game
-----------------------------------
A mouse can have 4 states: held up, held down, clicked down, let go. Think about how you could figure out when the latter 2 events happen (as one can't hold transient states).

-----------------------------------
nightfeng2
Mon Jan 10, 2011 10:18 pm

Re: mousewhere in a target shooting game
-----------------------------------
hi Tony,
i dont get what you mean by four states, how do you change the states? is it like 0,1,2,3 - held down , , etc

-----------------------------------
Tony
Mon Jan 10, 2011 11:19 pm

RE:mousewhere in a target shooting game
-----------------------------------
You change the states by clicking on the mouse. [tdoc]Mouse.Where[/tdoc] will tell you if the button is currently up or down (2 states). If you think about it, you can figure out how to make it into 4 states, to include events such as clicks.

That is, if you can use only "up" and "down" for words, how would you describe that a click happened?

-----------------------------------
nightfeng2
Tue Jan 11, 2011 9:04 am

Re: mousewhere in a target shooting game
-----------------------------------
i think u need like button=1 and then equal to 0 or something like that? i just cant program it out =[

-----------------------------------
DemonWasp
Tue Jan 11, 2011 9:58 am

RE:mousewhere in a target shooting game
-----------------------------------
I have discussed what you're after, which is called "polling input", in [url=http://compsci.ca/v3/viewtopic.php?t=21727]Part 3 of my basic game programming tutorial. Read through that carefully, replacing the minesweeper bits with your program.

-----------------------------------
nightfeng2
Tue Jan 11, 2011 9:30 pm

RE:mousewhere in a target shooting game
-----------------------------------
hi demonwasp, i read your tutorial, however, i really dont understand how i should do it,i know what is the polling input but i dont know the code or the logic for it

-----------------------------------
Tony
Tue Jan 11, 2011 9:38 pm

Re: RE:mousewhere in a target shooting game
-----------------------------------
i dont know the code or the logic for it
You have all the needed tools to figure out and implement that, available in this thread.

-----------------------------------
nightfeng2
Tue Jan 11, 2011 10:26 pm

RE:mousewhere in a target shooting game
-----------------------------------
ahhhhh, my brains stuck, i really cant do it. can you explain???

-----------------------------------
Tony
Tue Jan 11, 2011 10:53 pm

RE:mousewhere in a target shooting game
-----------------------------------
You should be able to do it. I've looked at your code, you've used all the right elements before.

If you are still having problems, try asking very specific questions and post the relevant (not all) bits of code that you are working on.

-----------------------------------
nightfeng2
Wed Jan 12, 2011 9:50 pm

RE:mousewhere in a target shooting game
-----------------------------------
The problem is that i dont know how to make the mouse into 4 states, i only have 2 states which is held down and held up.

-----------------------------------
TerranceN
Wed Jan 12, 2011 10:12 pm

RE:mousewhere in a target shooting game
-----------------------------------
Think about the previous state of the mouse button compared to the state it is currently in.

-----------------------------------
nightfeng2
Wed Jan 12, 2011 10:28 pm

Re: mousewhere in a target shooting game
-----------------------------------
i tried buttonwait but then the crosshair will not be moving as the mouse move


%By: Nightfeng2
setscreen ("graphics:800;600,offscreenonly")
var targetx, targety, Mx, My, button, CC, score, bullets, timer, button2 : int
score := 0
bullets := 20
CC := 7 %crosshair color



    for count : 1 .. 50
        randint (targetx, 50, 750)     %%%targets x coor
        randint (targety, 50, 550)     %targets y coor
        loop

            put "Your score: ", score, " Bullets: ", bullets
            %%%%the target
            drawfilloval (targetx, targety, 50, 50, 12)
            drawfilloval (targetx, targety, 35, 35, 31)
            drawfilloval (targetx, targety, 20, 20, 12)
            drawfilloval (targetx, targety, 5, 5, 31)

            %%%crosshair
            buttonwait ("down", Mx, My, button, button2)
            drawoval (Mx, My, 100, 100, CC)
            drawline (Mx, My, Mx, My + 100, CC)
            drawline (Mx, My, Mx + 100, My, CC)
            drawline (Mx, My, Mx - 100, My, CC)
            drawline (Mx, My, Mx, My - 100, CC)
            drawoval (Mx, My, 50, 50, CC)
            drawfilloval (Mx, My, 3, 3, 4)
            View.Update
            cls
            if Mx > targetx + 50 and button = 1 then %this part: if the crosshair is out of the target and the button is clicked, bullet -1
                bullets -= 1
            elsif Mx < targetx - 50 and button = 1 then
                bullets -= 1
            elsif My > targety + 50 and button = 1 then
                bullets -= 1
            elsif My < targety - 50 and button = 1 then
                bullets -= 1
            end if
            exit when Mx = targetx - 50 and My = targety - 50 and button = 1     %end the loop if the cc hits inside the target

            exit when bullets 