
-----------------------------------
rjm72
Thu Dec 16, 2004 2:24 pm

Update on my pinball
-----------------------------------
This is the same game i put on the forum a week or two ago but ive added a second level(note i will be maiking more levels) and changed a few other things.


 % Ryan Murray  TIK2O
% December 8, 2004
% pinball.t

cls

View.Set ("offscreenonly")


var xchange : int
var ychange : int
var count : int
var kolor : int
var count1 : int
var x : int
var y : int
var size : int
var col : int
var speed : int
col := 42
count := 0
count1 := 5
speed := 3

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
process ping
    var chars : array char of boolean
    View.Set ("offscreenonly")
    var x, x2 : int
    x := 320
    x2 := 260
    loop
        Input.KeyDown (chars)

        drawfillbox (x, 10, x2, 20, black)


        if chars (KEY_RIGHT_ARROW) then
            x := x + 10
            x2 := x2 + 10
        end if
        if chars (KEY_LEFT_ARROW) then
            x := x - 10
            x2 := x2 - 10
        end if
        if chars (KEY_ENTER) then
            col := black
        end if
        drawfillbox (x, 10, x2, 20, white)

        View.Update
        delay (20)
        exit when count1 = 0
    end loop


end ping
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
process ball
    % this loop sets up a random value for the change in the x direction
    % the reason for the loop with the exit is to allow values from -5 to +5 - but NOT allow 0
    loop
        xchange := speed % sets a random speed for the ball (between -5 and 5)
        exit when xchange not= 0
    end loop
    loop
        ychange := speed
        exit when ychange not= 0
    end loop

    % you should add a loop here to randomly assign a ychange value

    Draw.FillBox (5, 5, maxx - 5, maxy - 5, black)
    colorback (black)
    cls

    kolor := red            % sets a random colour for the ball (between 1 and 15)

    size := 6               % sets a random size for the ball (between 5 and 10)
    x := maxx div 2         % sets x position to half way across the screen
    y := maxy div 2         % sets y position to half way up the screen

    Draw.FillOval (x, y, size, size, kolor) % colours the background black
    loop
        drawfillbox (100, 100, 200, 200, col)
        drawfillbox (90, 90, 190, 190, black)
        drawfillbox (400, 100, 500, 200, col)
        drawfillbox (410, 90, 510, 190, black)

        drawfillbox (100, 300, 200, 210, col)
        drawfillbox (90, 300, 190, 220, black)

        drawfillbox (400, 300, 500, 210, col)
        drawfillbox (410, 300, 500, 220, black)

        delay (11)

        % the next if statement checks to see if the ball has hit the right wall
        % (maxx less 5 less the size of the ball less the speed of the ball)
        % or the left wall ( 5 away from 0 + size - speed)

        % when it hits a vertical wall, the x direction reverses.

        if (x >= maxx - 5 - size - xchange) or (x = maxy - 5 - size - ychange) then
            ychange := -ychange
        end if
        if (y  0 then
            if whatdotcolor (x + xchange + size, y) not= black then
                xchange := -xchange
                count := count + 1
            end if
        else
            if
                    whatdotcolor (x + xchange - size, y) not= black then
                xchange := -xchange
                count := count + 1
            end if

        end if

        if ychange > 0 then
            if whatdotcolor (x, y + ychange + size) not= black then
                ychange := -ychange


                count := count + 1

            end if
        else
            if
                    whatdotcolor (x, y + ychange - size) not= black then
                ychange := -ychange

                count := count + 1

            end if

        end if
        if count1 = 2 then
            kolor := yellow
        end if
        if count1 = 5 then
            kolor := blue
        end if
        if count1 = 1 then
            kolor := 12
        end if
        if count1 = 0 then
            kolor := black
        end if
        locate (1, 1)
        color (green)
        put "Score:", count
        put "Lives:", count1

        % erase old ball by covering it up with black
        Draw.FillOval (x, y, size, size, black)

        x := x + xchange
        y := y + ychange
        % draw new ball
        Draw.FillOval (x, y, size, size, kolor)
        View.Update

        if count1 = 0 then
            cls
            put ""
            put ""
            put ""
            put ""
            put ""
            put ""
            put ""
            put "                            -------------------"
            put "                                 GameOver      "
            put "                             Your Score is:", count
            put "                            -------------------"
            exit
        end if
        if count = 50 then
            cls
            put ""
            put ""
            put ""
            put ""
            put ""
            put ""
            put ""
            put "                             -------------------"
            put "                                    Level 2     "
            put "                             -------------------"
            delay (1000)
            cls
            exit
        end if
    end loop
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    loop
        xchange := speed         % sets a random speed for the ball (between -5 and 5)
        exit when xchange not= 0
    end loop
    loop
        ychange := speed
        exit when ychange not= 0
    end loop
    kolor := red            % sets a random colour for the ball (between 1 and 15)

    size := 6               % sets a random size for the ball (between 5 and 10)
    x := maxx div 2         % sets x position to half way across the screen
    y := maxy div 2         % sets y position to half way up the screen

    Draw.FillOval (x, y, size, size, kolor)         % colours the background black
    loop
        drawfilloval (100, 250, 100, 100, red)
        drawfilloval (150, 250, 100, 100, black)
        drawfilloval (540, 250, 100, 100, red)
        drawfilloval (490, 250, 100, 100, black)
        drawfillbox(250,200,375,300,42)
        drawfillbox(275,225,350,275,black)
        drawfillbox(290,200,340,275,black)
        delay (11)

        % the next if statement checks to see if the ball has hit the right wall
        % (maxx less 5 less the size of the ball less the speed of the ball)
        % or the left wall ( 5 away from 0 + size - speed)

        % when it hits a vertical wall, the x direction reverses.

        if (x >= maxx - 5 - size - xchange) or (x = maxy - 5 - size - ychange) then
            ychange := -ychange
        end if
        if (y  0 then
            if whatdotcolor (x + xchange + size, y) not= black then
                xchange := -xchange
                count := count + 1
            end if
        else
            if
                    whatdotcolor (x + xchange - size, y) not= black then
                xchange := -xchange
                count := count + 1
            end if

        end if

        if ychange > 0 then
            if whatdotcolor (x, y + ychange + size) not= black then
                ychange := -ychange


                count := count + 1

            end if
        else
            if
                    whatdotcolor (x, y + ychange - size) not= black then
                ychange := -ychange

                count := count + 1

            end if

        end if
        if count1 = 2 then
            kolor := yellow
        end if
        if count1 = 5 then
            kolor := blue
        end if
        if count1 = 1 then
            kolor := 12
        end if
        if count1 = 0 then
            kolor := black
        end if
        locate (1, 1)
        color (green)
        put "Score:", count
        put "Lives:", count1

        % erase old ball by covering it up with black
        Draw.FillOval (x, y, size, size, black)

        x := x + xchange
        y := y + ychange
        % draw new ball
        Draw.FillOval (x, y, size, size, kolor)
        View.Update

        if count1 = 0 then
            cls
            put ""
            put ""
            put ""
            put ""
            put ""
            put ""
            put ""
            put "                            -------------------"
            put "                                 GameOver      "
            put "                             Your Score is:", count
            put "                            -------------------"
            exit
        end if
    end loop
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
end ball
fork ball
fork ping


Well thats it give it a try :D :D :D

-----------------------------------
Tony
Thu Dec 16, 2004 5:23 pm


-----------------------------------
I don't really approve of your approach with two processes (they are inherently buggy), but otherwise the game looks good.

+20Bits

-----------------------------------
the_short1
Thu Dec 16, 2004 6:19 pm


-----------------------------------
the ball ran very slow for me... and is the squares suposed to fill .. or is that just flicker?/

few suggestions:

since ur code is long.. post as a .t file! 
try looking up the locate command...



otherwise.. not bad..

-----------------------------------
cool dude
Fri Dec 17, 2004 5:50 pm


-----------------------------------
not only that your source code is buggy as well u could go of the screen and the ball changes coulours sometimes when i don't even lose

-----------------------------------
hq78
Sat Dec 18, 2004 11:58 am


-----------------------------------
cool game, i liked it, but theres a problem,  i am losing lives sometimes even when  I hit it.

-----------------------------------
Pickles
Thu Dec 23, 2004 9:39 pm


-----------------------------------
idk works fine and dandy to me, i dont see any problems when i run it

-----------------------------------
cool dude
Thu Dec 30, 2004 11:29 am


-----------------------------------
a few other bugs are that the ball sometimes flickers when it hits the walls and sometimes when i lose the ball doesn't change colours, and the paddle can go off the screen, and when the ball hits the very corner of the paddle it takes a live away but doesn't change the colour of the ball.

-----------------------------------
gohan
Fri Apr 22, 2005 9:17 am


-----------------------------------
Nice Game man.....I don't think I had any problems except when the ball kept going in the same spot for like 45 secs..... i had to purposely lose a life to get it to stop..but other than that..GREAT CODE MAN

I need a new teacher, if you can make that..SHHHHH....I didn't say that

HE HE

-----------------------------------
jamonathin
Fri Apr 22, 2005 1:56 pm


-----------------------------------
gohan:http://www.compsci.ca/v2/viewtopic.php?t=7857&highlight=necro

-----------------------------------
Vertico
Fri Apr 22, 2005 2:27 pm


-----------------------------------
I enjoyed it.    I give it 2 Thumbs up

-----------------------------------
Shyfire
Sun Apr 24, 2005 5:44 pm


-----------------------------------
yo stop necro posting

-----------------------------------
white_dragon
Mon Apr 25, 2005 12:23 pm


-----------------------------------
and ur not fatboi?

-----------------------------------
pro123
Tue May 03, 2005 10:51 am


-----------------------------------
I also thought it was a pretty good game.
