• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
drowsyn

How to handle tracks in a 2D racing game?

7 posts in this topic

I've been tinkering with a 2D car game in the style of Slicks 'n Slide and GeneRally, and am not sure how to handle tracks, especially the collisions. My implementation at the moment is that I draw the track in Photoshop, and that's used as the actual graphic in the game. From that picture, I create a map that features just a few colors, which the game then reads, and assigns each pixel a state from an enumeration. These states are tarmac, grass, and wall. During gameplay, on every update, I check which pixels my car is colliding with, and react accordingly.

Now, this way of doing it works, but it feels like a complicated way of doing something fairly simple. I played around with two other options:
1. Create a pure tile-based level structure, where I just plop down tiles that have the corners on them. The problem with this approach is that I still can't figure out a good way of doing collisions. I'll still have to check each pixel on the tile, so really, this is just another way of doing exactly what I'm currently doing.
2. Draw the track as previously, but turn everything into objects. The road is made up of sections of "road objects", grass is "grass objects", and walls are "wall objects". Then check for collisions between the objects and the car, and react accordingly. The main issue with this is that it feels kind of clunky to me. The great thing with this approach is that I could easily add physics to everything, and thus for example have the walls move if someone hits them.

Does anyone have ideas? TIA.
0

Share this post


Link to post
Share on other sites
I was toying with this idea the other day, this is the idea i had

1/ Create a Map in Photoshop / paint or whatever, this is the artwork so don't worry about collisions when making this.

2/ Create another Texture, same size etc. which is colored Green/Red (Collision Map). This map is used to detect collisions, every time you update, grab a Rectangle of pixels from this Map (where the players car is) and check for any Non-green pixels.

To do Grass / Road / Wall you could use:

Green: Road
Yellow: Grass (car move speed *0.7 or whatever)
Red: Wall

I'm not sure how good this solution is in-terms of lag or efficiency. I used a technique similar when i did a 2D top-down shooter a while back, worked well, no lag.

What are you using C++, XNA java?


[EDIT] Found this, it is in java but basically describes what im talking about: [url="http://www.java-gaming.org/index.php?topic=23700.0"]Java Collision Maps[/url] Edited by Andy474
1

Share this post


Link to post
Share on other sites
I'm doing this in XNA. What you're describing sounds very similar to what I've been doing, just streamlined a little bit. I'll go ahead with this, and refine it as needed. It's definitely a workable solution.
0

Share this post


Link to post
Share on other sites
Here's an XNA tutorial containing what Andy474 suggested, if you think it might help.

[url="http://www.xnadevelopment.com/tutorials/theroadnottaken/theroadnottaken.shtml"]Tutorial[/url]
1

Share this post


Link to post
Share on other sites
Hiya, i did a very similar thing in VB6 a few years back. What i did was create a 2 dimensional array like "map(800,600)" then when the screen loads i get the pixel colour of each pixel and load it into the array following a quick case statement, i would use a slightly off black colour as collisional walls so if th pixel is off black the number "10" would be loaded into the array at that pixels coords, grass could be entered in as "5", tarmac as "0" and the actual players position would be entered as "1" so when a player moves you check hisnext coords on the map array - empty space would be "1+0" (allow to run normal), if you hit a wall "1+10 = 11" (collision detected, dont allow move) .




The benefit of doing it this way is that anything that could possibly cause you lag is done on loading, you can also easily change the map at runtime too without any slowdown. i know i didnt explain that very well and i think i made it sound alot more confusing than it actually is.. I would write you a little example in XNA but my laptop wont let me run it.. something about pixel shaders not being able to handle it.


Rob
1

Share this post


Link to post
Share on other sites
Thanks for all the help guys. I put together a version of the game yesterday, and it works beautifully.

So here's another thought... Is it possible to do bridges that go over the track while utilizing this kind of simple 2D geometry? I thought about making multiple layers, and then somehow testing the player's physics against the layer that he's on at any moment, but that seems like a really bad idea, and I don't even quite know how to make it work. I know Slicks 'N Slide had bridges, and it looked very 2D to me, so obviously there is a way. Obviously it would be easy in 3D, but I don't know if it's worth the hassle to go 3D with a game like this.
0

Share this post


Link to post
Share on other sites
[quote name='drowsyn' timestamp='1308295523' post='4824375']
So here's another thought... Is it possible to do bridges that go over the track while utilizing this kind of simple 2D geometry?
[/quote]


hmm prehaps you just have to be clever with the artwork? no need to look at 3D i can think of 2 solutions (i dont know if they'll work)

1/ Just be clever with the artwork on both art and collision map

2/ Use layers have a black or White strip on the Collision map which change the layer when the player triggers over them?
[Or checkpoints?]

e.g. instead of having the whole track as one Image file, use multiple files for between checkpoints.

So between the start flag and first checkpoint is one texture, this will prevent the bridge "overlapping" so the player can cut corners
maybe just have the checkpoint maps as collision maps?
- hope that makes sense :)



1

Share this post


Link to post
Share on other sites
Well to do a bridge u just need to add a height variable to ur car. Starts at height 1 and when he passes a hidden marker it's height changes to 2. When the height is 2 the car can drive over the bridge and when height is 1 he can drive under it, u just need to make the Walls on the bridge collision detection based on the height of the car and also change the cars z-order so he appears under or above the bridge.
1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0