Game Development Community

Maze Game example?

by Trent · in Torque Game Builder · 12/08/2006 (6:25 pm) · 11 replies

Is there a code example for a maze game lying around? I'm having so much trouble getting pixel perfect collisions in a simple square grid environment.

I am using a TileMap now, and for some reason, the same as when I was just using static sprites, the player is able to go into the walls.

I am using FULL detection mode and CLAMP collision response on both the player and the tile map. I'm using setLinearVelocity to move the player, and stop the player inside the onCollision of the player.

I've tried about 5 different movement mechanisms now and can't get any to work the way I want.

Any help or pointers would be appreciated.

#1
12/09/2006 (1:45 pm)
There aren't any that explicitly say how to create a maze game, but there is a nice tutorial that shows how to use collisions on a tile map with the Mini Platformer Tutorial. I used things I learned there to create an isometric-ish maze game.

Cheers!

--clint
#2
12/09/2006 (5:00 pm)
Thanks for the link.

I saw the extra bits to help, but after reading more of it it just seems like a pixel perfect maze game ala pacman is just impossible with TGB :(

I should say, after reading more and experimenting a lot, I just cannot get the results I need.
#3
12/09/2006 (9:50 pm)
Pacman moves on paths, not through collisions with walls. He is always on a path moving one way or the other. The only time he can stop is at the end of a path. The ends always happen to be right before a wall, but he never actually runs into a wall as far as the code is concerned.
#4
12/09/2006 (11:20 pm)
As Lance said, it would make a lot more sense for a Pcaman style game to implement its own system based on the tiles around Pacman. The physics system in TGB is more complicated than you need to make a tile-based game.
#5
12/10/2006 (1:58 pm)
I'm new to TGB, hadn't looked into paths yet.

Thanks, that gives me a whole new set of things to try!
#6
12/10/2006 (4:07 pm)
Oh wow... this is going to be tough
#7
12/12/2006 (9:33 am)
You'll be okay! Hey did you figure out how to get the collision to work with the tutorial? I'm not having any success...

Paths are one way, but I think you can avoid them... Have you tested out the fish demo? You could probably do something like that. You could have your pacman move at a constant speed and only use the arrow keys to set the direction... That way you could make bunches of crazy mazes without having to customize each of them.
#8
12/12/2006 (10:22 am)
Off the top of my head, without reaching for a computer science way of graphs and generating a path solution, here is how I'd do it:

1. tileset to build the maze. Each tile would give a visual indication of which directions would take you out of that tile.
2. when you click a direction while in a tile, it would check to see if you're on the proper axis to move that direction.
3. a - if you are on the proper axis then just set the direction to move that way.
b - if you aren't then do a moveTo to get to the center of that tile with a callback to move the proper direction when you reach the center.


I'm not sure how to handle running into walls with a tileset approach, since you'd want to stop in the center of the square. Maybe somehow check the direction you're going when you enter the tile and do a moveTo the center of it if you're going in a dead end direction.
#9
12/12/2006 (2:01 pm)
You'll be okay! Hey did you figure out how to get the collision to work with the tutorial? I'm not having any success...

Paths are one way, but I think you can avoid them... Have you tested out the fish demo? You could probably do something like that. You could have your pacman move at a constant speed and only use the arrow keys to set the direction... That way you could make bunches of crazy mazes without having to customize each of them.
#10
12/20/2006 (1:29 am)
@Lance

That's a good suggestion, it solves a couple of problems I was having with the other methods. Thanks!

@amaranthia

I eventually gave up and moved on to other projects. I like Lance's solution though, so if I revist it, that's the approach I will take.
#11
01/09/2007 (2:30 pm)
There is a maze in the Adventure Kit demo. I haven't looked at it in depth, but they are using collisions on sprites instead of on tilesets. In other words the walls are sprites (each with a collision box) and not tiles You could still use tilesets, but you'd need several transparent collision boxes placed on top, as those boxes need to be convex. It seems there was a note in the docs that said that approach yeilded better performance anyway too.