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

Username:   Password: 
 RegisterRegister   
 A ball physics program
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
petree08




PostPosted: Thu Apr 19, 2007 2:45 pm   Post subject: A ball physics program

Err yea, this is a "ball physics" program it has a few glitches
Any way enjoy

code:

const GRAVITY := 0.12
const FRICTION := 0.40
const MAX_POWER := 4
const B_F := 1.17


var DY, DX, X, Y, Power, Angle : real4
var Throw, Clicked : boolean
var XP, YP, Click, Xm, Ym : int
var Key : array char of boolean
var WinID : int
var Font1, Font2 : int

var Continue : char
Angle := 90
Power := 0.5
Throw := false
Clicked := false
X := 1
Y := 1
DX := 0
DY := 0
XP := 10
YP := 10


Font1 := Font.New ("Arial:30")
Font2 := Font.New ("Arial:20")
WinID := Window.Open ("graphics:max,max,nobuttonbar,offscreenonly,nocursor")

colorback (7)
color (0)
cls

Font.Draw ("SUPER BOUNCEY BALL", 10, maxy - 100, Font1, 0)
Font.Draw ("SUPER BOUNCEY BALL", 11, maxy - 99, Font1, 12)
Font.Draw ("MADE BY : PETER WATT", 11, maxy - 200, Font2, 0)
View.Update
Continue := getchar
cls

put "Use the left and right arrow keys to change the angle of ball"
put "Use the up and down keys to change the power of the ball"
put "use the mouse to place the ball."
put "press any key to continue"
View.Update
Continue := getchar

%MAIN
loop
    if Throw then
        cls
        Font.Draw ("Press spacebar to stop ball", 1, maxy - 20, Font2, 12)

    else
        cls
        put "Angle :", Angle, " degrees"
        put "Power :", Power
        put "press enter to throw"
        put "Press q to quit"
    end if
    if Throw = false then
        Input.KeyDown (Key)
        mousewhere (Xm, Ym, Click)
        drawline (Xm, 1, Xm, maxy, 12)
        drawline (1, Ym, maxx, Ym, 12)
        if Click = 1 and Clicked = false then
            Clicked := true

            XP := Xm
            YP := Ym

        end if
        if Key (KEY_RIGHT_ARROW) then
            Angle := Angle - .5
        end if
        if Key (KEY_LEFT_ARROW) then
            Angle := Angle + .5
        end if
        if Key (KEY_UP_ARROW) then
            Power := Power + 0.01
        end if
        if Key (KEY_DOWN_ARROW) then
            Power := Power - 0.01
        end if
        if Angle > 360 then
            Angle := 0
        end if
        if Angle < 0 then
            Angle := 360
        end if
        % display startpoint
        drawfilloval (XP, YP, 10, 10, 12)
        drawline (XP + (round (cosd (Angle) * 20)),
            YP + (round (sind (Angle) * 20)),
            XP, YP, 0)
        if Key (KEY_ENTER) then
            Throw := true

            DX := (XP + (round (cosd (Angle) * Power)) - XP)
            DY := (YP + (round (sind (Angle) * Power)) - YP)
            X := XP
            Y := YP

        end if
        if Click = 0 then
            Clicked := false
        end if
    else
        drawfilloval (round (X), round (Y), 10, 10, 12)

        if X < 1 or X > maxx then
            DX := -DX
        end if
        if Y < 1 then

            DY := - (DY / B_F)
            Y := Y + .75
            if DX < 0 then
                DX := DX + FRICTION
            elsif DX > 0 then
                DX := DX - FRICTION
            end if

        else
            DY := DY - GRAVITY

        end if
        X := X + DX
        Y := Y + DY
        Input.KeyDown (Key)
        if Key (' ') then
            Throw := false
        end if
        delay (5)
    end if
    if Key ('q') then
        exit
    end if
    View.Update

end loop

Window.Close (WinID)


Thanks for viewing Canada Mr. Green BooHoo Idea
Sponsor
Sponsor
Sponsor
sponsor
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  [ 1 Posts ]
Jump to:   


Style:  
Search: