Arturs Kozlovskis 201253737
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 /* 00002 ELEC2645 Embedded Systems Project 00003 School of Electronic & Electrical Engineering 00004 University of Leeds 00005 2019/20 00006 00007 Name:Arturs Kolovskis 00008 Username:el18ak 00009 Student ID Number: 201253737 00010 Date:08.03.2020 00011 */ 00012 00013 // includes 00014 #include "mbed.h" 00015 #include "Gamepad.h" 00016 #include "N5110.h" 00017 #include "Objects.h" 00018 #include "Functions.h" 00019 #include "Menu.h" 00020 00021 00022 // objects 00023 Gamepad pad; 00024 N5110 lcd; 00025 Menu menu(lcd,pad); 00026 00027 //functions 00028 void initialise(); 00029 void game(); 00030 00031 //variables 00032 bool game_check = false; 00033 int pause_return_value = 0; 00034 int game_return_value = 2; 00035 string game_speed; 00036 float extra_speed = 0.05; 00037 00038 int main() 00039 { 00040 initialise(); 00041 //creates the inital screen 00042 menu.first_screen(); 00043 //infinite game and menu loop 00044 while(1) { 00045 //menu 00046 menu.menu_screen(); 00047 //checks the game speed setting 00048 game_speed = menu.get_game_speed(); 00049 if (game_speed == "fast"){ 00050 extra_speed = 0.0f; 00051 }else{ 00052 //decreasesn the speed 00053 extra_speed = 0.05f; 00054 } 00055 //create the game 00056 game(); 00057 } 00058 } 00059 00060 void initialise() 00061 { 00062 pad.init();//initialises the gamepad 00063 lcd.init();//initialises the N5110 screen 00064 lcd.clear(); 00065 } 00066 00067 void game() 00068 { 00069 //creates class objects 00070 Objects objects; 00071 Functions functions; 00072 00073 //runs the game engine 00074 while(game_check == false) { 00075 00076 lcd.clear(); 00077 objects.draw_shots(lcd,pad, true);// draws the shot 00078 00079 //creates the balls and clears the shots 00080 functions.ball_creater_linear(lcd, objects, pad); 00081 functions.ball_creater_parabolic(lcd,objects,pad); 00082 00083 objects.draw_shots(lcd,pad, true);//again draws the shots so they would be visible on the screen 00084 functions.collision_checker(lcd,objects,pad);//cheks for the collisions 00085 objects.draw_base(lcd);//draws the base of the game 00086 objects.cannon_position(pad);//changes the cannon position 00087 objects.draw_cannon(lcd);//draws the cannon 00088 game_check = functions.cannon_smash(lcd, objects); //checks if the cannon has been hit by a ball 00089 lcd.refresh(); 00090 wait(0.1f + extra_speed); 00091 00092 //added this so the cannon moves faster than the balls 00093 lcd.clear(); 00094 objects.cannon_position(pad);//eveluates the cannon position 00095 objects.draw_cannon(lcd);//draws the cannon 00096 lcd.refresh(); 00097 wait(0.005); 00098 00099 //if a pressed display pause screen 00100 pause_return_value = menu.pause_screen(functions.get_score()); 00101 if(pause_return_value == 1) { 00102 break; 00103 } 00104 } 00105 00106 if(pause_return_value == 0) { 00107 //prints the the score and game over 00108 game_return_value = menu.game_over_screen(functions.get_score()); 00109 if (game_return_value == 2) { 00110 game_check = false; 00111 } 00112 } 00113 }
Generated on Thu Jul 14 2022 06:47:19 by
1.7.2