Computer Science Canada How do I control 2 lines at same time? |
Author: | Rinaldi363 [ Sat Sep 24, 2005 10:56 am ] | ||
Post subject: | How do I control 2 lines at same time? | ||
I got a code so I can get two lines. But they wont move at the same time. Can anyone help me out?
|
Author: | Mr. T [ Sat Sep 24, 2005 12:57 pm ] |
Post subject: | Alex's Opinion |
I would say try forking two processes, but then I would get yelled at. ![]() So, there must be another way. ![]() |
Author: | Cervantes [ Sat Sep 24, 2005 5:45 pm ] | ||||
Post subject: | Re: Alex's Opinion | ||||
Pwned wrote: I would say try forking two processes, but then I would get yelled at.
![]() Yes, you would. ![]() Make your lines into pseudo-objects. I'm not talking about making a class for your lines, but rather create an array of records (or just a bunch of variables, if you know neither records nor arrays) to store information about the x and y position, and the x and y velocity. You could also store things like angle, length, colour, thickness, x and y acceleration, x and y jerk (change in acceleration over time), x and y jerk^2 (change in jerk over time)... Now, looking at your code, we need to clean things up. You don't want to have those loops inside your main loop. They are unnecessary and also the source of your trouble. So what do you do? Well, I'm not going to tell you the answer, because that defeats the purpose of learning. Rather, I'll give you a hint. What do you want to happen when you press the arrow key? You want the pseudo-object to move. There is no need to go into nested loops and check for input all over again. Just move it. On that note, only draw the dot once. Only delay once. Only View.Update once. Only cls once. Lastly, take a look at the way you exit your loops. There is no need for that variable, ex, ex2, etc. Instead, try this:
Better yet:
|
Author: | Rinaldi363 [ Sat Sep 24, 2005 8:28 pm ] |
Post subject: | |
Can you please jsut tell me the answer. I learn better when I see it then I kinda realize what it does and how to use it. Thanks |
Author: | Cervantes [ Sun Sep 25, 2005 7:45 am ] |
Post subject: | |
Rinaldi363 wrote: Can you please jsut tell me the answer. I learn better when I see it then I kinda realize what it does and how to use it.
No, for two reasons. First, you won't always have someone around to tell you the answer. You will, in many situations, have to do it yourself! Second, if you always rely on others telling you the answer, you will always be (at least) one step behind. You'll never make your own discoveries; never get recognition for things you've done. You need to learn to learn for yourself. Try it! It's not that difficult. ![]() |
Author: | codemage [ Mon Sep 26, 2005 11:29 am ] |
Post subject: | |
Just go through point by point. Your code is rife with redundancy. ...and I quote (codemage paraphrase version):... Quote: *Clean things up. Don't have loops inside your main loop. *On that note, only draw the dot once *Only delay once *Only View.Update once *Only cls once. *Look at the way you exit your loops - no need for an exit variable Start with that. |