Steven Mahasin / Mbed 2 deprecated DreamDungeon

Dependencies:   mbed MotionSensor

Committer:
el17sm
Date:
Mon May 06 08:56:48 2019 +0000
Revision:
32:fe6359ef9916
Child:
33:4f3948dcd2f7
A bit of code cleanup;; Draw functions are now inside the classes;; Moved classes into it's folders;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
el17sm 32:fe6359ef9916 1 #include "Title.h"
el17sm 32:fe6359ef9916 2
el17sm 32:fe6359ef9916 3 Title::Title()
el17sm 32:fe6359ef9916 4 {
el17sm 32:fe6359ef9916 5 title_count = 0;
el17sm 32:fe6359ef9916 6 cursor_timer = 20;
el17sm 32:fe6359ef9916 7 title_option = 0;
el17sm 32:fe6359ef9916 8 }
el17sm 32:fe6359ef9916 9
el17sm 32:fe6359ef9916 10 int Title::get_seed()
el17sm 32:fe6359ef9916 11 {
el17sm 32:fe6359ef9916 12 return title_count;
el17sm 32:fe6359ef9916 13 }
el17sm 32:fe6359ef9916 14
el17sm 32:fe6359ef9916 15 void Title::main(N5110 &lcd, Gamepad &gamepad, float &global_contrast)
el17sm 32:fe6359ef9916 16 {
el17sm 32:fe6359ef9916 17 Player player(5, 36);
el17sm 32:fe6359ef9916 18 while(1){ // Title Screen Loop
el17sm 32:fe6359ef9916 19 title_option = 0;
el17sm 32:fe6359ef9916 20 while(!gamepad.check_event(Gamepad::A_PRESSED)){
el17sm 32:fe6359ef9916 21 lcd.clear();
el17sm 32:fe6359ef9916 22 draw_title_screen(lcd);
el17sm 32:fe6359ef9916 23 lcd.refresh();
el17sm 32:fe6359ef9916 24
el17sm 32:fe6359ef9916 25 title_options_joystick(gamepad);
el17sm 32:fe6359ef9916 26
el17sm 32:fe6359ef9916 27 title_count++;
el17sm 32:fe6359ef9916 28 wait_ms(1000/40); // 1s/framerate
el17sm 32:fe6359ef9916 29 }
el17sm 32:fe6359ef9916 30 while(gamepad.check_event(Gamepad::A_PRESSED)){}
el17sm 32:fe6359ef9916 31 if(title_option == 0) {
el17sm 32:fe6359ef9916 32 break;
el17sm 32:fe6359ef9916 33 } else if (title_option == 1) {
el17sm 32:fe6359ef9916 34 title_option_option(lcd, gamepad, player, global_contrast);
el17sm 32:fe6359ef9916 35 } else if (title_option == 2) {
el17sm 32:fe6359ef9916 36 title_option_credit(lcd, gamepad);
el17sm 32:fe6359ef9916 37 } else if (title_option == 3) {
el17sm 32:fe6359ef9916 38 title_option_hi_scores(lcd);
el17sm 32:fe6359ef9916 39 }
el17sm 32:fe6359ef9916 40 }
el17sm 32:fe6359ef9916 41 }
el17sm 32:fe6359ef9916 42
el17sm 32:fe6359ef9916 43 void Title::draw_title_screen(N5110 &lcd)
el17sm 32:fe6359ef9916 44 {
el17sm 32:fe6359ef9916 45 lcd.drawSprite(11, 4, 15, 44, (int *)title_name_0);
el17sm 32:fe6359ef9916 46 lcd.drawSpriteTransparent(19, 14, 17, 53, (int *)title_name_1);
el17sm 32:fe6359ef9916 47 lcd.drawCircle(79, 7, 10, FILL_BLACK);
el17sm 32:fe6359ef9916 48 lcd.drawCircle(81, 5, 8, FILL_WHITE);
el17sm 32:fe6359ef9916 49 lcd.drawSprite(56, 6, 11, 5, (int *)star_sprite[abs(((title_count/20) % 7) - 3)]);
el17sm 32:fe6359ef9916 50 lcd.drawSprite(12, 34, 8, 8, (int *)button_A_sprite);
el17sm 32:fe6359ef9916 51 lcd.drawSprite(22, 37, 3, 2, (int *)arrow_left_sprite);
el17sm 32:fe6359ef9916 52 lcd.drawSprite(59, 37, 3, 2, (int *)arrow_right_sprite);
el17sm 32:fe6359ef9916 53 lcd.drawSprite(69, 31, 12, 6, (int *)sprite_player[(title_count/40) % 4][(title_count/10) % 4]);
el17sm 32:fe6359ef9916 54 lcd.drawSprite(26, 35, 9, 32, (int *)title_options_sprite[title_option]);
el17sm 32:fe6359ef9916 55 }
el17sm 32:fe6359ef9916 56
el17sm 32:fe6359ef9916 57 void Title::title_options_joystick(Gamepad &gamepad)
el17sm 32:fe6359ef9916 58 {
el17sm 32:fe6359ef9916 59 if ((gamepad.get_direction() == 3) && (cursor_timer > 20)) { // Detect Joystick going right
el17sm 32:fe6359ef9916 60 cursor_timer = 0;
el17sm 32:fe6359ef9916 61 if (title_option >= 3) {
el17sm 32:fe6359ef9916 62 title_option = 0;
el17sm 32:fe6359ef9916 63 } else {
el17sm 32:fe6359ef9916 64 title_option++;
el17sm 32:fe6359ef9916 65 }
el17sm 32:fe6359ef9916 66 } else if ((gamepad.get_direction() == 7) && (cursor_timer > 20)) { // Detect Joystick going left
el17sm 32:fe6359ef9916 67 cursor_timer = 0;
el17sm 32:fe6359ef9916 68 if (title_option <= 0) {
el17sm 32:fe6359ef9916 69 title_option = 3;
el17sm 32:fe6359ef9916 70 } else {
el17sm 32:fe6359ef9916 71 title_option--;
el17sm 32:fe6359ef9916 72 }
el17sm 32:fe6359ef9916 73 }
el17sm 32:fe6359ef9916 74 cursor_timer++;
el17sm 32:fe6359ef9916 75 }
el17sm 32:fe6359ef9916 76
el17sm 32:fe6359ef9916 77 void Title::title_option_option(N5110 &lcd, Gamepad &gamepad, Player &player, float &global_contrast)
el17sm 32:fe6359ef9916 78 {
el17sm 32:fe6359ef9916 79 while(!gamepad.check_event(Gamepad::A_PRESSED)) {
el17sm 32:fe6359ef9916 80 global_contrast = gamepad.read_pot();
el17sm 32:fe6359ef9916 81 lcd.setContrast(global_contrast);
el17sm 32:fe6359ef9916 82 lcd.clear();
el17sm 32:fe6359ef9916 83 lcd.printString("Set contrast", 0, 0);
el17sm 32:fe6359ef9916 84 lcd.printString("using the", 0, 1);
el17sm 32:fe6359ef9916 85 lcd.printString("potentiometer", 0, 2);
el17sm 32:fe6359ef9916 86 player.draw(lcd);
el17sm 32:fe6359ef9916 87 lcd.refresh();
el17sm 32:fe6359ef9916 88 player.move(1, 0, (int *)level_map[0][0], (bool *)sprite_transparent_player);
el17sm 32:fe6359ef9916 89 player.buttons(false, true, false, false);
el17sm 32:fe6359ef9916 90 player.update_bullets((int *)level_map[0][0], (bool *)sprite_transparent_player);
el17sm 32:fe6359ef9916 91 wait_ms(1000/40);
el17sm 32:fe6359ef9916 92 }
el17sm 32:fe6359ef9916 93 wait(0.05);
el17sm 32:fe6359ef9916 94 while(gamepad.check_event(Gamepad::A_PRESSED)) {
el17sm 32:fe6359ef9916 95 }
el17sm 32:fe6359ef9916 96 }
el17sm 32:fe6359ef9916 97
el17sm 32:fe6359ef9916 98 void Title::title_option_credit(N5110 &lcd, Gamepad &gamepad)
el17sm 32:fe6359ef9916 99 {
el17sm 32:fe6359ef9916 100 lcd.clear();
el17sm 32:fe6359ef9916 101 lcd.printString("Made by:", 0, 0);
el17sm 32:fe6359ef9916 102 lcd.printString("Steven Mahasin", 0, 1);
el17sm 32:fe6359ef9916 103 lcd.printString("201192939", 0, 2);
el17sm 32:fe6359ef9916 104 lcd.refresh();
el17sm 32:fe6359ef9916 105 wait(0.05);
el17sm 32:fe6359ef9916 106 while(!gamepad.check_event(Gamepad::A_PRESSED)) {
el17sm 32:fe6359ef9916 107 }
el17sm 32:fe6359ef9916 108 wait(0.05);
el17sm 32:fe6359ef9916 109 while(gamepad.check_event(Gamepad::A_PRESSED)) {
el17sm 32:fe6359ef9916 110 }
el17sm 32:fe6359ef9916 111 }
el17sm 32:fe6359ef9916 112
el17sm 32:fe6359ef9916 113 void Title::title_option_hi_scores(N5110 &lcd)
el17sm 32:fe6359ef9916 114 {
el17sm 32:fe6359ef9916 115
el17sm 32:fe6359ef9916 116 }