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

Questions about AI

7 posts in this topic

Hello

I am making a 2d adventure/rpg game right now, and I just got the world/room thing working. Now the player (a white brick) can walk around two rooms made of identical tiles (blue bricks), and collision seem to work fine.

Now it is time to add some npc that can also walk around, do things, etc. The game is made of several rooms, and each room has a linked list of game objects. The game objects however know nothing about the surrounding.

I thought of passing a pointer of the room to the object, but that sound's like it can get messy because of the circular dependency.

Then I thought I'd use a sensory object that is basically a rectangle and a list, and it would follow the npc object around. The world update function would then update each object normally, and add any objects touching the sensory rectangle to that list.

My questions:

1. What is a good way to give awareness to npc objects?

2. If I want to add path finding to the AI later, is the linked list a good way to store game objects? game objects include tiles, player, npc, and every game object has a position, velocity, collision rectangle.

3. (don't know what to ask yet)
2

Share this post


Link to post
Share on other sites
As Katie told, be no afraid of circular references.

In your example - sooner or later you want not only to detect collisions but plan actions (pathfinding, discovery etc.). To do such actions your NPC needs the whole room/level, not only parts that are touching.

As of your second question - single linked list is most probably not enough. You need at least one spatially organized container (2D or 3D array, octree, quadtree...) that allows you to make fast spatial lookups (check whether certain grid spot is free, check what is at neighboring slot...). In addition to that you may want to have additional containers - for example all dynamic objects (mobs) can be in linked list, so you can quickly iterate over them.
Having single object referenced from many containers is acceptable - you only have to have clear idea who owns it (i.e. who is responsible of creating/deleting it).
0

Share this post


Link to post
Share on other sites
[quote name='Katie' timestamp='1351413348' post='4994654']
"I thought of passing a pointer of the room to the object, but that sound's like it can get messy because of the circular dependency."

It's not a 'circular dependency', it's a circular reference. Pointers [i]can[/i] but do not [i]necessarily[/i] convey memory ownership.

It's fairly typical in these sorts of games that the objects know which room structure they belong to and the room has references to all the objects contained in it. The room comes with nice utility functions such as "iterate over all contents except object X" or "iterate over all contents except the ones in this list" or "iterate over all the contents whose ID exceeds N" so that an object can cause things to happen to other objects more easily. Also you're going to have finder methods; "Find me all the objects which are touching object A". "Iterate over all objects within R of X,Y".


A circular dependency would imply that you're expect the room to delete the objects in it when they're not needed (probably the case) and also that the objects are expecting to delete the room they're in for some reason (which would be nuts. Not least because many objects would delete the room several times).

The directed and necessarily acyclic graph of memory ownership is not the same as the possibly cyclical graph of object references.
[/quote]

Thanks, I'll try that then.

Also, by circular dependency I meant the need to #include "gameobj.h" in world.h, and #include "world.h" in gameobj.h to allow rooms contain game objects, and at the same time allow game objects to have a pointer to rooms.

But hey, I guess thats what include guards are for ;o

[quote name='Lauris Kaplinski' timestamp='1351415587' post='4994659']
As Katie told, be no afraid of circular references.

In your example - sooner or later you want not only to detect collisions but plan actions (pathfinding, discovery etc.). To do such actions your NPC needs the whole room/level, not only parts that are touching.

As of your second question - single linked list is most probably not enough. You need at least one spatially organized container (2D or 3D array, octree, quadtree...) that allows you to make fast spatial lookups (check whether certain grid spot is free, check what is at neighboring slot...). In addition to that you may want to have additional containers - for example all dynamic objects (mobs) can be in linked list, so you can quickly iterate over them.
Having single object referenced from many containers is acceptable - you only have to have clear idea who owns it (i.e. who is responsible of creating/deleting it).
[/quote]

Whew, thats a lot of containers. I'd love to use a 2D array, but my game objects can be in any position (they are not confined to a fixed block). That leaves me with a 2D array of linked lists of objects, or a quadtree of objects, or something else.
0

Share this post


Link to post
Share on other sites
[quote name='ultramailman' timestamp='1351453177' post='4994820']
But hey, I guess thats what include guards are for ;o
[/quote]

You may also have to use [url="http://en.wikipedia.org/wiki/Forward_declaration"]forward declarations[/url]. Wikipedia has [url="http://en.wikipedia.org/wiki/Circular_dependency#Example_of_circular_dependencies_in_C.2B.2B"]an example of how to implement circular dependencies in C++[/url].
0

Share this post


Link to post
Share on other sites
[quote name='alvaro' timestamp='1351474173' post='4994898']
[quote name='ultramailman' timestamp='1351453177' post='4994820']
But hey, I guess thats what include guards are for ;o
[/quote]

You may also have to use [url="http://en.wikipedia.org/wiki/Forward_declaration"]forward declarations[/url]. Wikipedia has [url="http://en.wikipedia.org/wiki/Circular_dependency#Example_of_circular_dependencies_in_C.2B.2B"]an example of how to implement circular dependencies in C++[/url].
[/quote]

Thanks.

Now I find myself with two more options:
1. pass the objects the linked list instead.
2. pass nothing. The linked list I am using is actually embedded inside the object already, as was required by this particular linked list implementation.
0

Share this post


Link to post
Share on other sites
[quote name='ultramailman' timestamp='1351453177' post='4994820']
Whew, thats a lot of containers. I'd love to use a 2D array, but my game objects can be in any position (they are not confined to a fixed block). That leaves me with a 2D array of linked lists of objects, or a quadtree of objects, or something else.
[/quote]

Is it also true of your tiles? Because in most 2D dungeon-syled games level details (walls) are the most frequent colliders by an order of magnitude. Thus it may make sense to keep level details and movable objects in separate containers if it simplifies collision testing.

Otherwise either quadtree or array of lists seem reasonable. The latter is probably easier to implement. Just make your container interface abstract enough so you can change implementation details later if you find that your initial implementation is not flexible/fast enough.
0

Share this post


Link to post
Share on other sites
[quote name='Lauris Kaplinski' timestamp='1351507706' post='4995008']

Is it also true of your tiles? Because in most 2D dungeon-syled games level details (walls) are the most frequent colliders by an order of magnitude. Thus it may make sense to keep level details and movable objects in separate containers if it simplifies collision testing.
[/quote]

The game right now makes no distinction between tiles and game objects. Tiles are merely game objects whose "movable" flag is set to 0. I did however added two more linked list, one for the movable objects and the other for unmovable objects, like you suggested. I am not seeing any improvements because I only have around 60 objects in one room right now, but I am sure it will be helpful as I add more movable objects.

[quote name='Lauris Kaplinski' timestamp='1351507706' post='4995008']
Otherwise either quadtree or array of lists seem reasonable. The latter is probably easier to implement. Just make your container interface abstract enough so you can change implementation details later if you find that your initial implementation is not flexible/fast enough.
[/quote]

I think I will go with the quadtree, it feels like even if it is harder to implement, it will be more useful in the future. And I think it will be abstract enough, like using functions to read and modify it, using convenience macros to iterate through it, etc.
0

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