Computer Science Canada Problem getting two obstacles being drawn on the same spot regardless of a for loop. |
Author: | AustinRF [ Thu Jan 16, 2014 7:31 pm ] | ||
Post subject: | Problem getting two obstacles being drawn on the same spot regardless of a for loop. | ||
What is it you are trying to achieve? To make a game for my Grade 11 Computer Science course. As you can see, there is a loop drawing a line every time another line is 1/6th down the screen. the problem is the first line is drawing where the second one is as well. What is the problem you are having? Two obstacles are drawing on one spot regardless of the for loop "limiting" it to two separate ones. Describe what you have tried to solve this problem I've gone through my code trying to find my error and it seems I need a new persective on things. 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 Latest Version. |
Author: | Dreadnought [ Thu Jan 16, 2014 9:18 pm ] | ||||
Post subject: | Re: Problem getting two obstacles being drawn on the same spot regardless of a for loop. | ||||
From this we can see that firstLineY is never bigger than 480.
What is the value of (480 div 6) * i when i = 6 ? What does this mean about blacklines(1) and blacklines(6)? |
Author: | AustinRF [ Thu Jan 16, 2014 9:31 pm ] |
Post subject: | Re: Problem getting two obstacles being drawn on the same spot regardless of a for loop. |
well, they will equal 80, and 480. What I don't get is how to fix it. |
Author: | Zren [ Thu Jan 16, 2014 9:51 pm ] | ||
Post subject: | RE:Problem getting two obstacles being drawn on the same spot regardless of a for loop. | ||
Not terribly related to your problems but:
What happens if blacklines (i).y ends up negative? The "spawning" code won't execute. Try using y <= 0 in case y steps over the value of 0. |
Author: | Dreadnought [ Thu Jan 16, 2014 10:22 pm ] |
Post subject: | Re: Problem getting two obstacles being drawn on the same spot regardless of a for loop. |
AustinRF wrote: well, they will equal 80, and 480. What I don't get is how to fix it. If you print out the values of blacklines(1).y and blacklines(6).y you'll find that they always differ by 3 (except possibly when one is at the top and thee other at the bottom). Why might that be? What if you try to think about when blacklines(1).exists is true. What about blacklines(6).exists? |
Author: | AustinRF [ Fri Jan 17, 2014 2:08 pm ] |
Post subject: | Re: Problem getting two obstacles being drawn on the same spot regardless of a for loop. |
Dreadnought @ Thu Jan 16, 2014 10:22 pm wrote: AustinRF wrote: well, they will equal 80, and 480. What I don't get is how to fix it. If you print out the values of blacklines(1).y and blacklines(6).y you'll find that they always differ by 3 (except possibly when one is at the top and thee other at the bottom). Why might that be? What if you try to think about when blacklines(1).exists is true. What about blacklines(6).exists? Hm.. The problem is they are drawing only 3 pixels apart? Any idea how to fix it? |
Author: | Dreadnought [ Fri Jan 17, 2014 10:04 pm ] | ||
Post subject: | Re: Problem getting two obstacles being drawn on the same spot regardless of a for loop. | ||
Well I would rather you figured it out on your own, but I'll try to point you toward the problem. So you begin with all your lines at y = 480. You start lines moving according to this (except for the first line which starts in motion).
Notice that (480 div 6) * 6 is 480. Since your first line starts at 480 what happens to your sixth line? From here it isn't hard to figure out when each line starts moving. Which line is the last one to start moving? Maybe this could give you a hint of how you could change things. |