Global

Members

allSpritesGroup :Group

A helper group used to remove all unwanted Sprites from previous level
Type:
  • Group
Source:
See:

attackSpeed :number

Indicates the time between player attacks
Type:
  • number
Source:
See:

attackTimer :number

Timer ID for managing attack intervals.
Type:
  • number
Source:
See:

(constant) backgroundColor :string

Color of the background color of the document body (Area outside of canvas)
Type:
  • string
Source:

boss :Group

Sprite Group specifically for the boss Even if theres one boss, using a Group helps with spawning in the boss
Type:
  • Group
Source:
See:

bossAttackArea :Sprite

Sprite representing the area that the bosses attack takes Used to detect if the bosses attack hits the player
Type:
  • Sprite
Source:
See:

bossAttackAreaTimer :number

Timer ID for managing boss attack intervals.
Type:
  • number
Source:
See:

bossBackground :Array.<{backgroundLayer}>

An array representing layers of the boss room background for a parallax effect. Each layer contains the file path to the image, an image object (assigned later), its x-coordinate, and its scrolling speed.
Type:
Source:

bossBody :Sprite

Sprite spawned when the boss is defeated representing the defeated boss body
Type:
  • Sprite
Source:

bossPrevFrame :number

Stores the frame of the time of a boss attack Used to calculate when the boss can attack again
Type:
  • number
Source:
See:

cWidth :number

Canvas width and height
Type:
  • number
Source:

cameraYOffset :number

Y coordinate offset for the camera location
Type:
  • number
Source:

canAttack :boolean

Flag indicating when a character can attack
Type:
  • boolean
Source:
See:

canBossAttack :boolean

Flag indicating when the boss can attack
Type:
  • boolean
Source:
See:

canDamage :boolean

Flag indicating when a character can get damaged
Type:
  • boolean
Source:
See:

castleBackground :Array.<{backgroundLayer}>

An array representing layers of the castle background for a parallax effect. Each layer contains the file path to the image, an image object (assigned later), its x-coordinate, and its scrolling speed.
Type:
Source:

chasing

Flag indicating when the player's getting chased by an enemy(prevens enemy animation overlap)
Source:
See:

coins :Group

Children Sprite Groups of my myTiles Group Each Group has multuple instances(Sprites) on each level
Type:
  • Group
Source:
See:

coinsImg :q5.Image

Animation spritesheet for the collecatble coins Different animations are used in each level
Type:
  • q5.Image
Source:

currentLevel :number

Current game level
Type:
  • number
Source:

currentMap :string

Current game map
Type:
  • string
Source:

currentScene :number

Represents the current story scene shown in the intro and outro of the game
Type:
  • number
Source:
See:

damageTimer :number

Timer ID for managing damge taking intervals.
Type:
  • number
Source:
See:

deathTrigger :boolean

Indicator of the boss dying
Type:
  • boolean
Source:

direction :number

Used to indicate player direction Takes values of 1 or -1
Type:
  • number
Source:
See:

enemies :Group

Parent group for all enemy groups Used to acces all enemies from one place
Type:
  • Group
Source:
See:

enemyCurrentY :number

Enemy Y coordinate at begging of chase
Type:
  • number
Source:
See:

enemyGroup :Object

An object containing enemy groups for different types of enemies. Every map has its own two unique enemies
Type:
  • Object
Source:
See:

enemySpawn1 :Group

A subset of 'myTiles' used to determin the spawn coordinates for each enemy type
Type:
  • Group
Source:
See:

entranceBackground :Array.<{backgroundLayer}>

An array representing layers of the entance background for a parallax effect. Each layer contains the file path to the image, an image object (assigned later), its x-coordinate, and its scrolling speed.
Type:
Source:

fScale :number

Canvas scale
Type:
  • number
Source:

forestBackground :Array.<{backgroundLayer}>

An array representing layers of the forest background for a parallax effect. Each layer contains the file path to the image, an image object (assigned later), its x-coordinate, and its scrolling speed.
Type:
Source:

forestMusic :q5.Sound

Sound files for background music and sound effects
Type:
  • q5.Sound
Source:
See:

forestTiles :q5.Image

Conatins the single tile image sheets for each map
Type:
  • q5.Image
Source:

gameState :string

Current game state
Type:
  • string
Source:

groundSensor :Sprite

Sprites attached to the player, used as "sensors"
Type:
  • Sprite
Source:
See:

heart :Sprite

Sprite belonging to ui group Represents individual hearts(player hit points)
Type:
  • Sprite
Source:
See:
  • setUI

heartImg :q5.Image

Image sprite sheet for the ui's hearts
Type:
  • q5.Image
Source:

heroImg :q5.Image

Animation spritesheets caontaining the animaations for the player and enemies
Type:
  • q5.Image
Source:
See:

inSequence :boolean

Checks to see if player is in a movement sequence (prevents sequence cancellation)
Type:
  • boolean
Source:

introScenes :Array.<{storyScene}>

An array representing the intro story scenes. Each layer contains the file path to the image and an image object (assigned later),
Type:
Source:

levels :Array.<Level>

Array of game levels
Type:
Source:
See:

mapGravity :number

World gravity value
Type:
  • number
Source:
Images for the main menu and Controlls page
Type:
  • q5.Image
Source:
See:

mountainBackground :Array.<{backgroundLayer}>

An array representing layers of the mountain background for a parallax effect. Each layer contains the file path to the image, an image object (assigned later), its x-coordinate, and its scrolling speed.
Type:
Source:

myTiles :Group

Parent group for all the Sprite groups that build the level tiles Utilizes p5play's 'Group' class for handling collections of sprites.
Type:
  • Group
Source:
See:

outroScenes :Array.<{storyScene}>

An array representing the outro story scenes. Each layer contains the file path to the image and an image object (assigned later),
Type:
Source:

(constant) playerSpeed :number

The speed the player moves
Type:
  • number
Source:

prevFrame :number

Stores the frame of the time of an attack Used to calculate when the players sprite opacity returns to normal
Type:
  • number
Source:
See:

score :number

Keeps track of score (number of coins collected)
Type:
  • number
Source:
See:

spawnPoint :Group

A subset of `myTiles` containing the spawn and level end point Groups. Only one Sprite of each groupe is used per level to declare its starting and end point
Type:
  • Group
Source:
See:

tileGroup :Tiles

Group of all the tiles of the current level Utilizes p5play's 'Tiles' class for handling tile generation.
Type:
  • Tiles
Source:
See:

tileSize :number

The pixel size of each tile | 16x16
Type:
  • number
Source:

topSensor :Sprite

Sprites attached to the top of the player, used as "sensor"
Type:
  • Sprite
Deprecated:
  • to be removed
Source:
See:

ui :Group

Sprite Group used for the UI (Health bar)
Type:
  • Group
Source:
See:
  • setUI

walkableTiles :Group

A subset of `myTiles` containing only walkable tiles. Represents areas the player can move on.
Type:
  • Group
Source:
See:

witch :Group

Sprite groups for the player and the enemies
Type:
  • Group
Source:
See:

Methods

(async) attack(character) → {Promise.<void>}

Executes an attack action for the given character. Creates an invisible attack area in front of the character, plays the attack animation, and applies damage to enemies or the boss depending on the current level. This function uses GlueJoint to attach the attack area sprite to the player This function uses asynchronous operations to manage attack timing and resets the ability to attack after a cooldown period. Using await the attack animation is completed before damage calculations take place
Parameters:
Name Type Description
character Sprite The character performing the attack.
Source:
See:
Returns:
Resolves when the attack sequence is complete.
Type
Promise.<void>

attackAreaProximity(area) → {void}

Checks if the attacking area overlaps an enemy checks if enemy x cord is close enought to the attack area sprite x cord Kills enemies hit
Parameters:
Name Type Description
area Sprite The attacking area created during an attack
Source:
See:
Returns:
Type
void

backgroundMusic(volume) → {void}

Plays background music according to level Pauses previous level music and plays the current one
Parameters:
Name Type Description
volume number The volume at which the background music is played
Source:
See:
Returns:
Type
void

(async) bossAI() → {Promise.<void>}

Handles the behavior and logic of the boss character during gameplay. This asynchronous function manages the boss's actions and state transitions. If the boss's health is greater than zero, it performs its attacks. When the boss's health reaches zero, the function triggers its death sequence, including removing its attack area, transitioning its animations, and handling its removal from the game.
Source:
Returns:
Resolves when the boss's death sequence is complete.
Type
Promise.<void>

(async) bossAttack() → {Promise.<void>}

Executes the boss's attack behavior, including animation transitions and damage logic. - **Attack Triggering**: - The attack can only occur if `canBossAttack` is `true`. - Sets a cooldown for the boss's attack by toggling `canBossAttack` and storing the frame count in `bossPrevFrame`. - **Animation Sequence**: - Plays an upward and downward bounce animation for the boss (`bounceU` and `bounceD`). - Activates the attack area by making it visible, enabling damage, and switching to the 'active' animation state. - After the attack, transitions the boss back to its 'stand' animation state. - **Damage Logic**: - If the attack area overlaps with the player (`lizard`), the `damage` function is triggered. - **Attack Reset**: - After a specific number of frames, the attack area is deactivated by hiding it, disabling damage, and changing its animation state to 'inactive'. - Once the cooldown period is reached (350 frames), the boss is ready to attack again by setting `canBossAttack` to `true`.
Source:
Returns:
Resolves when the attack sequence is complete.
Type
Promise.<void>

cameraControll(player, map, zoom) → {void}

Controls the camera's movement and zoom level based on the player's position. The camera is follownig the camera sensor, a sprite following the player with a speed lower than the player speed
Parameters:
Name Type Description
player Sprite The player sprite, used to determine the cameraSensors's target.
map Tiles The map tiles or that define the camera's constraints.
zoom number The zoom level to set for the camera.
Source:
See:
Returns:
Does not return a value.
Type
void

canvasSetup() → {void}

Sets up the canvas for the game by defining its scale and dimensions The 'pixelated' attribute sets pixelDensity to 1 and various css styles are applied to the canvas to make it render without image smoothing
Source:
See:
Returns:
Type
void

changeLevel() → {void}

Handles the transition between levels by removing previous level's elements, setting up the environment, updating the tileset, and spawning new enemies. Also updates the player's position and other level-specific attributes like coin color and map name. This function handles the environment setup based on the current level, including tile groups and enemies.
Source:
See:
Returns:
Does not return a value.
Type
void

changeState(state) → {void}

Changes the current state of the player. The state transition is based on the provided state argument, which can either be a number or string representing the desired state.
Parameters:
Name Type Description
state string | number The new state to change the lizard to. This can be: - 'IDLE' or 0: Idle state. - 'WALK' or 1: Walking state. - 'JUMP' or 2: Jumping state. - 'ATTACK' or 3: Attacking state. - 'BLOCK' or 4: Blocking state. - 'STUCK' or 5: Stuck state.
Source:
See:
Returns:
Type
void

constrainCamera(tileGroup) → {void}

Constrains the camera's position to ensure it stays within the boundaries of the level. The camera's x and y coordinates are adjusted based on the player's position and the defined limits for the map. The function ensures that the camera does not go outside the designated area of the level, both horizontally and vertically. The horizontal borders boundaries are determined by the x coordinates of the spawn point and the end point The vertical borders boundaries are determined by the y coordinates of the cameraSensor and the last(lowest) tile
Parameters:
Name Type Description
tileGroup Array The group of tiles for the current level, used to calculate the vertical bounds of the camera.
Source:
See:
Returns:
Type
void

damage() → {void}

Applies damage to the player. Reduces health, plays a damage sound, shakes the character, and updates the UI to reflect the change in health. The function also manages the cooldown for when the character can take damage again.
Source:
See:
  • shake For handling the player shake effect when the character takes damage.
  • death For triggering the death sequence when health reaches zero.
Returns:
Type
void

(async) damageBoss(area) → {Promise.<void>}

Handles applying damage to the boss when certain conditions are met. Checks if the boss can damage the player and then if the player is within range. If so, it reduces the boss's health, plays a sound effect, and transitions the boss through its damage animation sequence.
Parameters:
Name Type Description
area Sprite The sprite or representing the bosses attack area.
Source:
Returns:
Resolves after the boss's damage animation sequence is complete.
Type
Promise.<void>

(async) death() → {void}

Plays dying animation and resets the player
Source:
See:
Returns:
Type
void

displayBackground() → {void}

Displays a parallax background based on the current map. The background image is chosen according to the current map, and it is drawn multiple times to create a scrolling effect. The background scrolls horizontally when the player is walking, unless the map is "entrance" or "bossRoom".
Source:
See:
  • currentMap For the current map, which determines the background to display.
  • changeState For the player states
  • direction For the direction in which the background scrolls.
Returns:
Type
void

drawFrame() → {void}

Draws the UI after turning of the camera, making it static
Source:
See:
Returns:
Type
void

endGame() → {void}

Displays the outro story scenes Has option to restart the game at last scene
Source:
Returns:
Type
void

endLevel() → {void}

Handles reaching the end of current level The player moves to the right and the level changes
Source:
See:
Returns:
Type
void

enemyProximity() → {void}

Constantly checks if an enemy is near the player and updates enemy behavior accordingly. If the enemy is within a specified proximity of the player, it will start chasing the player. It also handles enemy orientation, movement, and interactions with environmental elements like spikes and platforms. This function iterates over all the enemies in the map and checks if any of them are near the player. The proximity is determined by a distance check (100 units in both the X and Y axes). If an enemy is within this range, the following actions occur: - Enemy orientation is adjusted based on the player's position. - If the enemy is not already chasing, it begins chasing the player, and its Y-coordinate is tracked. - If the enemy's Y-coordinate changes significantly (i.e., falls to a lower level), it applies a downward force. - Flying enemies can move freely toward the player, while walking enemies are limited to moving along the X-axis. - Enemies also interact with environmental hazards (e.g., spikes) by dying upon overlap.
Source:
Returns:
Type
void

gameControlls(character) → {void}

Manages character controls, including movement, jumping and attacking. Handles input from the keyboard and controller, and updates the character's state and animation accordingly.
Parameters:
Name Type Description
character Sprite The character sprite whose controls are being managed.
Source:
See:
  • stuckCheck For handling scenarios where the character is stuck.
  • changeState For updating the character's state.
  • isOnGround For checking if the character is on the ground.
  • attack For handling attack actions.
Returns:
Does not return a value.
Type
void

initializeBoss() → {void}

Initializes the boss character and its associated attack area. This function creates an instance of the boss (Goblin King) at the boss spawner location and sets up its attack area. The boss attack area is an invisible sprite that overlaps with both the boss and the player (lizard) to detect attacks. The function configures the boss's visual properties, its attack area, and the animation states for the attack area.
Source:
Returns:
Does not return a value.
Type
void

initializeEnemies() → {void}

Initializes various enemy groups and assigns their properties, animations, and behaviors. Each enemy group is configured with specific attributes such as size, movement type, sprite sheet, animations, and other properties like speed, friction, and scale. The function also sets their initial animations to 'stand'. This function creates multiple types of enemies with different behaviors and characteristics. The enemies include flying enemies (like `fly` and `bat`), ground-based enemies (like `leaf`, `cobra`, `imp`, and `ghoul`), as well as special enemies like `boss`, `witch`, and `frog`. Each enemy type is configured with a sprite sheet, animations (stand, move, attack, death, etc.), speed, friction, and other relevant properties. The function ensures each enemy is set to its idle 'stand' animation upon initialization.
Source:
Returns:
Type
void
Example
//Enemy Properties explanation

	enemy = new enemies.Group(); (Subgroup of enemies Group)
	enemy.w = number;  									'(enemy width)'
	enemy.h = number;  									'(enemy height)'
	enemy.layer = number;   							'(Determines the layer of a Sprite in case of overlapping)'
	enemy.flying = false;								'(attribute determining if an enemy can fly)'
	enemy.rotationLock = 'true'; 						'(Prevents sprite from spinning)'
	enemy.spriteSheet = 'img';   						'(Sets animation spritesheet to group)'
	enemy.mass = 'number';	     						'(Sprites mass, is affected by gravity)'
	enemy.speed = 'number;  		 					'(Enemy speed, used in chasing)'
	enemy.friction = 'number;			 				'(Sprite friction with other sprites)'
	enemy.anis.w= 'number;			 					'(Widht of animation frame in spritesheet)'
	enemy.anis.h= 'number;				 				'(Height of animation frame in spritesheet)'
	enemy.scale = 'number;			 					'(Sprite size scalling)'
	enemy.anis.offset.x = 'number;	 					'(x cord offset of the animation frame to the center of the sprite)'
	enemy.anis.offset.y = 'number;  					'(y cord offset of the animation frame to the center of the sprite)'
	enemy.addAnis({										'(Determines which part of the spritesheet is corresponds to each animation)'
		stand: { row: 0, frames: 4, frameDelay: 10 },	
		move: { row: 1, frames: 8, frameDelay: 10 },
		attack: { row: 2, frames: 6, frameDelay: 13 },
     death: { row: 4, frames: 6, frameDelay: 10},
     dead: { row: 20, frames: 0}
	});

intro() → {void}

Displays the intro story scenes Starts the game when the scenes end
Source:
Returns:
Type
void

isOnGround() → {boolean}

Detects if the charater is on a Sprite/Tile that allows jumping Prevents multiple jumps and jumping while touching the sides of walls
Source:
See:
Returns:
Type
boolean

keepScore() → {void}

Checks if player goes through a coin The coin gets removed and the score updates Collecting coins also heals the player
Source:
Returns:
Type
void

killEnemy(e) → {void}

Cripples attacked enemy, plays its death animation and removes it
Parameters:
Name Type Description
e Sprite The specific enemy that gets hit by the attack
Source:
See:
Returns:
Type
void
Displays main menu. The first level is loaded in setup() but its turned invisible in the main menu
Source:
Returns:
Type
void

preload()

Q5 function that pre-loads assets before these are needed in the setup and update/draw function
Source:
See:

preloadLevels() → {void}

Preloads the level data by populating the `levels` array with information about platforms, maps, and level number. Sets `currentLevel` to the level of the first entry.
Source:
See:
  • levels For the array that stores the information of all levels in the game.
  • currentLevel For the variable that tracks the current level during gameplay.
Returns:
Type
void

resetPlayer(resetCamera, resetHealth) → {void}

Resets player back to spawning point
Parameters:
Name Type Description
resetCamera boolean Option to reset the camera | Avoid weird camera movements during level change
resetHealth boolean Option to reseet player health | Doesnt reset health on level change
Source:
See:
Returns:
Type
void

runGame() → {void}

Executes the main game loop, managing player interactions, camera controls, level transitions, enemy behavior, and game state logic. This function is called continuously to keep the game running.
Source:
See:
Returns:
Does not return a value.
Type
void

setEnviroment(tileSet) → {void}

Sets up the environment for the current map by defining various tiles and objects such as platforms, spawn points, enemy spanwers, and coins. It also assigns sprites and animations for different tile types. This function initializes myTiles and walkable tiles.
Parameters:
Name Type Description
tileSet Object The tile set used to create the environment for the level (e.g., forest, mountain).
Source:
See:
  • myTiles For the group that holds all tile-related objects in the environment.
  • walkableTiles For the collection of tiles the player can walk on.
  • spawnPoint For the initial spawn point of the player.
  • enemySpawn1 For the spawn point of the first type of enemy.
  • enemySpawn2 For the spawn point of the second type of enemy.
Returns:
Does not return a value.
Type
void
Example
//Group Properties Explanation

group = new Group() 									 '(No parent group)'
	group = new myTiles.Group() | walkableTiles.Group(); '(Determines which subgroup the group belongs)'
	group.layer = 'number'; 							 '(Determines the layer of a Sprite in case of overlapping)'
	group.collider = 'static'; 							 '(Determines sprite collider('none', 'static', 'kinematic'))'
	group.w = tileSize; 								 '(Sprite width)'
	group.h = tileSize; 								 '(Sprite Height)'
	group.tile = 'character'; 							 '(Determines which character the sprite represents in the tile map)'
	group.addAni({  									 '(Determines which part of the spritesheet is corresponds to the Sprite)'
		w: tileSize,
		h: tileSize,
		row: 0,
		col: 0
	});

setInput() → {void}

Sets up the UI - Player Health Creates heart sprites, same ammount as the players maxHealth property
Source:
Returns:
Type
void

setup() → {void}

Q5 function that runs one time when the program starts Sets up the game environment, including canvas, sprites, levels, and UI elements. Initializes global variables, loads resources, and prepares the game for play.
Source:
See:
Returns:
Does not return a value.
Type
void

(async) shake(entity) → {void}

Moves entity left and right
Parameters:
Name Type Description
entity Sprite Sprite that the shake is applied to
Source:
Returns:
Type
void

spawnEnemies(enemy1, enemy2) → {void}

Spawns enemies at predefined spawn points. This function creates enemy sprites for the specified enemies and places them at the positions defined in `enemySpawn1` and `enemySpawn2`.
Parameters:
Name Type Description
enemy1 Object Spawner tile for the first enemy type
enemy2 Object Spawner tile for the first enemy type
Source:
See:
  • enemySpawn1 For the first set of spawn points where enemy1 is placed.
  • enemySpawn2 For the second set of spawn points where enemy2 is placed.
Returns:
Type
void

spawnLizard(x, y) → {void}

Creates and initializes the lizard character sprite, including its size, animations, health, and various sensors that interact with the environment. The function sets up the lizard's appearance, behavior, and associated detection sensors to handle movement, collision, and state transitions during gameplay. -**Ground Sensor** -Sprite attached to bottom of player, used in isOnGround -**Left/Right Sensors** -Sprites attached in the left and right of the player used in stuckCheck -**Top Sensor** -Currently not in use -**Camera Sensor** - Floating Sprite on top of player used in cameraControll
Parameters:
Name Type Description
x number The x-coordinate for the lizard's spawn position.
y number The y-coordinate for the lizard's spawn position.
Source:
See:
Returns:
Does not return a value.
Type
void

spawner() → {Object}

Determines and returns the spawn coordinates for the character. Calculates the position based on the spawnPoint Sprite/Tile and adjusts the x and y coordinates for placement.
Source:
See:
  • spawnPoint For the reference to the spawn point from which the coordinates are derived.
Returns:
An object containing the x and y coordinates for the spawn point.
Type
Object

stuckCheck() → {void}

Checks if the player is stuck by checking if either the left or right sensor is overlapping with any walkable tiles. If the character is stuck, it changes the state to 'STUCK', otherwise, it changes the state to 'IDLE'. Used to prevent sprite bouncing and to controll the moving background
Source:
See:
Returns:
Type
void

update() → {void}

Q5 function that runs 60 times per second by default. Acts as game state machine
Source:
See:
Returns:
Does not return a value.
Type
void

updateTileset(set)

Updates the tileset image used for all the tile images Here addAni adds a single frame animation to each tile For the tile images to update on map change the animation need to be reassigned
Parameters:
Name Type Description
set q5.Image The tileset image of the current map
Source:
See:

Type Definitions

Level

Type:
  • Object
Properties:
Name Type Description
platforms string // The tile layout of the level
map string // The map of the level
level number //Number of the level
Source:

backgroundLayer

Properties:
Name Type Description
file string // The file path to the background image.
img q5.Image | undefined // The q5.Image object for the layer, initially undefined.
x number // The x-coordinate of the background layer.
speed number // The scrolling speed of the background layer.
Source:

storyScene

Properties:
Name Type Description
file string // The file path to the background image.
img q5.Image | undefined // The q5.Image object for the layer, initially undefined.
Source: