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

Username:   Password: 
 RegisterRegister   
 Anyone have a good working Pong game?
Index -> Programming, Turing -> Turing Help
Goto page Previous  1, 2, 3  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
roer




PostPosted: Tue Nov 25, 2003 8:53 pm   Post subject: (No subject)

code:
var x, y : int := 1
var direction : array char of boolean

procedure leftpaddle
    loop
        Draw.Box (x, y, 100, 100, green)
        Input.KeyDown (direction)
        if direction (KEY_UP_ARROW) then
            y := y + 10
        elsif direction (KEY_DOWN_ARROW) then
            y := y - 10
        end if
        View.Update
        delay (10)
        cls
    end loop
end leftpaddle

leftpaddle


Well, thats what I got with the procedure code so far. The box however is really something, when you press Up or Down the box simply grows. The bottom of the box stays the same however, anyone have any suggestions?
Sponsor
Sponsor
Sponsor
sponsor
Andy




PostPosted: Tue Nov 25, 2003 9:13 pm   Post subject: (No subject)

your drawing the box from y to 100, you should do from y to y+100 in your draw box thing. o and for collision detection, use whatdotcolor!
roer




PostPosted: Tue Nov 25, 2003 9:17 pm   Post subject: (No subject)

Lol dodge I heard you know a lot about whatdotcolour Smile Care to give me link or short explaination of its function?
Andy




PostPosted: Tue Nov 25, 2003 9:22 pm   Post subject: (No subject)

hey! great idea! tutorial on whatdotcolor! ok i'll give you the short version 1st
whatdotcolor(x,y) gives you an integer which is the color of the pixel at coordinates x,y. for a simple game like pong, your paddle is prolly gonna be all white, so you can simply go around the ball and see if it touches any white ie
code:

for i:-radius..radius
    for j:-radius.. radius
        if i^2+j^2=radius^2 and whatdotcolor(i,j)=white then
            %bounce ball back
        end if
    end for
end for


that will check if the ball had touched any white anywhere.
then basicly, if the ball touches, just switch directions
roer




PostPosted: Tue Nov 25, 2003 9:28 pm   Post subject: (No subject)

whatdotcolour seems to be very practical, is it efficent though? Even if it isn't, it gets the job done it seems Smile thanks for your explaination dodge, i'll use whatdotcolour in my game when I finish it Smile
Andy




PostPosted: Tue Nov 25, 2003 9:32 pm   Post subject: (No subject)

gj my young padawan ha tony take that! Razz
the only thing wrong wtih whatdotcolor is that it is not exactly the most function thing invented... other than that, its very useful... but oh well, in a couple of years, we'll all be runing comps with clock speeds of a couple yodahurtz so who cares about efficency...
i'm gonna invent a language based on whatdotcolor!
roer




PostPosted: Tue Nov 25, 2003 9:36 pm   Post subject: (No subject)

Lol, tony dosen't seem to agree with you on the whatdotcolour topic Rolling Eyes Good luck with that language by the way Wink
Mazer




PostPosted: Tue Nov 25, 2003 9:43 pm   Post subject: (No subject)

dodge_tomahawk wrote:
i'm gonna invent a language based on whatdotcolor!


heck yeah! it'll replace turing as the most taught language in canadian highschools. and then, some kid who sucks at math but excels in compsci will become the greatest in his class and be destined to write the whatdotcolor version of evasive maneuvers.
Sponsor
Sponsor
Sponsor
sponsor
roer




PostPosted: Tue Nov 25, 2003 9:59 pm   Post subject: (No subject)

One more question....when using procedures how do you display multiple procedures at once? For example, I'm trying to make both of my paddles appear at once using procedures, but it only displays one on the screen. Is there a function that enables both procedures to be operational at the same time?

code:
View.Set ("graphics")
var x, y, x1, y1 : int
var direction, direction1 : array char of boolean
x := 10
y := 10
x1 := 580
y1 := 180
procedure leftpaddle
    loop
        Draw.FillBox (x, y, x + 30, y + 120, green)
        Input.KeyDown (direction)
        if direction (KEY_CTRL) then
            y := y + 10
        elsif direction (KEY_ALT) then
            y := y - 10
        end if
        View.Update
        delay (50)
        cls
    end loop
end leftpaddle

procedure rightpaddle
    loop
        Draw.FillBox (x1, y1, x1 + 30, y1 + 120, blue)
        Input.KeyDown (direction1)
        if direction1 (KEY_UP_ARROW) then
            y := y + 10
        elsif direction1 (KEY_DOWN_ARROW) then
            y := y - 10
        end if
        View.Update
        delay (50)
        cls
    end loop
end rightpaddle

leftpaddle
rightpaddle


Here's the code so far, simple indeed Smile
Andy




PostPosted: Tue Nov 25, 2003 10:00 pm   Post subject: (No subject)

dont have a loop inside the procedure, run both procs in side a loop in your mainline
roer




PostPosted: Tue Nov 25, 2003 10:59 pm   Post subject: (No subject)

Oooooo...I should pay more attention to things like that Embarassed Just finished watching 24 Smile That was an awesome episode BTW Wink
Tony




PostPosted: Tue Nov 25, 2003 11:19 pm   Post subject: (No subject)

roer wrote:
i'll use whatdotcolour in my game when I finish it Smile


that's what happens when I step away from the computer to play some GTA3 Rolling Eyes
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
roer




PostPosted: Tue Nov 25, 2003 11:24 pm   Post subject: (No subject)

tony wrote:
roer wrote:
i'll use whatdotcolour in my game when I finish it Smile


that's what happens when I step away from the computer to play some GTA3 Rolling Eyes
Embarassed Actually I'm still at debate with myself as to use it or not...your not to late yet Wink
Tony




PostPosted: Tue Nov 25, 2003 11:42 pm   Post subject: (No subject)

dont use the evil!

I'll give you bits Laughing
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
roer




PostPosted: Wed Nov 26, 2003 12:13 am   Post subject: (No subject)

Lol, bribing me with bits Wink Heh, I'm not using whatdotcolour in my current version of pong...but who knows what the future may holy Wink
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 2 of 3  [ 36 Posts ]
Goto page Previous  1, 2, 3  Next
Jump to:   


Style:  
Search: