Many Different (simple) AI and collision questions!!!

Started by
5 comments, last by Brackus 22 years, 11 months ago
Okay, I am an idiot, I have deemed myself so no arguments!!! I am trying to figure out how to have little creatures(dots) run around on a screen, and perform tasks, for instance: I have a maze, basically, blue and red squares, one for wall, one for floor, i cannot, for the life of me, find a way to set the setting so that the cpu searches for an available spot, then moves to it, if i could find that out I would implement my idea of maze solving, say we have a mouse, and instead of constantly turning left, it would add a value to each space it goes on, and searches for the lowest value space next to it, now in this maze there is no need for diagonal movement, but it wouldnt be bad for me to know!!! I dont know how to test each square, how to have values for squares, how to add values to square name variables. I am no idiot, i know how to program, but this concept is and has been for almost a year out of my reach!!! I wish to have at least 2 cpu controlled guys run around and shoot at each other, like the above, its 2D, so I can make it so they can go towards each other, then i would have them shoot a little pixel sized bullet, but how do I make the game continue while the bullet continues on, and if I know the circles middle (x,y) pos, and their size, how do i test for a hit. Also, how can they find their way around obstacles, intelligently, this is a little more complicated than the above. Then, i have said before, have little dots play football, cept no passes(im not that good, and actually need help, anyone???) cause trajectories and stuff would be hard. How could i implement some physics by having guys speed up to hit and block, then having different sized guys weighing more, and blocking/hitting better, in a 2D, 640x480 pixel setting???? I realize this is a lot, so a simple link, or idea for even one of the many things i asked about here in a post is great!!! I would ask more things, but my brain is fried, i will come across more problems, and ask them later!!! Dustin
Mess With the Best, go down like the rest, but please visit:http://members.tripod.com/nu_bgameprogramming/
Advertisement
Might I suggest you read some books on game programming. Most of the things you want to do are covered in books like "Game Programming Gems".

Good luck,

Tim
I have Game Programming Gems but it sounds like this guy needs something much more beginner level. I don''t know of any such books, someone recommend something for him

Ok part 1: how to find your way through the maze. First of all make sure you are using some sort of data structure to hold your tiles,they should not be individual variables. At the very least put your tiles in a two dimensional array and have them store their position in that array as ints. Your tiles should be objects or structs, if your programming language doesn''t have stuff like that switch to another language. Then so a search on pathing and study up on it. You won''t need A* (that is the name of an algorithm), just go with a simpler solution. Whatever you choose you''re going to need to know about list like stuctures so make sure you know how linked lists work.

2: how do you make the game continue on. Well, from that question it sounds like you aren''t using a game loop. You must have a loop that runs until the game ends. Something like this:

process input
update all game objects
draw a frame

since you update all your game objects between drawing each frame it looks like all the action is happening simultaneously.

Next collision detection: if both things are circles first calculate the distance between the centers of the circles, using the distance formula. Then add the two radii of the circles, if the sum is greater than the distance they are overlapping.

As for momentum and having guys knock each other out of the way, it is definently going to be hard so you might want to save that for the sequal. Momentum is mass time velocity so keep that in mind. You''ll want to read a physics book for the details on momentum transfer. You shouldn''t bother calculating it through acceleration though, I think that takes calculus. Just do something simple like transfer a set fraction of the energy.

Well good luck, I''m sorry I can''t recommend any books. Try going to the bookstore and looking for game programming books, they ought to have a few.
*** Well good luck, I''m sorry I can''t recommend any books. Try going to the bookstore and looking for game programming books, they ought to have a few. ***




That depends on where you live :p
Hmm, this is interesting. Now, perhaps I have your questions wrong, yet I will try to answer them. I make the following assumption: you''re using c++.

make the board first, here is an example. By the way, we assume we''re controlling the ''mouse'' you spoke of.

int boardWidth=100;
int boardHeight=100;
int board[boardWidth][boardHeight];

then initialize the board, for this situation we''ll use a random one.

for(int x=0; x{
for(int y=0; y {
//Give each space a random value from zero to ten
board[x][y]=(rand()%10);
}
}

Then you could do the following to test for the lowest value square touching a location with the following command. It returns a variable where var[0]=x and var[1]=y.

int* checkMove(int x, int y)
{
int lvX=x;
int lvY=y;
int lv=10;
if((x+1) {
lvX=(x+1);
lvY=y;
lv=board[lvX][lvY];
}
if((x-1)>(-1))
{
if(board[x-1][y] {
lvX=(x-1);
lvY=y;
lv=board[lvX][lvY];
}
}
if((y-1)>(-1))
{
if(board[x][y-1] {
lvY=(y-1);
lvX=x;
lv=board[lvX][lvY];
}
}
if((y+1)>boardHeight)
{
if(board[x][y+1] {
lvY=(y+1);
lvX=x;
lv=board[lvX][lvY];
}
}
int *ret={lvX, lvY};
return ret;
}

And there you have it. Of course, I have things to do. So I didn''t make it test diagonals. But either way, it finds the lowest value slot touching the location passed to the function. If there, for some reason, is nowhere for it to go, it returns the original location. Usage is shown below.

placeToMove=checkMove(playerX, playerY);


Alex Broadwin
A-Tronic Software & Design
-----
"if you fail in life, you were destined to fail. If you suceed in life, call me."
"The answer is out there."
Alex BroadwinA-Tronic Software & Design-----"if you fail in life, you were destined to fail. If you suceed in life, call me.""The answer is out there.""Please help, I'm using Windows!"
Oh yea, and I don''t visit this forum often. So if you have any questions, e-mail me at alexb@a-tronic.com

Alex Broadwin
A-Tronic Software & Design
-----
"if you fail in life, you were destined to fail. If you suceed in life, call me."
"The answer is out there."
Alex BroadwinA-Tronic Software & Design-----"if you fail in life, you were destined to fail. If you suceed in life, call me.""The answer is out there.""Please help, I'm using Windows!"
Arg!! Seems the joy of html tags has screwed up the board generation code. But I assume you know how to make a for loop. If not, e-mail me. I have to go now...

Alex Broadwin
A-Tronic Software & Design
-----
"if you fail in life, you were destined to fail. If you suceed in life, call me."
"The answer is out there."
Alex BroadwinA-Tronic Software & Design-----"if you fail in life, you were destined to fail. If you suceed in life, call me.""The answer is out there.""Please help, I'm using Windows!"

This topic is closed to new replies.

Advertisement