Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Help me comprehend some (SIMPLE) Pong coding
Index -> Programming, Turing -> Turing Help
Goto page Previous  1, 2, 3
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Aange10




PostPosted: 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

Turing:

for x : 0 .. maxx by cellW

but i don't know what
Turing:

maxx by cellW

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
Sponsor
sponsor
Aange10




PostPosted: 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 := maxy div 2 % Mid
var cell_Width := 40 % width
var cell_Height := 10 % height
var w := cell_Width - 1
var h := cell_Height - 1
for y : 0 .. 100 by cell_Height % Goes by cell_height (AKA 10)
    for x : 0 .. maxx by 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)
    end for
end for
%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




PostPosted: 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:
Turing:

View.Set ("text")
var count : int

proc countRange (minN, maxN : int)
    count := 0
    for i : minN .. maxN
        put "i: ", i
        count += 1
    end for
    put skip, "count: ", count, skip
end countRange

countRange (0, 39)
countRange (0, 40)
countRange (40, 79)
Aange10




PostPosted: Wed Sep 14, 2011 6:45 pm   Post subject: RE:Help me comprehend some (SIMPLE) Pong coding

I see I see, thankyou!(:
Aange10




PostPosted: Wed Sep 14, 2011 8:51 pm   Post subject: Re: Help me comprehend some (SIMPLE) Pong coding

Alright, cool. So I've developed a program to randomly generate the blocks with a random width. Now I ask two questions.

1) Is there something I could use to make this very long line shorter?
Turing:

if color_1 + 10 = color_2 or color_1 + 9 = color_2 or color_1 + 8 = color_2 or color_1 + 7 = color_2 or color_1 + 6 = color_2 or color_1 + 5 = color_2 or color_1 + 4 = color_2 or color_1 + 3 = color_2 or color_1 + 2 = color_2 or color_1 + 1 = color_2 or color_1 = color_2 or color_1 - 1 = color_2 or color_1 - 2 = color_2 or color_1 - 3 = color_2 or color_1 - 4 = color_2 or color_1 - 5 = color_2 or color_1 - 6 = color_2 or color_1 - 7 = color_2 or color_1 - 8 = color_2 or color_1 - 9 = color_2 or color_1 - 10 = color_2 then


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




PostPosted: 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




PostPosted: 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?


Turing:

var start_x, start_y, box_width, box_height, color_1, bh, bw, color_2, color_3 : int
start_x := 0
start_y := 100
box_height := 20
box_width := Rand.Int (33, 120)
bh := box_height - 1
bw := box_width - 1
color_1 := Rand.Int (1, 255)
color_2 := color_1 + 11

View.Set ("Offscreenonly,graphics:maxx;maxxy")
procedure Draw_Brick
    box_width := Rand.Int (33, 120)
    for height_a : 0 .. 100 by box_height
        for width_a : 0 .. maxx by box_width
            loop
                color_1 := Rand.Int (1, 55)
                if color_1 - 25 <= color_2 and color_2 <= color_1 + 25 then
                else
                    exit
                end if
            end loop
            color_2 := color_1
            drawfillbox (start_x + width_a, start_y + height_a, start_x + width_a + bw, start_y + height_a + bh, color_2)
            locatexy (0, maxy)
            put "Height_A:", height_a, " Width_A:", width_a
            delay (50)
            View.Update
        end for
    end for
end Draw_Brick
%%%%%Main Loop
Draw_Brick
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 3 of 3  [ 37 Posts ]
Goto page Previous  1, 2, 3
Jump to:   


Style:  
Search: