Posted: Sat Sep 03, 2011 5:10 pm Post subject: Help me comprehend some (SIMPLE) Pong coding
What is it you are trying to achieve?
One of my friends had made this super simple pong game, and gave me the source code to play around with. I'm trying to learn how to code in turing, and I know that this is one of the best ways to go about it. I've read a lot of the walkthroughs, but everything is easier, and frankly better hands on. So I was wondering if somebody could help me understand this SIMPLE pong coding.
So I'm asking, to whoever finds time to help me out, if he/she would go through this short coding and put % comments, telling me what the computer is "doing now".
If you don't have time, I understand. Just please don't flame.
What is the problem you are having?
I'm not comprehending all of the coding.
Describe what you have tried to solve this problem
I've tried going through and taking mental notes of what i do know, but I run into gaps that pretty much make any information after it "come from nowhere" (because I don't know what had just happened).
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Turing:
View.Set("offscreenonly") var m, t, fontID, x, y, gx, gy, s, xdir, ydir, ip, fs, timeRunning :int
var ch :string(1)
var ps :string(24)
t :=0
m :=0
timeRunning :=Time.Elapsed
x :=1
y :=1
gx :=295
gy :=1
xdir :=1
ydir :=1
s :=0
ip :=2
fs :=0
loop%Main Loop if ip =2then
fontID :=Font.New("Courier:14:bold, italic") Font.Draw("Pong : A Lonely Existance",190, 250, fontID, black) Font.Free(fontID) locate(13, 39) put"Controls:" locate(15, 10) put"Red Paddle Left / Right -:- Left Arrow / Right Arrow" locate(16, 10) put"Pause -:- P" locate(17, 10) put"Quit -:- ESC" locate(24, 33) drawfillbox(100, 0, 500, 40, 0) if fs =0then
fontID :=Font.New("fixedsys:10") Font.Draw("Hold [Space] To Start",255, 25, fontID, black) Font.Free(fontID) endif
fs := fs + 1 if fs =2then
fs :=0 endif delay(450) var chars6 :arraycharofboolean Input.KeyDown(chars6) if chars6 (' ')then
ip :=0 drawfillbox(10, 10, 500, 390, 0) endif endif if ip =1then locate(11, 25) put"Game Paused Press [Space] to continue" if ip =1then locate(12, 25) locate(13, 25) put"Times Ape-Shit'd : ", s
locate(14, 25) put"Time Elapsed : ", m, ":", t div200 var chars5 :arraycharofboolean Input.KeyDown(chars5) if chars5 (' ')then
ip :=0 drawfillbox(10, 10, 500, 390, 0) endif endif endif if ip =0then drawfilloval(x, y, 10, 10, 0) drawoval(x, y, 10, 10, 0) drawfillbox(gx, gy, gx + 58, gy + 10, 0)
x := x + xdir
y := y + ydir
if x >= 640then
xdir := -1 endif if y < 0then
y :=200
x :=300 randint(xdir, -2, 2) randint(ydir, -2, 2) if ydir =0then
ydir := -1 endif if xdir =0then
xdir := -1 endif
s := s + 1 endif if y > 410then
ydir := -1 endif if x < 0then
xdir :=1 endif if y < 10then if gx - 5 < x then if gx + 5 + 60 > x then
ydir :=1 sound(550, 100) sound(1, 1) endif endif endif
var chars :arraycharofboolean Input.KeyDown(chars) if chars (KEY_LEFT_ARROW)then if gx > 20then
gx := gx - 3 endif endif if chars (KEY_RIGHT_ARROW)then if gx < 600 - 20then
gx := gx + 3 endif endif if chars ('p')then
ip :=1 endif
drawfilloval(x, y, 10, 10, 14) drawoval(x, y, 10, 10, 8) drawfillbox(gx, gy, gx + 58, gy + 10, 12) drawbox(gx, gy, gx + 58, gy + 10, 255) if chars (KEY_ESC)then
x :=1
y :=1
gx :=295
gy :=1
xdir :=1
ydir :=1
s :=0
ip :=2
fs :=0 drawfillbox(0, 0, 700, 400, 0) endif delay(5)
t := t + 1 if t div200=60then
m := m + 1
t :=0 endif endif View.Update endloop
Please specify what version of Turing you are using
This coding works with 4.1.1 (newest version)
Sponsor Sponsor
Insectoid
Posted: Sat Sep 03, 2011 5:26 pm Post subject: RE:Help me comprehend some (SIMPLE) Pong coding
Quote:
I'm trying to learn how to code in turing, and I know that this is one of the best ways to go about it.
I'm not a fan of this method of 'learning'. It's like saying taking apart your car is the best way to become a mechanic.
There are several tutorials that explain how to create a game in Turing from scratch. There's also the Turing Walkthrough, which will teach you enough to start using the language.
Nobody is gonna go through this code an explain it to you. It's not worth our time. If you really want to learn, put some effort in. Pasting code on a forum and asking us to explain it isn't effort.
Aange10
Posted: Sat Sep 03, 2011 5:41 pm Post subject: Re: Help me comprehend some (SIMPLE) Pong coding
Quote:
Nobody is gonna go through this code an explain it to you. It's not worth our time. If you really want to learn, put some effort in. Pasting code on a forum and asking us to explain it isn't effort.
If you don't want to do it, then don't. But don't flame me. For example, telling me that I am not trying to "put some effort in" is very unproductive, and I consider that flaming. Because you are insulting me when you have no idea what I've been doing. Also, I said very nicely if you didn't want to take the time to do it, then that is fine. But telling me that asking somebody to explain it to me isn't "effort" is ignorance on your part. I'm using this stuff to learn. I'm not being lazy OR lacking effort.
Simply putting it, your teacher explains a worksheet to you before you do it. Or the paper has directions at the top before you start working. I am just asking for somebody kind enough to help me, and ask those who don't want to NOT to flame me.
I'm currently working on coding a game based off the same code this is using. Sadly I don't think it's worth my time to copy and paste and just change some words... I'm trying to take this code and pretty much re-write the game, in my own taste.
I've read the walkthrough, and I use it as a reference everytime I need help. I said that I've read the walkthroughs in my post. It's just hard to read text straight from the book, and use it in practice. Which is why I said that hands on is better.
Raknarg
Posted: Sat Sep 03, 2011 5:45 pm Post subject: RE:Help me comprehend some (SIMPLE) Pong coding
If your friend is going to give you this as source code, he should comment it to make it easier for others to read.
Also he should start using variable with a little more meaning. Eventually once you get into larger and more complx games, you cannot have a hoarde of random letter variables. Not to mention its a pain in the ass to read.
Insectoid
Posted: Sat Sep 03, 2011 6:29 pm Post subject: RE:Help me comprehend some (SIMPLE) Pong coding
Ah, I missed the line where you said you read some walkthroughs.
However, that doesn't change my opinion. How is looking at someone else's code any more hands-on than reading a tutorial or textbook? They have examples with comments in them! I'd not be surprised if there was a specific Pong tutorial. Yes, I'm flaming. I admit it. But now I'm gonna help you out.
So, what is Pong? It's essentially two paddles, each of which moves up and down. Do you know how to take keyboard input and use it to make something move? If you don't, look up Input.KeyDown.
There's also a ball, which moves in many directions. For simplicity let's limit it to 4 (up right, down right, up left, down left). You'll want x and y direction variables, which are either 1 or -1. The ball moves at ball_speed*x_direction and ball_speed*y_direction (where ball_speed is the number of pixels the ball moves in the X or Y direction per frame). Changing the direction of the ball is as simple as multiplying the x_direction or y_direction by -1. For example, if your ball hits the roof, multiply the direction by -1 to change direction. If you don't know how to do basic rectangular collision (we can treat the ball as a rectangle) look it up. There's tons of tutorials.
As for score- maintain an integer variable for each player that represents the score.
If you want sounds, you can just play them whenever say, a collision happens (by the time you even think about sounds the game should be functional).
If you want the ball to move in more than 4 directions based on the speed of the paddle, look up 360 degree movement (there's a tutorial dedicated to it). If, say, the 'up' key is pressed when the ball collides with a paddle, the ball gains Y velocity and loses X velocity (the formula itself is up to you).
Oh, and you may run into issues with your ball or paddle 'sticking' to the walls. This is because the ball may be 5 pixels from the roof in one frame, and then it moves 10 pixels up so it's 5 pixels above the roof. If this happens the game will just keep flipping the y_direction variable so the ball will never really move. To remedy this, whenever the ball collides with the roof, set the y position to just under the roof (adapt for other walls).
tl;dr- things you need to know:
-Input.KeyDown
-Collision detection
-movement (basic or advanced. Up to you)
-Making things happen at the same time (I didn't mention this earlier)
-View.Update (I didn't mention this earlier either)
Thats it. That's all you need to know to build a functional game of Pong.
Zren
Posted: Sat Sep 03, 2011 6:36 pm Post subject: Re: Help me comprehend some (SIMPLE) Pong coding
These variables could be better.
ip = isPaused, but it really should be gameState if your using it as an integer instead of a boolean (as you use it for the main menu as well (values 2, 3, ... as well).
gx, gy = bottom left point of paddle. The size of the paddle are hardcoded constants (bad). Hardcoded constants make it hard to change sizes on the fly.
Right now its a 59x11 box. If we were to store then in paddleWidth and paddleHeight, then we could later on change the size of it easier (powerups etc).
x, y are the coordinates of the ball. You should specify it! Especially when you're dealing with more than one object with coordinates (which is nearly everytime).
xdir, ydir is the displacement in their respective planes each frame. When it hits a wall, exteremely simplified (and incorrect) collision detection is done.
Basically when you hit the left wall (x < 0) you reverse your direction in the x plane.
He screwed up since he used the range (-2, 2), so when it hit that wall:
if x < 0 then
xdir := 1
end if
Boom, the speed decreased.
Use: xDir := -xDir as -(-n) = +n
t represents the frameCount. t is usually short for time, so in this case he could probably get away with it.
m = minutes
delay(5) is 5 milliseconds.
1000 / 5 = 200 framesPerSecond
Since t = frameCount ...
frameCount / framesPerSecond = seconds
t div 200 = 60 is one minute.
s is a score -> put "Times Ape-Shit'd : ", s
fs is used to count frames. Specifically for the little blinking "hold space" message. It's one of the more attrocious variables here as your already counting the frames and could just do:
if frameCount % 3 = 0 then blink!
% is the modulus operator btw, it's to calculate the remainder in division. Useful for seeing if a number is even or odd (n % 2 = 0 -> even).
Ignore the fact he created 3 different arrays to capture keyboard states.
var chars : array char of boolean
var chars5 : array char of boolean
var chars6 : array char of boolean
Each section of block of code has it's own scope. At the end of that block of code, all local variables (those defined in the block of code) are forgotten).
Eg, This is valid code:
Turing:
iffalsethen var n :=0 elsiffalsethen var n :=0 else var n :=0 endif
var n :=0
... Okay, this turned out longer than I thought.
Aange10
Posted: Sat Sep 03, 2011 6:51 pm Post subject: RE:Help me comprehend some (SIMPLE) Pong coding
Thank you guys both for the help! I'm going to go begin a new coding, and start it from scratch. Shouldn't take me too long. I'll post the results here.
and
*ALSO* I'm very confused on how he made the "hold space" instead of "press space".
Zren
Posted: Sat Sep 03, 2011 7:09 pm Post subject: RE:Help me comprehend some (SIMPLE) Pong coding
I should probably mention the right ways to do things he did badly too... Mainly because there's the chance you'll try to copy this guy instead of thinking for yourself or searching around as you're probably ignorant to realizing there's better ways.
To calculate your timePlayed:
Turing:
var timeAtStart :=Time.Elapsed loop % The difference between now an then in milliseconds % Eg: Started at 7Pm, it's now 8Pm, it's been 1 hour. var timeNow :=Time.Elapsed var timeSinceThen := timeNow - timeAtStart
put timeSinceThen
endloop
I mentioned you could use the same variable name between different blocks of code (so long as they're locally declared variables), but you could just get array with one variable to begin with. I'm talking about the boolean array for keyboard input. The only reason you'd have two arrays is if you wanted to store what you pressed the last frame. Which is particularly useful if you wanted to find out if a key was released or pressed down from the last frame.
The "hold" thing works because he drew the text, then delayed for half a second before checking the keyboard input and reacting to it. If you released before the delay was up, it wouldn't register. It works, but only when nothing else is being drawn/calculated.
Sponsor Sponsor
Aange10
Posted: Sat Sep 03, 2011 9:54 pm Post subject: Re: Help me comprehend some (SIMPLE) Pong coding
Done! ... Thankyou guys for helping me. I really appreciate it. It helps a lot to learn this stuff, and i'm glad you guys took time out of your day for me!(:
..
And to prove i'm not just effortlessly sitting around, I've done my best at programming a paddle ball game (I call that pong, sorry) and keeping it nice and neat.
PLEASE critique!
Turing:
View.Set("Offscreen, graphics:maxx;maxxy") var mainmenu :boolean% Using this varriable to tell wether or not to pull up the main menu. var fontTNR :int% A to allow me to make a font style into a variable var mainmenuexit :string% The varriable i am using to exit the main meny/ skip past it var oval_x1,oval_y1,oval_xr1,oval_yr1 :int% I made the drawoval syntax as variables var oval_speed :int%This is to set my oval's speed var oval_directionx, oval_directiony :int% To set my ovals trajectory direction var box1_x1, box1_x2, box1_y1, box1_y2 :int var chars :arraycharofboolean% Not sure what this is, just know you have to have it to use keys var continue :string% Get the y/n asking if the player would like to continue var score :int% Keeps track of the score
oval_x1 :=70% the x cord for the ball
oval_y1 :=70% the y cord for the ball
oval_xr1 :=10% the radius x for the ball
oval_yr1 :=10% the radius y for the ball
oval_speed :=2% the speed of the ball pfp (Pixles per frame ;) )
oval_directionx :=1% Direction of the x cord of the oval (1 = right, -1 = left)
oval_directiony :=1% direction of the y cord of the oval ( 1 = up, -1 = down)
box1_x1 :=85% Box x1 cord
box1_x2 :=200% box x2 cord
box1_y1 :=20% box y1 cord
box1_y2 :=40% box y2 cord
mainmenu :=true%a varriable to control the main menu
continue :="y"%a varriable to tell wether or not to continue
score :=0 loop% Main loop cls loop% main menu debugging loop if mainmenu =truethen
fontTNR :=Font.New("TimeNewRoman:14") Font.Draw("Game O' Paddle Ball!",maxxdiv2, maxydiv2, fontTNR, green) delay(1000)
fontTNR :=Font.New("Courier:8") Font.Draw("Use AD or Arrow Keys to move! Press b to begin!",maxxdiv2 - 100, maxydiv2 - 20, fontTNR, red)
score :=0% Just to prevent people from spamming the debug system to gain points get mainmenuexit % It asks the user for input else% If mainmenu is not true then it exits this loop, and never brings up the main menu! exit endif if mainmenuexit ="b"then%When user inputs b, it changes mainmenu to false so that the loop will skip the main menu if statement
mainmenu :=false else cls put"Invalid key." delay(2000) exit endif endloop% Ends the main menu de bugging loop cls var timestart :=Time.Elapsed% So I can measure the time elapsed from this point put"Time elapsed:", timestart / 1000% How much time has elapsed since exiting the menu if oval_y1 >= 400then%if y cord of oval goes >=400 then it inverses the direction of the y
oval_directiony := oval_directiony * -1 endif if oval_x1 >= 630then%if the x cord of the oval goes >= 630 then it inverses the direction of the x
oval_directionx := oval_directionx * -1 endif if oval_x1 <= 0then% x cord direction inverse
oval_directionx := oval_directionx * -1 endif loop% Loop to de bug the continue system if oval_y1 <= 20then% if y cord hits <= 20 it asks if you'd like to continue (reseting score) cls put"Would you like to continue? y/n: "..
get continue % if you'd like to continue.. else exit endif if continue ="y"or continue ="n"then cls% Clears the screen after you type in a valid answer
oval_x1 :=328
oval_y1 :=228
oval_directionx :=1
oval_directiony :=1% Reset the direction & placement of the ball
score :=0% Resets the score exit else put"Invalid answer." delay(2000) cls endif endloop% End the debugging loop if continue ="n"then put"Good Bye!"%Says goodbye and closes if you chose not to keep going delay(2000) break endif
oval_x1 +=(oval_directionx * oval_speed)% adds the direction *speed to the x cord of the ball
oval_y1 +=(oval_directiony * oval_speed)% " but with the y cord drawfilloval(oval_x1,oval_y1,oval_xr1,oval_yr1,yellow)%draw the ball Input.KeyDown(chars) if chars (KEY_RIGHT_ARROW)then%Right key move the paddle to the right
box1_x1 := box1_x1 + 5
box1_x2 := box1_x2 + 5 endif if chars ('d')then% " but d
box1_x1 := box1_x1 + 5
box1_x2 := box1_x2 + 5 endif if chars (KEY_LEFT_ARROW)then% left key move paddle to the left
box1_x2 := box1_x2 - 5
box1_x1 := box1_x1 - 5 endif if chars ('a')then% " but a
box1_x2 := box1_x2 - 5
box1_x1 := box1_x1 - 5 endif if box1_x1 >= 630 - 115or box1_x2 >= 630then%Sets the far x bounds for the paddle
box1_x1 := box1_x1 - 5
box1_x2 := box1_x2 - 5 endif if box1_x1 <= 0or box1_x2 <= 15 + 115then%Sets the near x bounds for the paddle
box1_x1 := box1_x1 + 5
box1_x2 := box1_x2 + 5 endif drawfillbox(box1_x1, box1_y1, box1_x2, box1_y2, red)%Draw the changes to the box if oval_x1 <= box1_x2 & oval_y1 <= box1_y2 & oval_x1 >= box1_x1 & oval_y1 >= box1_y1 then%If collision occurs, the ball moves in the oposite direction
oval_directiony := oval_directiony * -1
score := score + 1 endif put"Score:", score
View.Update% Supposed to fix screen flickering delay(10) endloop
If you guys would.. I'd like to know 2 things.
1) How can i make my timer only tell me the integer the second is in, not the real number? (No decimals)
2) Can you help me fix my ball disappearing at the top (Because the put lines are coloring the yellow white)?
Also if you wanted to help me with an annoyance I have found...
My "Main Menu Debugging System" makes my menu tell you that you entered an incorrect key if you choose a key other than "b". When it does this all it does is put a statement, and then exits the loop and continues on through the main loop. (Which when you get back to go through it a second time, mainmenu will still be set to true since you never hit "b", making you go back through the main menu. Which is how the debugging works.) However, the "annoyance" is that it flickers the pong ball/paddle screen before it takes you back. Can you think of a way to prevent this?
Insectoid
Posted: Sat Sep 03, 2011 10:39 pm Post subject: RE:Help me comprehend some (SIMPLE) Pong coding
1. round() is your friend.
2. colorback() will change the color of those lines. Don't draw a box around the screen. Just use colorback().
Annoyance: Look at your code.
code:
else
cls
put "Invalid key."
delay (2000)
exit
end if
Remember that you're in offscreenonly mode.
Aange10
Posted: Sat Sep 03, 2011 11:17 pm Post subject: RE:Help me comprehend some (SIMPLE) Pong coding
Thankyou for the help! It all works! Anything that I should improve on/ add in?
Aange10
Posted: Mon Sep 05, 2011 1:05 am Post subject: Re: Help me comprehend some (SIMPLE) Pong coding
At this section in my coding i'd like to make my time reset. How would I go about doing that? I've tried a couple different ways, but none of them worked. Some steering in the right direction would be greatly appreciated!
This is the section i need to reset the time at.
Turing:
if continue ="y"or continue ="n"then cls% Clears the screen after you type in a valid answer
oval_x1 :=328
oval_y1 :=228
oval_directionx :=1
oval_directiony :=1% Reset the direction & placement of the ball
score :=0% Resets the score exit else
This is the full coding.
Turing:
View.Set("offscreenonly, graphics:maxx;maxxy") var mainmenu :boolean% Using this varriable to tell wether or not to pull up the main menu. var fontTNR :int% A to allow me to make a font style into a variable var mainmenuexit :string% The varriable i am using to exit the main meny/ skip past it var oval_x1,oval_y1,oval_xr1,oval_yr1 :int% I made the drawoval syntax as variables var oval_speed :int%This is to set my oval's speed var oval_directionx, oval_directiony :int% To set my ovals trajectory direction var box1_x1, box1_x2, box1_y1, box1_y2 :int var chars :arraycharofboolean% Not sure what this is, just know you have to have it to use keys var continue :string% Get the y/n asking if the player would like to continue var score :int% Keeps track of the score var time1 :real% Trying to reset timer...
oval_x1 :=70% the x cord for the ball
oval_y1 :=70% the y cord for the ball
oval_xr1 :=10% the radius x for the ball
oval_yr1 :=10% the radius y for the ball
oval_speed :=2% the speed of the ball pfp (Pixles per frame ;) )
oval_directionx :=1% Direction of the x cord of the oval (1 = right, -1 = left)
oval_directiony :=1% direction of the y cord of the oval ( 1 = up, -1 = down)
box1_x1 :=85% Box x1 cord
box1_x2 :=200% box x2 cord
box1_y1 :=20% box y1 cord
box1_y2 :=40% box y2 cord
mainmenu :=true%a varriable to control the main menu
continue :="y"%a varriable to tell wether or not to continue
score :=0
loop% Main loop cls Input.KeyDown(chars) loop% main menu debugging loop if mainmenu =truethen View.Set("nooffscreenonly, graphics:maxx;maxxy")
fontTNR :=Font.New("TimeNewRoman:14") Font.Draw("Game O' Paddle Ball!",maxxdiv2, maxydiv2, fontTNR, green) delay(1000)
fontTNR :=Font.New("Courier:8") Font.Draw("Use AD or Arrow Keys to move! Press b to begin!",maxxdiv2 - 100, maxydiv2 - 20, fontTNR, red)
score :=0% Just to prevent people from spamming the debug system to gain points get mainmenuexit % It asks the user for input View.Set("offscreenonly, graphics:maxx;maxxy") else exit endif if mainmenuexit ="b"then%When user inputs b, it changes mainmenu to false so that the loop will skip the main menu if statement
mainmenu :=false else cls put"Invalid key." View.Update delay(2000) exit endif endloop% Ends the main menu de bugging loop cls var timestart :=Time.Elapsed% So I can measure the time elapsed from this point
time1 := timestart
if oval_y1 >= 400then%if y cord of oval goes >=400 then it inverses the direction of the y
oval_directiony := oval_directiony * -1 endif if oval_x1 >= 630then%if the x cord of the oval goes >= 630 then it inverses the direction of the x
oval_directionx := oval_directionx * -1 endif if oval_x1 <= 0then% x cord direction inverse
oval_directionx := oval_directionx * -1 endif loop% Loop to de bug the continue system if oval_y1 <= 20then% if y cord hits <= 20 it asks if you'd like to continue (reseting score) cls put"Would you like to continue? y/n: "..
get continue % if you'd like to continue.. else exit endif if continue ="y"or continue ="n"then cls% Clears the screen after you type in a valid answer
oval_x1 :=328
oval_y1 :=228
oval_directionx :=1
oval_directiony :=1% Reset the direction & placement of the ball
score :=0% Resets the score exit else put"Invalid answer." delay(2000) cls endif endloop% End the debugging loop if continue ="n"then put"Good Bye!"%Says goodbye and closes if you chose not to keep going delay(2000) break endif
oval_x1 +=(oval_directionx * oval_speed)% adds the direction *speed to the x cord of the ball
oval_y1 +=(oval_directiony * oval_speed)% " but with the y cord if chars (KEY_RIGHT_ARROW)then%Right key move the paddle to the right
box1_x1 := box1_x1 + 5
box1_x2 := box1_x2 + 5 endif if chars ('d')then% " but d
box1_x1 := box1_x1 + 5
box1_x2 := box1_x2 + 5 endif if chars (KEY_LEFT_ARROW)then% left key move paddle to the left
box1_x2 := box1_x2 - 5
box1_x1 := box1_x1 - 5 endif if chars ('a')then% " but a
box1_x2 := box1_x2 - 5
box1_x1 := box1_x1 - 5 endif if box1_x1 >= 630 - 115or box1_x2 >= 630then%Sets the far x bounds for the paddle
box1_x1 := box1_x1 - 5
box1_x2 := box1_x2 - 5 endif if box1_x1 <= 0or box1_x2 <= 15 + 115then%Sets the near x bounds for the paddle
box1_x1 := box1_x1 + 5
box1_x2 := box1_x2 + 5 endif if oval_x1 <= box1_x2 & oval_y1 <= box1_y2 & oval_x1 >= box1_x1 & oval_y1 >= box1_y1 then%If collision occurs, the ball moves in the oposite direction
oval_directiony := oval_directiony * -1
score := score + 1 endif colourback(0)put"Score:", score
colourback(0)put"Time elapsed:",round(time1 / 1000)% How much time has elapsed since exiting the menu drawfillbox(box1_x1, box1_y1, box1_x2, box1_y2, red)%Draw the changes to the box drawfilloval(oval_x1,oval_y1,oval_xr1,oval_yr1,yellow)%draw the ball View.Update% Supposed to fix screen flickering delay(5) endloop
Insectoid
Posted: Mon Sep 05, 2011 1:19 am Post subject: RE:Help me comprehend some (SIMPLE) Pong coding
I'm sure you can figure it out. Remember Time.Elapsed()? Big hint right there.
Aange10
Posted: Mon Sep 05, 2011 11:43 am Post subject: Re: Help me comprehend some (SIMPLE) Pong coding
I've read all the help section on the turing window, and i've searched the forums for "Time.Elapsed()" "Time Resetting" "Resetting time", and spent about half an hour trying to find out the syntax of Time.Elapsed ... The help menu for turing didn't say what the () was for, and Time.Elapsed() seems to be the same as Time.Elapsed.
I've tried codes like
code:
timestart := Time.Elapsed() - timestart
% And
timestart := 0
% And
timestart := Time.Elapsed() * 0
I've tried a lot of other things that the turing said was inapproriate.
Turing:
Time.Elapsed:=0% Tells me time elapsed isn't a variable..
timestart :=Time.Elapsed(0)% Tells me the parameters for Time.Elapsed are inappropriate
Is there something i'm missing here? Is there not a way to say Time.Elapsed (or timestart since it's my variable) := 0 ...... And it work?
Insectoid
Posted: Mon Sep 05, 2011 12:24 pm Post subject: RE:Help me comprehend some (SIMPLE) Pong coding
The () just specifies that it's a function. That's right, it's not a variable. It *always* returns the time in milliseconds since the program began execution. You can't change what Time.Elapsed() returns. You can, however, assign the return value to a variable.
int i = Time.Elapsed()
You don't need any extra commands. You need math.
You have got a few things to work with.
-You can get the time since the program began (Time.Elapsed())
-You can assign that to a variable
-Because 'time' is just an integer, you can apply any math function to it (addition, subtraction, etc). Big hint: You need subtraction.