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 MotionSensor
Title/Title.cpp@48:f7d9ae3e554d, 2019-05-09 (annotated)
- Committer:
- el17sm
- Date:
- Thu May 09 02:46:44 2019 +0000
- Revision:
- 48:f7d9ae3e554d
- Parent:
- 47:6e31b195ce3c
- Child:
- 49:3f83ed62d123
Cleaned Main and title
Who changed what in which revision?
| User | Revision | Line number | New 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 | title_options_joystick(gamepad); |
| el17sm | 32:fe6359ef9916 | 25 | title_count++; |
| el17sm | 32:fe6359ef9916 | 26 | wait_ms(1000/40); // 1s/framerate |
| el17sm | 32:fe6359ef9916 | 27 | } |
| el17sm | 32:fe6359ef9916 | 28 | while(gamepad.check_event(Gamepad::A_PRESSED)){} |
| el17sm | 48:f7d9ae3e554d | 29 | |
| el17sm | 48:f7d9ae3e554d | 30 | if(title_option == 0) { break; // Start game, exit title loop |
| el17sm | 48:f7d9ae3e554d | 31 | } else if (title_option == 1) { title_option_option(lcd, gamepad, player, global_contrast); |
| el17sm | 48:f7d9ae3e554d | 32 | } else if (title_option == 2) { title_option_credit(lcd, gamepad); |
| el17sm | 48:f7d9ae3e554d | 33 | } else if (title_option == 3) { title_option_tutorial(lcd, gamepad); |
| el17sm | 32:fe6359ef9916 | 34 | } |
| el17sm | 32:fe6359ef9916 | 35 | } |
| el17sm | 40:cbcbf6fc1421 | 36 | player.~Player(); |
| el17sm | 32:fe6359ef9916 | 37 | } |
| el17sm | 32:fe6359ef9916 | 38 | |
| el17sm | 32:fe6359ef9916 | 39 | void Title::draw_title_screen(N5110 &lcd) |
| el17sm | 32:fe6359ef9916 | 40 | { |
| el17sm | 33:4f3948dcd2f7 | 41 | lcd.drawSprite(11, 4, 15, 44, (char *)title_name_0); |
| el17sm | 33:4f3948dcd2f7 | 42 | lcd.drawSpriteTransparent(19, 14, 17, 53, (char *)title_name_1); |
| el17sm | 32:fe6359ef9916 | 43 | lcd.drawCircle(79, 7, 10, FILL_BLACK); |
| el17sm | 32:fe6359ef9916 | 44 | lcd.drawCircle(81, 5, 8, FILL_WHITE); |
| el17sm | 33:4f3948dcd2f7 | 45 | lcd.drawSprite(56, 6, 11, 5, (char *)star_sprite[abs(((title_count/20) % 7) - 3)]); |
| el17sm | 33:4f3948dcd2f7 | 46 | lcd.drawSprite(12, 34, 8, 8, (char *)button_A_sprite); |
| el17sm | 33:4f3948dcd2f7 | 47 | lcd.drawSprite(22, 37, 3, 2, (char *)arrow_left_sprite); |
| el17sm | 33:4f3948dcd2f7 | 48 | lcd.drawSprite(59, 37, 3, 2, (char *)arrow_right_sprite); |
| el17sm | 33:4f3948dcd2f7 | 49 | lcd.drawSprite(69, 31, 12, 6, (char *)sprite_player[(title_count/40) % 4][(title_count/10) % 4]); |
| el17sm | 33:4f3948dcd2f7 | 50 | lcd.drawSprite(26, 35, 9, 32, (char *)title_options_sprite[title_option]); |
| el17sm | 32:fe6359ef9916 | 51 | } |
| el17sm | 32:fe6359ef9916 | 52 | |
| el17sm | 32:fe6359ef9916 | 53 | void Title::title_options_joystick(Gamepad &gamepad) |
| el17sm | 32:fe6359ef9916 | 54 | { |
| el17sm | 32:fe6359ef9916 | 55 | if ((gamepad.get_direction() == 3) && (cursor_timer > 20)) { // Detect Joystick going right |
| el17sm | 32:fe6359ef9916 | 56 | cursor_timer = 0; |
| el17sm | 32:fe6359ef9916 | 57 | if (title_option >= 3) { |
| el17sm | 32:fe6359ef9916 | 58 | title_option = 0; |
| el17sm | 32:fe6359ef9916 | 59 | } else { |
| el17sm | 32:fe6359ef9916 | 60 | title_option++; |
| el17sm | 32:fe6359ef9916 | 61 | } |
| el17sm | 32:fe6359ef9916 | 62 | } else if ((gamepad.get_direction() == 7) && (cursor_timer > 20)) { // Detect Joystick going left |
| el17sm | 32:fe6359ef9916 | 63 | cursor_timer = 0; |
| el17sm | 32:fe6359ef9916 | 64 | if (title_option <= 0) { |
| el17sm | 32:fe6359ef9916 | 65 | title_option = 3; |
| el17sm | 32:fe6359ef9916 | 66 | } else { |
| el17sm | 32:fe6359ef9916 | 67 | title_option--; |
| el17sm | 32:fe6359ef9916 | 68 | } |
| el17sm | 32:fe6359ef9916 | 69 | } |
| el17sm | 32:fe6359ef9916 | 70 | cursor_timer++; |
| el17sm | 32:fe6359ef9916 | 71 | } |
| el17sm | 32:fe6359ef9916 | 72 | |
| el17sm | 32:fe6359ef9916 | 73 | void Title::title_option_option(N5110 &lcd, Gamepad &gamepad, Player &player, float &global_contrast) |
| el17sm | 32:fe6359ef9916 | 74 | { |
| el17sm | 32:fe6359ef9916 | 75 | while(!gamepad.check_event(Gamepad::A_PRESSED)) { |
| el17sm | 32:fe6359ef9916 | 76 | global_contrast = gamepad.read_pot(); |
| el17sm | 32:fe6359ef9916 | 77 | lcd.setContrast(global_contrast); |
| el17sm | 32:fe6359ef9916 | 78 | lcd.clear(); |
| el17sm | 32:fe6359ef9916 | 79 | lcd.printString("Set contrast", 0, 0); |
| el17sm | 32:fe6359ef9916 | 80 | lcd.printString("using the", 0, 1); |
| el17sm | 32:fe6359ef9916 | 81 | lcd.printString("potentiometer", 0, 2); |
| el17sm | 32:fe6359ef9916 | 82 | player.draw(lcd); |
| el17sm | 45:8725b4171646 | 83 | player.draw_bullets(lcd, player.get_pos_y() + 2); |
| el17sm | 32:fe6359ef9916 | 84 | lcd.refresh(); |
| el17sm | 48:f7d9ae3e554d | 85 | player.move(1, 0, (char *)level_map[0][0], (bool *)sprite_transparent_player); // Adding animation of walking |
| el17sm | 48:f7d9ae3e554d | 86 | player.undo_move_x(true); // Keeping the player in place |
| el17sm | 48:f7d9ae3e554d | 87 | player.buttons(false, true, false, false); // Instructing player to shoot right |
| el17sm | 48:f7d9ae3e554d | 88 | player.update_bullets((char *)level_map[0][0], (bool *)sprite_transparent_player); // Move the bullets and delete those out of the screen |
| el17sm | 32:fe6359ef9916 | 89 | wait_ms(1000/40); |
| el17sm | 32:fe6359ef9916 | 90 | } |
| el17sm | 32:fe6359ef9916 | 91 | wait(0.05); |
| el17sm | 48:f7d9ae3e554d | 92 | while(gamepad.check_event(Gamepad::A_PRESSED)) {} |
| el17sm | 32:fe6359ef9916 | 93 | } |
| el17sm | 32:fe6359ef9916 | 94 | |
| el17sm | 32:fe6359ef9916 | 95 | void Title::title_option_credit(N5110 &lcd, Gamepad &gamepad) |
| el17sm | 32:fe6359ef9916 | 96 | { |
| el17sm | 32:fe6359ef9916 | 97 | lcd.clear(); |
| el17sm | 32:fe6359ef9916 | 98 | lcd.printString("Made by:", 0, 0); |
| el17sm | 32:fe6359ef9916 | 99 | lcd.printString("Steven Mahasin", 0, 1); |
| el17sm | 32:fe6359ef9916 | 100 | lcd.printString("201192939", 0, 2); |
| el17sm | 32:fe6359ef9916 | 101 | lcd.refresh(); |
| el17sm | 32:fe6359ef9916 | 102 | wait(0.05); |
| el17sm | 32:fe6359ef9916 | 103 | while(!gamepad.check_event(Gamepad::A_PRESSED)) { |
| el17sm | 32:fe6359ef9916 | 104 | } |
| 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 | } |
| el17sm | 32:fe6359ef9916 | 109 | |
| el17sm | 47:6e31b195ce3c | 110 | void Title::title_option_tutorial(N5110 &lcd, Gamepad &gamepad) |
| el17sm | 32:fe6359ef9916 | 111 | { |
| el17sm | 48:f7d9ae3e554d | 112 | print_tutorial_page_0(lcd); // print page 0 and wait for button toggle |
| el17sm | 48:f7d9ae3e554d | 113 | wait(0.05); |
| el17sm | 48:f7d9ae3e554d | 114 | while(!gamepad.check_event(Gamepad::A_PRESSED)) {} |
| el17sm | 48:f7d9ae3e554d | 115 | wait(0.05); |
| el17sm | 48:f7d9ae3e554d | 116 | while(gamepad.check_event(Gamepad::A_PRESSED)) {} |
| el17sm | 48:f7d9ae3e554d | 117 | print_tutorial_page_1(lcd); // print page 1 and wait for button toggle |
| el17sm | 48:f7d9ae3e554d | 118 | wait(0.05); |
| el17sm | 48:f7d9ae3e554d | 119 | while(!gamepad.check_event(Gamepad::A_PRESSED)) {} |
| el17sm | 48:f7d9ae3e554d | 120 | wait(0.05); |
| el17sm | 48:f7d9ae3e554d | 121 | while(gamepad.check_event(Gamepad::A_PRESSED)) {} |
| el17sm | 48:f7d9ae3e554d | 122 | print_tutorial_page_2(lcd); // print page 2 and wait for button toggle |
| el17sm | 48:f7d9ae3e554d | 123 | wait(0.05); |
| el17sm | 48:f7d9ae3e554d | 124 | while(!gamepad.check_event(Gamepad::A_PRESSED)) {} |
| el17sm | 48:f7d9ae3e554d | 125 | wait(0.05); |
| el17sm | 48:f7d9ae3e554d | 126 | while(gamepad.check_event(Gamepad::A_PRESSED)) {} |
| el17sm | 48:f7d9ae3e554d | 127 | } |
| el17sm | 48:f7d9ae3e554d | 128 | |
| el17sm | 48:f7d9ae3e554d | 129 | void Title::print_tutorial_page_0(N5110 &lcd) |
| el17sm | 48:f7d9ae3e554d | 130 | { |
| el17sm | 47:6e31b195ce3c | 131 | lcd.clear(); |
| el17sm | 47:6e31b195ce3c | 132 | lcd.printString("Use the joypad", 0, 0); |
| el17sm | 47:6e31b195ce3c | 133 | lcd.printString("to move the", 0, 1); |
| el17sm | 47:6e31b195ce3c | 134 | lcd.printString("player", 0, 2); |
| el17sm | 47:6e31b195ce3c | 135 | lcd.printString("Use buttons", 0, 3); |
| el17sm | 47:6e31b195ce3c | 136 | lcd.printString("ABXY to shoot", 0, 4); |
| el17sm | 47:6e31b195ce3c | 137 | lcd.printString("directionally", 0, 5); |
| el17sm | 47:6e31b195ce3c | 138 | lcd.refresh(); |
| el17sm | 48:f7d9ae3e554d | 139 | } |
| el17sm | 48:f7d9ae3e554d | 140 | |
| el17sm | 48:f7d9ae3e554d | 141 | void Title::print_tutorial_page_1(N5110 &lcd) |
| el17sm | 48:f7d9ae3e554d | 142 | { |
| el17sm | 47:6e31b195ce3c | 143 | lcd.clear(); |
| el17sm | 47:6e31b195ce3c | 144 | lcd.printString("Hold L to", 0, 0); |
| el17sm | 47:6e31b195ce3c | 145 | lcd.printString("show player", 0, 1); |
| el17sm | 47:6e31b195ce3c | 146 | lcd.printString("health", 0, 2); |
| el17sm | 47:6e31b195ce3c | 147 | lcd.printString("Hold Back", 0, 3); |
| el17sm | 47:6e31b195ce3c | 148 | lcd.printString("to view a", 0, 4); |
| el17sm | 47:6e31b195ce3c | 149 | lcd.printString("minimap", 0, 5); |
| el17sm | 47:6e31b195ce3c | 150 | lcd.refresh(); |
| el17sm | 48:f7d9ae3e554d | 151 | } |
| el17sm | 48:f7d9ae3e554d | 152 | |
| el17sm | 48:f7d9ae3e554d | 153 | void Title::print_tutorial_page_2(N5110 &lcd) |
| el17sm | 48:f7d9ae3e554d | 154 | { |
| el17sm | 47:6e31b195ce3c | 155 | lcd.clear(); |
| el17sm | 47:6e31b195ce3c | 156 | lcd.printString("Press Start", 0, 0); |
| el17sm | 47:6e31b195ce3c | 157 | lcd.printString("to pause", 0, 1); |
| el17sm | 47:6e31b195ce3c | 158 | lcd.printString("the game", 0, 2); |
| el17sm | 47:6e31b195ce3c | 159 | lcd.refresh(); |
| el17sm | 48:f7d9ae3e554d | 160 | } |