Moving and Shooting at the same time 
	 
	
		| Author | 
		Message | 
	 
		 
		TheBboy
 
 
 
    
		 | 
		
		
			
				  Posted: Fri Dec 14, 2012 11:30 pm    Post subject: Moving and Shooting at the same time  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				What is it you are trying to achieve?
 
I am try move the object and shoot another object at the same time.
 
 
What is the problem you are having?
 
If I don't press the shooting object first it would not work anymore. If I press it first it would work but then it would respond to any key, I want it so it would only respond to spacebar.
 
 
Describe what you have tried to solve this problem
 
I tired to look around the site for this solution could not find it.
 
 
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
 
 
	  | Turing: | 	 		  
%Moving Objects
var move  : string (1) %input
var x, y, x1, y1  : int %object
x  := 30
y  := 30
process user
     loop
        drawline (0,  20,  640,  20,  black) %surface
        drawfilloval (x, y,  10,  10,  black) %object
        getch (move )
        if move  = chr (205) then % moving right
            drawfilloval (x, y,  10,  10,  white) %object disapear
            x  := x +  5
            drawfilloval (x, y,  10,  10,  black) %object returns
        end if
        if move  = chr (203) then % moving left
            drawfilloval (x, y,  10,  10,  white) %object disapear
            x  := x -  5
            drawfilloval (x, y,  10,  10,  black) %object returns
        end if
        if (x <  0) then %blocking the outside
            x  := x +  20
        end if
    end loop
end user
 %Shooting
var move1  : string (1)
var x2, y2  : int
x2  := 20
y2  := 50
process shoot
     loop% I think the problem starts from here (1)
        drawfilloval (x2, y2,  5,  5,  purple)
        getch (move1 )
        if move1  = chr (32) then
            loop
                delay (20)
                drawfilloval (x2, y2,  5,  5,  white)
                x2  := x2 +  10
                drawfilloval (x2, y2,  5,  5,  purple)
                if x2 >  640 then
                    x2  := 20
                    y2  := 40
                    drawfilloval (x2, y2,  5,  5,  purple)
                    getch (move1 )%Till Here(1)
                end if
            end loop
        end if
    end loop
end shoot
 fork user
 fork shoot
   | 	  
 
 
Please specify what version of Turing you are using
 
4.1.1 | 
			 
			
				 | 
			 
		  | 
	 
	 
		 | 
		
		 | 
	 
	  
		  | 
	 
		 
		Sponsor Sponsor 
		 
  
		 | 
		
 | 
	 
	 
		  | 
	 
				 
		Insectoid
 
  
 
    
		 | 
		
		
			
				  Posted: Sat Dec 15, 2012 10:03 am    Post subject: RE:Moving and Shooting at the same time  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				I'm sorry to tell you this, but you're going to have to completely restructure your program to make this work correctly. However, once you do that, all your future animations will be much easier and look much better.
 
 
 
You should not be using processes for animations. That's your problem. Instead of doing one complete animation per process, you need to every animation in one procedure. It should look something like this:
 
 
	  | Turing: | 	 		  
 
procedure animate
 
    loop
 
        %get input (look up Input.KeyDown)
 
        %move character 1 frame forward
 
        %if a bullet was fired, create a new bullet
 
        %if a bullet exists, move that bullet 1 frame forward (apply to all bullets that exist)
 
        %draw everything
 
    end loop
 
end animate
 
  | 	 
  | 
			 
			
				 | 
			 
		  | 
	 
	 
		 | 
		
		 | 
	 
	  
		  | 
	 
				 
		TheBboy
 
 
 
    
		 | 
		
		
			
				  Posted: Sun Dec 16, 2012 4:25 am    Post subject: Re: Moving and Shooting at the same time  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				| Is it possible to do it without boolean logic(by the way I am new to turing). What statements should I use? | 
			 
			
				 | 
			 
		  | 
	 
	 
		 | 
		
		 | 
	 
	  
		  | 
	 
				 
		Insectoid
 
  
 
    
		 | 
		
		
			
				  Posted: Sun Dec 16, 2012 10:06 am    Post subject: RE:Moving and Shooting at the same time  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				| Of course you need boolean logic. There's not much you can do without it. Why would you want to avoid it? | 
			 
			
				 | 
			 
		  | 
	 
	 
		 | 
		
		 | 
	 
	  
		  | 
	 
				 
		TheBboy
 
 
 
    
		 | 
		
		
			
				  Posted: Sun Dec 16, 2012 12:30 pm    Post subject: Re: Moving and Shooting at the same time  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				| Ok thanks for telling me. I asked beacuse I am new to programming in general. And at school my teacher didn't teach us about boolean. | 
			 
			
				 | 
			 
		  | 
	 
	 
		 | 
		
		 | 
	 
	  
		  | 
	 
				 
		TheBboy
 
 
 
    
		 | 
		
		
			
				  Posted: Tue Dec 18, 2012 6:49 am    Post subject: Re: Moving and Shooting at the same time  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				How do I stop my object from disappearing when I shoot
 
 
The Code:
 
 
 
var x, y, x1, y1 : int := 40
 
var key : array char of boolean
 
 
 
procedure hi
 
    loop
 
        Input.KeyDown (key)
 
 
        %
 
        if key (KEY_UP_ARROW) then %up arrow
 
            y := y + 5
 
            y1 := y1 + 5
 
        end if
 
 
        if key (KEY_DOWN_ARROW) then %down arrow
 
            y := y - 5
 
            y1 := y1 - 5
 
        end if
 
 
        if key (KEY_LEFT_ARROW) then %left arrow
 
            x := x - 5
 
            x1 := x1 - 5
 
        end if
 
 
        if key (KEY_RIGHT_ARROW) then %right arrow
 
            x := x + 5
 
            x1 := x1 + 5
 
        end if
 
 
        if key (KEY_TAB) then%shooting
 
            for i : 1 .. 200
 
                drawfilloval (x1, y1, 5, 5, purple)
 
                delay (10)
 
                drawfilloval (x1, y1, 5, 5, white)
 
                x1 := x1 + 5
 
            end for
 
        end if
 
 
        drawfilloval (x, y, 10, 10, black) %object
 
        delay (50)
 
        drawfilloval (x, y, 10, 10, white) %clears the screen so it seems that the 'object' is moving
 
    end loop
 
end hi
 
 
hi | 
			 
			
				 | 
			 
		  | 
	 
	 
		 | 
		
		 | 
	 
	  
		  | 
	 
				 
		Insectoid
 
  
 
    
		 | 
		
		
			
				  Posted: Tue Dec 18, 2012 8:59 am    Post subject: RE:Moving and Shooting at the same time  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
					  | code: | 	 		  for i : 1 .. 200 
 
drawfilloval (x1, y1, 5, 5, purple) 
 
delay (10) 
 
drawfilloval (x1, y1, 5, 5, white) 
 
x1 := x1 + 5 
 
end for   | 	  
 
 
This is your problem. What's the rest of your code doing while this bit is running? | 
			 
			
				 | 
			 
		  | 
	 
	 
		 | 
		
		 | 
	 
	  
		  | 
	 
				 
		 | 
	 
 
	
	
	 
	
	 |