Computer Science Canada Game question |
Author: | Morice [ Sat Dec 17, 2005 9:48 am ] | ||
Post subject: | Game question | ||
This is what i have so far Im trying to make this racing, however i dont know how to do the time count. Later after i finish with all of this i will make it a 2 player game and add some more levels, but for now im trying to get time, so can anybody teach me? |
Author: | Cervantes [ Sat Dec 17, 2005 9:57 am ] |
Post subject: | |
Wow, that's a lot of hardcoding. I'm not really sure what you're asking, but I'm going to point you to Time.Elapsed. Check the Turing Help Manual, it should be pretty self explanitory. |
Author: | Morice [ Sat Dec 17, 2005 10:01 am ] |
Post subject: | |
I tried using the Time.Elapsed command as u can see almost at the end however it doesnt really work cause it gives me milliseconds instead of seconds and i can convert, i tried but couldnt, isnt there a much easier way. Oh ya also with restrictions u know so that my "car" wont touch the walls is ther an easier way.... |
Author: | Morice [ Sat Dec 17, 2005 10:08 am ] |
Post subject: | |
Ok nevermind with the time i serchead and figured it out, however i would still want to learn how to use restrictions an easier way, is it with whatdotcolor???/ |
Author: | Morice [ Sat Dec 17, 2005 10:19 am ] |
Post subject: | |
And one more thing... how to use acceleration to make my program a little bit more realistic.... thanks |
Author: | Cervantes [ Sat Dec 17, 2005 10:23 am ] |
Post subject: | |
Morice wrote: Ok nevermind with the time i serchead and figured it out, however i would still want to learn how to use restrictions an easier way, is it with whatdotcolor???/
whatdotcolour is one way. It'd probably be the easiest, but it's definately not the best. A better way might be to read your "map" in from a text file into a 2D array. Although I haven't actually run your program. ![]() |
Author: | Cervantes [ Sat Dec 17, 2005 10:34 am ] | ||||||||
Post subject: | |||||||||
Morice wrote: And one more thing... how to use acceleration to make my program a little bit more realistic.... thanks
Acceleration is to velocity as velocity is to displacement. In scalar form: Acceleration is to speed as speed is to distance. Let's set up a record for our car. Note that you don't actually have to use a record, but it keeps things nice and tidy.
Now, let's give that some values.
So, what should this car be doing? It should start in the middle and move up by 0.5 pixels each time through the loop (since we aren't going to bother with fps restrictions). It should accelerate by 0.1 pixels per frame^2 in the positive x direction. Now, let's apply this
So, what does this all mean to you? When you press the up arrow, you want to accelerate your car up:
Alternatively, you could make yourself accerlerate forwards, and have the left and right arrow keys turn you, while the down arrow accelerates you backwards. For this, you'll need to know some trig, but it's not hard. zylum wrote a good tutorial on this topic: http://www.compsci.ca/v2/viewtopic.php?t=3714. |
Author: | Morice [ Sat Dec 17, 2005 10:49 am ] |
Post subject: | |
Thanks, Cervants, i think i get it now, however i havent learned about record yet. But i get wat u did with the other stuff. |
Author: | Morice [ Sat Dec 17, 2005 11:24 am ] | ||
Post subject: | |||
ok now my restrictions wont work and i cant get it to stop, can somebody teach me how to use whatdotcolor...cause i hear that its much easier than my restrictions heres the new code
thanks.... |
Author: | Cervantes [ Sat Dec 17, 2005 11:45 am ] | ||
Post subject: | |||
If the dot colour just ahead of the car is the colour of the edge of the track or the grass beyond it, stop the car. This would be easier if you were using rotation and forwards/backwards.
You would also need to reverse the car a little bit, so that the car is free to move again. Again, this would be much easier with the rotation-backward/forward approach, and that approach suites a racing game better, IMO. |
Author: | Morice [ Sat Dec 17, 2005 11:50 am ] | ||
Post subject: | |||
Cervantes wrote: If the dot colour just ahead of the car is the colour of the edge of the track or the grass beyond it, stop the car. This would be easier if you were using rotation and forwards/backwards.
You would also need to reverse the car a little bit, so that the car is free to move again. Again, this would be much easier with the rotation-backward/forward approach, and that approach suites a racing game better, IMO. lol all i understood from ther was if whatdotcolor,btw i have turing 4.0.5 and some stuff dont work.... |
Author: | Morice [ Sat Dec 17, 2005 11:53 am ] |
Post subject: | |
i meant 4.0.3 dont know y i type 4.0.5 |
Author: | Cervantes [ Sat Dec 17, 2005 11:55 am ] |
Post subject: | |
You mean, you didn't understand the trig? No problem. I used arctan (which is the inverse tan function. Normall written on calculators as tan^-1) to find the angle that the player is moving. I then took the cos of that to get the component of that angle for a unit circle. I then multiplied it by car.radius so that we're checking out from a bit. This is assuming that the car is a circle. Further, it should have been multiplied by (car.radius + 1), because we want to check just beyond the edge of the car. I did similarly for the y plane, except I used sine. |
Author: | Morice [ Sat Dec 17, 2005 11:57 am ] | ||
Post subject: | |||
ohhh ok.... so if its a box then i shoud do this
|
Author: | Cervantes [ Sat Dec 17, 2005 12:10 pm ] |
Post subject: | |
Right, assuming the car is moving up. You could probably just check all around the car, and answer an all stop if the track colour is found. To allow for the car to be released from the track's edge, you might want to create a boolean flag that will say whether the car to check for a collision with the edge of the track or not. If you crash, set that flag to false, and by the time you're released again, set it back to true. |
Author: | Morice [ Sat Dec 17, 2005 12:30 pm ] | ||||
Post subject: | |||||
so instead of
i should do
to find the area however when i do that in turing i get an error that says "Argument wrong type" it wont let me do it |
Author: | Cervantes [ Sat Dec 17, 2005 12:39 pm ] | ||
Post subject: | |||
That's definately not how to do it. That won't search an area. whatdotcolour only looks at a single pixel, or dot. It also takes two parameters, but you've only given it one. If you want, you could make a function that checks an area for a certain colour:
Though this is not very efficient, and definately not the best way to approach your problem, sinec most of the time would be spent searching the colour of the car itself, which is pointless. |
Author: | Morice [ Sat Dec 17, 2005 12:49 pm ] |
Post subject: | |
argghhh i give up with the whatdotcolor it wont work guess that im gona go back to if x and y =blah blah blah then blah blah blah thanks though for ur help. I learned some stuff lol |