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

Username:   Password: 
 RegisterRegister   
 update on my pinball again
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
rjm72




PostPosted: Thu Jan 20, 2005 2:10 pm   Post subject: update on my pinball again

Hey another update on my pinball thank you ELCOMANDANTE for letting me use the turing piano music u made. Ill probably still fix more stuff. Very Happy Very Happy
code:

% Ryan Murray  TIK2O
% December 8, 2004
% pinball.t

cls
View.Set ("offscreenonly")


var xchange : int
var ychange : int
var score : int
var kolor : int
var lives : int
var x : int
var y : int
var size : int
var col : int  %stands for color
var speed : int
var kol : int
var kol2 : int
var gameOver : boolean
gameOver := false

col := 42
score := 0
lives := 5
speed := 0
kol := white
kol2 := black
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
process paddle
    var chars : array char of boolean
    View.Set ("offscreenonly")
    var x, x2 : int
    x := 320
    x2 := 260
    loop
        Input.KeyDown (chars)  %tells the computer that the user will be entering a character

        drawfillbox (x, 10, x2, 20, kol2)  %draws a black paddle to erase the white one at the end of the code


        if chars (KEY_RIGHT_ARROW) then   %tells the computer that if the user enters the right arrow key to move the paddle to the right
            x := x + 10
            x2 := x2 + 10
        end if
        if chars (KEY_LEFT_ARROW) then %tells the computer that if the user enters the left arrow key to move the paddle to the left
            x := x - 10
            x2 := x2 - 10
        end if
        drawfillbox (x, 10, x2, 20, kol) %draws the paddle

        View.Update
        delay (20)
        if score = 30 then
            kol2 := 11
        end if
        if score = 70 then
            kol2 := 50
        end if
        exit when gameOver %tells teh paddle to exit when count=0
    end loop


end paddle
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
process ball

    loop
        xchange := speed % sets a  speed for the ball
        exit when xchange not= 0
    end loop
    loop
        ychange := speed
        exit when ychange not= 0
    end loop



    Draw.FillBox (5, 5, maxx - 5, maxy - 5, black)
    colorback (black)
    cls

    kolor := red
    size := 6
    x := maxx div 2
    y := maxy div 2

    Draw.FillOval (x, y, size, size, kolor)
    loop
        drawfillbox (100, 100, 200, 200, col) %draws the shapes
        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)


        if (x >= maxx - 5 - size - xchange) or (x <= 5 + size - xchange) then %tells the program that if the ball hits the side it will bounce off
            xchange := -xchange
        end if
        if (y >= maxy - 5 - size - ychange) then        %tells the program that if th ball hits the top then the ball should bounce off
            ychange := -ychange
        end if
        if (y <= 5 + size - ychange) then               %tells the program that if the ball hits the bottom then the ball should bounce off
            lives := lives - 1
            ychange := -ychange
        end if
        if xchange > 0 then
            if whatdotcolor (x + xchange + size, y) not= black then %tells the program that if the ball hits a color thats not black  then it should add a point and bounce off
                xchange := -xchange
                score := score + 1
            end if
        else
            if
                    whatdotcolor (x + xchange - size, y) not= black then %tells the program that if the ball hits a color thats not black  then it should add a point and bounce off
                xchange := -xchange
                score := score + 1
            end if

        end if

        if ychange > 0 then
            if whatdotcolor (x, y + ychange + size) not= black then %tells the program that if the ball hits a color thats not black  then it should add a point and bounce off
                ychange := -ychange


                score := score + 1

            end if
        else
            if
                    whatdotcolor (x, y + ychange - size) not= black then    %tells the program that if the ball hits a color thats not black  then it should add a point and bounce off
                ychange := -ychange
                score := score + 1

            end if

        end if
        if lives = 2 then  %tells the computer that if the lives are at 2 then the ball is yellow
            kolor := yellow
        end if
        if lives = 5 then %tells the computer that if the lives are at 5 then the ball is blue
            kolor := blue
        end if
        if lives = 1 then %tells the computer that if the lives are at 1 then the ball is red
            kolor := 12
        end if
        if lives = 0 then %tells the computer that if the lives are at 0 then the ball is black
            kolor := black
        end if
        locate (1, 1)      %%tells the computer to show the score at the top of the screen
        color (green)
        put "Score:", score
        put "Lives:", lives


        Draw.FillOval (x, y, size, size, black) %earases the ball

        x := x + xchange %tells the ball how much to move
        y := y + ychange

        Draw.FillOval (x, y, size, size, kolor) %draws the ball
        View.Update

        if lives = 0 then  %tells the computer that if lives = 0 then the game is over
            cls
            put ""
            put ""
            put ""
            put ""
            put ""
            put ""
            put ""
            put "                            -------------------"
            put "                                 GameOver      "
            put "                             Your Score is:", score
            put "                            -------------------"
            exit
        end if
        if score = 30 then    %tells the computer that if the score is 30 to go to the next level
            kol := white
            cls
            put ""
            put ""
            put ""
            put ""
            put ""
            put ""
            put ""
            put "                             -------------------"
            put "                                    Level 2     "
            put "                             -------------------"
            delay (1000)
            cls
            exit
        end if
    end loop
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    loop
        xchange := speed
        exit when xchange not= 0
    end loop
    loop
        ychange := speed
        exit when ychange not= 0
    end loop
    size := 6
    x := maxx div 2
    y := maxy div 2
    Draw.FillBox (5, 5, maxx - 5, maxy - 5, 11)
    colorback (11)
    cls


    Draw.FillOval (x, y, size, size, kolor)
    loop
        drawfilloval (100, 250, 100, 100, 55)
        drawfilloval (150, 250, 100, 100, 11)
        drawfilloval (540, 250, 100, 100, 55)
        drawfilloval (490, 250, 100, 100, 11)
        drawfillbox (250, 200, 375, 300, 53)
        drawfillbox (275, 225, 350, 275, 11)
        drawfillbox (290, 200, 340, 275, 11)
        delay (11)



        if (x >= maxx - 5 - size - xchange) or (x <= 5 + size - xchange) then
            xchange := -xchange
        end if
        if (y >= maxy - 5 - size - ychange) then
            ychange := -ychange
        end if
        if (y <= 5 + size - ychange) then
            lives := lives - 1
            ychange := -ychange
        end if
        if xchange > 0 then
            if whatdotcolor (x + xchange + size, y) not= 11 then
                xchange := -xchange
                score := score + 1
            end if
        else
            if
                    whatdotcolor (x + xchange - size, y) not= 11 then
                xchange := -xchange
                score := score + 1
            end if

        end if

        if ychange > 0 then
            if whatdotcolor (x, y + ychange + size) not= 11 then
                ychange := -ychange


                score := score + 1

            end if
        else
            if
                    whatdotcolor (x, y + ychange - size) not= 11 then
                ychange := -ychange

                score := score + 1

            end if

        end if
        if lives = 2 then
            kolor := yellow
        end if
        if lives = 5 then
            kolor := blue
        end if
        if lives = 1 then
            kolor := 12
        end if
        if lives = 0 then
            kolor := black
        end if
        locate (1, 1)
        color (green)
        put "Score:", score
        put "Lives:", lives

        Draw.FillOval (x, y, size, size, 11)

        x := x + xchange
        y := y + ychange

        Draw.FillOval (x, y, size, size, kolor)
        View.Update

        if lives = 0 then
            cls
            put ""
            put ""
            put ""
            put ""
            put ""
            put ""
            put ""
            put "                            -------------------"
            put "                                 GameOver      "
            put "                             Your Score is:", score
            put "                            -------------------"
            exit
        end if
        if score = 70 then
            cls
            put ""
            put ""
            put ""
            put ""
            put ""
            put ""
            put ""
            put "                             -------------------"
            put "                                    Level 3     "
            put "                             -------------------"
            delay (1000)
            cls
            exit
        end if
    end loop
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    loop
        xchange := speed
        exit when xchange not= 0
    end loop
    loop
        ychange := speed
        exit when ychange not= 0
    end loop
    size := 6
    x := maxx div 2
    y := maxy div 2
    Draw.FillBox (5, 5, maxx - 5, maxy - 5, 50)
    colorback (50)
    cls

    Draw.FillOval (x, y, size, size, kolor)

    drawfilloval (320, 240, 50, 50, green)
    drawfilloval (320, 220, 50, 50, 50)
    drawfilloval (200, 240, 50, 50, green)
    drawfilloval (200, 220, 50, 50, 50)
    drawfilloval (440, 240, 50, 50, green)
    drawfilloval (440, 220, 50, 50, 50)
    drawfilloval (380, 150, 50, 50, green)
    drawfilloval (380, 130, 50, 50, 50)
    drawfilloval (260, 150, 50, 50, green)
    drawfilloval (260, 130, 50, 50, 50)

    loop

        delay (11)



        if (x >= maxx - 5 - size - xchange) or (x <= 5 + size - xchange) then
            xchange := -xchange
        end if
        if (y >= maxy - 5 - size - ychange) then
            ychange := -ychange
        end if
        if (y <= 5 + size - ychange) then
            lives := lives - 1
            ychange := -ychange
        end if
        if xchange > 0 then
            if whatdotcolor (x + xchange + size, y) not= 50 then
                xchange := -xchange
                score := score + 1
            end if
        else
            if
                    whatdotcolor (x + xchange - size, y) not= 50 then
                xchange := -xchange
                score := score + 1
            end if

        end if

        if ychange > 0 then
            if whatdotcolor (x, y + ychange + size) not= 50 then
                ychange := -ychange


                score := score + 1

            end if
        else
            if
                    whatdotcolor (x, y + ychange - size) not= 50 then
                ychange := -ychange

                score := score + 1

            end if

        end if
        if lives = 2 then
            kolor := yellow
        end if
        if lives = 5 then
            kolor := blue
        end if
        if lives = 1 then
            kolor := 12
        end if
        if lives = 0 then
            kolor := black
        end if
        locate (1, 1)
        color (green)
        put "Score:", score
        put "Lives:", lives

        Draw.FillOval (x, y, size, size, 50)

        x := x + xchange
        y := y + ychange

        Draw.FillOval (x, y, size, size, kolor)
        View.Update

        if lives = 0 then
            gameOver := true
            exit
        end if
    end loop
end ball
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
process kolo                   %makes the paddle and shapes flash
    loop
        delay (75)
        col := Rand.Int (33, 103)
        exit when gameOver
    end loop
end kolo
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
process music1
    loop
        %pirates/carribean
        play ("4d,8f,4g,4g,8g,8a,4b-,4b-,4b-,>4c,<8a,8a,8a,8g,8f,8d,2g") %makes the music %music is taken from compsci.ca and written in turing by ELCOMANDANTE
        play ("4d,8f,4g,4g,8g,8a,4b-,4b-,4b-,>4c,4d,8e-,8e-,8d,8c,8d,<1g")
        play ("4d,8f,4g,4g,8g,8a,4b-,4b-,4b-,>4c,<8a,8a,8a,8g,8f,8d,2g")
        exit when lives = 0
    end loop
end music1
process music2
    loop
        %Sonic the hedgehog casino theme(Sonic 2)
        play ("2c,>4e-,2c,4g-,2f,2e-,4c,<2g,4b-,4a-,2g,4e,4e,2e,4e") %makes the music %music is taken from compsci.ca and written in turing by ELCOMANDANTE
        play ("4f,4e,4a-,2e,4e,2a,2e,2c,4d,4c,4e-,4d,4c,4d,4c,4e,4e")
        play ("2e,4e,4f,4e,4a-,2e,4e,2a,2b,>2c,<2a,2g,4e,2c,2d,2a,2g")
        play ("4e,2c,2d,2a,2g,4e,2c,2d,1e-")
        exit when lives = 0
    end loop
end music2
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
color (blue)
put "Instructions:"
put
    "Use the keyboard to move the paddle,everytime you hit an object you get a point,once you get so many points you go to the next level. There are three levels.   Once you get to the 3rd level try to get the highest score possible."
var song : int
var dif : int
put ""
put "Choose a music:"
put ""
put "Press 1: for Pirates of the Carribean music"
put "Press 2: for Sonic casino music"
put "Press 0: for no music."
View.Update
get song
if song = 1 then
    fork music1
elsif song = 2 then
    fork music2
else
end if
put "Choose a dificulty level:"
put "1=Beginner"
put "2=Normal"
put "3=Hard"
put "4=Suicide(Good Luck)"
View.Update
get dif
if dif=1 then speed:=1
elsif dif=2 then speed:=3
elsif dif=3 then speed:=5
elsif dif=4 then speed:=15
end if
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%55
fork ball  %tells the computer to make the ball and background
fork kolo  %tells the computer to make the paddle flash
fork paddle %tells the computer to make the paddle

loop
    exit when gameOver = true
end loop

cls
put ""
put ""
put ""
put ""
put ""
put ""
put ""
put "                            -------------------"
put "                                 GameOver      "
put "                             Your Score is:", score
put "                            -------------------"

Sponsor
Sponsor
Sponsor
sponsor
rjm72




PostPosted: Thu Jan 20, 2005 2:19 pm   Post subject: (No subject)

Thats it hope its better then my last update or else it wouldnt be much of an update! :) :D :D :D :D
cool dude




PostPosted: Thu Jan 20, 2005 4:28 pm   Post subject: (No subject)

good job. it would be better if u had a high score list, and fixed a few glitches like the ball on level 3 i think ate a chunk of the wall and the paddles could go off the screen.
Cervantes




PostPosted: Thu Jan 20, 2005 4:49 pm   Post subject: (No subject)

1.)
Processes... Maybe it works, but in Turing, you should avoid using processes at all costs
2.)
It would be really cool if the ball actually bounced of the curved surfaces correctly.
3.)
I find that the game gets into a pattern. By that I mean you might not even have to move your paddle. Or you might have to move it to one side, hit the ball, then move it to the other side, hit the ball, then move it back to the exact same spot on the first side, etc. This makes it too easy.
4.)
Large sections of code like that should be posted as an attachment. Smile
5.)
Your avatar is enormous. Please shrink it, or use a different one.
-Cervantes
xHoly-Divinity




PostPosted: Thu Jan 20, 2005 8:55 pm   Post subject: (No subject)

Hey, I was experimenting with high score, and I used your program to test it out. Lucky for you it works!!! So here, you can incorprate this in your code. (First you'll have to create a text file called Highscore.txt, open it, type in 0, then save it).

code:

put "                            -------------------"
            put "                                 GameOver      "
            put "                             Your Score is:", count
            put "                            -------------------"
            var check : array 1 .. 1 of int
            const pathName : string := "Highscore.txt"
            var f : int
            open : f, pathName, get
            get : f, check (1)
            close : f
            if count > check (1) then
                open : f, pathName, put
                put : f, count
                close : f
            end if
            var one : int
            var sss : array 1 .. 1 of int
            open : one, "Highscore.txt", get
            get : one, sss (1)
            put "                              HIGH SCORE: ", sss (1)
            exit
rjm72




PostPosted: Fri Jan 21, 2005 12:50 pm   Post subject: (No subject)

Quote:

good job. it would be better if u had a high score list, and fixed a few glitches like the ball on level 3 i think ate a chunk of the wall and the paddles could go off the screen.


Im workin on it lol lol

Quote:

It would be really cool if the ball actually bounced of the curved surfaces correctly.

I dont know how :(
Quote:

Large sections of code like that should be posted as an attachment.

I should but this way i can access the program at home without downloading it cus i work on my programs at school
Quote:

Your avatar is enormous. Please shrink it, or use a different one.

I got rid of my avatar 8)

and thanx Holy-Divinity i put the Highscore in my Game don't worry i wont passs it off as my own.
zomg




PostPosted: Fri Jan 21, 2005 6:08 pm   Post subject: (No subject)

Cervantes, why are processes bad to use in turing? do they slow things down or something or is it just bad coding?
Dan




PostPosted: Fri Jan 21, 2005 6:24 pm   Post subject: (No subject)

shadow master wrote:
Cervantes, why are processes bad to use in turing? do they slow things down or something or is it just bad coding?


If you do not know how to use them right it can be very bad progaming and relsut in almost random events in your progames. To uses treading (processes) right you need to have some kind of system to keep the events hapning at the right times and not compley randomly, unless the events in the processes are of litte importeance such has back ground musick but even then u still need a good way of starting and stoping the thread (processe)
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
Sponsor
Sponsor
Sponsor
sponsor
Kyle




PostPosted: Fri Jan 21, 2005 8:10 pm   Post subject: (No subject)

Nice job on the game, very smoth and easy... Level 3 had some Gliches, and fealt like it was going on and on but over all its great Very Happy
cool dude




PostPosted: Sat Jan 22, 2005 12:24 pm   Post subject: (No subject)

shadow master wrote:
Cervantes, why are processes bad to use in turing? do they slow things down or something or is it just bad coding?


they're also very hard to get out of. a kid in my class used them and he had hard time getting out of them. same with forks.
zomg




PostPosted: Sat Jan 22, 2005 12:57 pm   Post subject: (No subject)

ya i had a problem with that a while ago when i first started programming now that i think about it
rjm72




PostPosted: Sun Jan 23, 2005 2:15 pm   Post subject: (No subject)

I try not to use process but i always ending up using them if u look at sum of my posts half of them use a process Sad
cycro1234




PostPosted: Mon Jan 24, 2005 6:03 pm   Post subject: (No subject)

Nice game I like it Very Happy Looking at flashing colours for too long though isn't that healthy..
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 13 Posts ]
Jump to:   


Style:  
Search: