You are on page 1of 24

Light the Way

Technical Document

Light The Way - Technical Document

Developments tool
Unity
Light the way will be developed using Unity 5 Game engine. The game engine supports
development for both 2D and 3D games, along with the ability to publish to a wide range of
platforms with ease. Unity has a power physics system which we will take advantage of to
create our game. The game engine uses a component system allowing for efficient reuse of
code and scripts, this will help to speed up the development of our games core mechanics
allowing us to spend more time on puzzle and level design.
Currently created, we have a basic version of a level creator which uses a BMP. asset to
generate the level using pixel sampling. Depending on whether it is necessary we will use this to
generate the levels and save them in Unity. Using this method will mean that the objects within
the level are consistently laid out and bugs/glitches caused by slight misplacements are
minimised. This will not account for all aspects of the level such as each specific objects colour
or any extra scenery layers we will be added to make the levels seem more unique.

Light The Way - Technical Document

High Level Game Flow

Class Diagram of Game Objects and Scripts


The game will use an object manager class to handle interaction between gameobject. All
gameObject will use an interface class gameObject which will contain function for the game's
core mechanic as well as a rigidBody2, BoxCollider2D, CircleCollider2D to handle physics.

Light The Way - Technical Document

Light The Way - Technical Document

Data Dictionary
Identifier

Data Type /
Component

Class / Location

Description

sprite

Texture Type (unity)

GameObject

The game object's


texture and animation

baseColour

ColourType(enum)

GameObject

the colour of the object it


will revert to, no
interaction from a light
source

currentColour

ColourType(enum)

GameObject

the colour the game


object will display and
use in interactions

body

RigidBody2D(unity)

GameObject

handles the physics


behaviors of game
objects

boxCol

BoxCollider2D(unity)

GameObject

used to check for


collisions between
objects

cirCol

CircleCollider2D
(unity)

GameObject

used to check for


collisions between
objects

width

int

Block/
MovingBlock

the width of the block

height

int

Block/
MovingBlock

the height of the block

width

int

Barrier /
MovingBarrier

the number of
blocks/MovingBlocks in
the X axis

height

int

Barrier /

the number of

Light The Way - Technical Document


MovingBarrier

blocks/MovingBlocks in
the Y axis

thrustVelociy

Vector2(unity)

JumpPad

the velocity applied to the


playerCharacter on
Collision

jumped

bool

playerCharacter

if the playerCharacter
has hit a jumpPad

currentState

PlayerState(enum)

playerCharacter

the the state of the


playCharacter that
dictates it behaviour

posOne

Vector2(unity)

Bounce

first position the object


will move between

posTwo

Vector2(unity)

Bounce

second position the


object will move between

speed

float

Bounce

the speed that object will


move between posOne &
posTwo

directionMove

Vector2(unity)

Bounce

direction its moving


between posOne &
posTwo

currentState

FlyingEnemyState
(enum)

FireFly / LightBug

the state that the


flyingEnemy is in that
dictates its behaviour

startPos

Vector2

Patrol

the start position of the


patrol

distance

float

Patrol

the max distance the


character can move

randomPos

Vector2

Patrol

a random position within


the given distance the
character will head
towards

speed

int

Patrol

the speed at which the


character will move
toward the randomPos

direction

Vector2

Chase

the direction of the object


being chased

speed

int

Chase

the speed at which the


character will head

Light The Way - Technical Document


toward the object
chaseRadius

int

Chase

the max distance the


object must before to
activate chase

currentState

SlunkState

Slunk

the state in which the


slunk is in that dictates
its behaviour

currentState

SwitchState

Switch/
SpecialSwitch

the state in which the


Switch/ SpecialSwitch is
in that dictates its
behaviour

ray

RayCast(unity)

Mirror

to detect if the reflected


light collides with an
object

cirCast

CircleCast(unity)

Mirror

used to draw the light


projected

currentState

TrapDoorState

TrapDoor

the state in which the


TrapDoor is in that
dictates its behaviour

rayOne

rayCast(unity)

LightSource

used to check for


collision between light
and ground

rayTwo

rayCast(unity)

LightSource

used to check for


collision between light
and ground

rayThree

rayCast(unity)

LightSource

created on collision
between spotLight and
rayOne/rayTwo. used to
generate polygon mesh
and arc

mesh

Mesh(unity)

LightSource

drawn to display the new


colour produced by
lightsource and spotlight
interaction

lightCirc

CircleCast(unit)

LightSource

drawn to show initial light


source

arc

Handle.Arc(unity)

LightSource

drawn to display the new


colour produced by
lightsource and spotlight

Light The Way - Technical Document


currentState

TurretState

Turret

the state in which the


Turret is in that dictates
its behaviour

velocity

Vector2

Bullet

the speed at which the


bullet moves.

Code Description
Classes
1. GameObject - (interface)
All object will inherit from this abstract class. It will hold the object's position, base colour, current
colour and a rigidBody2D component. Not all game objects will use the core game mechanic of
colours but it will be incorporated within our base interface should we choose to allow the player
to interact in this way with such objects later in the development process. RigidBody2D is one
of Unitys physic components used for 2D games. It can be used to handle game physics such
as collisions and motion.

2. Block : GameObject
A rectangle used to create solid terrain and platforms for the game's characters to navigate.
When used for terrain all blocks will have a base colour of black; meaning the player can not
interact with it using the light mechanic.

3. MovingBlock : GameObject
A platform that will move between two points. This block will have a base colour of black;
meaning the player can not interact with it using the light mechanic. it will have a Bounce script
attached which will make the block move back and forth between 2 points.

4. Barrier
A collection of Blocks of the same base colour and size, this will give the illusion of a normal
Block but coloured. Upon colliding with a spotlight of the same colour the collision of the each
blocks RigidBody2D will be turned off. This will appear as though a large full-sized Block is
being carved by the light.

Light The Way - Technical Document

5. MovingBarrier
A horizontal or vertical wall of MovingBlocks of the same base colour and size that will move
between two points in the same direction. Upon colliding with a spotlight of the same colour the
collision of the blocks rigidBody2D will be turned off.

6. SpotLight: GameObject
A circle of colour the player can place into the game world by pressing and holding the screen.
when the Spotlight interacts with another object with a colour it will change that object's colour
as described in the design document until the Spotlight is removed.

7. PlayerCharacter :GameObject
The character the player must guide through the environment to the goal. The playerCharacter
have several states: WALK, CLIMB, FALLING, DEAD. In the WALK state the character will
move in a direction along the X axis until it collides with an object it can not pass through, at that
point it will turn around and move in the other direction. whilst in the WALK state it will have the
walking animation.The player will enter the CLIMB state if they collide with a ladder. In this state
the playerCharacter move horizontally up the ladder if at the bottom or down the ladder if
colliding with the top of the ladder. In this state the climb animation will be displayed. The
playerCharacter will return to the WALK state once it has reached the bottom or top of the
ladder. it will continue walking in the same direction it was moving when it collided with the
ladder. The playerCharacter will enter the FALLING State if it becomes airborne. This will
trigger the falling animation. Upon landing on the a platform the playerCharacter can not pass
through the it will return to the WALK state. The playerCharacter will enter the DEAD state on
collision with a gameobject that has DeathOnCollision Script attached. This will start the death
animation trigger game over to be displayed. will It will have to following scripts attached: climb,
jump, changeBaseColour.
The playerCharacter can only ever have a base colour of WHITE, RED, GREEN, BLUE,
MAGENTA, YELLOW or CYAN. This is because the other colours (PINK, SKYBLUE and
TURQUOISE) will not mix again with RGB and these colours are only possible temporarily as
the currentColour(when a Spotlight touches the PlayerCharacter).

Light The Way - Technical Document

8. Slunk : GameObject
A grounded enemy which will run at the playerCharacter when the playerCharacter is within
its chase radius. If the playerCharacter collides with a slunk the PlayerCharacter dies. The
slunk has several states; IDLE, RETREAT, CHASE, DEAD, FALLING. The Slunk will begin in
the IDLE state. In the IDLE state the enemy will patrol a platform or area. The slunk will enter
the RETREAT state if the play places a light on or close to the slunk. In the RETREAT state the
slunk will run away from light. The slunk will always enter the CHASE state when
playerCharacter is within its attack radius AND in line of sight of the slunk, even if in RETREAT
STATE. The slunk will return to the idle state from the CHASE state if the playerCharacter
leaves the Slunks line of sight OR its attack radius. The Slunk will return to the IDLE state from
the RETREAT state if the players light is removed from the screen or if it is a safe distance from
the light. The Slunk will enter the DEAD state if it remains in a light source for a continuous 3
seconds. In the DEAD state it will stay in the position it was in when it entered the state. If the
playerCharacter collides with the Slunk in the DEAD state the playerCharacter will not die.
The Slunk will return to the idle state after a short period of time. The slunk will move into the
FALLING state when it is not touching the ground. The FALLING state is functionally identical to
the IDLE state however the animation would be changed to the falling animation until the Slunk
reaches the ground.

Light The Way - Technical Document

9. Fireflies: GameObject
A flying enemy that alters the colour of a light on collision.They have a set baseColour at the
beginning of the level. Fireflies have two states: IDLE, CHASE. In the IDLE state Fireflies will
hover in a given area. Fireflies will enter the CHASE state if a light source is within a given
radius. In this state they will move towards the center of the light source. The fireflies will
prioritise the players light source over others.

10

Light The Way - Technical Document

10. LightBugs: GameObject


A flying enemy that kills the playerCharacter on collision.They have a set base colour at the
beginning of the level. LightBugs have two states: IDLE, CHASE. In the IDLE state Fireflies will
hover in a given area. LightBugs will enter the CHASE state if a light source of a
complementary colour is within a given radius. In this state they will move towards the center of
the light source. The LightBugs will prioritise the players light source over others.

11

Light The Way - Technical Document

11. Turret: GameObject


A station enemy that fires shots at any character of contrasting colour. It has several states:
IDLE, TARGETING. In the IDLE state the turret runs the idle animation. The turret will enter the
TARGETING state if a character of contrasting colour enters its attack radius and the turret will
turn and face the targeted character. After a short delay, it will fire a colour bullet of its
baseColour at the character. The turret will revert to IDLE if there is no available targets.

12. Bullet: GameObject


A Bullet is a GameObject that is fired from the Turret. It travels at a constant velocity until it hits
an object which then causes it to use the script DeathOnCollision().

13. Switch:GameObject
An object that characters can interact with on collision. Switchs have two states: ON and OFF. A
switch enters the ON state when a character collides with it. When active all Barriers of the
same colour will be removed for a short period of time. While in the ON state the player cannot
interact with the switch using a spotLight. After the time period has expired the switch will
revert to the OFF state and all objects removed by the Switch will return.

14. SpecialSwitch:GameObject
An object that can only be interacted with by light sources. Special Switch have two states: ON
and OFF. At the start of a level a SpecialSwitch is in the OFF state. To switch to the ON a light
source of contrasting colour must be placed over the SpecialSwitch. Once in the ON state all
barriers of the same colour will be removed from the level. The switch stays in this state for the
rest of the level.

12

Light The Way - Technical Document

15. Mirror:GameObject
Mirrors will reflect light in a beam-like way when interacted with by a LightSource. This will
involve a raycast coming from it until it reaches a solid block. When a light touches the mirror
the beam will activate as a thick line of the same colour of the light on the raycast. This will be
done by creating a same colour CircleCast from the start to the end of the raycast in the colour.
The player will be able to rotate the mirror by touching it and dragging it in a circle. This will
change the direction of the raycast and thus the direction of the light beam.

16. Miasma
A rigidBody2D that prevents the player from placing a spotLight.

17. Teleporter:GameObject
The teleporter interacts with light. The currentColour of the teleporter is changed by using the
Spotlight, but only whilst placed over it, otherwise it defaults to its base colour. When interacted
with the teleporter will move a colliding PlayerCharacter or Slunk to another teleporter of the
same currentColour. This is done by editing the PlayerCharacters position variable to that of
the other portal. The teleporter may have a permanent base colour at the levels start.A
Teleporter as two states: ACTIVE and INACTIVE. A teleport is in the ACTIVE state whenever
there are two teleporters of same colour on screen. while the Teleporter is ACTIVE a player can
move between the two ACTIVE teleporters and they will both display an active teleporter
animation. If there is not another teleporter of the colour same colour in the level the the teleport
is INACTIVE.

18. Tinter:GameObject
The tinter is an object that interacts with the PlayerCharacter. It also has a base colour set at the
start, which can only be WHITE, RED, GREEN or BLUE (This is to avoid it being possible to set
the PlayerCharacters baseColour as a colour that would normally require 2 mixes). The
currentColour can be altered using the SpotLight. When the player character collides with the
Tinter the PlayersCharacter baseColour is changed to that of the tinter.

19. Spike:GameObject
This object interacts with the PlayerCharacter. On collision the PlayerCharacters state is set
to the DEAD state and the level resets.

20. JumpPad:GameObject
When the playerCharacter collides with a jumpPad it is given a horizontal and vertical velocity.
Propelling the playerCharacter upwards and in the direction it was walking.

21. Goal: GameObject


When the playerCharacter collides with the goal the level is complete and the gamestate will
change SCOREMENU.

13

Light The Way - Technical Document

22. Trapdoor
Trapdoor has two states: TRIGGERED, SET. At the start of the level all trapdoors will be in the
SET state. when a character collides with the trapdoor it will switch to the TRIGGERED state. At
the start of the TRIGGERED state an animation of the trapdoor opening will run and the fog of
war hiding the pit will disappear. The sprite will remain in on an open frame for the remained of
the level and the fog of war will not return.

14

Light The Way - Technical Document

23. LightSource

15

Light The Way - Technical Document


The light source is an object that shines a cone of light out from a point. This will generate a
triangle (object) of light. The diagram above explains how the players light source will interact
with a triangle of light from a LightSource and shows the differences between a partially clipped
light circle and a light circle fully inside the LightSource cone. Using layering of Arc and Polygon
(object) shapes we have come up with a basic theoretical method to create the illusion of light
mixing.

24. RotatingLightSource
This is the same as the LightSource (22.)however the light can rotate around its source point
(this is shown as the Pink point on the diagrams). It will work in the same way but have limiting
values in its properties to determine the how much it will rotate and its origin direction.

Pseudocode for Core Elements


HandleColour
Used for handling colour interactions between the spotlight and game
objects
Enumeration ColourType
ColourType HandleColour(ColourType addedColour)
{
ColourType newColour
if(currentColour != BLACK)
{
switch (currentColour)
case (ColourType.RED)
switch(addedColour)
case(ColourType.RED)
newColour = ColourType.RED
break
case(ColourType.GREEN)
newColour = ColourType.YELLOW
break
case(ColourType.BLUE)
newColour = ColourType.MAGENTA
break
break
case (ColourType.GREEN)
switch(addedColour)
case(ColourType.RED)
newColour = ColourType.YELLOW
break
case(ColourType.GREEN)
newColour = ColourType.GREEN

16

Light The Way - Technical Document


break
case(ColourType.BLUE)
newColour = ColourType.CYAN
break
break
case (ColourType.BLUE)
switch(addedColour)
case(ColourType.RED)
newColour = ColourType.MAGENTA
break
case(ColourType.GREEN)
newColour = ColourType.CYAN
break
case(ColourType.BLUE)
newColour = ColourType.BLUE
break
break
case (ColourType.MAGENTA)
switch(addedColour)
case(ColourType.RED)
newColour = ColourType.PINK
break
case(ColourType.GREEN)
newColour = ColourType.WHITE
break
case(ColourType.BLUE)
newColour = ColourType.PURPLE
break
break
case (ColourType.YELLOW)
switch(addedColour)
case(ColourType.RED)
newColour = ColourType.ORANGE
break
case(ColourType.GREEN)
newColour = ColourType.LIME
break
case(ColourType.BLUE)
newColour = ColourType.WHITE
break
break
case (ColourType.CYAN)
switch(addedColour)
case(ColourType.RED)

17

Light The Way - Technical Document


newColour = ColourType.WHITE
break
case(ColourType.GREEN)
newColour = ColourType.TURQUOISE
break
case(ColourType.BLUE)
newColour = ColourType.SKYBLUE
break
break
case (ColourType.WHITE)
newColour = addedColour
break
}
else
{
newColour = ColourType.BLACK
}
return newColour
}

Bounce
Makes an game object bounce between to loactions at a set speed
Vector2 pos1
Vector2 pos2
int direction = 1;
int speed = 5; //Example TO BE ALTERABLE
Vector2 directionMove = (pos1.position - pos2.position).UnitVector()*speed
void Bounce() //Called each frame
{
MoveObject(directionMove)
if(Object.RigidBody.IntersectsWith(pos1) ||Object.RigidBody.IntersectsWith(pos2))
{
direction = direction * -1
}
}
Patrol
Make a character patrol an area. moving a random distance in a direction within
a set space
Vector2 startPos = Vector2D(100,100) //Example TO BE WORKED OUT WHEN PLACED
float distance = 50 //Example TO BE ALTERABLE
Vector2 randomPos;
randomPos.position = Vector2(startPos.X+((rand%distance)-(distance/2)))

18

Light The Way - Technical Document


void Patrole() //Called each frame
{
MoveObject((randomPos - startPosition).UnitVector()*speed)
if(Object.RigidBody.IntersectsWith(randomPos))
{
randomPos.position = Vector2D(startPos.X+((rand%distance)-(distance/2)))
}
}

DeathOnCollision
Attached to game cause the playerCharacter to die on Collision, triggering
gameover
void DeathOnCollision(RigidBody2D collidedWith) // Called on collision
{
if(collidedWith() == PlayerCharacter.RigidBody2D)
{
PlayerCharacter.Die()
}
}
Chase (Slunk Example)
Vector2 direction
speed = 5; //Example TO BE ALTERABLE
void Chase
{
if(AttackRadius.collidedWith() = PlayerCharacter.RigidBody2D.position)
{
direction = (Player character.RigidBody2D.position)
MoveObject((direction - currentPosition).UnitVector()*speed)
}
}

Climb

Makes the character climb a ladder.

void Climb
{
if (PlayerCharacter.collidedWith() = Ladder.RigidBody2D)
{
Vector2D CurrentDirectionV = PlayerCharacter.currentVelocity
PlayerCharacter.currentVelocity = Vector2D(0,5)
while(PlayerCharacter.collidedWith() = Ladder.RigidBody2D)
{

19

Light The Way - Technical Document


Player character.MoveObject()
}
PlayerCharacter.currentVelocity = CurrentDirectionV
}
}

Jump
Causes the playerCharacter to jump with a given velocity
float xJump = 10 //Example TO BE ALTERABLE
float yJump = 30 //Example TO BE ALTERABLE
bool Jumped = false;
void Jump
{
if (PlayerCharacter.collidedWith() =JumpPad.RigidBody2D)
{
if(Jumped == false)
{
PlayerCharacter.currentVelocity += Vector2(xJump, yJump)
Jumped = true
}
}
else
{
Jumped = false
}
}
IsContrastingColour
Checks if two colours are contrasting. if combined together make white
Enumeration ColourType
bool isContrastingColour(ColourType Colour1, ColourType Colour2)
{
switch(Colour1)
case(ColourType.RED)
if(Colour2 == RED || Colour2 == YELLOW || Colour2 == MAGENTA
|| Colour2 == PINK || Colour2 == WHITE || Colour2 == PURPLE
|| Colour2 == ORANGE || Colour2 == LIME)
{
return false
}
else
{

20

Light The Way - Technical Document


return true
}
break
case(ColourType.GREEN)
if(Colour2 == GREEN || Colour2 == YELLOW || Colour2 == CYAN
|| Colour2 == LIME || Colour2 == WHITE || Colour2 == TURQUOISE
|| Colour2 == ORANGE || Colour2 == SKYBLUE)
{
return false
}
else
{
return true;
}
break
case(ColourType.BLUE)
if(Colour2 == BLUE || Colour2 == MAGENTA || Colour2 == CYAN
|| Colour2 == PINK || Colour2 == WHITE || Colour2 == TURQUOISE
|| Colour2 == PURPLE || Colour2 == SKYBLUE)
{
return false;
}
else
{
return true;
}
break
case(ColourType.MAGENTA)
if(Colour2 == RED || Colour2 == BLUE || Colour2 == MAGENTA
|| Colour2 == PINK || Colour2 == WHITE || Colour2 == PURPLE)
{
return false
}
else
{
return true
}
break
case(ColourType.CYAN)
if(Colour2 == GREEN || Colour2 == BLUE || Colour2 == CYAN
|| Colour2 == TURQUOISE || Colour2 == WHITE || Colour2 == SKYBLUE)
{
return false
}

21

Light The Way - Technical Document


else
{
return true
}
break
case(ColourType.YELLOW)
if(Colour2 == GREEN || Colour2 == RED || Colour2 == YELLOW
|| Colour2 == ORANGE || Colour2 == WHITE || Colour2 == LIME)
{
return false
}
else
{
return true
}
break
case(ColourType.SKYBLUE)
if(Colour2 == GREEN || Colour2 == RED || Colour2 == YELLOW
|| Colour2 == ORANGE || Colour2 == WHITE || Colour2 == LIME)
{
return false
}
else
{
return true
}
break
}
IsComplementaryColour
Checks if two colours are complementary. can be combined together to make a
secondary colour
(Opposite of Contrasting therefor could just use !ContastingColour())
Enumeration ColourType
bool isComplimentaryColour(ColourType Colour1, ColourType Colour2)
{
if(!isContrastingColour())
{
return true
}
else
{
return false
}

22

Light The Way - Technical Document


}

Prioritised List of Features


Core

playerCharacter
LightSources
Switch
Slunk
SpecialSwitch
Barrier
Block
Tinter
Spikes
Goal

FireFly
Turrets
LightBug
Mirror
Teleporter
JumpPad
TrapDoor
Miasma

Optional

23

You might also like