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

Username:   Password: 
 RegisterRegister   
 how do i make the ball go slower
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
shoobyman




PostPosted: Mon Jan 16, 2006 8:46 am   Post subject: how do i make the ball go slower

here is my program can u make the ball go slower than it is right now:

%import some important files
import GUI in "%oot/lib/GUI"

%Main Variables
var x, y := 10
var dx, dy := 2
var mousex, mousey, button, left, middle, right, rightDown := 0
var compY := (maxy div 4)
var compMoveY := 3
var status := 0
var challengeLevel := 0
var humanStart, humanEnd, humanSpeed := 0
var humScore, compScore := 0
var ch : char
var compStart, compEnd, compSpeed := 0
var testing := 0

var outputScore := 0

%fonts
var announceFont : int := Font.New ("Sanserif:72:bold")
var displayFont : int := Font.New ("Sanserif:14:bold")
var scoreFont : int := Font.New ("Sanserif:8:bold")

procedure CentreFont (s : string, x, y, f, clr : int)
var w : int := Font.Width (s, f)
Font.Draw (s, x - w div 2, y, f, clr)
end CentreFont

%like CentreFont just alligns the font to the left
procedure LAllignFont (s : string, x, y, f, clr : int)
Font.Draw (s, x, y, f, clr)
end LAllignFont

%like CentreFont just alligns the font to the right
procedure RAllignFont (s : string, x, y, f, clr : int)
var w : int := Font.Width (s, f)
Font.Draw (s, maxx - w, y, f, clr)
end RAllignFont


%set the screen with some graphics that might be important

View.Set ("graphics,nocursor,nobuttonbar")
View.Set ("position:centre;centre")
Mouse.ButtonChoose ("multibutton")

%the procedure that lets the user decide on the challenge level
procedure ChallengeLevel
cls
%draw the screen so the user know's what's going on

%the boxes
drawfillbox (80, (maxy div 4) * 3 - 20, 120, (maxy div 4) * 3 + 20, blue)
drawfillbox (80, (maxy div 4) * 2 - 20, 120, (maxy div 4) * 2 + 20, red)
drawfillbox (80, (maxy div 4) * 1 - 20, 120, (maxy div 4) * 1 + 20, green)
%title and box numbers
CentreFont ("Please Choose a Level.", maxx div 2, maxy - 30, displayFont, brightred)
CentreFont ("1", 100, (maxy div 4) * 3 - 6, displayFont, white)
CentreFont ("2", 100, (maxy div 4) * 2 - 6, displayFont, white)
CentreFont ("3", 100, (maxy div 4) * 1 - 6, displayFont, white)
%level descriptions
LAllignFont ("Average Computer, Larger Paddle", 180, (maxy div 4) * 3 - 6, displayFont, black)
LAllignFont ("Average Computer, Average Paddle", 180, (maxy div 4) * 2 - 6, displayFont, black)
LAllignFont ("Faster Computer, Smaller Paddle", 180, (maxy div 4) * 1 - 6, displayFont, black)
loop
%locate the mouse and get the specifics for the buttons
Mouse.Where (mousex, mousey, button)
left := button mod 10
middle := (button - left) mod 100
right := button - middle - left
%only be concerned if the left mouse button is pressed
if (left = 1) then
if (not (mousex < 80)) and (not (mousex > 120)) then
if (mousey > (maxy div 4) * 3 - 20) and (mousey < (maxy div 4) * 3 + 20) then
challengeLevel := 4
compMoveY := 3
elsif (mousey > (maxy div 4) * 2 - 20) and (mousey < (maxy div 4) * 2 + 20) then
challengeLevel := 3
compMoveY := 3
elsif (mousey > (maxy div 4) * 1 - 20) and (mousey < (maxy div 4) * 1 + 20) then
challengeLevel := 2
compMoveY := 5
end if
%testing mode - click the bottom right corner with both left and right mouse buttons
elsif (mousex > maxx - 20) and (mousey < 20) then
testing := 1
View.Set ("graphics,nocursor,buttonbar")
View.Update
challengeLevel := 4
compMoveY := 3
end if
end if
exit when challengeLevel not= 0
end loop
dx := 3
dy := 3
x := 50
y := maxy div 2 - 7
end ChallengeLevel

procedure DisplayScore
outputScore := (humScore + (16 * compScore))

end DisplayScore

%call the procedure that decides the challenge at which the person will play at
ChallengeLevel
cls

%get the picture of the human paddle
Draw.FillBox (0, 0, 5, (10 * challengeLevel), black)
var humanPaddle := Pic.New (0, 0, 5, (10 * challengeLevel))
cls
%get the picture of the ball
Draw.FillOval (5, 5, 5, 5, red)
var ballPicture := Pic.New (0, 0, 10, 10)
cls
%get the picture of hte computer's paddle
Draw.FillBox (0, 0, 5, 30, black)
var computerPaddle := Pic.New (0, 0, 5, 30)
cls

%set the screen to not display anything until all the graphics are drawn - smoother animation
setscreen ("offscreenonly")



loop

%locate the mouse
Mouse.Where (mousex, mousey, button)

%clear the screen so that we don't have multiple balls bouncing around
cls
drawline (10, 0, 10, maxy, green)
drawline (maxx - 10, 0, maxx - 10, maxy, black)

%display the current scores at the top of the screen
CentreFont ("Score: Human - " + intstr (humScore, 2) + " Computer - " + intstr (compScore, 2), maxx div 2, maxy - 8, scoreFont, 42)

%check to see if the computer paddle is parallel to the ball
if (compY < y - 6) then
compY := compY + compMoveY
elsif (compY > y + 6) then
compY := compY - compMoveY
end if

%the ball is too high up or too low down
if (y + dy < 0) or (y + dy + 20 > maxy) then
dy := -dy
end if

%move the ball location
x := x + dx
y := y + dy

%check to see if the paddle is going to go off the screen
if (mousey - (((10 * challengeLevel) div 2) - 2) < 0) then
mousey := ((10 * challengeLevel) div 2)
elsif (mousey + (((10 * challengeLevel) div 2) + 2) > maxy) then
mousey := maxy - ((10 * challengeLevel) div 2)
end if

%draw the human paddle
Pic.Draw (humanPaddle, 20, mousey - ((10 * challengeLevel) div 2), picMerge)
%draw the ball
Pic.Draw (ballPicture, x, y, picMerge)
%draw the computer paddle
Pic.Draw (computerPaddle, maxx - 25, compY, picMerge)

%calculate the speed of the human paddle to better bounce the ball off it - more realistic
humanEnd := mousey -4
humanSpeed := humanStart - humanEnd
compEnd := compY
compSpeed := compStart - compEnd
if (compSpeed < 0) then
compSpeed := compSpeed * -1
end if

%check to see if the ball hits the human paddle
if (((x + dx < 25) and (x + dx > 20)) and (dx < 0)) and ((y + dy < mousey + (((10 * challengeLevel) div 2) + 2)) and (y + dy > mousey - (((10 * challengeLevel) div 2) - 2))) then
dx := -dx
dy := dy + humanSpeed
end if

%check to see if the ball hits the computer paddle
if (((x + dx > maxx - 30) and (x + dx < maxx - 25)) and (dx > 0)) and ((y + dx < compY + 17) and (y + dx > compY - 17)) then
dx := -dx
randint (dy, -3, 3)
end if

%the ball went past the human line
if (x < 8) then
compScore := compScore + 1
if (compScore > 4) then
status := 2
exit
else
CentreFont ("The Computer Scored!", maxx div 2, maxy div 2, displayFont, brightred)
View.Update
delay (500)
CentreFont ("Press any key to continue.", maxx div 2, (maxy div 2) - 20, scoreFont, brightred)
View.Update
ch := getchar
x := 30
y := maxy div 2 - 7
dx := 2
randint (dy, -3, 3)
end if
end if

%the ball went past the computer's goal line
if (x > maxx - 8) then
humScore := humScore + 1
if (humScore > 4) then
status := 1
exit
else
CentreFont ("You Scored!", maxx div 2, maxy div 2, displayFont, green)
View.Update
delay (500)
CentreFont ("Press any key to continue...", maxx div 2, (maxy div 2) - 20, scoreFont, green)
View.Update
ch := getchar
x := 30
y := maxy div 3 - 7
dx := 2
randint (dy, -3, 3)
end if
end if

%get the location of the paddles paddle
humanStart := mousey
compStart := compY

%update the view so that we see everything
View.Update
exit when false
end loop
setscreen ("nooffscreenonly")

%computer loss
if (status = 1) then
CentreFont ("You Win!", maxx div 2, maxy div 2, announceFont, black)
delay (4000)
if (compScore not= 0) then
end if
end if

%human loss
if (status = 2) then
CentreFont ("You Lose!", maxx div 2, maxy div 2, announceFont, black)
delay (4000)
end if
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 1 Posts ]
Jump to:   


Style:  
Search: