Posted: 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
endloop if Mx <= targetx + 50and Mx >= targetx - 50and My <= targety + 50and My >= targety - 50and button =1then%if the cc hit the target, score+1
score +=1
endif endfor 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
Tony
Posted: 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).
Posted: 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
Posted: 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?
Posted: 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
Posted: 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
Posted: 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
Posted: 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.