A rouge-like rpg, heavily inspired on the binding of isaac. Running on a FRDM-K64F Mbed board. C++.
Dependencies: mbed MotionSensor
Diff: main.cpp
- Revision:
- 32:fe6359ef9916
- Parent:
- 31:ab24d028ddfd
- Child:
- 36:92d131695e7c
--- a/main.cpp Sun May 05 18:37:23 2019 +0000 +++ b/main.cpp Mon May 06 08:56:48 2019 +0000 @@ -19,37 +19,27 @@ #include "Headless.h" #include "Snake.h" #include "RoomEngine.h" -#include <time.h> +#include "Title.h" #define INSIDE 4 #define MAX_ROOMS_MAP_X 11 #define MAX_ROOMS_MAP_Y 11 // Variables -int title_count = 0; -int cursor_timer = 20; -int title_option = 0; float global_contrast = 0.5; +Player *player; +Room *rooms[MAX_ROOMS_MAP_Y][MAX_ROOMS_MAP_X]; +RoomEngine *room_engine; // Objects N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); Gamepad gamepad; +Title title; // Prototypes -void title_screen(); -void draw_title_screen(N5110 &lcd); -void title_options_joystick(Gamepad &gamepad); - -void title_option_option(); -void title_option_credit(); -void title_option_hi_scores(); void game_loop(); void game_over(); -Player *player; -Room *rooms[MAX_ROOMS_MAP_Y][MAX_ROOMS_MAP_X]; -RoomEngine *room_engine; -// Functions int main() { // Initialize @@ -59,11 +49,10 @@ while(1) { // Gameloop - player = new Player(5, 36); - title_screen(); + title.main(lcd, gamepad, global_contrast); delete player; - srand(title_count); + srand(title.get_seed()); player = new Player(39, 27); room_engine = new RoomEngine(global_contrast); @@ -74,108 +63,6 @@ } } -void draw_title_screen(N5110 &lcd) -{ - lcd.drawSprite(11, 4, 15, 44, (int *)title_name_0); - lcd.drawSpriteTransparent(19, 14, 17, 53, (int *)title_name_1); - lcd.drawCircle(79, 7, 10, FILL_BLACK); - lcd.drawCircle(81, 5, 8, FILL_WHITE); - lcd.drawSprite(56, 6, 11, 5, (int *)star_sprite[abs(((title_count/20) % 7) - 3)]); - lcd.drawSprite(12, 34, 8, 8, (int *)button_A_sprite); - lcd.drawSprite(22, 37, 3, 2, (int *)arrow_left_sprite); - lcd.drawSprite(59, 37, 3, 2, (int *)arrow_right_sprite); - lcd.drawSprite(69, 31, 12, 6, (int *)sprite_player[(title_count/40) % 4][(title_count/10) % 4]); - lcd.drawSprite(26, 35, 9, 32, (int *)title_options_sprite[title_option]); -} - -void title_options_joystick(Gamepad &gamepad) -{ - if ((gamepad.get_direction() == 3) && (cursor_timer > 20)) { // Detect Joystick going right - cursor_timer = 0; - if (title_option >= 3) { - title_option = 0; - } else { - title_option++; - } - } else if ((gamepad.get_direction() == 7) && (cursor_timer > 20)) { // Detect Joystick going left - cursor_timer = 0; - if (title_option <= 0) { - title_option = 3; - } else { - title_option--; - } - } - cursor_timer++; -} - -void title_screen() -{ - while(1){ // Title Screen Loop - title_option = 0; - while(!gamepad.check_event(Gamepad::A_PRESSED)){ - lcd.clear(); - draw_title_screen(lcd); - lcd.refresh(); - - title_options_joystick(gamepad); - - title_count++; - wait_ms(1000/40); // 1s/framerate - } - while(gamepad.check_event(Gamepad::A_PRESSED)){} - if(title_option == 0) { - break; - } else if (title_option == 1) { - while(!gamepad.check_event(Gamepad::A_PRESSED)) { - title_option_option(); - } - wait(0.05); - while(gamepad.check_event(Gamepad::A_PRESSED)) { - } - } else if (title_option == 2) { - title_option_credit(); - wait(0.05); - while(!gamepad.check_event(Gamepad::A_PRESSED)) { - } - wait(0.05); - while(gamepad.check_event(Gamepad::A_PRESSED)) { - } - } else if (title_option == 3) { - - } - } -} - -void title_option_option() -{ - global_contrast = gamepad.read_pot(); - lcd.setContrast(global_contrast); - lcd.clear(); - lcd.printString("Set contrast", 0, 0); - lcd.printString("using the", 0, 1); - lcd.printString("potentiometer", 0, 2); - player->draw(lcd); - lcd.refresh(); - player->move(1, 0, (int *)level_map[0][0], (bool *)sprite_transparent_player); - player->buttons(false, true, false, false); - player->update_bullets((int *)level_map[0][0], (bool *)sprite_transparent_player); - wait_ms(1000/40); -} - -void title_option_credit() -{ - lcd.clear(); - lcd.setContrast(global_contrast); - lcd.printString("Made by:", 0, 0); - lcd.printString("Steven Mahasin", 0, 1); - lcd.printString("201192939", 0, 2); - lcd.refresh(); -} -void title_option_hi_scores() -{ - -} - void game_loop() { while(1) { // Floor Loop