Note: UML Diagrams can be found in the Stick-Hero
folder in both PNG and UML format. Maven has not been configured yet as it is subject to change.
Stick Hero is fun and intuitive game designed to show how JavaFX can be used to create a game using OOP 's principals as well as various Design Patterns and using good coding practices in general.
- First, on starting the game the user is greeted with a pleasant start screen with a play button.
- After pressing the play button you are greeted with a map section screen after which you can begin the game.
- In the game you spawn at a platform and the objective is to reach the next platform without falling into the gap in between them.
- When you are on a platform you can hold the mouse button to generate a stick whose length is proportional to the duration of the mouse hold.
- Whilst traversing the stick you can flip to collect cherries or avoid wither(which is equivalent to -1 cherries) on the bottom side of the stick however if you crash into a platform you die.
- Once you die and reach the death screen you are presented between two options.
- This allows you to either revive if you have more than 2 cherries else you can return to the home screen.
Note: Please do not spam click inputs and wait patiently for the game to respond(there might be some slow responsiveness due to different hardware configurations)
- The code begins with the
Game
class which has thepublic static void main(Strings[] args)
function which calls the tests created using the Junit and then the runs thelaunch(args)
to start the application. - Now the main menu's fxml file is loaded using the
FXMLLoader
which was created using the Scene Builder. - Using the controller class
SplashTestController
we present the user with a big blue play button. - On hitting the button the user is asked for a username which is used to store his high score so even if he closes the game and plays it again his high score is saved.
- After this the map selection screen's fxml is loaded and the
SwitchMaps
class assumes control. - The user can select the map and hit the start button to begin the game.
- Starting the gameplay passes the control over to the
MainGame
class which handles all the core functionality of the game. - The
MainGame
initially calls thecreateContent
function to generate aAnchorPane
which houses two randomly generated platforms as well as a randomly generated cherry/wither between them. It also places the player at the starting platform. - After this we use the
handlleMouseEvents
to create a stick which has a length proportional to the time you hold the mouse button. The creation of the stick and its growth animation is handled by thehandleMousePressed
and thehandleMouseReleased
functions, the former of which also rotates the stick and begins the animation of the player moving across the stick. - The
handleMouseReleased
also uses thecheckCherryColission
,checkPillarColision
and thecheckWitherCollision
to ensure that cherries and wither are successfully collected and the player dies if he hits the pillar upside-down. - The
contentCreate
also checks for mouse clicks during the transition to flip the player using the functionhandleMouseClick
. - Furthermore, the pause functionality is also implemented using the
anchorPane.setOnKeyTyped(this::handlePauseResume)
to pause anywhere where the user can give command. - The functions
loadScores
andsaveScores
use the serializablePlayer
class to save the high score of the player at evey new platform so that even if the game is abruptly closed the High Sore of the user is saved with his username. - In this endeavour if the player hits a pillar or dies of falling due to other reasons the user is directed to the
DeathScreen.fxml
via thegameOver
function, which presents the user with two optionsRevive
orHome
. - The Functionality of these buttons is handled by the
DeathScreen
class. - The home buttons functionality is handled by the
home
function which basically resets the game and trows the user to the main screen. - While, the revive functionality is handled by the
revive
function, which calls thegetCherryScore
to check if the user has enough cherries to revive or else throws an error message in a new window. - The
revive
function calls thesetCherryScore
to decrement the number of cherries by two. and then calls thecontinueGame
method which calls therevived
functions which restores the game state to before the player died. - If the user does not die then the
gameContinue
function is called which calls thecreateContent
function to generate the next scene and keeps going in an infinite loop which ends with the player dying.
- Flyweight : The
Player
class implements the Flyweight design pattern. It maintains aVector
ofPlayer
's which stores all the scores and names of thePlayer
's in it. When thegetPlayerScore
function ensures there are only unique objects with unique names in theVector
. It takes as input a name and returns aPlayer
object with that name which was either in the Vector already or if not present creates aPlayer
with that name and adds it to the vector and then returns it. - Strategy : We use the
movable
interface to implement two classesisMoving
andisStationary
which help us identify is the player is moving or not.
- Background Music : There is randomly selected music from a wide variety of songs, playing in the background while you play to add to the ambiance.
- Wither : There is another type of consumable in your path which you must avoid as eating it causes you to lose cherries.
- Map Selection : The player can pick through a wide variety of distinct and unique maps to enhance the gameplay.
- Special Sound Effects : Special events like dying, reviving, consuming cherries or wither produce special sound effects to add to the audiovisual experience of the player.
- Java Development Kit (JDK)
- JavaFX SDK
- JavaFX-Media-18.01
- Junit 4
-
Clone the repository:
git clone https://github.com/your-username/stick-hero-game.git
-
Open the project in IntelliJ IDEA Ultimate Edition.
-
Configure the project to use the JDK and JavaFX SDK.
-
Run the Game class to start the application.
-
Else you can press this button in the IntelliJ IDEA Software
Game
.
- Launch the application.
- Navigate through the splash screen.
- Click the "Play" button to play the game.
Note: Some functionality of this file might only work in the README.md file in IntelliJ IDEA Ultimate Edition Software.
- Group Number : 71
- Rohak Kansal - 2022412
- Swapnil Panigrahi - 2022522