My ELEC2645 project. Nikollao Sulollari. 200804685

Dependencies:   N5110 SoftPWM mbed

Fork of Treasure_Hunt by ELEC2645 (2015/16)

Embed: (wiki syntax)

« Back to documentation index

main.h File Reference

main.h File Reference

Header file contains functions and variables. More...

Go to the source code of this file.

Namespaces

namespace  g_led
 

output for status of green LED


namespace  b_led
 

output for status of blue LED


namespace  blue_led
 

output for status of blue LED, lights when game tool is loaded


namespace  led_output
 

output for status of left tries for the user to win the game


namespace  lcd
 

object of the N5110 class


namespace  pc
 

serial connection between mbed and pc


namespace  xPot
 

read x-axis position from the value of the joystick


namespace  yPot
 

read y-axis position from the value of the joystick


namespace  button
 

interrupt executes an event triggered task


namespace  buzzer
 

create PWM signal using the SoftPWM library to set buzzer duty cycle and period


namespace  ticker
 

interrupt executes a time-triggered task


namespace  timer
 

interface is used to measure the time between start and stop


namespace  game_ticker
 

interrupt executes a time-triggered task


namespace  timeout
 

interrupt calls a function after a specified amount of time


namespace  DirectionName
 

define joystick's direction based on its x,y values


namespace  Joystick
 

create strcut Joystick


Functions

DigitalOut r_led (LED_RED)
 r_led
int main ()
 The main function where the program takes place.
void init_serial ()
 set-up serial port
void init_K64F ()
 set-up the on-board LEDs and switches
void init_game ()
 Set-up random variables and game menu.
void timer_isr ()
 Set-up flag to 1.
void game_timer_isr ()
 Set-up flag to 1.
void sw2_isr ()
 Set-up flag to 1.
void sw3_isr ()
 Set-up flag to 1.
void button_isr ()
 Set-up flag to 1.
void button1_isr ()
 Set-up flag to 1.
void timeout_isr ()
 Set-up flag to 1.
void calibrateJoystick ()
 Set current position to default position of Joystick.
void updateJoystick ()
 Update the values of the joystick to get current position.
void enemyRect ()
 Create an enemy rectangular shape.
void enemyRocket ()
 Create an enemy rectangular shape.
void enemyCircle ()
 Create circle shape enemy.
void hero ()
 creates the hero of the game
void guidance ()
 Shows the right direction.
void obstacles ()
 Locates obstacles in the screen.
void enemies ()
 Gets enemies depending on the level.
void menu ()
 Implement Menu in the game and display on screen.
void checkOverlap ()
 Check for overlap between hero and enemies or obstacles.
int intersection (int i, int j)
 Check for intrersection.

Variables

Joystick joystick
 create struct variable
volatile int rectX
volatile int rectY
volatile int circleX
volatile int circleY
volatile int heroX
volatile int heroY
volatile int level = 0
volatile int g_timer_flag = 0
volatile int g_game_timer_flag = 0
volatile int g_sw2_flag = 0
volatile int g_sw3_flag = 0
volatile int g_button_flag = 0
volatile int g_button1_flag = 0
volatile int option = 0
volatile int play = 0
volatile int tries = 3
volatile int n
volatile float game_speed = 0.05
int fsm [4] = {7,6,4,0}
int fsm_state = 0
int reset = 0
int objectX = 0
int objectY = 20
int state = 0
int objectX1 = 58
int state1 = 1
int speed = 1
bool normal = 0
bool sound = 0

Detailed Description

Header file contains functions and variables.

Treasure Hunt - Embedded Systems Project Revision 1.0

Author:
Nikollao Sulollari 26/03/2016

Definition in file main.h.


Function Documentation

void button1_isr (  )

Set-up flag to 1.

Definition at line 116 of file main.cpp.

void button_isr (  )

Set-up flag to 1.

Definition at line 111 of file main.cpp.

void calibrateJoystick (  )

Set current position to default position of Joystick.

Definition at line 483 of file main.cpp.

void checkOverlap (  )

Check for overlap between hero and enemies or obstacles.

loop follows the hero and checks for overlap around him

int gets number of pixels around the hero

provides safety if hero is in default position he doesn't get killed by enemies

6 is the offset of the neigbours, as hero has his own neighbours pixels

Bang message is displayed when overlap has occured

2 lives left

attach a slower ticker to save power while not playing

if button1 is pressed

reset button1 flag

reset parameters

reset values

call main

Definition at line 769 of file main.cpp.

void enemies (  )

Gets enemies depending on the level.

generate enemies in the screen depending on the level of difficulty

generate enemies at level 0

generate enemies at level 1

generate enemies at level 2

generate enemies at level 3

generate enemies at level 4

generate enemies at level 5

generate enemies at level 6

generate enemies at level 7

if button1 is pressed don't allow to use at level 7

Definition at line 131 of file main.cpp.

void enemyCircle (  )

Create circle shape enemy.

generate circle shape enemy

set the boundaries of the enemy

enemy moving towards hero

Definition at line 223 of file main.cpp.

void enemyRect (  )

Create an enemy rectangular shape.

generate rectangular shape enemy

enemy moving towards hero

set boundaries for enemy position

Definition at line 189 of file main.cpp.

void enemyRocket (  )

Create an enemy rectangular shape.

generate a "rocket-like" enemy

enemy moving towards hero

set boundaries for position of enemy

Definition at line 205 of file main.cpp.

void game_timer_isr (  )

Set-up flag to 1.

Set-up flag to 1

Definition at line 96 of file main.cpp.

void guidance (  )

Shows the right direction.

function acts as guidance towards the treasure

print the treasure icon

stop timer

value reads the time taken to win the game

create an array of chars

create string

print the time taken to win the game on screen

provide play again option

if button1 is pressed

reset

Definition at line 315 of file main.cpp.

void hero (  )

creates the hero of the game

cotrol hero

joystick direction points to the right

joystick direction points to the left

joystick direction points to the top

joystick direction points down

joystick is centred

joystick direction points up and left

joystick direction points up and right

joystick direction points down and right

joystick direction points down and left

set x-axis boundaries so hero does not go out of screen

if hero has reached the top of the screen

hero goes back to the bottom of the screen

increase level of the game

hero cannot go to previous level

draw hero

variables heroX and heroY are used to control the direction of the hero

Definition at line 240 of file main.cpp.

void init_game (  )

Set-up random variables and game menu.

initialise game

generate random numbers

init rectX, rectY

init circleX, circleY

small delay prints welcome message

Definition at line 296 of file main.cpp.

void init_K64F (  )

set-up the on-board LEDs and switches

assign rise with ISR

use PullDown mode

Definition at line 69 of file main.cpp.

void init_serial (  )

set-up serial port

Definition at line 63 of file main.cpp.

int intersection ( int  i,
int  j 
)

Check for intrersection.

Parameters:
iloops through x direction
jloops through y direction
Returns:
the number of pixels around the hero detected

check for overlap between enemies and hero

Definition at line 745 of file main.cpp.

int main (  )

The main function where the program takes place.

initialise LED

init K64F

initiate connection with PC port

initialize game

set FSM to turn on LEDs

calibrate joystick

attach ticker for the menu different from the main ticker

attach ticker with ISR. Speed is selected by the user

set reset = level to check later if level has increased

if timer flag is UP

reset flag

if level has increased

reset weapon button

update reset

set enemies to default position

get guidance

call hero

generate enemies

generate obstacles

the blue LED indicates if the weapon is ready to use or not

check is hero has overlapped with enemies or obstacles

update joystick

use sleep and timer triggered interrupt to save power

Definition at line 9 of file main.cpp.

void menu (  )

Implement Menu in the game and display on screen.

print the main

check the direction of joystick

if the last (down) option is set for selection and user presses joystick down, selector moves at the top

if the first (up) option is set for selection and user presses joystick up, selector moves at the bottom

selection in menu depends on the value of int option

if button is pressed

reset flag

break the while loop, start game

enter settings menu

update joystick position

print settings menu

print settings menu

print settings menu

print settings menu

if selector is on the top of the screen and UP is pressed, selector goes to the bottom

if selector is on the bottom of the screen and DOWN is pressed, selector goes to the top

menu selection depends on the position of the Joystick

if button is pressed

reset button

if user selects to modify speed of the game

set speed of the game

print game speed menu

slow

normal

fast

Lcd inverse mode

select sound or not

go back to main menu

turn off LED

Definition at line 520 of file main.cpp.

void obstacles (  )

Locates obstacles in the screen.

place obstacles in the screen as level difficulty increases, more obstacles are added

obstacles are located in the ground and they change from one level to another

make obstacles moveable by adding a small random variance in position

check position of obstacle

assign states to the position of the obstacle

if state is 0 increase position on x-axis

else if state is 1 decrease position on x-axis

set poistion of obstacle on y-axis to be valuable

keep moving object within boundaries

draw obstacle

draw boundaries

draw moving obstacles on screen

draw stable obstacles

Definition at line 363 of file main.cpp.

DigitalOut r_led ( LED_RED   )

r_led

output for status of red LED

void sw2_isr (  )

Set-up flag to 1.

Definition at line 101 of file main.cpp.

void sw3_isr (  )

Set-up flag to 1.

Definition at line 106 of file main.cpp.

void timeout_isr (  )

Set-up flag to 1.

Definition at line 122 of file main.cpp.

void timer_isr (  )

Set-up flag to 1.

Set-up flag to 1

Definition at line 91 of file main.cpp.

void updateJoystick (  )

Update the values of the joystick to get current position.

Definition at line 489 of file main.cpp.


Variable Documentation

volatile int circleX

used to determine x-axis position of the circular enemy

Definition at line 284 of file main.h.

volatile int circleY

used to determine y-axis position of the circular enemy

Definition at line 286 of file main.h.

int fsm[4] = {7,6,4,0}

array of elements in the FSM, each element is the output of the counter

Definition at line 316 of file main.h.

int fsm_state = 0

variable is used to access the array of states and produce an output

Definition at line 318 of file main.h.

volatile int g_button1_flag = 0

set flag in the isr, event trigger interrupt

Definition at line 304 of file main.h.

volatile int g_button_flag = 0

set flag in the isr, event trigger interrupt

Definition at line 302 of file main.h.

volatile int g_game_timer_flag = 0

set timer flag in the isr, timer trigger interrupt

Definition at line 296 of file main.h.

volatile int g_sw2_flag = 0

set timer flag in the isr, event trigger interrupt

Definition at line 298 of file main.h.

volatile int g_sw3_flag = 0

set timer flag in the isr, event trigger interrupt

Definition at line 300 of file main.h.

volatile int g_timer_flag = 0

set timer flag in the isr, timer trigger interrupt

Definition at line 294 of file main.h.

volatile float game_speed = 0.05

value is set to the ticker, allows user to select game speed

Definition at line 314 of file main.h.

volatile int heroX

used to move the hero along x-axis

Definition at line 288 of file main.h.

volatile int heroY

used to move the hero along y-axis

Definition at line 290 of file main.h.

Joystick joystick

create struct variable

Definition at line 149 of file main.h.

volatile int level = 0

initiate the level difficulty of the game

Definition at line 292 of file main.h.

volatile int n

number of pixels overlapping

Definition at line 312 of file main.h.

bool normal = 0

controls the lcd mode selection on menu

Definition at line 334 of file main.h.

int objectX = 0

used to move obstacles in the x-axis

Definition at line 322 of file main.h.

int objectX1 = 58

used to move obstacles in the x-axis

Definition at line 328 of file main.h.

int objectY = 20

used to move obstacles in the y-axis

Definition at line 324 of file main.h.

volatile int option = 0

select option in menu based on Joystick's movement

Definition at line 306 of file main.h.

volatile int play = 0

counts the number of plays

Definition at line 308 of file main.h.

volatile int rectX

used to determine x-axis position of the rect enemy

Definition at line 280 of file main.h.

volatile int rectY

used to determine y-axis position of the rect enemy

Definition at line 282 of file main.h.

int reset = 0

used to save current level of difficulty

Definition at line 320 of file main.h.

bool sound = 0

determines if sound is on or off

Definition at line 336 of file main.h.

int speed = 1

controls the speed menu display

Definition at line 332 of file main.h.

int state = 0

controls the direction of the objtacle

Definition at line 326 of file main.h.

int state1 = 1

controls the direction of the objtacle

Definition at line 330 of file main.h.

volatile int tries = 3

counts the number of trials

Definition at line 310 of file main.h.