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

Username:   Password: 
 RegisterRegister   
 Air Hockey Help!
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Eny




PostPosted: Mon Jun 05, 2006 8:54 am   Post subject: Air Hockey Help!

Hi, I need some help with programming an airhockey game.
I already have the graphics for it but I'm a bit confused on how to setup the key movements and collision.

Theres nothing in my turing book I was given that answers my question and my teacher doesn't explain things very well... he leaves out a lot of information.

Any tutorials or tips would be great...
Sponsor
Sponsor
Sponsor
sponsor
Remm




PostPosted: Mon Jun 05, 2006 9:32 am   Post subject: (No subject)

Hello and welcome to Compsci!

First of all, the best place you could head to would be the Turing Walkthrough -- a collection of basic to advanced tutorials and such made by other programmers.

Oh yeah - you can look in turing refrance under help in the acual turing program.
Eny




PostPosted: Mon Jun 05, 2006 10:14 am   Post subject: (No subject)

Thanks, I'll check that out... however, the help reference just confuses me further. I get half of what they say, hopefully that link will help.
Eny




PostPosted: Mon Jun 05, 2006 10:36 am   Post subject: (No subject)

Ok, I'm still a bit confused about how to make collision and the mouse keys work with the puck and 'sticks'(those puck looking things that push the puck).

I have a bit of a learning disability, so could someone dumb it down a bit for me? Embarassed Sometimes I need to learn specifics.
Dan




PostPosted: Mon Jun 05, 2006 8:33 pm   Post subject: (No subject)

Well there are a few difrent ways to do collision dectionion for this case:

1. The math + if staments way:

    This is where you check to see if a point x,y or in this case your puck is past a line. For example you check to see if your puck's x value is greater then 0 and less then the maxX value and that your puck's y value is greater then 0 and less then the maxY value. If this NOT the case the you will whont to chage the direction of the puck.

    For the padels you will whont do the same but the line you are checking agisted is moving.

    Check out http://www.compsci.ca/v2/viewtopic.php?t=75 for examples and a tutoral about this.


2. The whatdocolor way: This way is probly the simplest tho not as dynaick or as efsihment.


The [Turing Walkthrough] has alot of other tutorals that will be help full. Also there is a fourm full of example sorce code. I whould try sreaching for pong as it is a game that is prity much the same as what you are doing.

Also for more help tyring coding somthing, and when you get stuck come back here and post your code and what you are having problems with. Poeleop give alot more helpfull help when you have code posted.
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
Clayton




PostPosted: Mon Jun 05, 2006 8:52 pm   Post subject: (No subject)

key movements are simple, use Input.KeyDown or a combination of hasch and getch to get the value of the key you want to use to move whatever it is you want to move:D also, plz excuse Hacker Dan's horrible spelling, as he has had a problem with it ever since well....forever:D other than that good luck and check through the Turing Walkthrough for specific tutorials on subjects that you are having problems with:D
Eny




PostPosted: Tue Jun 06, 2006 9:59 am   Post subject: (No subject)

Thanks a bunch! If I have any more questions I'll do that Smile
Eny




PostPosted: Tue Jun 06, 2006 10:20 am   Post subject: (No subject)

Well I found a code here for air hockey, and asked my teacher to explain it to me so I understand it. So I took the coding idea and am going to modify it to my original designing..I hope thats not a cheap way to do it Embarassed

code:

setscreen ("graphics:700,max,position:center;center,nobuttonbar,offscreenonly")
var x, y, button, paddlex, paddley, lastballx, lastbally := 100
var ballx, bally : real := 100
var power := 5
var dx, dy : real := 1
proc drawscreen
    drawfillbox (0, 0, maxx, maxy, grey) % Border
    drawfillbox (20, 20, maxx - 20, maxy - 20, 1) %Background
    drawfillbox (20, 20, maxx - 20, 30, grey) % bottom
    drawfillbox (maxx div 2 - 70, 20, maxx div 2 + 70, 40, black) % net
    drawfillbox (20, maxy - 20, maxx - 20, maxy - 30, grey) % top
    drawfillbox (maxx div 2 - 70, maxy - 20, maxx div 2 + 70, maxy - 40, black) % net
    drawfillbox (20, maxy div 2, maxx - 20, maxy div 2 + 5, grey) %center line
    %ball
    drawfilloval (round (ballx), round (bally), 15, 15, 7)
    %paddle
    drawfilloval (paddlex, paddley, 35, 35, red)
    View.Update
    cls
end drawscreen
proc detection
    if ballx > maxx or ballx < 0 then
        dx *= -1
    end if
    if bally > maxy or bally < 0 then
        dy *= -1
    end if
    if abs (sqrt ((ballx - paddlex) ** 2 + (bally - paddley) ** 2)) < 35 then
        dx := (ballx - paddlex) / 10
        dy := (bally - paddley) / 10
    end if
end detection
loop
    mousewhere (x, y, button)
    if y > maxy div 2 then
        paddley := maxy div 2
    else
        paddley := y
    end if
    if x > maxx then
        paddlex := maxx
    elsif x < 0 then
        paddlex := 0
    else
        paddlex := x
    end if
    ballx += dx
    bally += dy
    detection
    if abs (ballx - lastballx) > power or abs (bally - lastbally) > power then
        lastballx := round (ballx)
        lastbally := round (bally)
        drawscreen
    end if
end loop


Code orgianly by rich cash.

Now if I were to add a score code area for the nets, what would I have to use?
Sponsor
Sponsor
Sponsor
sponsor
Clayton




PostPosted: Tue Jun 06, 2006 11:24 am   Post subject: (No subject)

just create a seperate procedure to add to the score each time the pucks coordinates on the screen go beyond a certain point (you can also use View.WhatDotColor to do this) run the procedure and add to the score Very Happy
Eny




PostPosted: Tue Jun 06, 2006 11:25 am   Post subject: (No subject)

Smile Okey dokey, I'll try that now.
Eny




PostPosted: Wed Jun 07, 2006 8:47 am   Post subject: (No subject)

The perimeters are all wrong, I forget how to check them when you run the program but I'm sure I have some saved code that will do that...

So something like this?
code:

if x = 280 and y = 680 then
        put "score"
    end if
Remm




PostPosted: Wed Jun 07, 2006 9:31 am   Post subject: (No subject)

is that code you posted above the detection for the puck going in? if so, its only checking one single pixel :/
Have like
if x > num and x < num and y > num and y < num then
so you got if its greater than x value, but less than another x value, same with y
Eny




PostPosted: Wed Jun 07, 2006 9:33 am   Post subject: (No subject)

Oh! I get it now! Thanks.
Eny




PostPosted: Wed Jun 07, 2006 12:38 pm   Post subject: (No subject)

Ok, another problem... I can't get the mouse.where to work with the graphics... is there something I need to put in the code for text?(other than put "")
Eny




PostPosted: Thu Jun 08, 2006 8:59 am   Post subject: (No subject)

Ok, nevermind... I fixed it Very Happy

Now I got it reconizing the nets and I'm happy.

I'm just having one more problem... Ok, I got it to say , "SCORE!" everytime it goes into the net but it flashes by too fast and if I put a delay on it the entire screen goes white with the score text...

even if I do it like this:
code:
put "Score!" ..
it still covers the rest of the screen with white.
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 2  [ 20 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: