Computer Science Canada 2 getch lines at once |
Author: | MeTaLPyTHoN [ Tue Jan 06, 2004 8:52 pm ] |
Post subject: | 2 getch lines at once |
Hey... Im a pretty novice programmer but rather intrested in it and advancing my skills, but for the moment i dont know if what im asking about is possible in turing, or how to do it, so i figured this would be the place to come... im trying to make a pong game for computer science, and cant figure out how to get the computer to accept 2 key press values at once, right now im using a process for each paddle, and they work, but only one at a time, like only one paddle will move at one time bcuz it wont read 2 getch statements at one time... is there an easier statement for this or are processes the wrong way to go (forking was my only guess at getting 2 things to ahppen at once).. anyway, heres the code, if anyone has suggestions, they would be much appreciated:) setscreen ("graphics:700;500") var screen, paddle1y, paddle2y, paddlepic : int drawfillbox (0, 0, 10, 50, 10) paddlepic := Pic.New (0, 0, 10, 50) cls screen := Pic.New (0, 0, 10, 10) paddle1y := 0 paddle2y := 0 proc drawBackGround () Draw.FillBox (0, 0, maxx, maxy, 7) Draw.Line (70, 0, 70, maxy, 10) Draw.Line (maxx - 70, 0, maxx - 70, maxy, 10) Draw.Oval (round (maxx / 2), round (maxy / 2), 75, 75, 10) Draw.Line (round (maxx / 2), maxy, round (maxx / 2), maxy - 100, 10) Draw.Line (round (maxx / 2), maxy - 200, round (maxx / 2), maxy - 300, 10) Draw.Line (round (maxx / 2), maxy - 400, round (maxx / 2), 0, 10) end drawBackGround proc saveScreen (var screen : int) screen := Pic.New (0, 0, maxx, maxy) end saveScreen proc drawSaved (screen : int) Pic.Draw (screen, 0, 0, picCopy) end drawSaved proc drawpaddle (x, y : int) Pic.Draw (paddlepic, x, y, picCopy) end drawpaddle process movepaddle1 () var select : string (1) setscreen ("offscreenonly") loop loop getch (select) if select = "a" then paddle1y += 5 if paddle1y >= maxy - 50 then paddle1y := maxy - 50 end if exit elsif select = "z" then paddle1y -= 5 if paddle1y <= 0 then paddle1y := 0 end if exit end if end loop drawBackGround drawpaddle (60, paddle1y) drawpaddle (maxx - 70, paddle2y) View.Update end loop end movepaddle1 process movepaddle2 () setscreen ("offscreenonly") var select : string (1) loop loop getch (select) if select = "k" then paddle2y += 5 if paddle2y >= maxy - 50 then paddle2y := maxy - 50 end if exit elsif select = "m" then paddle2y -= 5 if paddle2y <= 0 then paddle2y := 0 end if exit end if end loop drawBackGround drawpaddle (maxx - 70, paddle2y) drawpaddle (60, paddle1y) View.Update end loop end movepaddle2 fork movepaddle2 fork movepaddle1 |
Author: | Mazer [ Tue Jan 06, 2004 9:07 pm ] |
Post subject: | |
you can't. not like that, anyway, not with getch. you'll need to use Input.KeyDown... i think there's a tutorial on it in teh tutorials section so you should check there. if ther isn't, try the turing reference (F10) and look up Input.KeyDown, it does a pretty good job of explaining it. |
Author: | MeTaLPyTHoN [ Tue Jan 06, 2004 9:08 pm ] |
Post subject: | |
thanks a bunch! |
Author: | MeTaLPyTHoN [ Wed Jan 07, 2004 8:57 am ] |
Post subject: | Thanks lots |
here is what i ended up with, works like a charm:> i kept the processes and used the input.keydown setscreen ("graphics:700;500") var screen, paddle1y, paddle2y, paddlepic : int drawfillbox (0, 0, 10, 50, 10) paddlepic := Pic.New (0, 0, 10, 50) cls screen := Pic.New (0, 0, 10, 10) paddle1y := 0 paddle2y := 0 proc drawBackGround () Draw.FillBox (0, 0, maxx, maxy, 7) Draw.Line (70, 0, 70, maxy, 10) Draw.Line (maxx - 70, 0, maxx - 70, maxy, 10) Draw.Oval (round (maxx / 2), round (maxy / 2), 75, 75, 10) Draw.Line (round (maxx / 2), maxy, round (maxx / 2), maxy - 100, 10) Draw.Line (round (maxx / 2), maxy - 200, round (maxx / 2), maxy - 300, 10) Draw.Line (round (maxx / 2), maxy - 400, round (maxx / 2), 0, 10) end drawBackGround proc saveScreen (var screen : int) screen := Pic.New (0, 0, maxx, maxy) end saveScreen proc drawSaved (screen : int) Pic.Draw (screen, 0, 0, picCopy) end drawSaved proc drawpaddle (x, y : int) Pic.Draw (paddlepic, x, y, picCopy) end drawpaddle process movepaddle1 () var select : array char of boolean setscreen ("offscreenonly") loop loop Input.KeyDown(select) if select ( 'a') then paddle1y += 5 if paddle1y >= maxy - 50 then paddle1y := maxy - 50 end if exit elsif select ('z') then paddle1y -= 5 if paddle1y <= 0 then paddle1y := 0 end if exit end if end loop drawBackGround drawpaddle (60, paddle1y) drawpaddle (maxx - 70, paddle2y) View.Update Time.Delay(10) end loop end movepaddle1 process movepaddle2 () var select : array char of boolean setscreen ("offscreenonly") loop loop Input.KeyDown(select) if select ( 'k') then paddle2y += 5 if paddle2y >= maxy - 50 then paddle2y := maxy - 50 end if exit elsif select ('m') then paddle2y -= 5 if paddle2y <= 0 then paddle2y := 0 end if exit end if end loop drawBackGround drawpaddle (60, paddle1y) drawpaddle (maxx - 70, paddle2y) View.Update Time.Delay(10) end loop end movepaddle2 drawBackGround fork movepaddle2 fork movepaddle1 |
Author: | shorthair [ Wed Jan 07, 2004 11:00 am ] |
Post subject: | |
For a new programmer , looks like you pic e dup the language pretty well , keep up this good code , all these mew people ar ejsut amazing me with what they can do , |