Computer Science Canada Air Hockey Help! |
Author: | Eny [ 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... |
Author: | Remm [ Mon Jun 05, 2006 9:32 am ] |
Post 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. |
Author: | Eny [ Mon Jun 05, 2006 10:14 am ] |
Post 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. |
Author: | Eny [ Mon Jun 05, 2006 10:36 am ] |
Post 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? ![]() |
Author: | Dan [ Mon Jun 05, 2006 8:33 pm ] |
Post 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. What you do is check the color of the pixel where the puck is going to be and if it is the color of the padal or wall chage directions. Check out http://www.compsci.ca/v2/viewtopic.php?t=2381 for more info on whatdotcolor. 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. |
Author: | Clayton [ Mon Jun 05, 2006 8:52 pm ] |
Post 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 |
Author: | Eny [ Tue Jun 06, 2006 9:59 am ] |
Post subject: | |
Thanks a bunch! If I have any more questions I'll do that ![]() |
Author: | Eny [ Tue Jun 06, 2006 10:20 am ] | ||
Post 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 ![]()
Code orgianly by rich cash. Now if I were to add a score code area for the nets, what would I have to use? |
Author: | Clayton [ Tue Jun 06, 2006 11:24 am ] |
Post 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 ![]() |
Author: | Eny [ Tue Jun 06, 2006 11:25 am ] |
Post subject: | |
![]() |
Author: | Eny [ Wed Jun 07, 2006 8:47 am ] | ||
Post 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?
|
Author: | Remm [ Wed Jun 07, 2006 9:31 am ] |
Post 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 |
Author: | Eny [ Wed Jun 07, 2006 9:33 am ] |
Post subject: | |
Oh! I get it now! Thanks. |
Author: | Eny [ Wed Jun 07, 2006 12:38 pm ] |
Post 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 "") |
Author: | Eny [ Thu Jun 08, 2006 8:59 am ] | ||
Post subject: | |||
Ok, nevermind... I fixed it ![]() 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:
|
Author: | Dan [ Thu Jun 08, 2006 11:33 am ] |
Post subject: | |
You should not mix "put" and grpahics of any kind. Instented use Font.Draw to display text when your are doing somthing grpahical. See the info on Font.Draw from your turings help refercen (f10). |
Author: | PhOtO! [ Thu Jun 08, 2006 3:49 pm ] |
Post subject: | |
that souce code you gave was made by me and rich cash, and u only took out the background! Even though u already said that it's not your code and u're gonna change it, i would appreaciate you to give credit (to rich cash) if u took a code that he posted! |
Author: | Eny [ Fri Jun 09, 2006 9:34 am ] |
Post subject: | |
![]() I showed my teacher and I even said it wasn't my code, he told me how the coding works so I could learn and said thats how he would do it. Either way, my teacher said it would be something like that. Is that ok? I wouldn't want to make anyone angry. |
Author: | [Gandalf] [ Sat Jun 10, 2006 7:37 pm ] |
Post subject: | |
Hacker Dan wrote: You should not mix "put" and grpahics of any kind.
While this is generally a good mindset to follow, I've found that it's not always the case. For example, when I'm testing out some feature of a program or I want to quickly display a statistic to the user, put works just fine. Take a frames per second counter for example, it is a perfect thing to keep at the top right had corner of the screen in the small put font. The only thing you must consider when doing this is that your put statement should be behind all other drawings so that the horizontal bar created by the text background colour will not interfere. |
Author: | Eny [ Mon Jun 12, 2006 8:45 am ] |
Post subject: | |
Thanks for all your help, guys. My only problem is that it still flashes over the background... but I'll figure it out. |