| How do I control 2 lines at same time? 
 
	 
	
		| Author | Message |   
		| Rinaldi363 
 
 
 
 
 | 
			
				|  Posted: 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? 
 
 	  | code: |  	  | var ex : int
var x, y, ex2 : int
 var x2, y2, ex3 : int
 x := 480
 y := 200
 x2 := 160
 y2 := 200
 var chars : array char of boolean
 ex := 0
 colorback (black)
 color (white)
 cls
 put "To start playing press ENTER."
 loop
 Input.KeyDown (chars)
 if chars (KEY_ENTER) then
 ex := 1
 end if
 exit when ex = 1
 end loop
 cls
 
 loop
 Input.KeyDown (chars)
 
 %Player 1 Controls
 if chars ('8') then
 loop
 drawdot (x, y, red)
 y := y + 1
 delay (10)
 Input.KeyDown (chars)
 if chars ('2') then
 ex2 := 1
 elsif chars ('6') then
 ex2 := 1
 elsif chars ('4') then
 ex2 := 1
 end if
 exit when ex2 = 1
 end loop
 
 
 elsif chars ('6') then
 loop
 drawdot (x, y, red)
 x := x + 1
 delay (10)
 Input.KeyDown (chars)
 if chars ('2') then
 ex2 := 1
 elsif chars ('8') then
 ex2 := 1
 elsif chars ('4') then
 ex2 := 1
 end if
 exit when ex2 = 1
 end loop
 
 
 elsif chars ('2') then
 loop
 drawdot (x, y, red)
 y := y - 1
 delay (10)
 Input.KeyDown (chars)
 if chars ('6') then
 ex2 := 1
 elsif chars ('8') then
 ex2 := 1
 elsif chars ('4') then
 ex2 := 1
 end if
 exit when ex2 = 1
 end loop
 
 
 elsif chars ('4') then
 loop
 drawdot (x, y, red)
 x := x - 1
 delay (10)
 Input.KeyDown (chars)
 if chars ('2') then
 ex2 := 1
 elsif chars ('8') then
 ex2 := 1
 elsif chars ('6') then
 ex2 := 1
 end if
 exit when ex2 = 1
 end loop
 end if
 ex2 := 0
 
 
 %Player 2 Controls
 
 
 if chars ('w') then
 loop
 drawdot (x2, y2, green)
 y2 := y2 + 1
 delay(10)
 Input.KeyDown (chars)
 if chars ('d') then
 ex3 := 1
 elsif chars ('s') then
 ex3 := 1
 elsif chars ('a') then
 ex3 := 1
 end if
 exit when ex3 = 1
 end loop
 
 
 elsif chars ('d') then
 loop
 drawdot (x2, y2, green)
 x2 := x2 + 1
 delay (10)
 Input.KeyDown (chars)
 if chars ('w') then
 ex3 := 1
 elsif chars ('a') then
 ex3 := 1
 elsif chars ('s') then
 ex3 := 1
 end if
 exit when ex3 = 1
 end loop
 
 
 elsif chars ('s') then
 loop
 drawdot (x2, y2, green)
 y2 := y2 - 1
 delay (10)
 Input.KeyDown (chars)
 if chars ('d') then
 ex3 := 1
 elsif chars ('a') then
 ex3 := 1
 elsif chars ('w') then
 ex3 := 1
 end if
 exit when ex3 = 1
 end loop
 
 
 elsif chars ('a') then
 loop
 drawdot (x2, y2, green)
 x2 := x2 - 1
 delay (10)
 Input.KeyDown (chars)
 if chars ('w') then
 ex3 := 1
 elsif chars ('d') then
 ex3 := 1
 elsif chars ('s') then
 ex3 := 1
 end if
 exit when ex3 = 1
 end loop
 
 
 end if
 ex3 := 0
 end loop
 
 | 
 |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| Sponsor Sponsor
 
  
   |  |   
		|  |   
		| Mr. T 
 
  
 
 
 | 
			
				|  Posted: 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.
  |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| Cervantes 
 
  
 
 
 | 
			
				|  Posted: 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:
 
 
 	  | Turing: |  	  | 
loop
    Input.KeyDown (chars)
    if  chars ( KEY_ENTER) then
        exit
    end if
end loop | 
 Better yet:
 
 |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| Rinaldi363 
 
 
 
 
 | 
			
				|  Posted: Sat Sep 24, 2005 8:28 pm    Post subject: (No 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
 |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| Cervantes 
 
  
 
 
 | 
			
				|  Posted: Sun Sep 25, 2005 7:45 am    Post subject: (No 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.
  |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| codemage 
 
  
 
 
 | 
			
				|  Posted: Mon Sep 26, 2005 11:29 am    Post subject: (No 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.
 |  
				|  |  |   
		|  |  |  
	  
		|  |   
		|  |  
 |