Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
EngineController.cpp
00001 #include "EngineController.h" 00002 00003 // Define sprite array. 00004 int intro_text[12][42] = { 00005 { 1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 00006 1,1,1,1 }, 00007 { 1,1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 00008 1,1,1,1 }, 00009 { 1,1,0,0,0,0,0,1,1,0,0,1,1,0,1,1,0,0,0,1,1,0,0,1,1,0,0,0,1,1,0,0,0,0,0,1,1,0, 00010 0,0,1,1 }, 00011 { 1,1,0,0,0,0,0,1,1,0,1,1,1,0,1,1,0,0,0,1,1,0,0,1,1,0,0,0,1,1,0,0,0,0,0,1,1,0, 00012 0,0,1,1 }, 00013 { 1,1,0,0,0,0,0,1,1,0,1,1,0,0,1,1,1,1,1,1,1,0,0,1,1,0,0,0,1,1,0,0,0,0,0,1,1,1, 00014 1,1,1,1 }, 00015 { 1,1,1,1,1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,0,0,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1, 00016 1,1,1,1 }, 00017 { 1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,0,0,0,1,1,0,0,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1, 00018 1,0,0,0 }, 00019 { 0,0,0,0,0,1,1,1,1,1,1,1,0,0,1,1,0,0,0,1,1,0,0,1,1,0,0,0,1,1,0,0,0,0,0,1,1,1, 00020 1,0,0,0 }, 00021 { 0,0,0,0,0,1,1,1,1,0,1,1,1,0,1,1,0,0,0,1,1,0,0,1,1,0,0,0,1,1,0,0,0,0,0,1,1,0, 00022 1,1,0,0 }, 00023 { 0,0,0,0,0,1,1,1,1,0,0,1,1,1,1,1,0,0,0,1,1,0,0,1,1,0,0,0,1,1,0,0,0,0,0,1,1,0, 00024 1,1,0,0 }, 00025 { 1,1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,0,0,0,1,1,0,0,1,1,0,0,0,1,1,1,1,1,1,1,1,1,0, 00026 1,1,1,0 }, 00027 { 1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,0,0,0,1,1,0,0,1,1,0,0,0,1,1,1,1,1,1,1,1,1,0, 00028 1,1,1,1 } 00029 }; 00030 00031 // Constructor and destructor. 00032 EngineController::EngineController() {} 00033 00034 EngineController::~EngineController() {} 00035 00036 void EngineController::init() { 00037 // Statrting values for the controller. 00038 _game_engine.init(); 00039 _game_counter = 0; 00040 _speed_divider = 10; 00041 _start_platform_flag = true; 00042 _change_speed_flag = false; 00043 } 00044 00045 void EngineController::run_game_engine(N5110 &lcd, Gamepad &gamepad) { 00046 // The main game loop. 00047 check_for_start(lcd, gamepad); // Check to see if it should print starting 00048 // text. 00049 if (_game_counter == 100) _game_counter = 0; 00050 update_game(lcd, gamepad); 00051 if (_game_counter % _speed_divider == 0) 00052 _game_engine.generate_level(_game_counter); // Level speed is determined by 00053 // speed divider. 00054 _game_counter++; 00055 _player_score = _game_engine.get_player_score(); 00056 _speed_divider = int(-0.25*_player_score + 10); // Speed divider is dependent 00057 // on how many coins you have 00058 } 00059 00060 void EngineController::check_for_start(N5110 &lcd, Gamepad &gamepad) { 00061 // Print the intro text if the game has just started or jump has not been 00062 // pressed. 00063 if (_start_platform_flag) print_intro_text(lcd); 00064 _game_engine.check_reset(lcd, gamepad); // Resets the game if skater has 00065 // died. 00066 _start_platform_flag = _game_engine.get_start_platform_flag(); // Returns 00067 // false when jump is pressed. 00068 } 00069 00070 void EngineController::print_intro_text(N5110 &lcd) { 00071 lcd.drawLine(0,17,80,17,FILL_WHITE); 00072 lcd.drawSprite(40,4,12,42,(int *)intro_text); 00073 } 00074 00075 void EngineController::update_game(N5110 &lcd, Gamepad &gamepad) { 00076 // Run the game engine. 00077 _game_engine.read_input(gamepad); 00078 _game_engine.set_level_condition(); // Determines if the skater is under 00079 // upper platforms. 00080 _game_engine.process_y(gamepad); 00081 _game_engine.process_x(_game_counter); 00082 _game_engine.process_sprite(); 00083 _game_engine.check_coin_collision(gamepad); 00084 _game_engine.check_fire_collision(gamepad, _game_counter); 00085 _game_engine.update_lcd(lcd, _game_counter); 00086 } 00087
Generated on Mon Jul 18 2022 14:06:02 by
 1.7.2