public class SpaceSmasherFunctionalAPI
extends SpaceSmasher.SpaceSmasher
| Modifier and Type | Field and Description |
|---|---|
static int[] |
keyEventMap
Used in the wrapper API function isKeyboardButtonDown, this array maps a shorter abbreviation like RIGHT to the virtual key event KeyEvent.VK_RIGHT
|
| Constructor and Description |
|---|
SpaceSmasherFunctionalAPI() |
| Modifier and Type | Method and Description |
|---|---|
protected void |
addToBallSetAndSpawn(SpaceSmasher.Ball ball)
Use this to add the ball provided to the ballSet and spawn it near the "default" paddle.
|
protected void |
addToBallSetAndSpawn(SpaceSmasher.Ball ball,
int whichPaddle)
Use this to add the ball provided to the ballSet and spawn it near the specified paddle.
|
protected boolean |
areAllBlocksRemoved()
This method is responsible for determining if all blocks have been removed and we've
met our winning condition for the game
|
protected void |
ballAndBlockCollisionCheck()
Use this to check if the "default" ball is colliding with any block in the blockSet.
|
protected void |
ballAndWallCollisionCheck()
Use this method to process collisions between the ball (or balls) and the walls.
|
protected void |
ballChecks()
Top-Level API Method - calls other methods.
|
protected boolean |
ballCollidedWithBlock()
Use this to determine if the "default" ball is colliding with any block in the blockSet.
|
protected boolean |
ballCollidedWithBlock(int whichBall)
Use this method to determine if a specific ball is colliding with any block in the blockSet.
|
boolean |
ballCollidedWithPaddle()
Use this method to determine if the "default" ball is colliding with the "default" paddle, both at index 0.
|
boolean |
ballCollidedWithPaddle(int whichBall,
int whichPaddle)
Use this method to determine if a specific ball (from the ballSet) is colliding with a specific
paddle (from the paddleSet).
|
SpaceSmasher_FunctionalAPI.PaddleAndBallStatesEnum |
ballGetState()
This gives you the state of the "default" or first ball at index 0.
|
SpaceSmasher_FunctionalAPI.PaddleAndBallStatesEnum |
ballGetState(int whichBall)
This gives you the state of one of many balls in the ballSet
|
boolean |
ballGetVisibility()
Use this method to get the "default" ball's visibility status
|
boolean |
ballGetVisibility(int whichBall)
Use this to get the specified ball's visibility status out of the ballSet.
|
void |
ballPlayBounceSound()
Use this method to play a bounce sound relative to the ball
|
void |
ballReflectOffBottomWall()
Use this to flip the sign of the y_increment and reverse direction in the y.
|
void |
ballReflectOffBottomWall(int whichBall)
Use this to flip the sign of the y_increment and reverse direction in the y.
|
void |
ballReflectOffLeftWall()
Use this to flip the sign of the x_increment and reverse direction in the x.
|
void |
ballReflectOffLeftWall(int whichBall)
Use this to specify which ball amongst many to reflect.
|
void |
ballReflectOffPaddle()
Use this method to reflect the "default" ball off of the "default" paddle.
|
void |
ballReflectOffPaddle(int whichBall,
int whichPaddle)
Use this method to reflect the specified ball off of the specified paddle.
|
void |
ballReflectOffRightWall()
Use this to flip the sign of the x_increment and reverse direction in the x.
|
void |
ballReflectOffRightWall(int whichBall)
Use this to specify which ball amongst many to reflect.
|
void |
ballReflectOffTopWall()
Use this to flip the sign of the y_increment and reverse direction in the y.
|
void |
ballReflectOffTopWall(int whichBall)
Use this to flip the sign of the y_increment and reverse direction in the y.
|
void |
ballSetState(SpaceSmasher_FunctionalAPI.PaddleAndBallStatesEnum state)
Use this in conjunction with power-ups to set the state of the ball
|
void |
ballSetState(SpaceSmasher_FunctionalAPI.PaddleAndBallStatesEnum state,
int whichBall)
Use this to specify which ball in the ballSet that you want to change state.
|
protected void |
ballSetToInvisible()
Use this to set the ball to invisible
|
protected void |
ballSetToInvisible(int whichBall)
Use this to pick one ball from the ballSet to set to invisible
|
void |
ballSpawnNearPaddle()
Use this method to spawn the "default" ball near the "default" paddle.
|
void |
ballSpawnNearPaddle(int whichBall,
int whichPaddle)
Use this method to spawn the specified ball near the specified paddle.
|
void |
changePaddleImageCheck()
Use this to check for the user pressing "P", which should then change the image associated with the
"default" paddle.
|
protected void |
collisionChecks()
Top-Level API method which invokes other methods checks, indicated here:
(1) paddle and ball collision checks
(2) ball and block collision checks
(3) ball and wall collision checks
|
void |
consoleReportOnScores()
This method could be overridden to add extra features not covered in the TODOs,
offering console support in the lab, which can be used to report scores, test min/max functions
or even just debug output.
|
protected SpaceSmasher.Ball |
createNewBall()
Use this method to create a new Ball that can be added to the ballSet and spawned with another method.
|
protected Engine.World.BoundCollidedStatus |
getBallAndWallCollisionStatus()
Use this to determine the collision status of the "default" ball in the ballSet at index 0.
|
protected Engine.World.BoundCollidedStatus |
getBallAndWallCollisionStatus(int whichBall)
Use this to determine the collision status of a specific ball from the ballSet
|
protected SpaceSmasher_FunctionalAPI.WallsEnum |
getCollidedWall()
Use this to determine the wall (if any) that the "default" ball collided with.
|
protected SpaceSmasher_FunctionalAPI.WallsEnum |
getCollidedWall(int whichBall)
Use this to determine the wall (if any) that a specific ball collided with.
|
protected float |
getMouseXCoordinate()
Use this to obtain the x coordinate of the mouse that is on screen.
|
protected float |
getMouseYCoordinate()
Use this to obtain the y coordinate of the mouse that is on screen.
|
protected void |
handleBlockBallCollision()
API utility method
Used to process all block collisions with the "default" ball in the ballSet
|
protected void |
handleBlockBallCollision(int whichBall,
int whichPaddle)
API utility method
Used to process all block and ball collisions for the specified ball and paddle
The paddle is passed as input here so we can change its state state if a
special block was destroyed, for example.
|
protected void |
initialize()
Top-Level API Method - calls other methods.
|
void |
initializeBallSet()
This method could be overridden to add extra features not covered in the TODOs
such as adding in multi-ball at the start of some levels
|
void |
initializeBlockSet()
This method could be overridden to add extra features not covered in the TODOs
such as building customized levels for the user to progress through
|
void |
initializeLifeSet()
This method could be overridden to add extra features not covered in the TODOs,
such as increasing the number of lives (up, up, down, down, left, right...)
|
void |
initializePaddleSet()
This method could be overridden to add extra features not covered in the TODOs
such as making a 2-paddle, 2-player version of this game.
|
boolean |
isKeyboardButtonDown(SpaceSmasher_FunctionalAPI.KeysEnum key)
API utility method
Use this boolean function to determine if a key is being pressed.
|
protected boolean |
isMouseButtonDown(SpaceSmasher_FunctionalAPI.MouseClicksEnum button)
API utility method
|
protected boolean |
isMouseOnScreen()
Use this to determine if the mouse is available (on screen) for use.
|
protected void |
loseALife()
Use this method to subtract exactly one life from the set of lives.
|
protected void |
lostGameCheck()
Use this method to invoke gameLost() if the game is truly over (no remaining lives?)
|
protected int |
max(int a,
int b)
To be overridden via TODOS
|
int |
max(int a,
int b,
int c)
This max method is similar to Math.max() but takes three inputs
(to be overridden via TODOS)
|
protected void |
mousePaddleMovementCheck()
This method is used to determine if the mouse is available for use (on screen), and if so,
maps the paddle position to where the mouse X cursor is.
|
protected void |
mouseSpawnBallCheck()
Use this method checks for mouse or keyboard input and spawns a single
ball accordingly.
|
protected void |
multiBallCheck()
Multi-ball check (to be overridden by TODOs)
If the user is pressing specific keys, then extra balls can be spawned in this method.
|
void |
paddleAndBallStateSynchronization()
This method is important when considering paddle power-ups in order to synchronize
the state of the ball based on the current state of the paddle
(This method is to be overridden via TODOS)
|
void |
paddleBallCollisionCheck()
Use this method to determine if the paddle is currently colliding with a ball in the ballSet
|
protected void |
paddleChecks()
Top-Level API Method - calls other methods
This method could be overridden to add extra features not covered in the TODOs
specific to any check involving a paddle, such as movement via keyboard or mouse,
changing the image associated with a paddle, or synchronizing the state of the paddle and ball
|
SpaceSmasher_FunctionalAPI.PaddleAndBallStatesEnum |
paddleGetState()
Get the state of the "default" (or player 1) paddle, stored at index 0.
|
SpaceSmasher_FunctionalAPI.PaddleAndBallStatesEnum |
paddleGetState(int whichPaddle)
This gives you the state of one of many paddles in the paddleSet
|
void |
paddleMoveLeft()
API utility method
Use this method to move the "default" paddle left, typically in response to some user input.
|
void |
paddleMoveLeft(int whichPaddle)
API utility method
Use this method to move the specified paddle left, typically in response to some user input.
|
void |
paddleMovementCheck()
Use this method to check for user input and then to move the paddle(s) accordingly
You could add to this method so that two people can play on one computer, using
the WASD and arrow keys, for example.
|
void |
paddleMoveRight()
API utility method
Use this method to move the "default" paddle right, typically in response to some user input.
|
void |
paddleMoveRight(int whichPaddle)
API utility method
Use this method to move the specified paddle right, typically in response to some user input.
|
protected void |
paddleSetCenterX(float x)
Use this to set the x-position of the paddle.
|
protected void |
paddleSetCenterX(float x,
int whichPaddle)
Use this to set the x coordinate of a specific paddle in the paddle set
|
void |
paddleSetImage(java.lang.String fileName)
Use this to change the image associated with the "default" paddle, for use with
paddle power-ups, etc.
|
void |
paddleSetImage(java.lang.String fileName,
int whichPaddle)
Use this to change the image associated with a specified paddle, for use with
paddle power-ups, etc.
|
SpaceSmasher_FunctionalAPI.PaddleAndBallStatesEnum |
paddleStateTranslate(SpaceSmasher.Paddle.PaddleState input)
API utility method - functional wrapper (not to be overridden)
|
void |
spawnBallCheck()
Use this method to determine if keys are being pressed in order to spawn a new ball and add
it to the ballSet.
|
SpaceSmasher.Ball.BallType |
toBallState(SpaceSmasher_FunctionalAPI.PaddleAndBallStatesEnum input)
API utility method - functional wrapper to hide enclosing enums and match states transparently
(not to be overridden)
|
protected SpaceSmasher_FunctionalAPI.WallsEnum |
toWallsEnum(Engine.World.BoundCollidedStatus input)
API utility method - functional wrapper (not to be overridden)
|
protected void |
update()
Top-Level API Method - calls other methods
This method could be overridden to add extra features not covered in the TODOs
specific to winning the game, paddle checks and ball checks
|
void |
wonGameCheck()
Use this method to determine if the level has been cleared and the game is won.
|
ballSwitchCollision, clean, decreaseScore, gameLost, gameWin, goToStartScreen, increaseScore, initializeWorld, newGame, preloadResources, setAllowDebug, setDebugMode, setDebugMouseControl, setLevel, SetShowFlashScreen, updateWorldclear, getBackgroundImage, getInitHeight, getInitWidth, initConfig, setBackgroundImagepublic static final int[] keyEventMap
protected void initialize()
initialize in class SpaceSmasher.SpaceSmasherpublic void initializeLifeSet()
public void initializeBlockSet()
public void initializeBallSet()
public void initializePaddleSet()
public void consoleReportOnScores()
protected boolean areAllBlocksRemoved()
protected void update()
update in class SpaceSmasher.SpaceSmasherprotected void paddleChecks()
public void paddleAndBallStateSynchronization()
protected void ballChecks()
public int max(int a,
int b,
int c)
a - - the first of three inputsb - - the second of three inputsc - - the third of three inputsprotected void multiBallCheck()
protected void addToBallSetAndSpawn(SpaceSmasher.Ball ball)
ball - - the ball to add to the ballSet and also spawn on screenprotected void addToBallSetAndSpawn(SpaceSmasher.Ball ball,
int whichPaddle)
ball - - the ball to add to the ballSet and also spawn on screenwhichPaddle - - the integer index specifying which paddle inside of the paddleSet should be usedprotected SpaceSmasher.Ball createNewBall()
protected void collisionChecks()
protected void ballAndBlockCollisionCheck()
protected boolean ballCollidedWithBlock()
protected boolean ballCollidedWithBlock(int whichBall)
whichBall - - an integer index to specify which ball out of all balls in the ballSetprotected void mouseSpawnBallCheck()
protected boolean isMouseButtonDown(SpaceSmasher_FunctionalAPI.MouseClicksEnum button)
button - - the mouse button in questionprotected int max(int a,
int b)
a - - one of two integer valuesb - - the second of two integer valuespublic void ballReflectOffTopWall()
public void ballReflectOffTopWall(int whichBall)
whichBall - - the index used to select the ball to use out of the ballSetpublic void ballReflectOffLeftWall()
public void ballReflectOffLeftWall(int whichBall)
whichBall - - the index used to select the ball to use out of the ballSet .public void ballReflectOffRightWall()
public void ballReflectOffRightWall(int whichBall)
whichBall - - the index used to select the ball to use out of the ballSetpublic void ballReflectOffBottomWall()
public void ballReflectOffBottomWall(int whichBall)
whichBall - - the index used to select the ball to use out of the ballSetprotected void ballSetToInvisible()
protected void ballSetToInvisible(int whichBall)
whichBall - - the index used to select the ball to use out of the ballSetpublic void ballSetState(SpaceSmasher_FunctionalAPI.PaddleAndBallStatesEnum state)
state - - the state you want the ball to be set topublic void ballSetState(SpaceSmasher_FunctionalAPI.PaddleAndBallStatesEnum state,
int whichBall)
state - - the state you want the ball to be set towhichBall - - the index used to select the ball to use out of the ballSetpublic SpaceSmasher_FunctionalAPI.PaddleAndBallStatesEnum ballGetState()
public SpaceSmasher_FunctionalAPI.PaddleAndBallStatesEnum ballGetState(int whichBall)
whichBall - - the index used to select the ball to use out of the ballSetpublic SpaceSmasher_FunctionalAPI.PaddleAndBallStatesEnum paddleGetState()
public SpaceSmasher_FunctionalAPI.PaddleAndBallStatesEnum paddleGetState(int whichPaddle)
whichPaddle - - the index used to select the paddle to use out of the paddleSetpublic SpaceSmasher.Ball.BallType toBallState(SpaceSmasher_FunctionalAPI.PaddleAndBallStatesEnum input)
input - - the state for use with the mid-level SpaceSmasher CS1 Functional API wrapperpublic SpaceSmasher_FunctionalAPI.PaddleAndBallStatesEnum paddleStateTranslate(SpaceSmasher.Paddle.PaddleState input)
input - - the state for use with the top-level SpaceSmasher APIprotected Engine.World.BoundCollidedStatus getBallAndWallCollisionStatus(int whichBall)
whichBall - - the index used to select the ball to use out of the ballSetprotected Engine.World.BoundCollidedStatus getBallAndWallCollisionStatus()
protected SpaceSmasher_FunctionalAPI.WallsEnum getCollidedWall()
protected SpaceSmasher_FunctionalAPI.WallsEnum getCollidedWall(int whichBall)
whichBall - - the index used to select the ball to use out of the ballSetprotected SpaceSmasher_FunctionalAPI.WallsEnum toWallsEnum(Engine.World.BoundCollidedStatus input)
input - - the status for use with the top-level SpaceSmasher APIprotected void ballAndWallCollisionCheck()
protected void loseALife()
protected void lostGameCheck()
protected void mousePaddleMovementCheck()
protected boolean isMouseOnScreen()
protected float getMouseXCoordinate()
protected float getMouseYCoordinate()
protected void paddleSetCenterX(float x)
x - - the x value that will be assigned to the first paddle in the paddleSetprotected void paddleSetCenterX(float x,
int whichPaddle)
x - - the x value that will be assigned to the first paddle in the paddleSetwhichPaddle - - the index used to select the paddle to use out of the paddleSetpublic void wonGameCheck()
public void paddleBallCollisionCheck()
public boolean ballCollidedWithPaddle()
public boolean ballCollidedWithPaddle(int whichBall,
int whichPaddle)
whichBall - - an index to select the ball to use out of the ballSetwhichPaddle - - an index to select the paddle to use out of the paddleSetpublic void ballReflectOffPaddle()
public void ballReflectOffPaddle(int whichBall,
int whichPaddle)
whichBall - - an index to select the ball to use out of the ballSetwhichPaddle - - an index to select the paddle to use out of the paddleSetpublic void ballPlayBounceSound()
public boolean ballGetVisibility()
public boolean ballGetVisibility(int whichBall)
whichBall - - the index used to select the ball to use out of the ballSetpublic void ballSpawnNearPaddle(int whichBall,
int whichPaddle)
whichBall - - an index to select the ball to use out of the ballSetwhichPaddle - - an index to select the paddle to use out of the paddleSetpublic void ballSpawnNearPaddle()
public void spawnBallCheck()
public void changePaddleImageCheck()
public void paddleSetImage(java.lang.String fileName)
fileName - - the name of the image to set the paddle to, prefixed with "paddles/", as in "paddles/P2.png"public void paddleSetImage(java.lang.String fileName,
int whichPaddle)
fileName - - the name of the image to set the paddle to, prefixed with "paddles/", as in "paddles/P2.png"whichPaddle - - the index of the paddle to select out of the paddleSetpublic void paddleMovementCheck()
public boolean isKeyboardButtonDown(SpaceSmasher_FunctionalAPI.KeysEnum key)
key - - the key we're investigatingpublic void paddleMoveLeft()
public void paddleMoveLeft(int whichPaddle)
whichPaddle - - the index used to select the paddle to use out of the paddleSetpublic void paddleMoveRight()
public void paddleMoveRight(int whichPaddle)
whichPaddle - - the index used to select the paddle to use out of the paddleSetprotected void handleBlockBallCollision()
protected void handleBlockBallCollision(int whichBall,
int whichPaddle)
whichBall - - an index to select the ball to use out of the ballSetwhichPaddle - - an index to select the paddle to use out of the paddleSet