Racing game (Qt/Box2D)

Post your tutorials and samples here.
luke_c
Posts: 7
Joined: Mon Mar 05, 2012 2:33 pm

Racing game (Qt/Box2D)

Postby luke_c » Sat Mar 10, 2012 1:07 pm

This is a top-down racing game that I wrote to add interactivity to my stand at the national science and engineering competition.
I have placed it online as example of how to use QT alongside Box2D, not because I feel that my code is a particularly good example, but because I couldn't find any others.
If you find any bugs, or bad practice, feel free to contact me. I'll probably reply, but don't expect me to fix it. ;)

The game requires the use of wired PS3 remotes and linux. Ensure that you have the joystick API in your kernel. You will in most distributions, including ubuntu. To test your remote, type the following into the terminal:

Code: Select all

cat /dev/input/js0

Now press some buttons on the remote. If nothing happens in the terminal / in the game then:
    1) Unplug the wire
    2) Press "PS"
    3) Plug the wire back in
    4) Select restart
    5) Unpause the game.
If the command doesn't produce an error, but also doesn't respond to button presses even after following the above procedure, ensure that your PS3 is turned off.

Control Scheme:
Cross / R2 - Accelerator
L / R stick - Steer
Square / R1 - Handbrake
Circle / L2 - Reverse
Start - (Un)pause
Select - Return to previous checkpoint

I'm releasing this before I start working on the actual level, since I'd have to speak to the artist about whether I can release the graphics I'll be using on it or not. Instead, you get my lovely 256-colour grayscale friction map!

And yes, I know how hard it is to steer.

Edit:
To use the files below, you have to extract them using tar. Since you're going to be using linux to run the game, this shouldn't be a problem. Typing the following into the terminal should do it:

Code: Select all

mkdir ~/DrivingGame
cp ~/Downloads/DrivingGame.tar.gz ~/DrivingGame
cd ~/DrivingGame
tar -xf DrivingGame.tar.gz
Attachments
DrivingGame.tar.gz
Source code
(90 KiB) Downloaded 606 times
FrictionMap.tar.gz
Friction map
(210 KiB) Downloaded 549 times
Last edited by luke_c on Sun Mar 11, 2012 6:46 pm, edited 3 times in total.

irresistible force
Posts: 1991
Joined: Tue Jun 24, 2008 8:25 pm
Location: Tokyo
Contact:

Re: Racing game (Qt/Box2D)

Postby irresistible force » Sun Mar 11, 2012 7:23 am

:o
gzip: DrivingGame.tar.gz: not in gzip format

luke_c
Posts: 7
Joined: Mon Mar 05, 2012 2:33 pm

Re: Racing game (Qt/Box2D)

Postby luke_c » Sun Mar 11, 2012 6:30 pm

Don't use gzip to decompress it: I get the same error. Use tar instead.

Code: Select all

mkdir ~/DrivingGame
cp ~/Downloads/DrivingGame.tar.gz ~/DrivingGame
cd ~/DrivingGame
tar -xf DrivingGame.tar.gz

irresistible force
Posts: 1991
Joined: Tue Jun 24, 2008 8:25 pm
Location: Tokyo
Contact:

Re: Racing game (Qt/Box2D)

Postby irresistible force » Mon Mar 12, 2012 5:01 am

Ah, so these files are not actually compressed. It might be clearer to leave out the .gz extension as that is typically used when a file has been compressed with gzip.

The file 'Startup.ui' seems to be missing but I took it out of the .pro and the project compiles ok without it, so maybe it was not a necessary file. I also had to replace the "/home/luke..." references so that the png could be loaded.

At that point I remembered that I need a PS3 controller... :D Would you be able to add regular keyboard control for the other 95% of us?

luke_c
Posts: 7
Joined: Mon Mar 05, 2012 2:33 pm

Re: Racing game (Qt/Box2D)

Postby luke_c » Mon Mar 12, 2012 5:54 am

Ah, so these files are not actually compressed. It might be clearer to leave out the .gz extension as that is typically used when a file has been compressed with gzip.

I was under the impression that tar auto-detected the type of compression to use from the file type. If I've been using it incorrectly, then hoepfulyl I should be able to get it all into one archine. I'll reread the manual some time.


The file 'Startup.ui' seems to be missing but I took it out of the .pro and the project compiles ok without it, so maybe it was not a necessary file. I also had to replace the "/home/luke..." references so that the png could be loaded.


Yes. I left out Startup.ui. It was going to be a sort of settings window. As I mentioned in the OP, this is for a science competition. I didn't want visitors to be messing around with picking a car / colour, etc. so I removed it. I never actually deleted the file, in case I changed my mind, but it doesn't have any actual use.

At that point I remembered that I need a PS3 controller... Would you be able to add regular keyboard control for the other 95% of us?

You don't have a PS3 remote? I'd assumed that they'd be more common than linux desktops. ;)
It'll have to be after I get back, but it shouldn't take to long. Derive the PSRemote class from a Controller class. Make the update / fireevents virtual, then you should be able to add any type of joystick controller quickly and easily. The important bit is where I have QObject::connect( #, BUTTON, #, CARCONTROL). A keyboard wouldn't use the joystick controller, but would probably be even easier to add.

irresistible force
Posts: 1991
Joined: Tue Jun 24, 2008 8:25 pm
Location: Tokyo
Contact:

Re: Racing game (Qt/Box2D)

Postby irresistible force » Tue Mar 13, 2012 4:01 am

luke_c wrote:... tar auto-detected the type of compression to use from the file type.
For decompression, it seems to be able to detect whether gzip has been used or not regardless of the file extension, but for compression you need to explicitly say gzip should be used (just add a 'z' to the options, eg 'czf'). My problem was that I was trying 'xzf' to decompress which forces the decompression filter, and my graphical file manager (Fedora Nautilus) also could not open the file so I guess it was doing the same thing :D

Yeah I guess there are more PS3 controllers out there... I was kinda thinking of numbers of people who have both. Btw the physics objects are displaying as red blocks, is that correct?
Attachments
dg.png
dg.png (16.53 KiB) Viewed 7206 times

luke_c
Posts: 7
Joined: Mon Mar 05, 2012 2:33 pm

Re: Racing game (Qt/Box2D)

Postby luke_c » Tue Mar 13, 2012 11:58 am

Yeah I guess there are more PS3 controllers out there... I was kinda thinking of numbers of people who have both. Btw the physics objects are displaying as red blocks, is that correct?


I always knew it would be a very select group of people who'd have any interest in this, let alone want to try it out! I'll see what I can do, but it'll be a week at the earliest.

Yes. I uploaded my development version before I added the graphics. I've spoken to my friend who did the artwork. He's fine with me releasing them, so I should be able to upload much more interesting version once I've sorted out the code for the level.


Return to “Tutorials and Samples”



Who is online

Users browsing this forum: No registered users and 3 guests