Computer Science Canada Duck Hunt in Turing |
Author: | FredB [ Mon Nov 07, 2016 10:31 am ] | ||
Post subject: | Duck Hunt in Turing | ||
What is it you are trying to achieve? I am trying to make a game similar to Duck Hunt, I do not need to add any graphics to it, I just need the base of the game. What is the problem you are having? I don't know how to make my target (a square bouncing around the screen) a button in order for it to act like the duck. I also don't know how to put in a crosshair and a bullet system. Describe what you have tried to solve this problem I have tried using previous coding lessons to try and solve my issue but I am seriously confused. Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Please specify what version of Turing you are using 4.1.1 |
Author: | lordroba [ Mon Nov 07, 2016 6:17 pm ] | ||
Post subject: | Re: Duck Hunt in Turing | ||
There's many ways you can go about this. You can have a stationary object shoot bullets at the duck, you can have a moving crosshair, or you can have a player that moves and shoots bullets. With the code below you can have a moving crosshair which is similar to what you would get with the NES duckhunt. With a little bit of extra code you can make it so that whenever you press the SPACE BAR for example, the gun fires. You just have to do some collision detection and see if the duck is hit. Just a matter of comparing the x and y coordinates of the crosshair to that of the duck and make sure they fall within a certain range.
|
Author: | FredB [ Tue Nov 08, 2016 1:55 pm ] | ||
Post subject: | Re: Duck Hunt in Turing | ||
Hello again, I have played around a bit with the code you have posted and ended up turning the crosshair to move with my mouse instead, and I had turned in into something else. I think all I have left to do is add a bullet system, make it so my target is a button, and figure out how to increase the difficulty. I have an idea for each but I am not sure on how to proceed with it. I would like to : Turn the target into a button. Learn how to determine whether or not the target was hit or not. Have a scoring system that can be used to determine difficulty. (ie : if score reaches a certain level, have a higher value for xdir and/or ydir. Have a randint that changes the xdir and ydir values to increase difficulty, rather than playing wtih the delay. Thank you again in advance.
|
Author: | Insectoid [ Wed Nov 09, 2016 8:49 am ] |
Post subject: | RE:Duck Hunt in Turing |
Quote: Turn the target into a button.
Learn how to determine whether or not the target was hit or not. What is a button, but a target that's been hit by the mouse? The code for these to things are exactly the same. All you're doing is comparing two sets of coordinates to see if they intersect or collide. There are many collision detection tutorials on this site. Quote: Have a scoring system that can be used to determine difficulty. (ie : if score reaches a certain level, have a higher value for xdir and/or ydir.
You might want to refine your bird's movement system or this will be a pain in the ass. Right now you control speed and direction by manipulating vertical and horizontal velocity. That makes it really, really hard to find the speed and direction you want. Better to have speed and direction variables and then use your grade 10 trig to calculate your vertical and horizontal velocities. Now increasing the difficulty is easy, just increase the speed. |
Author: | FredB [ Thu Nov 10, 2016 12:08 pm ] | ||
Post subject: | Re: Duck Hunt in Turing | ||
I tried to have this for collision detection just as a start but I'm seriously lost. Even when I click absolutely nothing happens.. |
Author: | TipsyCzar [ Thu Nov 10, 2016 12:27 pm ] |
Post subject: | Re: Duck Hunt in Turing |
I don't think you need the (exit when) line of code. You could replace it with this : if x >= xpos and x <= (xpos + 35) and y >= ypos and y <= (ypos + 35) and b = 1 then put "You hit the target!" exit else put "Try again!" end if |
Author: | Insectoid [ Fri Nov 11, 2016 8:52 am ] |
Post subject: | RE:Duck Hunt in Turing |
That code snippet looks fine to me, so if it's doing nothing, then it's not even running. Can you think of a reason this code might never be executed? |
Author: | FredB [ Fri Nov 11, 2016 10:27 am ] | ||
Post subject: | Re: Duck Hunt in Turing | ||
So I've made it so if I hit the target, the program ends and the message displays that you have hit the target, which is a good step forward. For now I just need to figure out how to make it loop and add a scaling difficulty system and bullets. And also making it display the message if you miss would be good as well.
|