Monday, March 26, 2012

3D Minesweeper Game

As an interesting amalgamation of game design and algorithm development, I worked on a 3D minesweeper game in the past week.  It turned out pretty well, I think.  It has awesome explosions (when you click on a mine) and cute little red and white cubes with numbers on them.  You can also move the camera by using the W, A, S, and D keys as well as rotate and zoom in and out by using Q, E, Z, and X keys. 

The code design is facilitated by the use of recursive methods, which help reduce processing time tremendously.  Mines are generated randomly in a two-dimensional array that represents the grid.  Because the cubes are represented in a three-dimensional way, handling the user clicks was interesting.  When the user clicks on any point in the world, we perform what is called a raycast.  Raycast creates a ray of predefined length from the user's point of view in the direction of the position of the mouse click.  If the ray hits any cube, then we consider that cube to have been clicked.

I've tested this program up to 60 by 60 grid and it has worked beautifully with little lag.  Enjoy the screenshots!

I'll gladly provide with the download if you ask.







No comments:

Post a Comment