Skip to content

Select_Weapons_Menu

Riemann edited this page Nov 20, 2013 · 9 revisions

ABOUT

The game is implementing a Slick2d StateBasedGame for this project, therefore this file extends the superclass StateBasedGame. This select weapons menu is a secondary menu that the user will be sent to before the game begins. The weapons will be selected individually and stored as their ammo for the game. After all weapons have been selected and distributed between the two players, The user will be able to press the "play game" button and will then be sent to the actual play state of the game.

init

the init method will run one time and will load things such as all of the background images which are located in the res folder.

enter

The enter method is used to make and fill an array for the weapons that we have, we do this by making each weapon a button so that we can display it on the screen so the user can select thew weapon of choice. For this, we send each weapon to the button.java class.

render

In the render method, this is where objects will be rendered to the screen. This means that all of the background images and buttons that the user will see will be rendered to the screen. This method includes for loops to get the buttons for each player as well as the unselected weapons. Their is also a few "if" statements to check whose turn it is to select a weapon since this is a two player game using a single computer, we have to track who's turn it is by alternating between selecting weapons(player one will select a weapon and then player two will select a weapon and so on...) as these weapons/buttons are selected, they will be re-rendered to their respected side of the screen.

update

The update method is ran most often so it is important that we monitor what goes into this method to keep the game from bogging down. With that being said, the update method will keep track of the input of the mouse so when a user selects a button on the screen, the update method will know where the mouse is on the screen when clicked to correspond that position to the correct button.

buttonpressed

This method will be called anytime a weapon button is selected and will be passed in the button with the coordinates and will determine which shot/button that button represents and will put it in the players array depending on who's turn it is to select the weapon.

gettanks

This will get the tanks and merge the weapons to the tanks to be used for gameplay.

previousState

This is an static integer that holds the value of the previous state. This should be set when exiting a state so the next state can act accordingly.

Screenshot

See: Source

page created by: Ben Riemann with help from Adam Lutz

Clone this wiki locally