Question:

Java (Creation of a 2d Maze Game)

by  |  earlier

0 LIKES UnLike

Alright, i have a few questions i would like to confirm before creating a 2d maze game. This game is about 2 players trying to get to the end and collecting as many points as possible from items around the maze.

1) Should I create a String or Int 2d arrayList

2) Should I use paint(graphics g) or other ways of displayin the 2d maze in GUI

3) how do i add a character inside and show its in the maze

4) How do i make the character move?

5) And how do i ensure that the character will not walk through the walls?

Additional Information or Tips would be appreciated

 Tags:

   Report

1 ANSWERS


  1. 1) It doesn't matter.  I would probably use int[][]

    2) I would use paint(graphics g) but it's been a long time since I've done AWT stuff

    3) you should keep track of the character's x and y positions (ints).  Then in paint() you will 1: draw the maze and 2: draw the character according to its (x, y)

    4) Listen for keyboard or mouse inputs.  When you get them, increment or decrement character's x or y, and repaint()

    5) Don't worry about this at first, and get to the point where the game works except for this.  Now, simply use the character's x and y (transformed by some math, more on that below) as indices into the int[][] array.  If the value in the array indicates a wall, then don't increment/decrement the character's x or y, and maybe play a sound.

    As far as the math transform...say your screen is 600x600.  Maybe you want the array to be 600x600, in which case no need to transform.  But maybe you want the array to be 60x60 instead, so that you can make each cell in the array be represented by a 10x10 image showing a brick pattern or something.  Then you'd need to say something like:

    if (userPressedUpKey && array[charX/10][(charY+1)/10] != WALL) { charY++; repaint(); } else { /* make a beep sound */ }

    One last thing...if a character is going up, you want to stop him when his head hits a wall.  If he is going down, you want to stop him when his foot hits a wall.  So assuming your character is bigger than just a pixel or two, you may have to tweak the above collision-check code some.

Question Stats

Latest activity: earlier.
This question has 1 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.