Computer Science Canada How to make Turing sense that you have moved something to a certain position? |
Author: | Destro [ Mon Jan 13, 2014 8:19 pm ] | ||
Post subject: | How to make Turing sense that you have moved something to a certain position? | ||
What is it you are trying to achieve? When I move the ball to a certain position, I want to to 'sense' that and draw another line. What is the problem you are having? I have absolutely no idea what to use to achieve this. Describe what you have tried to solve this problem I tried using the if command. Post any relevant code (You may choose to attach the file instead of posting the code if it is too long) This is the section with the code, keep in mind that all variables have been previously stated. It is just a long program. If you need the whole thing, let me know.
Please specify what version of Turing you are using 4.1.1 Thanks guys! |
Author: | Raknarg [ Mon Jan 13, 2014 9:08 pm ] |
Post subject: | RE:How to make Turing sense that you have moved something to a certain position? |
You can have two variables. One keeps track of its old position, one keeps track of its new position. If the new position is different from the old one, then do something. |
Author: | Destro [ Tue Jan 14, 2014 11:19 am ] | ||
Post subject: | Re: How to make Turing sense that you have moved something to a certain position? | ||
Could you explain that further? I am new to Turing so I have no idea. I want it so that when I move the ball to the end of the line, it draws a new line. This is my full code:
|
Author: | Raknarg [ Tue Jan 14, 2014 11:33 am ] | ||
Post subject: | RE:How to make Turing sense that you have moved something to a certain position? | ||
Just a quick note, you can comment on everything if you want, but you don't need to comment on things that are self explanatory (or if your teacher really wants you to do it) Well let's look at your code. You have a main loop here. You can consider one iteration through the loop a frame. Each frame, you detect the user's key presses. If they press the right key, they move. You also have an x variable that keeps track of what the x position of the ball is. Let's think about two frames. What could happen between each frame? Sometimes the player will chose to move, sometimes not. Let'salso say you had another pair of x and y variables that remembered what the position of the ball was last time. We can compare what the position is now with the old ones, and do a little analysis. What happens if they're different? That means they moves. What happens if they're he same? it means they didn't move. You can do something different in each case. For instance, here's a quick program to show you how this might work:
see if you can analyze how this code works. If you need explanation, just ask. |
Author: | Raknarg [ Tue Jan 14, 2014 1:56 pm ] |
Post subject: | RE:How to make Turing sense that you have moved something to a certain position? |
Sorry, I realize I likely misread your intention. Are you saying that if the ball moves to, let's say, position 300,400 you want to do something at that moment? |
Author: | Destro [ Tue Jan 14, 2014 8:12 pm ] |
Post subject: | RE:How to make Turing sense that you have moved something to a certain position? |
Yeah, that's exactly what I want. |
Author: | Nathan4102 [ Tue Jan 14, 2014 8:26 pm ] | ||
Post subject: | RE:How to make Turing sense that you have moved something to a certain position? | ||
Somewhere in your main loop, assuming one loop is one frame, you need to have:
Replace the ... with your code you want happening when x is 300 and y is 400. |
Author: | Destro [ Tue Jan 14, 2014 8:27 pm ] |
Post subject: | RE:How to make Turing sense that you have moved something to a certain position? |
Do I need the Mouse.Where? My program has nothing to do with the mouse :( |
Author: | evildaddy911 [ Tue Jan 14, 2014 8:36 pm ] |
Post subject: | RE:How to make Turing sense that you have moved something to a certain position? |
no, the x and y coordinates should be replaced with whatever you are checking the location of |
Author: | Destro [ Tue Jan 14, 2014 8:44 pm ] |
Post subject: | RE:How to make Turing sense that you have moved something to a certain position? |
Alright, I made it work, by moving it out of the "if chars ('g') then" command. Thanks guys! However, I want it only to draw another line when you activate the game by pressing 'g'. By moving it out, it draws the line all the time. |
Author: | Nathan4102 [ Tue Jan 14, 2014 9:56 pm ] |
Post subject: | RE:How to make Turing sense that you have moved something to a certain position? |
Apologies, I was going off Raknargs post. Can you show us your new main loop? |