Box2D Forums

It is currently Tue May 21, 2013 1:58 pm

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: Racing game (Qt/Box2D)
PostPosted: Sat Mar 10, 2012 1:07 pm 
Offline

Joined: Mon Mar 05, 2012 2:33 pm
Posts: 7
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:
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:
mkdir ~/DrivingGame
cp ~/Downloads/DrivingGame.tar.gz ~/DrivingGame
cd ~/DrivingGame
tar -xf DrivingGame.tar.gz


Attachments:
File comment: Source code
DrivingGame.tar.gz [90 KiB]
Downloaded 300 times
File comment: Friction map
FrictionMap.tar.gz [210 KiB]
Downloaded 208 times


Last edited by luke_c on Sun Mar 11, 2012 6:46 pm, edited 3 times in total.
Top
 Profile  
 
PostPosted: Sun Mar 11, 2012 7:23 am 
Offline

Joined: Tue Jun 24, 2008 8:25 pm
Posts: 1515
Location: Tokyo
:o
gzip: DrivingGame.tar.gz: not in gzip format


Top
 Profile  
 
PostPosted: Sun Mar 11, 2012 6:30 pm 
Offline

Joined: Mon Mar 05, 2012 2:33 pm
Posts: 7
Don't use gzip to decompress it: I get the same error. Use tar instead.
Code:
mkdir ~/DrivingGame
cp ~/Downloads/DrivingGame.tar.gz ~/DrivingGame
cd ~/DrivingGame
tar -xf DrivingGame.tar.gz


Top
 Profile  
 
PostPosted: Mon Mar 12, 2012 5:01 am 
Offline

Joined: Tue Jun 24, 2008 8:25 pm
Posts: 1515
Location: Tokyo
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?


Top
 Profile  
 
PostPosted: Mon Mar 12, 2012 5:54 am 
Offline

Joined: Mon Mar 05, 2012 2:33 pm
Posts: 7
Quote:
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.


Quote:
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.

Quote:
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.


Top
 Profile  
 
PostPosted: Tue Mar 13, 2012 4:01 am 
Offline

Joined: Tue Jun 24, 2008 8:25 pm
Posts: 1515
Location: Tokyo
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 2691 times ]
Top
 Profile  
 
PostPosted: Tue Mar 13, 2012 11:58 am 
Offline

Joined: Mon Mar 05, 2012 2:33 pm
Posts: 7
Quote:
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group