Need help with flickering
Author |
Message |
Mizzie30
|
Posted: Mon Jan 16, 2012 5:41 pm Post subject: Need help with flickering |
|
|
I need some help with my pong game. Its flickering so much that it's hard to see, ive tried to use cls and View.Update but it doesn't seem to work.
Turing: |
%Set screen and home screen
var font, font1 : int
var ch : string (1)
var X, Y : int := 30 %Placement of the ball
var R1, R2 : int := 10 %Radius of the ball
var DX, DY : int := 1
var key : string (1) % key board character
var num : int
var y1, y2, y3, y4, x1, x2, x3, x4 : int
var getkey : array char of boolean
var input : string (1)
var i1 : string (1) := '1'
var i2 : string (1) := '2'
var ydir : int
var play1score, play2score : int := 0
var p1 : int
p1 := Pic.FileNew ("pongback.bmp")
setscreen ("graphics:1000;800,nobuttonbar,nocursor") %screen size
colourback (black) %backround colour
process song
loop
Music.PlayFile ("zizibum.mp3")
end loop
end song
fork song
cls
font := Font.New ("Palatino:18:bold,italic") %font colour and size
Draw.Text ("Welcome to Eric's pong game.", 400, 405, font, white) %text line 1
Draw.Text ("Press any key to continue.", 330, 355, font, white) %text line 2
getch (ch ) %starts game
cls
Draw.Text ("Player 1 use the W and S keys to move.", 275, 175, font, white) %text line 1
Draw.Text ("Player 2 use the Up and Down arrow keys to move.", 205, 105, font, white) %text line 2
%Instructions
Draw.Text ("Instructions.", 400, 730, font, white)
Draw.Line (380, 725, 560, 725, white)
Draw.Text ("Press 1 for one player.", 350, 670, font, white)
Draw.Text ("Press 2 for two player.", 350, 630, font, white)
Draw.Text ("One Player", 400, 470, font, white)
Draw.Text ("Two Player", 400, 430, font, white)
getch (input )
if input = i1 then
Draw.Text ("One Player", 400, 470, font, white)
delay (200)
Draw.Text ("One Player", 400, 470, font, blue)
delay (200)
Draw.Text ("One Player", 400, 470, font, white)
delay (200)
Draw.Text ("One Player", 400, 470, font, blue)
delay (200)
Draw.Text ("One Player", 400, 470, font, white)
delay (200)
Draw.Text ("One Player", 400, 470, font, blue)
delay (200)
Draw.Text ("One Player", 400, 470, font, white)
end if
if input = i2 then
Draw.Text ("Two Player", 400, 430, font, white)
delay (200)
Draw.Text ("Two Player", 400, 430, font, blue)
delay (200)
Draw.Text ("Two Player", 400, 430, font, white)
delay (200)
Draw.Text ("Two Player", 400, 430, font, blue)
delay (200)
Draw.Text ("Two Player", 400, 430, font, white)
delay (200)
Draw.Text ("Two Player", 400, 430, font, blue)
delay (200)
Draw.Text ("Two Player", 400, 430, font, white)
end if
View.Update
process ball
loop
%Pic.Draw (p1,200,200,picCopy)
color (2)
locate (1, 1)
put "P1 Score"
locate (2, 1)
put play1score
locate (1, 10)
put "P2 Score"
locate (2, 10)
put play2score
drawfilloval (X, Y, R1, R2, black)
drawfilloval (X, Y, R1, R2, red)
View.Update
X := X + DX
Y := Y + DY
View.Update
if X = maxx then % Check if ball hits left or right border
View.Update
play1score := play1score + 1
X := 500
Y := 400
View.Update
elsif X = 0 then
View.Update
play2score := play2score + 1
X := 500
Y := 400
elsif Y = 0 or Y = maxy then % Check if ball hits top or bottom border
DY := (- 1) * DY
end if
if play1score = 10 then
cls
Draw.Text ("Thanks for playing.", 400, 405, font, white) %text line 1
end if
if play2score = 10 then
cls
Draw.Text ("Thanks for playing.", 400, 405, font, white) %text line 1
end if
cls
end loop
end ball
fork ball
View.Update
y1 := maxy - 490
y2 := maxy - 310
y3 := maxy - 490
y4 := maxy - 310
x1 := 5
x2 := 15
x3 := maxx - 5
x4 := maxx - 15
ydir := 3
View.Update
process p1paddleup
loop
drawfillbox (x1, y1, x2, y2, white)
drawfillbox (x1, y1, x2, y2, white)
Input.KeyDown (getkey )
if getkey ('w') then
y1 := y1 + 1
y2 := y2 + 1
end if
View.Update
end loop
end p1paddleup
fork p1paddleup
View.Update
process p1paddledown
loop
drawfillbox (x1, y1, x2, y2, white)
drawfillbox (x1, y1, x2, y2, white)
Input.KeyDown (getkey )
if getkey ('s') then
y1 := y1 - 1
y2 := y2 - 1
end if
end loop
end p1paddledown
fork p1paddledown
process p2paddleup
loop
drawfillbox (x3, y3, x4, y4, white)
drawfillbox (x3, y3, x4, y4, white)
Input.KeyDown (getkey )
if getkey (KEY_UP_ARROW) then
y3 := y3 + 1
y4 := y4 + 1
end if
cls
end loop
end p2paddleup
fork p2paddleup
View.Update
process p2paddledown
loop
drawfillbox (x3, y3, x4, y4, white)
drawfillbox (x3, y3, x4, y4, white)
if getkey (KEY_DOWN_ARROW) then
y3 := y3 - 1
y4 := y4 - 1
end if
cls
end loop
end p2paddledown
fork p2paddledown
process bouncep12
loop
if whatdotcolour (X, Y ) = white then %Ball bounce for both paddles
DX := (- 1) * DX
end if
end loop
end bouncep12
fork bouncep12
if play1score = 10 then
cls
Draw.Text ("Thanks for playing.", 400, 405, font, white) %text line 1
end if
if play2score = 10 then
cls
Draw.Text ("Thanks for playing.", 400, 405, font, white) %text line 1
end if
|
Please specify what version of Turing you are using
4.0.5 |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Tony
|
Posted: Mon Jan 16, 2012 5:50 pm Post subject: RE:Need help with flickering |
|
|
- you're not setting offscreenonly
- you have more than one View.Update
View.Update is fundamentally incompatible with processes (think about what each one does). You'd have to remove processes before you can start using View.Update. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
Mizzie30
|
Posted: Mon Jan 16, 2012 8:33 pm Post subject: Re: RE:Need help with flickering |
|
|
Tony @ Mon Jan 16, 2012 5:50 pm wrote: - you're not setting offscreenonly
- you have more than one View.Update
View.Update is fundamentally incompatible with processes (think about what each one does). You'd have to remove processes before you can start using View.Update.
I tried to set it to offscreenonly but when I do it freezes the program and I don't know how to use anything but a process. |
|
|
|
|
|
Raknarg
|
Posted: Mon Jan 16, 2012 8:34 pm Post subject: RE:Need help with flickering |
|
|
The question you must ask yourself is why are you using a process? What are you trying to accomplish with it? |
|
|
|
|
|
Mizzie30
|
Posted: Mon Jan 16, 2012 8:41 pm Post subject: Re: RE:Need help with flickering |
|
|
Raknarg @ Mon Jan 16, 2012 8:34 pm wrote: The question you must ask yourself is why are you using a process? What are you trying to accomplish with it?
I'm using process because my teacher never taught us how to do forks so I am trying to figure this out myself. I have no clue how to do procedures or anything other then processes. |
|
|
|
|
|
Aange10
|
Posted: Mon Jan 16, 2012 8:41 pm Post subject: Re: RE:Need help with flickering |
|
|
Mizzie30 @ 16/1/2012, 7:41 pm wrote: Raknarg @ Mon Jan 16, 2012 8:34 pm wrote: The question you must ask yourself is why are you using a process? What are you trying to accomplish with it?
I'm using process because my teacher never taught us how to do forks so I am trying to figure this out myself. I have no clue how to do procedures or anything other then processes.
Okay, so what's a process? |
|
|
|
|
|
Mizzie30
|
Posted: Mon Jan 16, 2012 8:48 pm Post subject: Re: RE:Need help with flickering |
|
|
Aange10 @ Mon Jan 16, 2012 8:41 pm wrote: Mizzie30 @ 16/1/2012, 7:41 pm wrote: Raknarg @ Mon Jan 16, 2012 8:34 pm wrote: The question you must ask yourself is why are you using a process? What are you trying to accomplish with it?
I'm using process because my teacher never taught us how to do forks so I am trying to figure this out myself. I have no clue how to do procedures or anything other then processes.
Okay, so what's a process?
All I know is that I can use it to run multiple things. |
|
|
|
|
|
mirhagk
|
Posted: Mon Jan 16, 2012 8:58 pm Post subject: RE:Need help with flickering |
|
|
basically you need to restructure your game like the following:
loop
draw paddle1
draw paddle2
draw ball
etc....
View.Update
update paddle1
update paddle2
update ball
etc
delay
end loop |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Raknarg
|
Posted: Mon Jan 16, 2012 8:58 pm Post subject: RE:Need help with flickering |
|
|
Yes. Now the problem with this in turing, is that (if I remember correctly) it's uncontrollable and unpredictable, so you never really know the outcome of the fork. The second thing is that using a process will interfere with View.Update.
However, there is a solution. Do you need these things to run at the same time? the answer is NO. You need it to LOOK like it's running at the same time. |
|
|
|
|
|
Beastinonyou
|
Posted: Tue Jan 17, 2012 7:34 am Post subject: Re: RE:Need help with flickering |
|
|
Mizzie30 @ Mon Jan 16, 2012 8:48 pm wrote: Aange10 @ Mon Jan 16, 2012 8:41 pm wrote: Mizzie30 @ 16/1/2012, 7:41 pm wrote: Raknarg @ Mon Jan 16, 2012 8:34 pm wrote: The question you must ask yourself is why are you using a process? What are you trying to accomplish with it?
I'm using process because my teacher never taught us how to do forks so I am trying to figure this out myself. I have no clue how to do procedures or anything other then processes.
Okay, so what's a process?
All I know is that I can use it to run multiple things.
So, you understand that processes can run multiple things, but you don't understand how procedures work?
the only thing I ever use processes for is music playing in the background for programs, procedures are what you need to be doing.
for Processes, you call it whatever you want, put in a bunch of code you want to be run, and call it with fork. However, the way it runs is far different from using procedures.
think of Procedures as just a chunk of code that you can call anytime you want, and it will do whatever is inside.
Turing: |
procedure drawEnemies
% Code in here to draw all your Enemies
end drawEnemies
drawEnemies
|
it's really simple, and far more effective for running something more than once.
Once you have that down, you can move onto understand how to pass parameters, and utilize the ability
You should also understand when to use Procedures and when to use Functions. |
|
|
|
|
|
Mizzie30
|
Posted: Tue Jan 17, 2012 8:30 pm Post subject: Re: Need help with flickering |
|
|
Thanks everyone for you help I kind of figured out procedures and the ball now runs smoothly but my paddles don't show up how can I run multiple procedures? |
|
|
|
|
|
Dreadnought
|
Posted: Tue Jan 17, 2012 8:36 pm Post subject: Re: Need help with flickering |
|
|
Mizzie30 wrote: how can I run multiple procedures?
Turing: |
% Some Turing code
procedure1
procedure2
% ...
% More Turing code
|
|
|
|
|
|
|
Mizzie30
|
Posted: Tue Jan 17, 2012 8:48 pm Post subject: Re: Need help with flickering |
|
|
Dreadnought @ Tue Jan 17, 2012 8:36 pm wrote: Mizzie30 wrote: how can I run multiple procedures?
Turing: |
% Some Turing code
procedure1
procedure2
% ...
% More Turing code
|
Tried that It only runs the first procedure. |
|
|
|
|
|
mirhagk
|
Posted: Tue Jan 17, 2012 10:20 pm Post subject: RE:Need help with flickering |
|
|
move the loops outside of the procedures, make the loops call each procedure, have them run once each, and then hit the end of the loop and restart. |
|
|
|
|
|
|
|