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

Username:   Password: 
 RegisterRegister   
 Could someone tell me what to fix for this pong?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
juniorspank




PostPosted: Mon Dec 08, 2003 9:33 pm   Post subject: Could someone tell me what to fix for this pong?

I have many problems and need help Embarassed

code:
setscreen ("graphics:700;300")
var x1, y1, x2, y2, x3, y3, x4, y4, xy1, xy2, xy3, xy4 : int
x1 := 3
y1 := 200
x2 := 11
y2 := 250
x3 := 680
y3 := 200
x4 := 688
y4 := 250
xy1 := x1 and y1
xy2 := x2 and y2
xy3 := x3 and y3
xy4 := x4 and y4
var yt1, yt2 : int
var paddle : int
paddle := x1 and y1 and x2 and y2
yt1 := y2 - y1
yt2 := y4 - y3
var ballt1, ballt2 : int
ballt1 := x2 and >= y1, <= y2
ballt2 := x3 and >= y3, <= y4
var chars : array char of boolean
var row, column : int
var score1, score2 : int := 0
var ballrow, ballcolumn : int := 200
row := 7
column := 5
var ballrowChange, ballcolumnChange := 1
loop
    delay (7)
    if ballrow = ballt1 or ballrow = ballt2 then
        ballrowChange := -ballrowChange
    end if
    if ballcolumn = 292 or ballcolumn = 3 then
        ballcolumnChange := -ballcolumnChange
    end if
    if ballrow = ballt2 then
        ballrowChange := -ballrowChange
    end if
    cls
    drawfilloval (ballrow, ballcolumn, 10, 10, 7)
    ballrow := ballrow + ballrowChange
    ballcolumn := ballcolumn + ballcolumnChange
    if ballcolumn = 292 or ballcolumn = 3 then
        sound (500, 50)
    end if
    if ballrow = 688 then
        score2 := score2 + 1
        ballrowChange := -ballrowChange
    end if
    if ballrow = 8 then
        score1 := score1 + 1
        ballrowChange := -ballrowChange
    end if
    locate (2, 2)
    put "Player 1 score: ", score2
    locate (2, 68)
    put "Player 2 score: ", score1
    Input.KeyDown (chars)

    %-----------------------------------------------------------------
    %Paddle one                                                      |
    %-----------------------------------------------------------------

    if chars (KEY_UP_ARROW) then
        y1 := y1 + 5
        y2 := y2 + 5
    end if
    if chars (KEY_DOWN_ARROW) then
        y1 := y1 - 5
        y2 := y2 - 5
    end if
    drawfillbox (x1, y1, x2, y2, 12)


    %-----------------------------------------------------------------
    %Paddle two                                                       |
    %-----------------------------------------------------------------

    if chars ('w') then
        y3 := y3 + 5
        y4 := y4 + 5
    end if
    if chars ('s') then
        y3 := y3 - 5
        y4 := y4 - 5
    end if
    drawfillbox (x3, y3, x4, y4, 12)

    %-----------------------------------------------------------------
    %End paddle two                                                   |
    %-----------------------------------------------------------------

end loop


If you help, thanks. If you can't, I understand.
Sponsor
Sponsor
Sponsor
sponsor
AsianSensation




PostPosted: Mon Dec 08, 2003 10:16 pm   Post subject: (No subject)

when you say
code:
xy1 := x1 and y1
do you mean xy1 is equal to x1 + y1? Because and cannot be used as an operator there when assigning values.

same thing with this
code:
ballt1 := x2 and >= y1, <= y2
what are you trying to say here? Basicly, you can't use comparison operators when assigning values to variables like that.
juniorspank




PostPosted: Tue Dec 09, 2003 9:06 am   Post subject: (No subject)

I was trying to mess around with a way to make a collision detection, perhaps I could check for this in a tutorial.
DanShadow




PostPosted: Thu Dec 11, 2003 6:23 pm   Post subject: (No subject)

hm
code:

var ballx, bally : int := 200
var xstep, ystep : int := 1
var paddle_x1, paddle_x2, paddle_y1, paddle_y2 : int
var key : string (1) := ""
var score : int := 0
paddle_x1 := 3
paddle_x2 := 23
paddle_y1 := 280
paddle_y2 := 200
loop
    Draw.FillOval (ballx, bally, 15, 15, 0)
    Draw.FillBox (paddle_x1, paddle_y1, paddle_x2, paddle_y2, 1)
    delay (1)
    ballx := ballx + xstep
    bally := bally + ystep
    if whatdotcolor (ballx - 15, bally) = 1 then
        xstep := +1
    end if
    Draw.FillOval (ballx, bally, 15, 15, 12)
    Draw.FillBox (paddle_x1, paddle_y1, paddle_x2, paddle_y2, 0)
    if hasch then
        getch (key)
    end if
    if paddle_y1 >= maxy then
        key := ""
        paddle_y1 := paddle_y1 - 1
        paddle_y2 := paddle_y2 - 1
    elsif paddle_y2 <= 0 then
        key := ""
        paddle_y1 := paddle_y1 + 1
        paddle_y2 := paddle_y2 + 1
    end if
    if key = (KEY_UP_ARROW) then
        paddle_y1 := paddle_y1 + 1
        paddle_y2 := paddle_y2 + 1
    elsif key = (KEY_DOWN_ARROW) then
        paddle_y1 := paddle_y1 - 1
        paddle_y2 := paddle_y2 - 1
    end if
    if bally + 15 >= maxy then
        ystep := -1
    elsif bally - 15 <= 0 then
        ystep := +1
    elsif ballx + 15 >= maxx then
        xstep := -1
    elsif ballx - 15 <= 0 then
        xstep := +1
    end if
    if ballx - 15 <= 0 then
        Draw.FillOval (ballx, bally, 15, 15, 0)
        ballx := 200
        bally := 200
        score := score + 1
    end if
    locate (15, 30)
    put "Times Ball Got Passed: ", score
end loop


Sorry, g2g, couldnt finish it...use "WhatDotColor" for paddle detection
AsianSensation




PostPosted: Thu Dec 11, 2003 7:24 pm   Post subject: (No subject)

DanShadow wrote:
Sorry, g2g, couldnt finish it...use "WhatDotColor" for paddle detection


NO!!!!!!!!!!!!!!!!!!

I swear andy, it's all your fault, you have corrupted the minds of our new generation of compsci people.

seriously though, don't use whatdotcolor, it's kinda unreliable at times. instead, use math, math is always realiable.
DanShadow




PostPosted: Fri Dec 12, 2003 4:06 pm   Post subject: (No subject)

Well yeah, whatdotcolor is screwy at some times, but in th e instance of a simple game of pong, its ok. (Except that whatdotcolor is only going in one location...) Maybe if you use math, and whatdotcolor, you could make collision detection that wont mess up...just maybe though. Smile
Andy




PostPosted: Fri Dec 12, 2003 5:44 pm   Post subject: (No subject)

WHAT??? whatdotcolor screwy? thats it ur going down... 0 bits for you!























jk... but i'm serious... whatdotcolor never fails... and azn, wtf u talking about? these kids should be thanking me for teaching them the sacred art
DanShadow




PostPosted: Sat Dec 13, 2003 4:55 pm   Post subject: (No subject)

I fixed my comment about whatdotcolor being screwy....It is excellent, as long as you have some math there. Like for example, you have a circle, you must use math to check whatdotcolor in a circumference (1 pixel away) around the circle for unstoppable elite whatdotcolor co llision detection. I believe in whatdotcolor, I swear! (...master? heh)
Sponsor
Sponsor
Sponsor
sponsor
Andy




PostPosted: Sat Dec 13, 2003 4:57 pm   Post subject: (No subject)

just plug the point in the circle formula x^2+y^2=r^2
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  [ 9 Posts ]
Jump to:   


Style:  
Search: