|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
logic.GameEngine
public class GameEngine
| Nested Class Summary | |
|---|---|
private class |
GameEngine.KeyInputHandler
This class manages our key input processes. |
| Nested classes/interfaces inherited from class javax.swing.JPanel |
|---|
javax.swing.JPanel.AccessibleJPanel |
| Nested classes/interfaces inherited from class javax.swing.JComponent |
|---|
javax.swing.JComponent.AccessibleJComponent |
| Nested classes/interfaces inherited from class java.awt.Container |
|---|
java.awt.Container.AccessibleAWTContainer |
| Nested classes/interfaces inherited from class java.awt.Component |
|---|
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy |
| Field Summary | |
|---|---|
private Sprite |
background
Our game screen background. |
private int |
balloonCount
This integer holds the number of the valus on the screen to determine if if the level was cleared or not. |
private static java.lang.String |
balloonPath
|
private javax.swing.JPanel |
cardPanel
|
private static boolean |
debug
This boolean is for testing the GameEngine. |
private java.util.ArrayList |
entities
This arraylist holds all the entities on the screen to check collisions and make drawing works easier, withouth checking too many types. |
private boolean |
gameRunning
True if the game is currently "running", i.e. the game loop is looping |
private boolean |
isMainMenu
This variable is for determining if the game is on main menu Because game will be paused and it will be prevented from rendering again and again. |
private java.awt.CardLayout |
layout
We need an instance of the layout when we lost our focus on the game screen |
private int |
level
This integer holds the level number. |
private MainPanel |
mainPanel
|
private java.lang.String |
message
The message to display which waiting for a key press |
private java.lang.String |
message2
The message to display which waiting for a key press |
private boolean |
multiplayer
This boolean let us know if the game is initialized as multiplayer. |
private static java.lang.String |
obstaclePath
|
private boolean |
pause
True if the game is currently "paused" |
private Player |
playerOne
This is one of the mosp important game objects: Player One. |
private static java.lang.String |
playerPath
And finally to prevent to write paths for images every time we declare them here to make the future changes and coding below easier. |
private static java.lang.String |
playerPath2
|
private Player |
playerTwo
Player Two is created on only multiplayer games. |
private java.util.ArrayList |
removeList
This arraylist holds the objects to be removed at the end of each game loop |
private int |
rounded
For the widh of the rounded rectangle to be drawn before the screen text |
private SaveManager |
save
Our Save manager |
private HighScoreManager |
score
Our HighScore manager |
private ScreenManager |
sm
Our Screen manager. |
private SoundManager |
sound
Our Sound manager |
private boolean |
timeStop
|
private long |
timeStopTime
|
private boolean |
waitingForKeyPressed
On rare occasions, our game will stop for user to press any key on keyboard to continue to prevent any unexpected occurrences. |
| Fields inherited from class javax.swing.JComponent |
|---|
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW |
| Fields inherited from class java.awt.Component |
|---|
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
| Fields inherited from interface java.awt.image.ImageObserver |
|---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
| Constructor Summary | |
|---|---|
GameEngine(ScreenManager sm,
SaveManager save,
SoundManager sound,
HighScoreManager score,
javax.swing.JPanel cardPanel,
java.awt.CardLayout layout,
MainPanel mainPanel,
boolean multiplayer,
int level)
Here our constructor, GameEngine is being initialized. |
|
| Method Summary | |
|---|---|
void |
addBalloon()
Since one level's state depends on number of balloons every time we add a new balloon, we need to hold the exact number of balloons in the list. |
void |
addEntity(GameEntity entity)
In this method we add new entity (like bonus or sting) to our GameEntity list. |
void |
checkCollisions()
This method doesn't actually check collisions, but instead calls entities to check their own collisions. |
void |
debug()
|
void |
deleteBalloon()
Same thing as addballoon method applies here but in reverse order. |
void |
draw(java.awt.Graphics2D g)
It's pretty much obvious, this method draws every object in the list. |
void |
initialize(int level,
boolean multiplayer)
This method initializes our game for every level. |
void |
mainMenu(boolean isMainMenu)
This method switches between main menu and our game. |
void |
mainMenuDeath()
|
void |
moveEntities(long delta)
This method moves all the entities in the list. |
void |
notifyDeath()
This method decides if the game is over or not. |
void |
notifyLevelEnd()
When a level finished we need a player input to begin the new level. |
void |
pause(boolean pause)
This method pauses and unpauses the game. |
void |
removeEntity(GameEntity entity)
This method removes a certain entity from the list. |
void |
setTimeStop(boolean timeStop)
This method manages the Freezer bonus as all entities on the screen except player is to be frozen. |
void |
startGame()
This method creates a new thread for game to start. |
| Methods inherited from class javax.swing.JPanel |
|---|
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI |
| Methods inherited from class javax.swing.JComponent |
|---|
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update |
| Methods inherited from class java.awt.Container |
|---|
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree |
| Methods inherited from class java.awt.Component |
|---|
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
private static final boolean debug
private ScreenManager sm
private SoundManager sound
private HighScoreManager score
private SaveManager save
private java.awt.CardLayout layout
private javax.swing.JPanel cardPanel
private MainPanel mainPanel
private boolean gameRunning
private boolean pause
private java.lang.String message
private java.lang.String message2
private int level
private boolean multiplayer
private boolean waitingForKeyPressed
private boolean isMainMenu
private int rounded
private int balloonCount
private boolean timeStop
private long timeStopTime
private java.util.ArrayList entities
private java.util.ArrayList removeList
private Player playerOne
private Player playerTwo
private Sprite background
private static final java.lang.String playerPath
private static final java.lang.String playerPath2
private static final java.lang.String balloonPath
private static final java.lang.String obstaclePath
| Constructor Detail |
|---|
public GameEngine(ScreenManager sm,
SaveManager save,
SoundManager sound,
HighScoreManager score,
javax.swing.JPanel cardPanel,
java.awt.CardLayout layout,
MainPanel mainPanel,
boolean multiplayer,
int level)
sm - ScreenManager objectcardPanel - cardPanel to switch between menu and gamelayout - layout to choose between menu and gamemultiplayer - to set the game to be initialized to be multiplayer or notmainPanel - to set menu options like continue button| Method Detail |
|---|
public void initialize(int level,
boolean multiplayer)
level - This parameter helps us to initialize a certain level.multiplayer - This parameter helps us to initialize second character if our game is multiplayerpublic void addEntity(GameEntity entity)
entity - is the new entity to be added.public void removeEntity(GameEntity entity)
entity - public void notifyDeath()
Player class so that
player object decides game's state.
public void notifyLevelEnd()
public void draw(java.awt.Graphics2D g)
g - This parameter is coming from ScreenManager as it is
Double Buffered and produces a Graphics2D object.public void moveEntities(long delta)
delta - This parameter is send to entities to determine how much they will move.public void checkCollisions()
public void startGame()
Runnable and
when the level is chosen from game panel, it initializes
and starts the game.
public void pause(boolean pause)
pause - Is game paused?public void mainMenu(boolean isMainMenu)
isMainMenu - are we in main menu or game.public void mainMenuDeath()
public void debug()
public void addBalloon()
public void deleteBalloon()
public void setTimeStop(boolean timeStop)
timeStop - if bonus is taken.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||