Help with racing game
Author |
Message |
zeoxyman
|
Posted: Sat Jan 09, 2010 1:11 pm Post subject: Help with racing game |
|
|
I am a relative newbie at Turing (1st year) and trying to make a 2D racing game for my school ISP. Basically the user steers his/her car to avoid other cars appearing at the top of the screen. When a crash occurs, the game ends and the score is displayed.
What I have so far:
- A player car controlled by the arrow keys.
- An enemy car which appears at a random x-coordinate at the top of the screen and moves down at one of three speeds.
- A re-spawn mechanism which causes the car to reappear at the top when it leaves the screen.
- A road background to which the cars are constrained.
What I want added:
- Four more enemy cars, which spawn and re-spawn like the first car but at different places and times.
- A crash detector for the cars, and a way to prevent enemy cars from spawning inside each other/at the same x coordinate.
- A difficulty setting which sets the number of enemies to 2, 3, or 5, and also affects the speed of the enemy cars.
- A high score tracker (+1 point per millisecond) and a button operated interface with a menu and high score (I can probably do this myself).
- Music to play in-game (I've made this myself and can implement it with a process, so no problem here).
Any help I can get will be appreciated, this ISP is due in a week.
Turing Version: 4. 1. 1 (latest)
Description: |
|
![](http://compsci.ca/v3/pafiledb/images/icons/clip.gif) Download |
Filename: |
Turing_ISP.rar |
Filesize: |
8.35 KB |
Downloaded: |
82 Time(s) |
|
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
zeoxyman
|
Posted: Sat Jan 09, 2010 7:04 pm Post subject: Re: Help with racing game |
|
|
Sorry if anyone was confused, I just saw someone else getting owned for not having comments.
Thereby, updated version (with comments).
Description: |
|
![](http://compsci.ca/v3/pafiledb/images/icons/clip.gif) Download |
Filename: |
Turing_ISP.rar |
Filesize: |
8.59 KB |
Downloaded: |
80 Time(s) |
|
|
|
|
|
![](images/spacer.gif) |
Ktomislav
![](http://compsci.ca/v3/uploads/user_avatars/208162377548d53ef771951.jpg)
|
Posted: Sat Jan 09, 2010 7:42 pm Post subject: Re: Help with racing game |
|
|
To add more cars you have to use arrays. So you need one array for x coordinates, one for y coordinates
and one for picture of that car if you want enemy cars to be different coloured.
For collision detection use this tutorial http://compsci.ca/v3/viewtopic.php?t=13661
To get greatest X and Y value use Pic.Width+enemyX and Pic.Height+enemyY.
For difficulty setting you can use something like this:
code: | var difficulty: string
put "What difficulty level do you want? (easy, medium, hard)"
get difficulty
if (difficulty = "easy") then
...
end |
For score just add a counter like var score: int and increas its value every frame
by value of milliseconds in delay procedure.
Hope this helps.
|
|
|
|
|
![](images/spacer.gif) |
zeoxyman
|
Posted: Sat Jan 09, 2010 10:25 pm Post subject: Re: Help with racing game |
|
|
Thanks, that appears to have taken care of everything for now. I will be posting the completed version on the Submissions forum later on.
I've decided on four difficulties: Easy, medium, hard, and impossible. Easy has one car, medium has two, hard has three, and impossible has four. So far, I haven't actually implemented them, and have therefore only played on "impossible" (and have not lasted over 30 seconds on it).
Meanwhile, if you have any system to prevent cars from spawning inside each other, please tell me.
|
|
|
|
|
![](images/spacer.gif) |
Ktomislav
![](http://compsci.ca/v3/uploads/user_avatars/208162377548d53ef771951.jpg)
|
Posted: Sun Jan 10, 2010 5:23 am Post subject: Re: Help with racing game |
|
|
Well, to prevent cars from spawning inside each other use something like this
code: | loop
spawnpointY := randint (Miny, Maxy);
// if not(cars collide) then
exit
end if
end loop |
That if loop should check if enemy cars collide with new car. This is buggy though because
you can't always spawn a car so that it doesn't collide with other cars, but this is the basic concept.
|
|
|
|
|
![](images/spacer.gif) |
zeoxyman
|
Posted: Mon Jan 11, 2010 6:42 pm Post subject: Re: Help with racing game |
|
|
I actually ended up doing it by each individual car, which was not buggy but maybe a bit overcomplicated. Thanks anyway, if I can find a way to improve my method, I will do so. That is all for now, the rest of the project should go smoothly.
|
|
|
|
|
![](images/spacer.gif) |
Ktomislav
![](http://compsci.ca/v3/uploads/user_avatars/208162377548d53ef771951.jpg)
|
Posted: Mon Jan 11, 2010 7:58 pm Post subject: Re: Help with racing game |
|
|
That's called brute forcing, I recommend you not to do that.
|
|
|
|
|
![](images/spacer.gif) |
zeoxyman
|
Posted: Wed Jan 13, 2010 10:59 pm Post subject: Re: Help with racing game |
|
|
OK, new problem. The program is done (though the buttons won't press down, they still work), but I edited the "PlayerCar.bmp" pic a little (I made it smaller to help dodge enemy cars), and now the program won't run it or any copy of it. Have I corrupted one of the two files, or am I just missing some really obvious code problem? And, in the process, is anything else wrong (besides the buttons)? What's the deal here?
EDIT: Disregard the post, it must have been a Windows glitch because it's working again.
Description: |
|
![](http://compsci.ca/v3/pafiledb/images/icons/clip.gif) Download |
Filename: |
Turing_ISP.rar |
Filesize: |
10.15 KB |
Downloaded: |
82 Time(s) |
|
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
|
|