Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 mousewhere in a target shooting game
Index -> Programming, Turing -> Turing Help
Goto page 1, 2, 3  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
nightfeng2




PostPosted: Mon Jan 10, 2011 9:49 pm   Post subject: mousewhere in a target shooting game

Turing:


%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 Mx >= targetx - 50 and My <= targety + 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 Mx >= targetx - 50 and My <= targety + 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.
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Mon Jan 10, 2011 9:53 pm   Post subject: 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).
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
nightfeng2




PostPosted: Mon Jan 10, 2011 10:18 pm   Post subject: 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




PostPosted: Mon Jan 10, 2011 11:19 pm   Post subject: RE:mousewhere in a target shooting game

You change the states by clicking on the mouse. Mouse.Where 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?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
nightfeng2




PostPosted: Tue Jan 11, 2011 9:04 am   Post subject: 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




PostPosted: Tue Jan 11, 2011 9:58 am   Post subject: RE:mousewhere in a target shooting game

I have discussed what you're after, which is called "polling input", in Part 3 of my basic game programming tutorial. Read through that carefully, replacing the minesweeper bits with your program.
nightfeng2




PostPosted: Tue Jan 11, 2011 9:30 pm   Post subject: 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




PostPosted: Tue Jan 11, 2011 9:38 pm   Post subject: Re: RE:mousewhere in a target shooting game

nightfeng2 @ Tue Jan 11, 2011 9:30 pm wrote:
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.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Sponsor
Sponsor
Sponsor
sponsor
nightfeng2




PostPosted: Tue Jan 11, 2011 10:26 pm   Post subject: RE:mousewhere in a target shooting game

ahhhhh, my brains stuck, i really cant do it. can you explain???
Tony




PostPosted: Tue Jan 11, 2011 10:53 pm   Post subject: 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.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
nightfeng2




PostPosted: Wed Jan 12, 2011 9:50 pm   Post subject: 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




PostPosted: Wed Jan 12, 2011 10:12 pm   Post subject: 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




PostPosted: Wed Jan 12, 2011 10:28 pm   Post subject: Re: mousewhere in a target shooting game

i tried buttonwait but then the crosshair will not be moving as the mouse move

Turing:

%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 Mx >= targetx - 50 and My <= targety + 50 and My >= targety - 50 and button = 1     %end the loop if the cc hits inside the target

            exit when bullets <= 0
        end loop
        if Mx <= targetx + 50 and Mx >= targetx - 50 and My <= targety + 50 and My >= targety - 50 and button = 1 then     %if the cc hit the target, score+1
            score += 1
            bullets -= 1
            exit when bullets <= 0
        end if
        exit when bullets <= 0
    end for
    put "Your final score is: ", score



it really doesnt work that well, i still want mousewhere to work. and the projects due very soon =S really need help.
Tony




PostPosted: Wed Jan 12, 2011 10:38 pm   Post subject: RE:mousewhere in a target shooting game

try harder. Mouse.ButtonWait
Quote:

If there isn't such an event, Mouse.ButtonWait waits until there is one and then returns (much like getch handles keystrokes).

It is doing _exactly_ what it says it should be doing.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
nightfeng2




PostPosted: Wed Jan 12, 2011 11:24 pm   Post subject: Re: mousewhere in a target shooting game

Turing:

%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
            Mouse.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
                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 Mx >= targetx - 50 and My <= targety + 50 and My >= targety - 50 and button = 1     %end the loop if the cc hits inside the target

            exit when bullets <= 0
        end loop
        if Mx <= targetx + 50 and Mx >= targetx - 50 and My <= targety + 50 and My >= targety - 50 and button = 1 then     %if the cc hit the target, score+1
            score += 1
            bullets -= 1
            exit when bullets <= 0
        end if
        exit when bullets <= 0
    end for
    put "Your final score is: ", score


this does the same thing, ill try something tomorrow and see if it works
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 3  [ 33 Posts ]
Goto page 1, 2, 3  Next
Jump to:   


Style:  
Search: