Computer Science Canada Help with racing game |
Author: | Ldomi [ Fri Jan 05, 2007 3:02 pm ] | ||
Post subject: | Help with racing game | ||
Hi, I'm trying to make a racing game but I'm running into a lot of problems...Can anyone help me? Problem 1: How do i get the computer car to move by itself at the same time the other car that is being controlled by the user is moving? (Someone told me to use Input.KeyDown instead of getch but i don't really understand how that solves the problem) Problem 2: When I play again, why does the car move slower when it reaches a certain point on the screen? Problem 3:Why doesn't the Main Menu Button in the displayEasy procedure work? I'd appreciate any help you can give. (I'd also like some suggestions for the game if anyone has any) Thanks in advance. =D Here's the code so far...
|
Author: | Ldomi [ Fri Jan 05, 2007 3:04 pm ] |
Post subject: | |
I forgot, don't mind if the quit button doesn't work. |
Author: | BenLi [ Fri Jan 05, 2007 3:39 pm ] |
Post subject: | |
the answer to one of your question: The advantage Input.KeyDown has over getch is that it can check for multiple keys pressed. This is extremely important in a racing game where the user may need to accelerate and turn at the same time. |
Author: | Ldomi [ Fri Jan 05, 2007 3:56 pm ] |
Post subject: | |
BenLi wrote: This is extremely important in a racing game where the user may need to accelerate and turn at the same time.
Thanks and I agree, but in my racing game, the user does not necessarily have to turn because all they really have to do to win is go in a straight line (I made my game really noobish =P). However, if i later on decide to put rocks or other obstacles on the game to actually make it fun, then i'll use input.keydown. For now i'll just stick with getch. |
Author: | neufelni [ Fri Jan 05, 2007 5:13 pm ] | ||||
Post subject: | |||||
The reason that you should use Input.KeyDown instead of getch is that with getch, the program waits until the user enters something before it will do anything else. With Input.KeyDown, the program will keep doing other stuff while waiting for input. So in your racing game, if you use getch the other car won't move until you hit a key, then it will move 1(or howmanyever) pixels, and then wait for you to hit a key again. With Input.KeyDown, the other car will move normally even if you don't hit a key right aways. Here is an example to show the difference: Using Getch
Using Input.KeyDown
Output |
Author: | Ldomi [ Sat Jan 06, 2007 1:37 am ] | ||
Post subject: | |||
i tried using Input.keydown but all it is doing is making the blue car move using the arrow keys and also move by itself, not making the blue car move by itself and the yellow car move using the arrow keys at the same time.
^^here's the code using inpuy.keydown |
Author: | neufelni [ Sat Jan 06, 2007 10:45 am ] | ||||
Post subject: | |||||
OK, so here are a few things that you should change in your code. 1. Instead of declaring one pictureID variable at the the beginning of your program and then assigning it to a different picture each time you need to draw a pic, declare one for each of your pictures at the beginnig. Like this:
And then when you need to draw the picture, alls you need to do is this:
2. You need to bring the Pic.Draw to draw your yellow car inside the loop. This way the yellow car will move too when you press the arrow keys. 3. You need to have separate variables for the p1 car and the comp car. You are using the same x variables for both, that is why when you hit the arrow keys the blue car moves faster. So give those things a try and if you have any problems, let me know. |
Author: | ericfourfour [ Sat Jan 06, 2007 5:56 pm ] | ||
Post subject: | |||
It is annoying when I post a link to style guidelines and then no one follows them. Either choose between picture_racing_flags or pictureRacingFlags but do not mix the two together. You are just going to confuse people. |
Author: | Ldomi [ Sat Jan 06, 2007 6:21 pm ] |
Post subject: | |
Thank you very very much Nick! ![]() I have a few problems with delay, but i'll try solving them first. |