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

Username:   Password: 
 RegisterRegister   
 Bouncing Ball Program!
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
@DRI@N




PostPosted: Tue May 25, 2004 4:59 pm   Post subject: Bouncing Ball Program!

This is the basic bouncing ball program...
code:

setscreen("graphics:640;400")
View.Set ("offscreenonly")
color(white)
colorback(black)
cls

var x : int :=  320   
var y : int := 350     
var xchange:int:=1
var ychange:int:=1



loop
cls
    x := x - xchange
    y := y + ychange
   
    Draw.FillOval (x, y, 10, 10, white)
    delay(5)
   
   
    if x = 10 or x =630 then
        xchange:=xchange*-1
   
    end if
    if y = 10 or y = 390 then
        ychange :=ychange*-1
    end if
View.Update
end loop
Sponsor
Sponsor
Sponsor
sponsor
guruguru




PostPosted: Tue May 25, 2004 6:05 pm   Post subject: (No subject)

Source code. #3
rollerdude




PostPosted: Wed Sep 15, 2004 4:41 pm   Post subject: (No subject)

what version is this code for, because View.Update comes up as an error
Tony




PostPosted: Wed Sep 15, 2004 5:01 pm   Post subject: (No subject)

View.Update is a 4.x feature.

most of us use 4.0.5
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
shorthair




PostPosted: Mon Sep 20, 2004 9:20 pm   Post subject: (No subject)

Add Plug here , * which was Brought by Justin To COmpsci, thanks to shorthair there was a little more piracy in the world , * but if you need it , ask your teacher to send an email to holfsoft they offer it to all classes that need it , it has major fixes for hte grade 11 curicullem ( cant spell tonight )
lama_daboul




PostPosted: Thu Oct 14, 2004 7:56 am   Post subject: Comments

Would someone please take 5 minutes to quickly comment or explain to me what each line in the basic bouncing ball program does. I need it for an Assignment
josh




PostPosted: Thu Oct 14, 2004 8:34 am   Post subject: (No subject)

you could also do this using the Pic.New and Pic.Draw commands if u want to practice for more complex animations. U You use Pic.New to take a "Picture" of the part of the screen u want to move (all the objects in it become sotored in one variable) and then Pic.Draw to display everything that was taken in that picture.
How U Doin




PostPosted: Tue Oct 26, 2004 8:59 am   Post subject: (No subject)

This is what I was learning in my computer programming class Razz
Sponsor
Sponsor
Sponsor
sponsor
djlenny_3000




PostPosted: Tue Oct 26, 2004 7:22 pm   Post subject: (No subject)

true you can make it as a picture, but i want to see if you can make it a box, or rectangular shape, and as it hits the wall the rectangle shifts its angle to suit hte new direction
gigaman




PostPosted: Wed Oct 27, 2004 11:47 am   Post subject: (No subject)

DJ in response. you would do sumthing like when it hits the side one side the far side moves faster until it's back at it's original position. if i have time i'll write it up
gigaman




PostPosted: Wed Oct 27, 2004 11:58 am   Post subject: (No subject)

This is the commented version of the ball bouncing that lama_daboul asked for. FYI commenting is not 5 minutes but it is important.

code:

%Gigaman's commented version

setscreen("graphics:640;400") %sets the screen size and graphics mode
View.Set ("offscreenonly")  %this makes it so that the ball doesn't flicker,all commands are done offscreen can also just put ",offscreenonly" in the setscreen command
color(white) %sets the colour of everything on the screen to default white
colorback(black) %sets the background colour to black
cls %clears the screen

var x : int :=  320    %starting x cooridinate for the ball
var y : int := 350      %stariting y coordinate for the ball
var xchange:int:=1      %direction of the ball, x
var ychange:int:=1      %direction of the ball, y



loop
cls
    x := x - xchange %equation for the x position
    y := y + ychange %equation for the x position
   
    Draw.FillOval (x, y, 10, 10, white) %draws the ball (obviously)
    delay(5) %delay(duh)
   
   
    if x = 10 or x =630 then %if for when the ball resches a side
        xchange:=xchange*-1 %equation that changes direction
   
    end if
    if y = 10 or y = 390 then %if for when the ball reaches ceiling or floor
        ychange :=ychange*-1 %equation that changes direction
    end if
View.Update %put the ball on the screen
end loop
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  [ 11 Posts ]
Jump to:   


Style:  
Search: