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

Username:   Password: 
 RegisterRegister   
 bouncing balls
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
gtahunter




PostPosted: Sun May 13, 2007 7:37 pm   Post subject: bouncing balls

this program has balls continuously bouncing off the sides of the window






var xdir:int
var ydir:int
var xpos:int
var ypos:int

var xdir1:int
var ydir1:int
var xpos1:int
var ypos1:int

xdir :=1
ydir :=2
xpos :=50
ypos :=100

xdir1:=2
ydir1:=2
xpos1:=100
ypos1:=45

setscreen("graphics:400;400")

loop
cls
if xpos >= maxx or xpos <= 0 then
xdir*=-1
end if
if xpos1 >= maxx or xpos1 <= 0 then
xdir1*=-1
end if
if ypos >= maxy or ypos <= 0 then
ydir*=-1
end if
if ypos1 >= maxy or ypos1 <= 0 then
ydir1*=-1
end if

xpos+=xdir
ypos+=ydir
xpos1+=xdir1
ypos1+=ydir1

drawfilloval(xpos,ypos,10,10,255)
delay(5)

drawfilloval(xpos1,ypos1,10,10,255)
delay(5)
if xpos=xpos1 then
end if
end loop



bouncing balls.t
 Description:

Download
 Filename:  bouncing balls.t
 Filesize:  732 Bytes
 Downloaded:  467 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
Prince Pwn




PostPosted: Sun May 13, 2007 9:17 pm   Post subject: Re: bouncing balls

It looks better like this:

Turing:

var xdir : int
var ydir : int
var xpos : int
var ypos : int

var xdir1 : int
var ydir1 : int
var xpos1 : int
var ypos1 : int

xdir := 1
ydir := 2
xpos := 50
ypos := 100

xdir1 := 2
ydir1 := 2
xpos1 := 100
ypos1 := 45

setscreen ("graphics:400;400")

loop
    cls
    if xpos >= maxx or xpos <= 0 then
        xdir *= -1
    end if
    if xpos1 >= maxx or xpos1 <= 0 then
        xdir1 *= -1
    end if
    if ypos >= maxy or ypos <= 0 then
        ydir *= -1
    end if
    if ypos1 >= maxy or ypos1 <= 0 then
        ydir1 *= -1
    end if

    xpos += xdir
    ypos += ydir
    xpos1 += xdir1
    ypos1 += ydir1

    drawfilloval (xpos, ypos, 10, 10, 255)
    delay (5)

    drawfilloval (xpos1, ypos1, 10, 10, 255)
    delay (5)
    if xpos = xpos1 then
    end if
end loop
lilmizeminem




PostPosted: Wed May 16, 2007 11:15 am   Post subject: RE:bouncing balls

cooooooool.
petree08




PostPosted: Wed May 23, 2007 11:06 am   Post subject: RE:bouncing balls

er yeah try using an array
Tallguy




PostPosted: Thu May 24, 2007 12:11 pm   Post subject: RE:bouncing balls

very cool, but is there a point to this?
carGUY17




PostPosted: Mon May 28, 2007 6:46 pm   Post subject: Re: bouncing balls

sorry but that really sucks.
TWizard




PostPosted: Sun Aug 13, 2017 12:15 pm   Post subject: Re: bouncing balls

Thought I would give this abit of an update.

There was some flickering, which is now removed.

I've removed the delays, and added a counter system.

code:

%bouncy balls
%Creater: joe
%April 24,2007

%Updated By: LithianCoth
%August 13, 2017

setscreen ("offscreenonly,graphics:400;400")

var xdir : int := 1
var ydir : int := 2
var xpos : int := 50
var ypos : int := 100

var xdir1 : int := 2
var ydir1 : int := 2
var xpos1 : int := 100
var ypos1 : int := 45

var counter : int := 0

loop
    counter += 1

    if counter >= 15 then
        counter := 0
        if xpos >= maxx or xpos <= 0 then
            xdir *= -1
        end if
        if xpos1 >= maxx or xpos1 <= 0 then
            xdir1 *= -1
        end if
        if ypos >= maxy or ypos <= 0 then
            ydir *= -1
        end if
        if ypos1 >= maxy or ypos1 <= 0 then
            ydir1 *= -1
        end if

        xpos += xdir
        ypos += ydir
        xpos1 += xdir1
        ypos1 += ydir1
    end if

    drawfilloval (xpos, ypos, 10, 10, 255)
    drawfilloval (xpos1, ypos1, 10, 10, 255)

    View.Update ()
    cls
end loop



bouncing balls.t
 Description:
Update to Joe's creation!

Download
 Filename:  bouncing balls.t
 Filesize:  883 Bytes
 Downloaded:  223 Time(s)

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  [ 7 Posts ]
Jump to:   


Style:  
Search: