• 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
black_darkness

My idea for a 2d collision algorithm.

3 posts in this topic

Hello. Feedback appreciated.

So all my algorithm will need are

[u]2 integers[/u][list=1]
[*]currentx
[*]currenty
[/list]

[u]1 2d matrix of bools[/u][list=1]
[*]index[x][y]
[/list]
So for example I will create the matrix like this
Border is False
5x3 rectangle impassable in center

[CODE]
bool index[11][11] =
{
{false,false,false,false,false,false,false,false,false,false,false }, // row 0
{false,true,true,true,true,true,true,true,true,true,false }, // row 1
{false,true,true,true,true,true,true,true,true,true,false }, // row 2
{false,true,true,true,true,true,true,true,true,true,false }, // row 3
{false,true,true,false,false,false,false,false,true,true,false }, // row 4
{false,true,true,false,false,false,false,false,true,true,false }, // row 5
{false,true,true,false,false,false,false,false,true,true,false }, // row 6
{false,true,true,true,true,true,true,true,true,true,false }, // row 7
{false,true,true,true,true,true,true,true,true,true,false }, // row 8
{false,true,true,true,true,true,true,true,true,true,false }, // row 9
{false,false,false,false,false,false,false,false,false,false,false }, // row 0
};
[/CODE]

Here is a graph of what it will look like
X = boolean false;
O = boolean true;

[CODE]
XXXXXXXXXXX //row 0
XOOOOOOOOOX //row 1
XOOOOOOOOOX //row 2
XOOOOOOOOOX //row 3
XOOXXXXXOOX //row 4
XOOXXXXXOOX //row 5
XOOXXXXXOOX //row 6
XOOOOOOOOOX //row 7
XOOOOOOOOOX //row 8
XOOOOOOOOOX //row 9
XXXXXXXXXXX //row 10[/font]
[/CODE]

So now all we need is the initial position.
int curx = 1;
int cury = 1;

So 3 inital values are as follows[list]
[*]curx
[*]cury
[*]index
[/list]
Now here is my algorithm to test if square moving to is passable.

I will write my algorithm in C++ notation.
[CODE]
//assuming you are going up.
//translates well into all 4 directions.

if(index[cury-1][curx]==true) {
cury-=1;
}
else {
//collision sound
}

[/CODE]


So when I implement this I think I will implement it as a function. I may create a class for map so it will be easy to create a rectangular grid. Edited by black_darkness
0

Share this post


Link to post
Share on other sites
That'll work. For the sake of your sanity, if you plan on doing large maps, then it might be worth plugging in code so you can load in your index array from a .bmp or something. Failing that, at the very least you could create your map from a string, so you could use the XOOOOXXOOO style notation. Something like:

[source lang="cpp"]const char *pGameMap[] =
{
"XXXXXOOOOOXXXXX",
"XXXXOOOOOOOXXXX",
};[/source]

You could convert that into a bool array, or just do your tests directly on the string seeing as a char is no bigger than a bool. Edited by C0lumbo
1

Share this post


Link to post
Share on other sites
[quote name='C0lumbo' timestamp='1355639146' post='5011184']
That'll work. For the sake of your sanity, if you plan on doing large maps, then it might be worth plugging in code so you can load in your index array from a .bmp or something. Failing that, at the very least you could create your map from a string, so you could use the XOOOOXXOOO style notation. Something like:

[source lang="cpp"]const char *pGameMap[] =
{
"XXXXXOOOOOXXXXX",
"XXXXOOOOOOOXXXX",
};[/source]

You could convert that into a bool array, or just do your tests directly on the string seeing as a char is no bigger than a bool.
[/quote]

I still get confused by pointers.

Does the source code snippet create a constant of datatype char* and name it pGameMap[]? if so how can I assign a string to a char* type? That is overly complex for me to conceptualize without a little breakdown.
0

Share this post


Link to post
Share on other sites
[quote name='black_darkness' timestamp='1355640107' post='5011189']
I still get confused by pointers.

Does the source code snippet create a constant of datatype char* and name it pGameMap[]? if so how can I assign a string to a char* type? That is overly complex for me to conceptualize without a little breakdown.
[/quote]

It's a little complicated to explain exactly what that code is doing. Essentially, each line of "XXXOOOXXX" becomes a NULL terminated string and pGameMap is an array of pointers that point to those strings, I used [] instead of specifying a size of the array so that the compiler can infer the number of strings by the number of entries. C Strings are simply an array of char (8 bit numbers) where a value of 0 indicates the end.

In terms of you using it, your sample code would become:

[source lang="cpp"]//assuming you are going up.
//translates well into all 4 directions.

if(pGameMap[cury-1][curx]=='O') {
cury-=1;
}
else {
//collision sound
}
[/source]
Other things to watch out for are that you would not be allowed to modify pGameMap at runtime which might be an issue if you want a dynamic world (you could copy the data from pGameMap and modify that though). Also I'd recommend throwing a few asserts into your code to make sure all the strings are the same length and that there's a safe border of X around the edge of the map.
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