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
Diff: main.cpp
- Revision:
- 5:eda40cdde3e7
- Parent:
- 4:ce4eea1c2a28
- Child:
- 6:8741d2011692
--- a/main.cpp Sun Mar 17 13:36:10 2019 +0000 +++ b/main.cpp Sun Mar 17 14:45:37 2019 +0000 @@ -9,48 +9,29 @@ #include "N5110.h" #include "Gamepad.h" #include "Skateboarder.h" +#include "Engine.h" #include <cmath> N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); Gamepad gamepad; -Skateboarder skater; +Engine game_engine; + void init_game(); -void process_inputs(); -void update_lcd(int x, int y, Sprite_value sprite); + int main(){ init_game(); - int moving_counter = 0; - int x; - int y; - int level = 0; - int jump_counter = 0; - Skate_Direction direction = Left; - Sprite_value sprite; - + while(1){ - lcd.clear(); - Vector2D coord = gamepad.get_mapped_coord(); - - if((x >= 1 && x <= 30 && y < 15) || (x >= 45 && x <= 80 && y < 15)){ - level = 1; - } else { - level = 0; - } - - skater.set_y_position( gamepad.check_event(Gamepad::A_PRESSED), jump_counter, level ); - y = skater.get_y_position(); - jump_counter = skater.get_jump_counter(); - - skater.set_x_position( coord.x, moving_counter, direction, coord.y ); - x = skater.get_x_position(); - moving_counter = skater.get_moving_counter(); - sprite = skater.get_sprite_value(); - direction = skater.get_direction(); - - update_lcd(x, y, sprite); + lcd.clear(); + game_engine.read_input(gamepad); + game_engine.find_level(); + game_engine.process_y(); + game_engine.process_x(); + game_engine.process_sprite(); + game_engine.update_lcd(lcd); lcd.refresh(); wait(0.01); @@ -59,17 +40,10 @@ void init_game() { gamepad.init(); + game_engine.init(); lcd.init(); lcd.setContrast(0.5); lcd.normalMode(); lcd.setBrightness(0.5); } - -void update_lcd(int x, int y, Sprite_value sprite) { - int* skate_sprite = skater.get_sprite(sprite); - lcd.drawSprite(x,y,17,10,(int *)skate_sprite); - lcd.drawLine(5,40,80,40,FILL_BLACK); - lcd.drawLine(5,22,30,22,FILL_BLACK); - lcd.drawLine(50,22,80,22,FILL_BLACK); -} - \ No newline at end of file +