| Author | 
		Message | 
	
		 
		chaos
 
 
 
    
		 | 
		
		
			
				  Posted: Fri Dec 17, 2010 9:12 pm    Post subject: Movement and shooting  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				I need some help.
 
 
I'm creating a game cinsisting of shooting people using text graphics.
 
But, the problem is that whenever the bullet is shot, the player is frozen, until the bullet stops or leaves the screen.
 
How can I move the player while the bullet is moving? | 
			 
			
				 | 
			 
		  | 
	
	 
		 | 
		
		 | 
	
	
 
		  | 
	
		 
		Sponsor Sponsor 
		 
  
		 | 
		
 | 
	
	 
		  | 
	
				 
		TokenHerbz
 
  
 
    
		 | 
		
		
			
				  Posted: Fri Dec 17, 2010 9:28 pm    Post subject: RE:Movement and shooting  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				| take the bullet out of its own loop and put it inside a fnc or proc to run the same time as the person. | 
			 
			
				 | 
			 
		  | 
	
	 
		 | 
		
		 | 
	
	
 
		  | 
	
				 
		Insectoid
 
  
 
    
		 | 
		
		 | 
	
	 
		 | 
		
		 | 
	
	
 
		  | 
	
				 
		chaos
 
 
 
    
		 | 
		
		
			
				  Posted: Fri Dec 17, 2010 11:15 pm    Post subject: Re: Movement and shooting  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				@tokenherbz
 
Are you saying that i should put the buullets in a separate loop
 
Please clarify. | 
			 
			
				 | 
			 
		  | 
	
	 
		 | 
		
		 | 
	
	
 
		  | 
	
				 
		TokenHerbz
 
  
 
    
		 | 
		
		
			
				  Posted: Sat Dec 18, 2010 12:08 am    Post subject: RE:Movement and shooting  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				| No, I'm saying you need to take it out of its own loop, is what i think the problem is.  however, i could be of more assistance with code. | 
			 
			
				 | 
			 
		  | 
	
	 
		 | 
		
		 | 
	
	
 
		  | 
	
				 
		TheGuardian001
 
 
 
    
		 | 
		
		
			
				  Posted: Sat Dec 18, 2010 12:52 am    Post subject: Re: Movement and shooting  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				If you put the bullet in its own loop, nothing outside of that loop will run until the bullet is done. IE,
 
WRONG:
 
	  | code: | 	 		  
 
loop
 
    if (player moving)
 
        move player
 
    end if
 
    if (bullet shot)
 
        loop %we don't leave this till the bullet is done. Everything else stops.
 
            move bullet
 
            draw bullet
 
        end loop
 
    end if
 
   draw player
 
end loop
 
  | 	  
 
The player moves, then the bullet moves, then the bullet moves, then the bullet moves, etc. The loop prevents the (player moving) statement from being run.
 
 
RIGHT:
 
	  | code: | 	 		  
 
%Main loop. Contains EVERYTHING that needs to be repeated (NO LOOPS INSIDE THIS ONE!)
 
loop
 
    if (player moving)
 
        move player ONCE
 
    end if
 
    if (bullet moving)
 
        move bullet ONCE
 
    end if
 
 
    draw player
 
    draw bullet
 
 
    update screen
 
end loop.
 
  | 	  
 
The player moves, then the bullet moves, then the player moves, then the bullet moves, etc. They take turns, instead of blocking each other. | 
			 
			
				 | 
			 
		  | 
	
	 
		 | 
		
		 | 
	
	
 
		  | 
	
				 
		chaos
 
 
 
    
		 | 
		
		
			
				  Posted: Thu Dec 23, 2010 5:28 pm    Post subject: Re: Movement and shooting  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				So would it be something like this? :
 
 
var y1 : int := 10
 
var x1 : int := 10
 
var y2 : int := 20
 
var x2 : int := 20
 
var count : int := 1
 
var chars : array char of boolean
 
 
loop
 
    Input.KeyDown (chars)
 
    
 
    if chars (KEY_UP_ARROW) then       
 
        y1 := y1 - 1
 
        if y1 < 1 then                  
 
            y1 := 1
 
        end if
 
    end if
 
    if chars (KEY_RIGHT_ARROW) then     
 
        x1 := x1 + 1
 
        if x1 > 80 then                
 
            x1 := 80
 
        end if
 
    end if
 
    if chars (KEY_LEFT_ARROW) then     
 
        x1 := x1 - 1
 
        if x1 < 1 then         
 
            x1 := 1
 
        end if
 
    end if
 
    if chars (KEY_DOWN_ARROW) then     
 
        y1 := y1 + 1
 
        if y1 > 24 then                
 
            y1 := 24
 
        end if
 
    end if
 
    if chars (' ') and chars (KEY_RIGHT_ARROW) then
 
    count:=1 
 
        for limitx : 1 .. 80-x1
 
            count := count + 1
 
            if x1+count>80 then
 
            count:=1
 
            end if
 
            locate (y1, x1 + count)
 
            put "." ..
 
            delay(50)
 
            cls
 
        end for
 
    end if
 
    locate (y1, x1)
 
    put "A" ..
 
    delay(50)
 
    cls
 
   
 
end loop | 
			 
			
				 | 
			 
		  | 
	
	 
		 | 
		
		 | 
	
	
 
		  | 
	
				 
		Insectoid
 
  
 
    
		 | 
		
		
			
				  Posted: Thu Dec 23, 2010 5:45 pm    Post subject: RE:Movement and shooting  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				| You have 2 delays in there. That's bad. Also, I don't know why you have a for loop. Try using code tags to format your code so I can be bothered to actually read it instead of just skimming over it. | 
			 
			
				 | 
			 
		  | 
	
	 
		 | 
		
		 | 
	
	
 
		  | 
	
		 
		Sponsor Sponsor 
		 
  
		 | 
		
 | 
	
	 
		  | 
	
				 
		chaos
 
 
 
    
		 | 
		
		
			
				  Posted: Thu Dec 23, 2010 7:15 pm    Post subject: Re: Movement and shooting  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				Hers's the code with tags:
 
 
%VARIABLE DECLARATION
 
var y1 : int := 10 
 
var x1 : int := 10 
 
var y2 : int := 20 
 
var x2 : int := 20 
 
var count : int := 1 
 
var chars : array char of boolean 
 
 
loop 
 
Input.KeyDown (chars) 
 
 
%CONTROLS FOR MOVEMENT
 
if chars (KEY_UP_ARROW) then                                               %MOVING UP 
 
y1 := y1 - 1 
 
if y1 < 1 then                                                                        %BORDER PARAMETERS FOR MOVING UP
 
y1 := 1 
 
end if 
 
end if 
 
 
if chars (KEY_RIGHT_ARROW) then                                         %MOVING RIGHT
 
x1 := x1 + 1 
 
if x1 > 80 then                                                                      %BORDER PARAMETERS FOR MOVING RIGHT 
 
x1 := 80 
 
end if 
 
end if
 
 
 
if chars (KEY_LEFT_ARROW) then                                           %MOVING LEFT 
 
x1 := x1 - 1 
 
if x1 < 1 then                                                                       %BORDER PARAMETERS FOR MOVING LEFT
 
x1 := 1 
 
end if 
 
end if 
 
 
if chars (KEY_DOWN_ARROW) then                                        %MOVING DOWN 
 
y1 := y1 + 1 
 
if y1 > 24 then                                                                     %BORDER PARAMETERS FOR MOVING DOWN
 
y1 := 24 
 
end if 
 
end if 
 
 
if chars (' ') and chars (KEY_RIGHT_ARROW) then                   %PLAYER SHOOTING 
 
count:=1 
 
for limitx : 1 .. 80-x1                                                             %FOR LOOP IS USED TO MOVE BULLET ENTIRELY WHEN CONTROL IS PRESSED ONCE
 
count := count + 1 
 
if x1+count>80 then                                                              %BORDER PARAMETERS FOR BULLET
 
count:=1 
 
end if 
 
locate (y1, x1 + count)                                                           %LOCATE BULLET
 
put "." ..                                                                                %OUTPUT BULLET
 
delay(50)                                                                              
 
cls 
 
end for 
 
end if 
 
locate (y1, x1)                                                                   %LOCATE PLAYER
 
put "A" ..                                                                           %OUTPUT PLAYER
 
delay(50)                                                                          
 
cls 
 
 
end loop | 
			 
			
				 | 
			 
		  | 
	
	 
		 | 
		
		 | 
	
	
 
		  | 
	
				 
		Insectoid
 
  
 
    
		 | 
		
		
			
				  Posted: Thu Dec 23, 2010 7:58 pm    Post subject: RE:Movement and shooting  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				I think you're confusing comments with tags. Syntax tags highlight your code and preserve formatting. example:
 
 
	  | code: | 	 		  [syntax="turing"]
 
*code here*
 
[/syntax]  | 	  
 
 
If you do this, you get code like this
 
	  | Turing: | 	 		  
 
put "This is highlighted!"
 
loop
 
    put "This is indented! OMG!"
 
end loop
 
  | 	 
  | 
			 
			
				 | 
			 
		  | 
	
	 
		 | 
		
		 | 
	
	
 
		  | 
	
				 
		ProgrammingFun
 
  
 
    
		 | 
		
		
			
				  Posted: Thu Dec 23, 2010 8:18 pm    Post subject: RE:Movement and shooting  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				You could always do it for the person:
 
	  | Turing: | 	 		  
%VARIABLE DECLARATION
var y1  : int := 10
var x1  : int := 10
var y2  : int := 20
var x2  : int := 20
var count  : int := 1
var chars  : array char of boolean
loop
    Input.KeyDown (chars )
    %CONTROLS FOR MOVEMENT
    if chars  (KEY_UP_ARROW) then %MOVING UP
        y1  := y1 -  1
        if y1 <  1 then %BORDER PARAMETERS FOR MOVING UP
            y1  := 1
        end if
    end if
    if chars  (KEY_RIGHT_ARROW) then %MOVING RIGHT
        x1  := x1 +  1
        if x1 >  80 then %BORDER PARAMETERS FOR MOVING RIGHT
            x1  := 80
        end if
    end if
    if chars  (KEY_LEFT_ARROW) then %MOVING LEFT
        x1  := x1 -  1
        if x1 <  1 then %BORDER PARAMETERS FOR MOVING LEFT
            x1  := 1
        end if
    end if
    if chars  (KEY_DOWN_ARROW) then %MOVING DOWN
        y1  := y1 +  1
        if y1 >  24 then %BORDER PARAMETERS FOR MOVING DOWN
            y1  := 24
        end if
    end if
    if chars  (' ') and chars  (KEY_RIGHT_ARROW) then %PLAYER SHOOTING
        count  := 1
        for limitx  : 1 ..  80 - x1  %FOR LOOP IS USED TO MOVE BULLET ENTIRELY WHEN CONTROL IS PRESSED ONCE
            count  := count +  1
            if x1 + count >  80 then %BORDER PARAMETERS FOR BULLET
                count  := 1
            end if
            locate (y1, x1 + count ) %LOCATE BULLET
            put "." ..  %OUTPUT BULLET
            delay (50)
            cls
        end for
    end if
    locate (y1, x1 ) %LOCATE PLAYER
    put "A" ..  %OUTPUT PLAYER
    delay (50)
    cls
end loop  | 	  
 
But Insectoid does have a point...from now on, please try to use the syntax tags so that your code is easier to comprehend for those who might want to help you out... | 
			 
			
				 | 
			 
		  | 
	
	 
		 | 
		
		 | 
	
	
 
		  | 
	
				 
		chaos
 
 
 
    
		 | 
		
		
			
				  Posted: Thu Dec 23, 2010 9:05 pm    Post subject: Re: Movement and shooting  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				| so based on the code i gave, how would i go about moving the player and the bullet at the same time? | 
			 
			
				 | 
			 
		  | 
	
	 
		 | 
		
		 | 
	
	
 
		  | 
	
				 
		TokenHerbz
 
  
 
    
		 | 
		
		
			
				  Posted: Thu Dec 23, 2010 9:49 pm    Post subject: RE:Movement and shooting  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				your for loop which moves the bullet is wrong.
 
 
what you are doing is, "DO ALL OF THIS LOOP NOW BEFORE WE GO BACK TO MAIN LOOP"
 
 
what you want to do, is move the BULLET WHILE going back to the main loop.
 
 
you want to use the for loop to just move it by a vector at a time then if statement to check to see if its passed boundries and time to remove it from the program. | 
			 
			
				 | 
			 
		  | 
	
	 
		 | 
		
		 | 
	
	
 
		  | 
	
				 
		chaos
 
 
 
    
		 | 
		
		
			
				  Posted: Thu Dec 23, 2010 10:36 pm    Post subject: Re: Movement and shooting  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				| could u show me what u mean using code please? | 
			 
			
				 | 
			 
		  | 
	
	 
		 | 
		
		 | 
	
	
 
		  | 
	
				 
		SS1389
 
 
 
    
		 | 
		
		
			
				  Posted: Thu Dec 23, 2010 10:51 pm    Post subject: Re: Movement and shooting  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				  | 
			 
			
				 | 
			 
		  | 
	
	 
		 | 
		
		 | 
	
	
 
		  | 
	
				 
		 |