Computer Science Canada
Explain code please =)
|Author:||Nezura [ Sat May 01, 2004 8:20 pm ]|
|Post subject:||Explain code please =)|
Could someone explain every line of this code? i get most of it but it'll be better if someone could go more indepth.
|Author:||GreenTiger [ Sat May 01, 2004 8:47 pm ]|
Okay the first three lines are a function that can be run at any time in the program. WHen you call distance, it will output the ABSOLUTE value of x1-y1, that is, making it positive even if it's a negative.
After the function, it calls the variables and starts them all off at 320, except for y1.
Then, we enter a never-ending loop
Inside this loop, it checks the mouse's position, and puts the x position in x2, the y in y2 and records if there's a mouse button press in mb.
Keep in mind y is the vertical position while x is horizontal.
Ok, then a bunch of if statements:
if those conditions are true, it adds/subtracts the result of the distance function.
IE: for the first one, the ABSOLUTE value of x1 - x2 divided by 10
After those if statements, it draws an oval centered at x1, y1, of a radius of 20 and colour 9 and delays, clears the screen and updates the view.
One of those last two is redundant.
From now on, highlight a term you don't understand and press F9 that should help you better than I can.
|Author:||Nezura [ Sun May 02, 2004 1:22 pm ]|