Making a Program Do 2 Actions at Once... please help
Author |
Message |
UnTiteled
![](http://compsci.ca/v3/uploads/user_avatars/2343022534b4e3d964f6c6.gif)
|
Posted: Mon Jan 11, 2010 8:40 pm Post subject: Making a Program Do 2 Actions at Once... please help |
|
|
What is it you are trying to achieve?
<Replace all the <> with your answers/code and remove the <>>
i am trying to make my fireball move accross the screen while you can still move the character
(please dont post any links to tutorials, and i know my program has alot of junk variables and constants )
What is the problem you are having?
<Answer Here>
onve you press space to shoot the fireball, everything else dissapears and the fireball moves accross the screen
once the fireball arives at its destination, everything else is vissible again, until u press space again
Describe what you have tried to solve this problem
<Answer Here>
i have tryed everything my mind can think of
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
<Answer Here>
Turing: |
const GROUND_HEIGHT := 120
const RUN_SPEED := 10
const JUMP_SPEED := 30
const GRAVITY := 2
var manfig1 := Pic.FileNew ("stand.gif")
var manfig2 := Pic.FileNew ("face.gif")
var monsterfig2 := Pic.FileNew ("monster_face.gif")
var chars : array char of boolean
var posx, posy : int
var velx, vely : real
posx := 20
velx := 0
posy := 400
vely := 0
setscreen ("graphics:max;max")
put ""
put ""
put ""
put ""
put ""
put ""
put ""
put ""
put ""
put "Loading Game..."
colourback (40)
put ""
locate (11, 79)
colourback (50)
put " "
delay (100)
locate (11, 78)
put " "
delay (100)
locate (11, 77)
put " "
delay (100)
locate (11, 76)
put " "
delay (100)
locate (11, 75)
put " "
delay (100)
locate (11, 74)
put " "
delay (100)
locate (11, 73)
put " "
delay (100)
locate (11, 73)
put " "
delay (100)
locate (11, 72)
put " "
delay (100)
locate (11, 71)
put " "
delay (100)
locate (11, 70)
put " "
delay (100)
locate (11, 69)
put " "
delay (100)
locate (11, 68)
put " "
delay (100)
locate (11, 67)
put " "
delay (100)
locate (11, 66)
put " "
delay (200)
locate (11, 65)
put " "
delay (100)
locate (11, 64)
put " "
delay (100)
locate (11, 63)
put " "
delay (100)
locate (11, 62)
put " "
delay (100)
locate (11, 61)
put " "
delay (100)
locate (11, 60)
put " "
delay (100)
locate (11, 59)
put " "
delay (500)
locate (11, 58)
put " "
delay (100)
locate (11, 57)
put " "
delay (100)
locate (11, 56)
put " "
delay (100)
locate (11, 55)
put " "
delay (100)
locate (11, 54)
put " "
delay (100)
locate (11, 53)
put " "
delay (100)
locate (11, 52)
put " "
delay (200)
locate (11, 51)
put " "
delay (100)
locate (11, 50)
put " "
delay (100)
locate (11, 49)
put " "
delay (100)
locate (11, 48)
put " "
delay (100)
locate (11, 47)
put " "
delay (100)
locate (11, 46)
put " "
delay (100)
locate (11, 45)
put " "
delay (100)
locate (11, 44)
put " "
delay (100)
locate (11, 43)
put " "
delay (300)
locate (11, 42)
put " "
delay (100)
locate (11, 41)
put " "
delay (100)
locate (11, 40)
put " "
delay (100)
locate (11, 39)
put " "
delay (100)
locate (11, 38)
put " "
delay (100)
locate (11, 37)
put " "
delay (100)
locate (11, 36)
put " "
delay (100)
locate (11, 35)
put " "
delay (100)
locate (11, 34)
put " "
delay (100)
locate (11, 33)
put " "
delay (100)
locate (11, 32)
put " "
delay (100)
locate (11, 31)
put " "
delay (100)
locate (11, 30)
put " "
delay (100)
locate (11, 29)
put " "
delay (100)
locate (11, 28)
put " "
delay (100)
locate (11, 27)
put " "
delay (100)
locate (11, 26)
put " "
delay (200)
locate (11, 25)
put " "
delay (100)
locate (11, 24)
put " "
delay (100)
locate (11, 23)
put " "
delay (100)
locate (11, 22)
put " "
delay (100)
locate (11, 21)
put " "
delay (100)
locate (11, 20)
put " "
delay (100)
locate (11, 19)
put " "
delay (500)
locate (11, 18)
put " "
delay (100)
locate (11, 17)
put " "
delay (100)
locate (11, 16)
put " "
delay (100)
locate (11, 15)
put " "
delay (100)
locate (11, 14)
put " "
delay (100)
locate (11, 13)
put " "
delay (100)
locate (11, 12)
put " "
delay (200)
locate (11, 11)
put " "
delay (100)
locate (11, 10)
put " "
delay (100)
locate (11, 9)
put " "
delay (100)
locate (11, 8)
put " "
delay (100)
locate (11, 7)
put " "
delay (100)
locate (11, 6)
put " "
delay (100)
locate (11, 5)
put " "
delay (100)
locate (11, 4)
put " "
delay (100)
locate (11, 3)
put " "
delay (300)
locate (11, 2)
put " "
delay (300)
locate (11, 1)
put " "
delay (100)
colourback (70)
cls
locate (15, 20)
put "___________.__"
locate (16, 20)
put "\\__ ___/| |__ ____ "
locate (17, 20)
put " | | | | \\_/ __ \\ "
locate (18, 20)
put " | | | Y \\ ___/ "
locate (19, 20)
put " |____| |___| /\\___ >"
locate (20, 20)
put " \\/ \\/ "
locate (21, 20)
put " _____ .__ .__ .__ __ "
locate (22, 20)
put " / _ \\ | | ____ | |__ ____ _____ |__| _______/ |_ "
locate (23, 20)
put " / /_\\ \\| | _/ ___\\| | \\_/ __ \\ / \\| |/ ___/\\ __\\"
locate (24, 20)
put "/ | \\ |_\\ \\___| Y \\ ___/| Y Y \\ |\\___ \\ | | "
locate (25, 20)
put "\\____|__ /____/\\___ >___| /\\___ >__|_| /__/____ > |__| "
locate (26, 20)
put " \\/ \\/ \\/ \\/ \\/ \\/ "
put "Instructions: Move with the 'up, down, left, and right buttons', shoot with the space bar"
put ""
put "On the first day, God created the Heavens and The earth..."
put "On the sixth day, God created the creatures of the earth, and with them"
put "came a soul devouring beast, once the humans were put on the earth, so"
put "did the demon start to hunt for souls"
put ""
put "your quest iss to defeat these demons and save the world from darkness"
put "hit any key to begin"
Input.Pause
colourback (white)
colour (white)
cls
View.Set ("graphics,offscreenonly:max;max")
locate (16, 20)
colour (black)
put " _______________"
locate (17, 20)
put "|prepare |"
locate (18, 20)
put "|to |"
locate (19, 20)
put "|be destroyed. |"
locate (20, 20)
put "| ______________|"
locate (21, 20)
put "|/"
Pic.Draw (manfig2, 120, 240, picMerge)
Pic.Draw (manfig1, 50, 50, picMerge)
drawline (0, GROUND_HEIGHT, maxx, GROUND_HEIGHT, blue)
locate (41, 10)
put "hit any key to continue"
Input.Pause
locate (16, 90)
put " _______________"
locate (17, 90)
put "| |"
locate (18, 90)
put "|GRAAAWWWWRRRRR |"
locate (19, 90)
put "|______________ |"
locate (20, 90)
put " |/"
Pic.Draw (monsterfig2, 790, 250, picMerge)
locate (41, 10)
Input.Pause
loop
Input.KeyDown (chars )
if chars ('q') then
exit
end if
if chars (KEY_LEFT_ARROW) then
velx := -RUN_SPEED
elsif chars (KEY_RIGHT_ARROW) then
velx := RUN_SPEED
else
velx := 0
end if
if chars (KEY_UP_ARROW) and posy = GROUND_HEIGHT then
vely := JUMP_SPEED
end if
vely - = GRAVITY
posx + = round (velx )
posy + = round (vely )
if posy < GROUND_HEIGHT then
posy := GROUND_HEIGHT
vely := 0
end if
Pic.Draw (manfig1, posx, posy, picMerge)
drawline (0, GROUND_HEIGHT, maxx, GROUND_HEIGHT, blue)
View.Update
delay (35)
cls
if posx < 0 then
posx := - 1
elsif posx > 600 then
posx := 600
end if
var yx := 260
var y := - 10
var x := yx
var pic := Pic.FileNew ("fireball2.gif")
cls
Time.DelaySinceLast(10)
Input.KeyDown (chars )
if chars (' ') then
loop
View.Update
cls
Pic.Draw (pic,y,x, picMerge)
y + = 1
delay (3)
if y = 700 then
y := - 10
exit
end if
end loop
end if
end loop
|
Please specify what version of Turing you are using
<Answer Here>
i am using 4.1.1 |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
UnTiteled
![](http://compsci.ca/v3/uploads/user_avatars/2343022534b4e3d964f6c6.gif)
|
Posted: Mon Jan 11, 2010 8:48 pm Post subject: RE:Making a Program Do 2 Actions at Once... please help |
|
|
And if you're just gonna tell me to learn more about turing, juist dont post anything, I have my knolage about turing and what i know doesnt work...Thank you
(actually i dont have too much junk VARs) |
|
|
|
|
![](images/spacer.gif) |
B-Man 31
![](http://compsci.ca/v3/uploads/user_avatars/370363944af8c60a7db3b.jpg)
|
Posted: Mon Jan 11, 2010 10:16 pm Post subject: RE:Making a Program Do 2 Actions at Once... please help |
|
|
you could save a lot of space if you use a for loop for the loading bar. |
|
|
|
|
![](images/spacer.gif) |
syntax_error
![](http://compsci.ca/v3/uploads/user_avatars/196798963948cf16794b6e5.jpg)
|
Posted: Mon Jan 11, 2010 10:46 pm Post subject: RE:Making a Program Do 2 Actions at Once... please help |
|
|
Im not sure exactly what you want to do your code seemed overly repetitive for me to read through but to have to 2 different proc running at once use fork but I suggest you find a way around it forking isnt a great idea. |
|
|
|
|
![](images/spacer.gif) |
TerranceN
|
Posted: Tue Jan 12, 2010 1:58 am Post subject: Re: Making a Program Do 2 Actions at Once... please help |
|
|
You need to only use one loop.
Let me explain why this approach is giving you the results you are getting
your logic is like this
(pseudo code, dont try to compile this)
code: | loop % loop 1
% update main stuff
if (fireball_starts) then
loop % loop 2 when fireball has started it goes from here
% update fireball
exit when done_fireball_stuff
end loop % end loop 2 to here, but never outside, therefore not updating the main stuff
end if
end loop % end loop 1 |
when the fireball stuff isn't running, all is fine and well, but when fireball_starts your code ONLY updates the fireball until the fireball is not needed anymore, but you want it to update both the main stuff and the fireball. In order to do this you need to only have one loop and surround the fireball update code in an if statement that will only run when the fireball is active, and set the fireball to inactive when appropriate
(pseudo code once again)
code: | loop % loop 1
% update main stuff
if (fireball_isActive) then
% update fireball
if (fireball_not_needed_anymore)
fireball_isActive := false
end if
end if
end loop % end loop 1 |
Finally, a few things you may want to do to help your coding
-use the debugger controls, especially trace execution, in order to see the flow of you program
-use the indent tool, it also makes it easier to see the flow of your program
-theres no need for the loading screen, having to wait for stuff to load is supposed to be a bad thing (and can be annoying for others debugging/reading your code)
-you should absolutely learn more about turing, for example, putting a lot of your code into functions would make it much easier to read, and therefore debug
Hope this helps |
|
|
|
|
![](images/spacer.gif) |
UnTiteled
![](http://compsci.ca/v3/uploads/user_avatars/2343022534b4e3d964f6c6.gif)
|
Posted: Tue Jan 12, 2010 7:03 am Post subject: RE:Making a Program Do 2 Actions at Once... please help |
|
|
thanks guys for this i cant try it right now but jim sure itll work |
|
|
|
|
![](images/spacer.gif) |
UnTiteled
![](http://compsci.ca/v3/uploads/user_avatars/2343022534b4e3d964f6c6.gif)
|
Posted: Tue Jan 12, 2010 3:09 pm Post subject: RE:Making a Program Do 2 Actions at Once... please help |
|
|
alright i tryed it now and it almost works perfectly thanks for the help |
|
|
|
|
![](images/spacer.gif) |
|
|