Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

SPECIFIC GAME COMPONENTS


I created a SpaceShip class, an Asteroid class, an AsteroidHandler class, and a StateHandler class to monitor the different states of the game i.e. START, RUNNING.

SpaceShip

There is a begin method that when called, adds a forever action to the space ship that will rotate it around the origin that was set in it's constructor.

In it's act method, it checks whether screen has a touch event.

If it does it sets a timer to slowly slow down the space ship to make it look more realistic.

If the current speed is less than the fall back speed, the space ship sets a timer to do the opposite of the previous.

Additionally SpaceShip records the current score, every time it completes an orbit around earth. At finishing its rotation should be a multiple of 360.

Asteroid

Is added to stage via a parent - AsteroidHandler.

Requires for its constructor a place to start, and a place to finish. The place to start, and end have to be on the edge of screen, because asteroids travel from one end to the other end of the screen.Asteroid then takes these values, and sets a moveTo action with the respective values.

In its act method it tests whether it still has actions assigned to it. If not, then it removes itself from its parent - AsteroidHandler.

AsteroidHandler

Responsible for creating asteroids, and testing if there is collision between any of its children (asteroids), and the space ship.

There is a begin method that when called, creates a timer that runs forever adding asteroids every second.

Asteroids are added with a random number seed. The random number generates its start position, and is required to make the asteroid's end position more than or less than its start position respectively. This ensures that it will have a general diagonal direction, which will not create impossible scenarios with the space ships travel.

StateHandler

Hosts an enum with the game states: START, RUNNIG, PAUSE, GAMEOVER. (note PAUSE is not used)

Is responsible for setting state to RUNNING when user touches anywhere outside of the earth, or spaceship. If user touches one of those, they handle it and call the StateHanlder's startGame() method.

Aside for that responsibility, it is the central point to make state changes, meaning AsteroidHandler will set the current state held within StateHandler, when there is a collision.