Posted: Tue Sep 13, 2011 8:05 pm Post subject: RE:Help me comprehend some (SIMPLE) Pong coding
I'm trying to decipher this (so I can use it in my own programs) and I'm tracing the execution to see how it is working. But what it is doing is when it hits the right edge it ends the x for and adds 1 to the y for, and repeats. ... I don't know what is telling it to do that! I think it has to do with
means. Could you please explain the "by cellW"? ... also what is making the y jump up by 10 and not 1?
Thanks a ton for the code, it's a ton of help!(:
EDIT: I just realized that the "by cellW" is just saying to move it by increments of CellW! xD I'm very happy to have figure that out.
However I'm a bit confused with
Turing:
var cell_Width :=40 var cell_Height :=10 var w := cell_Width - 1 var h := cell_Height - 1
in it's relation to
Turing:
Draw.FillBox(startX + x, startY + y, startX + x + w, startY + y + h, Rand.Int (0, maxcolor))
...
What is the point of making it 1 less than cell_width?
Sponsor Sponsor
Aange10
Posted: Tue Sep 13, 2011 8:26 pm Post subject: RE:Help me comprehend some (SIMPLE) Pong coding
Also, I hate to double post.. But this is my deciphered version of the code. If there is any concept i missed/ incorrectly analyzed, please tell me!(: Thanks
Turing:
var startX :=0% Bottom left var startY :=maxydiv2% Mid var cell_Width :=40% width var cell_Height :=10% height var w := cell_Width - 1 var h := cell_Height - 1 for y :0.. 100by cell_Height % Goes by cell_height (AKA 10) for x :0.. maxxby cell_Width % Goes by cell width (AKA 40) locatexy(maxx*0, maxy) colorback(0)put"For y :", y, " For x :",x
Draw.FillBox(startX + x, startY + y, startX + x + w, startY + y + h, Rand.Int (0, maxcolor)) delay(100) endfor endfor %startX + x is adding the box number (because x is going to make box 1 % = to 40, box 2 = 80, etc.) to the start x. So if it's on box 2 it will % go 80 away from the start point.
%startY + y is the same idea; everytime the x reaches maxx the y is %increased by 10 (from the first for) which is making the seperate %rows.
%startX + x + w is doing the same as StartX + x (finding the position) %and then adding the a width to it (so that the points are drawn apart) % StartX + x + w is StartX + x + 39 [dunno why not 40]
%startY + y + h is doing the same as startY (positioning it) and adding % a height to it so that the points are drawn apart % StartY + y + h is StartY + y + 9 [dunno why not 39]
Zren
Posted: Tue Sep 13, 2011 10:04 pm Post subject: RE:Help me comprehend some (SIMPLE) Pong coding
We don't want the boxes to overlap. Drawing (0 .. 40) and then (40 .. 80) would have the second box draw over (a small) bit of the previous box.
Also:
The range of numbers 0 .. 39, or 40 .. 79 is exactly 40, or the target width we desire.
0 <= x <= 39
0 <= x <= 40
The latter has 41 numbers.
if you still don't understand, try this:
My goal here is to say that if any integer within 10 numbers of color_1 is = color_2 then it will execute the if statement.
2) I have my blocks being generated. But now how will I set up collision on these blocks (My ball colliding on them)? Also, once i do set up collision, how do i make the block disappear?
Thanks!
EDIT: And I'm also still having the same problem as before; My ball is going into the sides of my paddle and my code isn't exactly showing me why.
Turing:
if oval_x1 <= box1_x2 & oval_y1 <= box1_y2 & oval_x1 >= box1_x1 & oval_y1 >= box1_y1 then
Zren
Posted: Thu Sep 15, 2011 1:16 am Post subject: RE:Help me comprehend some (SIMPLE) Pong coding
Please tell me you're not using whatdotcolor colision.
As for Q1: isn't that just a-10 <= b <= a+10 ?
Q2: Either remove it from the flexible array, or have a 'flag' variable for if it exists anymore.
Q3: You're only checking if the center point is within the rectangle.
Aange10
Posted: Thu Sep 15, 2011 5:14 pm Post subject: RE:Help me comprehend some (SIMPLE) Pong coding
Q1: Fixed, thankyou Zren!
and for Q3: I'll go and re read some of the tutorials to get the entire ball to be detected, thanks!
Q2: Well I'm not using an array (my codes at the bottom), so I guess i'll have to go with a flag variable. But how would I program collision on these random width blocks, and how would i make the flag detect if the blocks are still there?