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

Username:   Password: 
 RegisterRegister   
 need help with pong
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
cop_mike




PostPosted: Thu Nov 04, 2004 9:02 pm   Post subject: need help with pong

hey i found out how to add the score and stuff but the score keeps adding up when it hits the walls and even when the ball hits the paddles its gives the other person a couple points can u fix this and send it back to me?



View.Set ("graphics:640;480")


var x, y, xr, yr, c, x1, y1, x2, y2 : int
var xstep, ystep : int := 5
var key : string (1)
var count1, count2 := 0
var font, font1 : int
font := Font.New ("arial :20:bold")
font1 := Font.New ("arial :30:bold")
ystep := 6
x := 480
y := 240
xr := 8
yr := 8
x1 := 10
y1 := 240
x2 := 620
y2 := 240
count1 := 0
count2 := 0
drawfillbox (640, 0, 0, 480, 2)
Font.Draw ("Welcome to MIke's game of...", 72, 320, font, 0)
delay (3000)
cls
delay (10)
drawfillbox (640, 0, 0, 480, 2)
Font.Draw ("!~!~!~!~PONG~!~!~!~!", 190, 320, font, 0)
delay (3000)
cls
delay (10)

loop
randint (c, 10, 69)
%line in middle
drawline (320, 480, 320, 0, 7)
%circle in middle
drawoval (320, 210, 80, 80, 7)
%score border
drawfillbox (640, 420, 0, 480, 4)
%score
Font.Draw (intstr (count1), 175, maxy - 25, font, 0)
Font.Draw (intstr (count2), maxx - 175, maxy - 25, font, 0)
%ball
drawfilloval (x, y, xr, yr, c)
% right paddle
drawfillbox (x1, y1, x1 + 10, y1 + 60, c)
%left paddle
drawfillbox (x2, y2, x2 + 10, y2 + 60, c)
delay (30)
% clear ball
drawfilloval (x, y, xr, yr, 0)
%clear right paddle
drawfillbox (x1, y1, x1 + 10, y1 + 60, 0)
%clear left paddle
drawfillbox (x2, y2, x2 + 10, y2 + 60, 0)
x := x + xstep
y := y + ystep
%keys
if hasch then
getch (key)
if key = "W" or key = "w" and y1 < 350 then
y1 := y1 + 20
elsif key = "S" or key = "s" and y1 > 0 then
y1 := y1 - 20
elsif key = chr (200) and y2 < 350 then
y2 := y2 + 20
elsif key = chr (208) and y2 > 0 then
y2 := y2 - 20
end if
end if
%makes it bounce
if x > 630 or x < 10 then
xstep := -xstep
end if
if y > 410 or y < 10 then
ystep := -ystep
end if
if x - 8 <= x1 + 10 then
if y >= y1 and y <= y1 + 50 then
xstep := -xstep
end if

end if
%bounces off paddles
if x + 8 >= x2 then
if y >= y2 and y <= y2 + 50 then
xstep := -xstep
end if
end if
%marks score
if x >= 640 - 35 then
count1 := count1 + 1
elsif x <= 35 then
count2 := count2 + 1
end if
end loop
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Thu Nov 04, 2004 9:06 pm   Post subject: (No subject)

oh yes! I'm on it Surprised One pong assignment comming right up, would you like a sideorder of a loading bar with that?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
AsianSensation




PostPosted: Thu Nov 04, 2004 9:10 pm   Post subject: (No subject)

here, Pong:

code:
loop
    locate (1, 1)
    put "|.  |"
    locate (1, 1)
    put "| . |"
    locate (1, 1)
    put "|  .|"
    locate (1, 1)
    put "| . |"
end loop
cop_mike




PostPosted: Thu Nov 04, 2004 9:10 pm   Post subject: (No subject)

so ur going to help me?
SuperGenius




PostPosted: Thu Nov 04, 2004 9:40 pm   Post subject: (No subject)

most people will be glad to help you, however most people around here are not a fan of doing your work for you.
Tony




PostPosted: Thu Nov 04, 2004 9:47 pm   Post subject: (No subject)

oh, I am! I enjoy doing work for others!
here's your pong
code:

var x : int := 1
var dir : int := 1
proc drawPong (x : int)
    locate (1, 1)
    if x > -1 and x < 7 then
        put " |", repeat (" ", x), ".", repeat (" ", 6 - x), "| "
    end if
    if x = -1 then
        put ".|       | "
    elsif x = 7 then
        put " |       |."
    end if
    delay (100)
end drawPong

loop
    if (x > 5) or (x < 1) then
        if Rand.Int (1, 5) = 1 then
            x += dir
            drawPong (x)
            locate (2, 1)
            if x < 1 then
                put "Player 2 wins"
                exit
            else
                put "Player 1 wins"
                exit
            end if
        end if
        dir *= -1
    end if
    x += dir
    drawPong (x)
end loop
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Neo




PostPosted: Thu Nov 04, 2004 10:56 pm   Post subject: (No subject)

Here you GO!!!!

code:
View.Set ("graphics:640;480")

var x, y, xr, yr, c, x1, y1, x2, y2 : int
var xstep, ystep : int := 5
var key : string (1)
var count1, count2 := 0
var font, font1 : int
font := Font.New ("arial :20:bold")
font1 := Font.New ("arial :30:bold")
ystep := 6
x := 480
y := 240
xr := 8
yr := 8
x1 := 10
y1 := 240
x2 := 620
y2 := 240
count1 := 0
count2 := 0
drawfillbox (640, 0, 0, 480, 2)
Font.Draw ("Welcome to MIke's game of...", 72, 320, font, 0)
delay (3000)
cls
delay (10)
drawfillbox (640, 0, 0, 480, 2)
Font.Draw ("!~!~!~!~PONG~!~!~!~!", 190, 320, font, 0)
delay (3000)
cls
delay (10)

loop
    randint (c, 10, 69)
    %line in middle
    drawline (320, 480, 320, 0, 7)
    %circle in middle
    drawoval (320, 210, 80, 80, 7)
    %score border
    drawfillbox (640, 420, 0, 480, 4)
    %score
    Font.Draw (intstr (count1), 175, maxy - 25, font, 0)
    Font.Draw (intstr (count2), maxx - 175, maxy - 25, font, 0)
    %ball
    drawfilloval (x, y, xr, yr, c)
    % right paddle
    drawfillbox (x1, y1, x1 + 10, y1 + 60, c)
    %left paddle
    drawfillbox (x2, y2, x2 + 10, y2 + 60, c)
    delay (30)
    % clear ball
    drawfilloval (x, y, xr, yr, 0)
    %clear right paddle
    drawfillbox (x1, y1, x1 + 10, y1 + 60, 0)
    %clear left paddle
    drawfillbox (x2, y2, x2 + 10, y2 + 60, 0)
    x := x + xstep
    y := y + ystep
    %keys
    if hasch then
        getch (key)
        if key = "W" or key = "w" and y1 < 350 then
            y1 := y1 + 20
        elsif key = "S" or key = "s" and y1 > 0 then
            y1 := y1 - 20
        elsif key = chr (200) and y2 < 350 then
            y2 := y2 + 20
        elsif key = chr (208) and y2 > 0 then
            y2 := y2 - 20
        end if
    end if
    %makes it bounce
    if y > 410 or y < 10 then
        ystep := -ystep
    end if
    if x - 8 <= x1 + 10 then
        if y >= y1 and y <= y1 + 50 then
            xstep := -xstep
        end if

    end if
    %bounces off paddles
    if x + 8 >= x2 then
        if y >= y2 and y <= y2 + 50 then
            xstep := -xstep
        end if
    end if
    %marks score
    if x >= maxx + 20 then
        count1 := count1 + 1
        x := maxx div 2 - 50
        y := maxy div 2
        Font.Draw ("Player 1 Scores!", 190, 320, font, black)
        delay (500)
        cls
    elsif x <= -20 then
        count2 := count2 + 1
        x := maxx div 2 - 50
        y := maxy div 2
        Font.Draw ("Player 2 Scores!", 190, 320, font, black)
        delay (500)
        cls
    end if
end loop
Tony




PostPosted: Thu Nov 04, 2004 11:11 pm   Post subject: (No subject)

Neo : its flash, slow and too long.

how about pong in 20 lines? Laughing
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Sponsor
Sponsor
Sponsor
sponsor
Neo




PostPosted: Thu Nov 04, 2004 11:26 pm   Post subject: (No subject)

That pong is not mine, its cop_mike's, I just fixed his scoring problem.
cop_mike




PostPosted: Fri Nov 05, 2004 7:15 pm   Post subject: (No subject)

no its ok i didnt want someone to do it for me i just needed help but its ok now i got it working by myself at school today. thanx nyways
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  [ 10 Posts ]
Jump to:   


Style:  
Search: