Computer Science Canada Movement and shooting |
Author: | chaos [ 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? |
Author: | TokenHerbz [ 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. |
Author: | Insectoid [ Fri Dec 17, 2010 10:00 pm ] |
Post subject: | RE:Movement and shooting |
This is a common question and as such has many, many solutions (almost all of which are the same) posted around the Turing board. |
Author: | chaos [ 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. |
Author: | TokenHerbz [ 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. |
Author: | TheGuardian001 [ 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:
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:
The player moves, then the bullet moves, then the player moves, then the bullet moves, etc. They take turns, instead of blocking each other. |
Author: | chaos [ 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 |
Author: | Insectoid [ 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. |
Author: | chaos [ 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 |
Author: | Insectoid [ 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:
If you do this, you get code like this
|
Author: | ProgrammingFun [ Thu Dec 23, 2010 8:18 pm ] | ||
Post subject: | RE:Movement and shooting | ||
You could always do it for the person:
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... |
Author: | chaos [ 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? |
Author: | TokenHerbz [ 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. |
Author: | chaos [ Thu Dec 23, 2010 10:36 pm ] |
Post subject: | Re: Movement and shooting |
could u show me what u mean using code please? |
Author: | SS1389 [ Thu Dec 23, 2010 10:51 pm ] |
Post subject: | Re: Movement and shooting |
![]() |
Author: | chaos [ Fri Dec 24, 2010 8:13 am ] |
Post subject: | Re: Movement and shooting |
??????? |
Author: | TokenHerbz [ Fri Dec 24, 2010 12:31 pm ] | ||
Post subject: | Re: Movement and shooting | ||
@SS1389: please don't spam. @chaos: Sure I'll make you a quick example to show you how it works.
|
Author: | SS1389 [ Fri Dec 24, 2010 2:14 pm ] |
Post subject: | Re: Movement and shooting |
Sorry. Won't happen again. |
Author: | chaos [ Mon Dec 27, 2010 4:33 pm ] |
Post subject: | Re: Movement and shooting |
@Tokenherbz: I am amazed by the results, but i don not understand the "type" and "record" syntax. I checked F10 in turing but they don't help, could u explain what this means? Or, is there a way to do this with text graphics? |
Author: | Tony [ Mon Dec 27, 2010 4:46 pm ] |
Post subject: | RE:Movement and shooting |
Tutorial on records from The Turing Walkthrough |
Author: | chaos [ Tue Dec 28, 2010 12:07 am ] |
Post subject: | Re: Movement and shooting |
@tokenherbz: could u show me this bullet movement using text graphics using the code i already gave before in this topic ? |
Author: | TokenHerbz [ Tue Dec 28, 2010 9:49 am ] | ||||||
Post subject: | RE:Movement and shooting | ||||||
There is more then enough info inside this thread to make your program work. Your drawing your bullet in it's own loop so that the main loop (which moves/does everything else like your "A" player) isn't executed. To get everything to work, you need to take that bullet loop out. You said it yourself inside your own program with comments: "FOR LOOP IS USED TO MOVE BULLET ENTIRELY WHEN CONTROL IS PRESSED ONCE" Now, then, First lets start with the shooting. Why not have to shoot with just space.
and like we said many many times above, what your program does is this
Now thats how your program works, this is how it SHOULD WORK, so re-read these posts here, and check out the link in turing walk thru, IF YOU POST NEW CODE (that shows effort to what we suggested) then we'll assist more.
|
Author: | chaos [ Tue Dec 28, 2010 2:33 pm ] |
Post subject: | Re: Movement and shooting |
Here is my code. It is an attachment. |
Author: | ProgrammingFun [ Tue Dec 28, 2010 3:50 pm ] |
Post subject: | RE:Movement and shooting |
I tried your code...there are some things I noticed (I do not know if they have been previously mentioned):
![]() Other than that, it's a good program. ![]() |
Author: | chaos [ Tue Dec 28, 2010 9:51 pm ] |
Post subject: | Re: Movement and shooting |
@ProgrammingFun: To shoot , you hit the spacebar. |
Author: | ProgrammingFun [ Tue Dec 28, 2010 10:01 pm ] |
Post subject: | Re: Movement and shooting |
chaos @ Tue Dec 28, 2010 9:51 pm wrote: @ProgrammingFun: To shoot , you hit the spacebar.
Perhaps you misunderstood me....I meant to say that there is nothing which should be shot (you know...as in enemies etc)... |
Author: | chaos [ Tue Dec 28, 2010 10:05 pm ] |
Post subject: | Re: Movement and shooting |
I have listed my code above. I am just wondering if it is as Tokenherbz described?? Could someone help me please?? @Tokenherbz: When you made the post about how my program should be, within it you stated that "if the bullet exists". I do not understand what this means, could u explain it to me or give me the code to it please? |
Author: | TheGuardian001 [ Tue Dec 28, 2010 11:14 pm ] |
Post subject: | Re: Movement and shooting |
by exists, he means as a part of the world. the bullet always "exists" as a variable, but in this case "exists" means that it has been fired but has not yet hit a target (meaning you still need to do stuff with it.) You can represent this (if you want) in the form of a boolean variable. If the variable is true, the bullet "exists" and we need to move it, draw it, and check for collisions. If it's false, we ignore that bullet. If the bullet hits something, we set that variable to false, and the bullet no longer "exists". |
Author: | chaos [ Wed Dec 29, 2010 1:40 pm ] |
Post subject: | Re: Movement and shooting |
Can someone help me. I have given my code below in an attachment. The problem is that the program stops at random times. I can't seem to find the problem. |
Author: | TokenHerbz [ Wed Dec 29, 2010 2:54 pm ] | ||
Post subject: | Re: Movement and shooting | ||
|
Author: | chaos [ Wed Dec 29, 2010 3:03 pm ] |
Post subject: | Re: Movement and shooting |
@Tokenherbz: Is the way of removal in my code okay. If not, could u help me out? |
Author: | TokenHerbz [ Wed Dec 29, 2010 5:30 pm ] |
Post subject: | RE:Movement and shooting |
its not okay, in the first part if you read my "comments" it tells you why your program doesn't work. post me some code to the logic iv'e also put on that last post and ill assist you more... |
Author: | chaos [ Wed Dec 29, 2010 11:19 pm ] |
Post subject: | Re: Movement and shooting |
Here is the code. |