Computer Science Canada mousewhere in a target shooting game |
Author: | nightfeng2 [ Mon Jan 10, 2011 9:49 pm ] | ||
Post subject: | mousewhere in a target shooting game | ||
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. |
Author: | Tony [ 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). |
Author: | nightfeng2 [ 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 |
Author: | Tony [ 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? |
Author: | nightfeng2 [ 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 =[ |
Author: | DemonWasp [ 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. |
Author: | nightfeng2 [ 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 |
Author: | Tony [ 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. |
Author: | nightfeng2 [ 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??? |
Author: | Tony [ 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. |
Author: | nightfeng2 [ 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. |
Author: | TerranceN [ 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. |
Author: | nightfeng2 [ 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
it really doesnt work that well, i still want mousewhere to work. and the projects due very soon =S really need help. |
Author: | Tony [ 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. |
Author: | nightfeng2 [ Wed Jan 12, 2011 11:24 pm ] | ||
Post subject: | Re: mousewhere in a target shooting game | ||
this does the same thing, ill try something tomorrow and see if it works |
Author: | TheGuardian001 [ Thu Jan 13, 2011 8:06 am ] |
Post subject: | Re: mousewhere in a target shooting game |
Mouse.ButtonWait and buttonwait are the same command. The point Tony was making is that that command waits until there is input before continuing. When your program gets to that line, it waits until it sees the "down" event before continuing. You need a different command. |
Author: | nightfeng2 [ Thu Jan 13, 2011 8:47 am ] |
Post subject: | RE:mousewhere in a target shooting game |
ive tried mousewhere but its not working properly |
Author: | nightfeng2 [ Thu Jan 13, 2011 2:59 pm ] |
Post subject: | RE:mousewhere in a target shooting game |
Maybe i'll delete this function in the game if it still doesn't work |
Author: | Tony [ Thu Jan 13, 2011 3:06 pm ] |
Post subject: | Re: RE:mousewhere in a target shooting game |
nightfeng2 @ Thu Jan 13, 2011 8:47 am wrote: ive tried mousewhere but its not working properly
I am fairly certain that the command is working exactly as it's expected to work |
Author: | nightfeng2 [ Thu Jan 13, 2011 3:59 pm ] |
Post subject: | RE:mousewhere in a target shooting game |
ok maybe the command itself is working properly but its not wat i want it to be. The one i want is like down-buttonwait, but then the whole program will wait until mouse is clicked, so i really dont know wat to do. |
Author: | TerranceN [ Thu Jan 13, 2011 4:30 pm ] | ||
Post subject: | Re: mousewhere in a target shooting game | ||
Look at the following table,
Now try to match these descriptions to each row -mouse is being held down -mouse has just been released -mouse has just been pressed -mouse is not being pressed |
Author: | nightfeng2 [ Thu Jan 13, 2011 5:10 pm ] |
Post subject: | RE:mousewhere in a target shooting game |
-mouse is being held down 1 1 -mouse has just been released 0 1 -mouse has just been pressed 1 0 -mouse is not being pressed 0 0 |
Author: | TerranceN [ Thu Jan 13, 2011 5:19 pm ] |
Post subject: | RE:mousewhere in a target shooting game |
Ok, since you want to register a click when the mouse is just pressed, before you call Mouse.Where, store the previous mouse button value. Then just change your if statement to make sure the mouse button is down now, but was not last frame. |
Author: | nightfeng2 [ Thu Jan 13, 2011 10:04 pm ] |
Post subject: | RE:mousewhere in a target shooting game |
Sounds so complicated, i want to try what you are saying, but what do you mean by store the previous mouse button value before calling mousewhere. Can you gimme an example of that ? |
Author: | Tony [ Thu Jan 13, 2011 10:09 pm ] |
Post subject: | Re: RE:mousewhere in a target shooting game |
nightfeng2 @ Thu Jan 13, 2011 10:04 pm wrote: store ... value
usually suggests that you might want to use some variable. |
Author: | nightfeng2 [ Thu Jan 13, 2011 10:16 pm ] |
Post subject: | RE:mousewhere in a target shooting game |
The previous button value should be 0 since the mouse is not pressed, that means I store 0 into a variable. If this part is right, the next part is giving me a headache cause i really dont understand it. |
Author: | Tony [ Thu Jan 13, 2011 10:25 pm ] |
Post subject: | RE:mousewhere in a target shooting game |
Not quite. You can only know what the value of the mouse is _right now_. For it to become a previous value, you would have to wait some time. |
Author: | nightfeng2 [ Thu Jan 13, 2011 10:33 pm ] |
Post subject: | RE:mousewhere in a target shooting game |
ah, here comes the complicated stuff xD |
Author: | nightfeng2 [ Thu Jan 13, 2011 11:13 pm ] |
Post subject: | RE:mousewhere in a target shooting game |
instead of the bullet system and -1 score, ill change it to a timer instead. |
Author: | Tony [ Thu Jan 13, 2011 11:23 pm ] | ||
Post subject: | RE:mousewhere in a target shooting game | ||
You could do better than that, come on: You have a loop, it looks something like this
And it has two variables we've already discussed: mouse_now and mouse_previous. They had some values. Going forward, you know that you want mouse_now to be... what it is now. And you want mouse_previous to remember what happened in the previous loop. How do you make this happen? |
Author: | nightfeng2 [ Fri Jan 14, 2011 9:25 am ] | ||
Post subject: | Re: mousewhere in a target shooting game | ||
this is what i can do right now, im sure u what you mean is different from me. giving an example of code would really help. thx |
Author: | Tony [ Fri Jan 14, 2011 1:08 pm ] |
Post subject: | Re: mousewhere in a target shooting game |
nightfeng2 @ Fri Jan 14, 2011 9:25 am wrote: if button = 1 then button2 := button This part will guarantees that both button and button2 will always be the same when you exit the loop. Read your if statements out-loud to make sure they make sense to you: "if button is 1 then assign value of button (1) to button2". |
Author: | nightfeng2 [ Fri Jan 14, 2011 7:15 pm ] |
Post subject: | RE:mousewhere in a target shooting game |
i changed the game to timer system, its not bad actually, ill try the bullet system again after the assignment cuz its due very soon |