My ELEC2645 project. Nikollao Sulollari. 200804685
Dependencies: N5110 SoftPWM mbed
Fork of Treasure_Hunt by
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
Definition in file main.h.
Function Documentation
void calibrateJoystick | ( | ) |
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
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
void enemyCircle | ( | ) |
void enemyRect | ( | ) |
void enemyRocket | ( | ) |
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
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
void init_game | ( | ) |
void init_K64F | ( | ) |
int intersection | ( | int | i, |
int | j | ||
) |
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
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
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
DigitalOut r_led | ( | LED_RED | ) |
r_led
output for status of red LED
void updateJoystick | ( | ) |
Variable Documentation
volatile int circleX |
volatile int circleY |
int fsm[4] = {7,6,4,0} |
int fsm_state = 0 |
volatile int g_button1_flag = 0 |
volatile int g_button_flag = 0 |
volatile int g_game_timer_flag = 0 |
volatile int g_sw2_flag = 0 |
volatile int g_sw3_flag = 0 |
volatile int g_timer_flag = 0 |
volatile float game_speed = 0.05 |
volatile int level = 0 |
volatile int option = 0 |
volatile int rectX |
volatile int rectY |
Generated on Tue Jul 12 2022 18:32:59 by 1.7.2