Bubble Hero Engine
This is the game engine for the iOS game Bubble Hero, built with Swift 4 and latest API from iOS 11. It was built by Yunpeng in 2018.
This engine is published as a Cocoapod. Add the following line to your Podfile
for usage:
pod 'GameEngine', :git => 'git@github.com:yunpengn/BubbleHeroEngine.git', :branch => 'master'
Design & Class Diagram
(Credit to ProcessOn for providing us with an excellent online tool to draw UML diagram)
This Bubble Hero Engine
application follows the MVC (model, view, controller) architecture. Each component is explained as follows:
- Model: The model provides a reliable backend store for all the data in the game. Similar to Problem Set 3, a
Level
is composed of manyBubble
s. By default, eachLevel
has 12 rows, 11/12 columns ofFilledBubble
s. However, note that theLevel
class this type supports more functionalities compared to Problem Set 3.Stack
is used to support some of these functionalities internally. In Problem Set 5, we may create subclasses forFilledBubble
since there are special bubbles. EachFilledBubble
has aBubbleType
. For example,FilledBubble
s of different colors are of differentBubbleType
s. Each object controlled by thePhysicsEngine
must be aGameObject
. AGameObject
represents a simplified idealized physical object that obeys a certain subset of physics laws. In this problem set, it is a 2D object with no mass or volumn. However, it has a fixed size and its shape is a perfect circle. If itsisRigidBody
attribute istrue
, then it becomes a rigid body. Collision may happen between two rigid bodies. AGameObject
can have speed and acceleration, both of which can be seen as a 2D vector. TheBubbleProvider
will continously generate randomBubbleType
, as a supplier for the bubble launcher. - Controller: The
BubbleArenaController
is the main controller for the game view. To supportbubbleArena
which is aUICollectionView
, this class will conform toUICollectionViewDataSource
,UICollectionViewDelegate
andUICollectionViewDelegateFlowLayout
protocols. TheBubbleLauncherController
controls the related operations and user input about launching a bubble (using the bubble launcher at the middle bottom of the screen). After a bubble has been launched, theShootingBubbleController
will take over the control. It will work closely withPhysicsEngine
andGameObjectsController
to instruct the movement of shooted bubbles and detect collision. Whenver collision happens, thePhysicsEngine
will informShootingBubbleController
to handle the game-specific logic.GameObjectsController
acts as a bridge and mapping between theGameObject
s managed in the game engine andFilledBubble
s stored in the model. For information passing and notification of events happened, delegate pattern is applied to the three main controllers. They conform toBubbleArenaControllerDelegate
,BubbleLauncherControllerDelegate
andShootingBubbleControllerDelegate
protocols respectively. - View: The view in this problem set is pretty simple. It mainly consists of two parts, the
BubbleArena
and theBubbleLauncher
. TheBubbleArena
is aUICollectionView
, which is composed of manyBubbleCell
s, which conforms to theUICollectionViewCell
protocol. TheBubbleLauncher
is simply aUIImageVIew
, which shows the next bubble to be launched. Whenever the player shoots a bubble, it will be updated according to the supply fromBubbleProvider
.
(The idea of rigid body & collision is adapted from Unity3D game engine, although there are variations.)
Acknowledgements
We would like appreciate the wonderful resources provided by the following websites:
- Flat Icons [https://www.flaticon.com]
- Pexels [https://www.pexels.com]
- ProcessOn [https://www.processon.com/]
- Unity3D Game Engine [https://unity3d.com/]