
-----------------------------------
mike200015
Thu Apr 14, 2005 1:15 pm

Objects
-----------------------------------
I was wondering how to make objects in turing, or if there is a tutorial about it?

-----------------------------------
jamonathin
Thu Apr 14, 2005 3:06 pm


-----------------------------------
Does this answer your question? http://www.compsci.ca/v2/viewtopic.php?t=8349&highlight=object

-----------------------------------
Tony
Thu Apr 14, 2005 3:19 pm


-----------------------------------
I think he might be looking for

var id: pointer to Class
new Class, id
id -> method(argument)


-----------------------------------
Cervantes
Thu Apr 14, 2005 5:20 pm


-----------------------------------
Or perhaps records and types?


type student :
  record
    id : int
    class : array 1 .. 8 of string
    mark : array 1 .. 8 of real
  end record

var Billy_Joel : student

    
Search the tutorials for whichever you're looking for.

-----------------------------------
mike200015
Thu Apr 14, 2005 10:15 pm


-----------------------------------
Does this answer your question? 
That tutorial helped alot. 

Im adding a blockout/bustout.. watever its called game, to my pong game. so i have 156 blocks that draw on the screen each with a random colour.. and to do that i made a record for the x,y and an array of it. So wat i need to do now is make the block dissapear when the ball hits it. But i dont know how to go about doing that. Heres the blockout part that i have so far, with bricks and ball and paddle:

There is also a few other problems with it:
1. When the paddle is moving and the ball hits it, the ball sometimes stays on the paddle and slides with it.
2. Sometimes the ball gets stuck inbetween the bricks and doesnt come out.
3. The ball sometimes slides along the bricks.

Also if there is a better way of doing this than the way i did.

If anyone can help I'd appreciate it!



type block :
    record
        x : int
        y : int
    end record
var xvalue : int := -15
var yvalue : int := 0
var blocks : array 1 .. 156 of block
var colours : array 1 .. 10 of int := init (40, 50, 60, 70, 80, 90, 100, 110, 120, 130)
var blockcol : array 1 .. 156 of int
var chars : array char of boolean
var ballx := maxx div 2
var bally := 15
var pos := maxx div 2
var xmod := 1
var ymod := 1
var tries := 3
var score := 0
var font3 := Font.New ("Courier New:10:bold") %All other font
var keyPressed : string (1)
setscreen ("graphics:640;400,title:Mikes X-Treme Pong Game,nocursor")
loop
    cls
    for i : 1 .. 156
        randint (blockcol (i), 1, 10)
    end for
    setscreen ("offscreenonly")
    loop
        cls
        for i : 1 .. 156
            if (i - 1) rem 12 = 0 then
                xvalue += 45
                yvalue := 230
            end if
            blocks (i).x := xvalue
            blocks (i).y := yvalue
            drawfillbox (blocks (i).x, blocks (i).y + 2, blocks (i).x + 40, blocks (i).y + 10, colours (blockcol (i)))
            yvalue += 12
        end for
        drawfillbox (pos - 25, 0, pos + 25, 5, 1)     %user paddle
        drawfilloval (ballx, bally, 10, 10, 12)             %ball
        Font.Draw ("Tries Remaining: " + intstr (tries), 2, maxy - 12, font3, blue)
        Font.Draw ("Score:  " + intstr (score), maxx - 83, maxy - 12, font3, blue)
        drawline (0, maxy - 20, maxx, maxy - 20, RGB.AddColor (0.1, 0.1, 0.1))         %top boundary line
        Input.KeyDown (chars)
        if chars (KEY_LEFT_ARROW) and pos - 25 > 0 then          %Moves paddle left
            pos -= 1
            ballx -= 1
        elsif chars (KEY_RIGHT_ARROW) and pos + 30 < maxx then          %Moves paddle right
            pos += 1
            ballx += 1
        elsif chars (KEY_UP_ARROW) then
            exit
        end if
        xvalue := -15
        yvalue := 0
        View.Update
    end loop
    loop
        ballx += xmod
        bally += ymod
        if ballx >= maxx then
            xmod := -xmod                 %ball goes in opposite x-direction
            sound (500, 10)
        elsif ballx = maxy - 30 then
            ymod := -ymod                 %ball goes in opposite y-direction
            sound (500, 10)
        elsif bally  0 then          %Moves paddle left
            pos -= 2
        elsif chars (KEY_RIGHT_ARROW) and pos + 25 < maxx then          %Moves paddle right
            pos += 2
        end if
        if chars ('x') then
            exit
        elsif chars ('p') then             %Pauses game
            setscreen ("nooffscreenonly")
            Font.Draw ("GAME PAUSED", maxx div 2 - 20, maxy - 12, font3, blue)
            Font.Draw ("*Press ENTER To Resume*", maxx div 2 - Font.Width ("*Press ENTER To Resume*", font3)
                div 2, 100, font3, blue)
            loop
                getch (keyPressed)
                exit when keyPressed = KEY_ENTER
            end loop
            setscreen ("offscreenonly")
        end if
        xvalue := -15
        yvalue := 0
        case whatdotcolour (ballx + 11, bally) or whatdotcolour (ballx - 11, bally) of                           %if ball hits anything green (2)
            label 40, 50, 60, 70, 80, 90, 100, 110, 120, 130 :                                             %it will go in opposite x-direction
                xmod := -xmod
            label blue, 12, yellow, black, 5, 2 :
                xmod := -xmod
            label :
                ballx += xmod
        end case
        case whatdotcolour (ballx, bally + 11) or whatdotcolour (ballx, bally - 11) of                %if ball hits anything green (2)
            label 40, 50, 60, 70, 80, 90, 100, 110, 120, 130 :                                                        %it will go in opposite y-direction
                ymod := -ymod
            label blue, 12, yellow, black, 5, 2 :
                ymod := -ymod
            label :
                bally += ymod
        end case
        /*
         if whatdotcolour (ballx + 11, bally) = padcol or whatdotcolour (ballx - 11, bally) = padcol or
         whatdotcolour (ballx + 11, bally) = blockcol () or whatdotcolour (ballx - 11, bally) = padcol then
         xmod := -xmod
         end if
         if whatdotcolour (ballx, bally + 11) = padcol or whatdotcolour (ballx, bally - 11) = padcol then
         ymod := -ymod
         end if
         */
        View.Update
        delay (2)
        cls
    end loop
    if chars ('x') then
        exit
    end if
end loop


-----------------------------------
jamonathin
Fri Apr 15, 2005 7:59 am


-----------------------------------
What I suggest doing is making a "hit" variable (int) in your "type". Assign all 156 "hit"s to 0, making all of them not hit.  When the ball does hit that block, then make "hit" 1.  When you go to redraw all of the blocks, use an if statement like this
for i : 1 .. 156
        if blocks(i).hit = 0 then
             drawfillbox (whatever)
        end if
end for

Now what I suggest for determining if the blocks are beign hit is a for loop such as this:
 
for i : 1 .. upper (colours)
    if whatdotcolour (ballx + 11, bally) = colours (i) or whatdotcolour (ballx - 11, bally) = colours (i) then
        xmod *= -1 % same as xmod := - xmod
    end if
    if whatdotcolour (ballx, bally + 11) = colours (i) or whatdotcolour (ballx, bally - 11) = colours (i) then
        ymod *= -1
    end if
end for

The reason they're in two 'if' statements is because if the ball hits a corner, it will bounce off both sides (top and side).

-----------------------------------
mike200015
Fri Apr 15, 2005 1:42 pm


-----------------------------------
so when the ball hits the block, and the hit is set to 1, then do i redraw the block in the bakground colour.. or do i somehow delete it from the array or something??

-----------------------------------
jamonathin
Fri Apr 15, 2005 1:48 pm


-----------------------------------
use a for loop in when you draw all the boxes.  And check every hit, and if the hit on any of the blocks = 1 then dont draw the box.

-----------------------------------
mike200015
Fri Apr 15, 2005 3:24 pm


-----------------------------------
how do i check which block the ball hit, im using a case for the ball to bounce off:
 case whatdotcolour (ballx + 11, bally) or whatdotcolour (ballx - 11, bally) of                           %if ball hits anything green (2)
            label 40, 50, 60, 70, 80, 90, 100, 110, 120, 130 :                                             %it will go in opposite x-direction
                xmod *= -1
            label blue, 12, yellow, black, 5, 2 :
                xmod *= -1
            label :
                xmod *= 1
        end case
        case whatdotcolour (ballx, bally + 11) or whatdotcolour (ballx, bally - 11) of                %if ball hits anything green (2)
            label 40, 50, 60, 70, 80, 90, 100, 110, 120, 130 :                                                        %it will go in opposite y-direction
                ymod *= -1
            label blue, 12, yellow, black, 5, 2 :
                ymod *= -1
            label :
                ymod *= 1
        end case
i made the hits record and set them all to 0, now i need to set to 1 when the ball hits the block, but how do i check which block the ball hit?

-----------------------------------
jamonathin
Fri Apr 15, 2005 3:40 pm


-----------------------------------
well, what you can do is check coordinates.  Since the ball hits at the tip, you can use the x-value of the ball to determine which block is it.  Now for the y-value, you need to check the radius of the ball and the location of the block.
Basically if the y-value of the ball + the radius of the ball is equal to the y-value of the block then. . .   But, if that doesn't work, then check if the difference between the 2 co-ordinates is less than, 4 or so then.

So . . .

for i: 1 .. blocks
     if x >= blockx (i) and x = blocky (i) then
     end if
%OR
     if x >= blockx (i) and x 