Game codes for Pokemon Academy Yiu Fai Kwok - 201198802 I have read the University Regulations on Plagiarism and state that the work covered by this declaration is my own and does not contain any unacknowledged work from other sources.
Dependencies: mbed FXOS8700CQ mbed-rtos
Start/Start.cpp@17:5d8ff39a0e49, 2019-04-21 (annotated)
- Committer:
- yfkwok
- Date:
- Sun Apr 21 11:02:28 2019 +0000
- Revision:
- 17:5d8ff39a0e49
- Parent:
- 11:5a6b9dffd78a
- Child:
- 32:58def659f463
21/04/2019 - Add Doxygen comments for the following classes: Exam, Characters, Score and Start
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yfkwok | 2:464c7e62d97d | 1 | #include "Start.h" |
yfkwok | 2:464c7e62d97d | 2 | |
yfkwok | 2:464c7e62d97d | 3 | Start::Start() |
yfkwok | 2:464c7e62d97d | 4 | { |
yfkwok | 2:464c7e62d97d | 5 | |
yfkwok | 2:464c7e62d97d | 6 | } |
yfkwok | 2:464c7e62d97d | 7 | |
yfkwok | 2:464c7e62d97d | 8 | Start::~Start() |
yfkwok | 2:464c7e62d97d | 9 | { |
yfkwok | 2:464c7e62d97d | 10 | |
yfkwok | 2:464c7e62d97d | 11 | } |
yfkwok | 2:464c7e62d97d | 12 | |
yfkwok | 5:bc0691d02fd5 | 13 | void Start::init(Gamepad &pad) |
yfkwok | 2:464c7e62d97d | 14 | { |
yfkwok | 17:5d8ff39a0e49 | 15 | // Initialize the positions for all objects |
yfkwok | 2:464c7e62d97d | 16 | _pos_x = 2; |
yfkwok | 2:464c7e62d97d | 17 | _pos_y = 8; |
yfkwok | 2:464c7e62d97d | 18 | _pos_cy = 5; |
yfkwok | 2:464c7e62d97d | 19 | _pos_sy = 9; |
yfkwok | 2:464c7e62d97d | 20 | _pos_by = 13; |
yfkwok | 2:464c7e62d97d | 21 | _alt = 0; |
yfkwok | 5:bc0691d02fd5 | 22 | pad.init(); |
yfkwok | 2:464c7e62d97d | 23 | } |
yfkwok | 2:464c7e62d97d | 24 | |
yfkwok | 2:464c7e62d97d | 25 | void Start::starter_draw(N5110 &lcd) |
yfkwok | 2:464c7e62d97d | 26 | { |
yfkwok | 2:464c7e62d97d | 27 | lcd.clear(); |
yfkwok | 2:464c7e62d97d | 28 | _c1.draw_cha1_sprite(60, _pos_cy, lcd); |
yfkwok | 2:464c7e62d97d | 29 | _s1.draw_cha1_sprite(32, _pos_sy, lcd); |
yfkwok | 2:464c7e62d97d | 30 | _b1.draw_cha1_sprite(4, _pos_by, lcd); |
yfkwok | 2:464c7e62d97d | 31 | lcd.drawRect(_pos_x, _pos_y, 25, 25, FILL_TRANSPARENT); |
yfkwok | 11:5a6b9dffd78a | 32 | int instruct_data[15][69] = { |
yfkwok | 11:5a6b9dffd78a | 33 | {1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0}, |
yfkwok | 11:5a6b9dffd78a | 34 | {1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0}, |
yfkwok | 11:5a6b9dffd78a | 35 | {1,0,0,1,0,1,1,1,1,0,1,1,1,1,0,1,1,1,1,0,1,1,1,1,0,0,0,0,1,0,0,1,0,0,0,0,1,1,1,0,1,1,1,1,0,1,1,1,1,0,0,0,0,1,0,1,1,1,1,0,1,1,1,0,1,1,1,1,0}, |
yfkwok | 11:5a6b9dffd78a | 36 | {1,1,1,1,0,1,0,0,1,0,1,0,0,1,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,1,0,0,1,0,0,1,0,1,0,0,1,0,0,0,0,1,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0}, |
yfkwok | 11:5a6b9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,0,0,1,0,0,1,0,1,0,0,1,0,0,0,1,0,0,0,0,0,0,1,1,1,0,0,1,1,1,1,0,0,0,0,1,1,1,1,0,1,1,1,1,0,1,0,1,1,1,1,0,1,1,1,1,0,1,1,1,0}, |
yfkwok | 11:5a6b9dffd78a | 44 | {1,1,1,1,0,0,0,1,0,0,0,1,1,1,1,0,1,1,1,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,1,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,1,0,1,0,1,0,0,1,0,1,0,0,1,0,1,0,0,0}, |
yfkwok | 11:5a6b9dffd78a | 45 | {0,0,0,1,0,0,0,1,0,0,0,1,0,0,1,0,1,0,0,1,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,1,0,0,1,0,0,0,0,1,1,1,1,0,1,1,1,1,0,1,0,1,1,1,1,0,1,0,0,0,0,1,0,0,0}, |
yfkwok | 11:5a6b9dffd78a | 46 | {0,0,0,1,0,0,0,1,0,0,0,1,0,0,1,0,1,0,0,1,0,0,0,1,0,0,0,0,0,0,1,0,0,1,0,1,0,0,1,0,0,0,0,0,0,0,1,0,1,0,0,0,0,1,0,1,0,0,0,0,1,0,0,1,0,1,0,0,1}, |
yfkwok | 11:5a6b9dffd78a | 47 | {1,1,1,1,0,0,0,1,0,0,0,1,0,0,1,0,1,0,0,1,0,0,0,1,0,0,0,0,0,0,1,1,1,1,0,1,1,1,1,0,0,0,0,1,1,1,1,0,1,1,1,1,0,1,0,1,1,1,1,0,1,1,1,1,0,1,1,1,1}, |
yfkwok | 2:464c7e62d97d | 48 | }; |
yfkwok | 11:5a6b9dffd78a | 49 | lcd.drawSprite(5, 33, 15, 69, (int*)instruct_data); |
yfkwok | 2:464c7e62d97d | 50 | lcd.refresh(); |
yfkwok | 2:464c7e62d97d | 51 | } |
yfkwok | 2:464c7e62d97d | 52 | |
yfkwok | 2:464c7e62d97d | 53 | void Start::starter_update(Gamepad &pad) |
yfkwok | 2:464c7e62d97d | 54 | { |
yfkwok | 2:464c7e62d97d | 55 | update_select(pad); |
yfkwok | 2:464c7e62d97d | 56 | update_animation_b(pad); |
yfkwok | 2:464c7e62d97d | 57 | update_animation_c(pad); |
yfkwok | 2:464c7e62d97d | 58 | update_animation_s(pad); |
yfkwok | 2:464c7e62d97d | 59 | update_alt(); |
yfkwok | 2:464c7e62d97d | 60 | } |
yfkwok | 2:464c7e62d97d | 61 | |
yfkwok | 2:464c7e62d97d | 62 | Vector2D Start::update_select(Gamepad &pad) |
yfkwok | 2:464c7e62d97d | 63 | { |
yfkwok | 17:5d8ff39a0e49 | 64 | // Move the selection box according to the joystick input to move left and right |
yfkwok | 2:464c7e62d97d | 65 | if(pad.get_direction() == E && _pos_x < 58){_pos_x = _pos_x + 28; _pos_y = _pos_y - 4;} |
yfkwok | 2:464c7e62d97d | 66 | else if(pad.get_direction() == W && _pos_x > 2){_pos_x = _pos_x - 28;_pos_y = _pos_y + 4;} |
yfkwok | 2:464c7e62d97d | 67 | Vector2D p = {_pos_x, _pos_y}; |
yfkwok | 2:464c7e62d97d | 68 | return p; |
yfkwok | 2:464c7e62d97d | 69 | } |
yfkwok | 2:464c7e62d97d | 70 | |
yfkwok | 2:464c7e62d97d | 71 | int Start::update_animation_b(Gamepad &pad) |
yfkwok | 2:464c7e62d97d | 72 | { |
yfkwok | 17:5d8ff39a0e49 | 73 | // Update the sprite's position according to parameter alt to create animation |
yfkwok | 2:464c7e62d97d | 74 | if(_alt == 0 && _pos_x == 2){_pos_by = 13;} |
yfkwok | 2:464c7e62d97d | 75 | else if(_alt == 1 && _pos_x == 2){_pos_by = 11;} |
yfkwok | 2:464c7e62d97d | 76 | int pos_by = _pos_by; |
yfkwok | 2:464c7e62d97d | 77 | return pos_by; |
yfkwok | 2:464c7e62d97d | 78 | } |
yfkwok | 2:464c7e62d97d | 79 | |
yfkwok | 2:464c7e62d97d | 80 | int Start::update_animation_c(Gamepad &pad) |
yfkwok | 2:464c7e62d97d | 81 | { |
yfkwok | 17:5d8ff39a0e49 | 82 | // Update the sprite's position according to parameter alt to create animation |
yfkwok | 2:464c7e62d97d | 83 | if(_alt == 0 && _pos_x == 58){_pos_cy = 3;} |
yfkwok | 2:464c7e62d97d | 84 | else if(_alt == 1 && _pos_x == 58){_pos_cy = 5;} |
yfkwok | 2:464c7e62d97d | 85 | int pos_cy = _pos_cy; |
yfkwok | 2:464c7e62d97d | 86 | return pos_cy; |
yfkwok | 2:464c7e62d97d | 87 | } |
yfkwok | 2:464c7e62d97d | 88 | |
yfkwok | 2:464c7e62d97d | 89 | int Start::update_animation_s(Gamepad &pad) |
yfkwok | 2:464c7e62d97d | 90 | { |
yfkwok | 17:5d8ff39a0e49 | 91 | // Update the sprite's position according to parameter alt to create animation |
yfkwok | 2:464c7e62d97d | 92 | if(_alt == 0 && _pos_x == 30){_pos_sy = 7;} |
yfkwok | 2:464c7e62d97d | 93 | else if(_alt == 1 && _pos_x == 30){_pos_sy = 9;} |
yfkwok | 2:464c7e62d97d | 94 | int pos_sy = _pos_sy; |
yfkwok | 2:464c7e62d97d | 95 | return pos_sy; |
yfkwok | 2:464c7e62d97d | 96 | } |
yfkwok | 2:464c7e62d97d | 97 | |
yfkwok | 2:464c7e62d97d | 98 | int Start::update_alt() |
yfkwok | 2:464c7e62d97d | 99 | { |
yfkwok | 2:464c7e62d97d | 100 | if(_alt == 0){_alt = 1;} |
yfkwok | 2:464c7e62d97d | 101 | else {_alt = 0;} |
yfkwok | 2:464c7e62d97d | 102 | int alt = _alt; |
yfkwok | 2:464c7e62d97d | 103 | return alt; |
yfkwok | 2:464c7e62d97d | 104 | } |
yfkwok | 2:464c7e62d97d | 105 | |
yfkwok | 2:464c7e62d97d | 106 | void Start::set_pos(Vector2D p) |
yfkwok | 2:464c7e62d97d | 107 | { |
yfkwok | 2:464c7e62d97d | 108 | _pos_x = p.x; |
yfkwok | 2:464c7e62d97d | 109 | _pos_y = p.y; |
yfkwok | 2:464c7e62d97d | 110 | } |
yfkwok | 2:464c7e62d97d | 111 | |
yfkwok | 2:464c7e62d97d | 112 | void Start::set_pos_csb(int pos_cy, int pos_sy, int pos_by) |
yfkwok | 2:464c7e62d97d | 113 | { |
yfkwok | 2:464c7e62d97d | 114 | _pos_cy = pos_cy; |
yfkwok | 2:464c7e62d97d | 115 | _pos_sy = pos_sy; |
yfkwok | 2:464c7e62d97d | 116 | _pos_by = pos_by; |
yfkwok | 2:464c7e62d97d | 117 | } |
yfkwok | 2:464c7e62d97d | 118 | |
yfkwok | 2:464c7e62d97d | 119 | void Start::set_alt(int alt) |
yfkwok | 2:464c7e62d97d | 120 | { |
yfkwok | 2:464c7e62d97d | 121 | _alt = alt; |
yfkwok | 2:464c7e62d97d | 122 | } |
yfkwok | 2:464c7e62d97d | 123 | |
yfkwok | 2:464c7e62d97d | 124 | int Start::get_select(Vector2D p) |
yfkwok | 2:464c7e62d97d | 125 | { |
yfkwok | 17:5d8ff39a0e49 | 126 | // Return a value to represent the character that is being selected by the selection box |
yfkwok | 2:464c7e62d97d | 127 | int select = 0; |
yfkwok | 2:464c7e62d97d | 128 | int x = p.x; |
yfkwok | 2:464c7e62d97d | 129 | if(x == 2) {select = 0;} |
yfkwok | 2:464c7e62d97d | 130 | else if(x == 30) {select = 1;} |
yfkwok | 2:464c7e62d97d | 131 | else if(x == 58) {select = 2;} |
yfkwok | 2:464c7e62d97d | 132 | return select; |
yfkwok | 2:464c7e62d97d | 133 | } |
yfkwok | 2:464c7e62d97d | 134 | |
yfkwok | 2:464c7e62d97d | 135 | void Start::intro(int select,Gamepad &pad, N5110 &lcd) |
yfkwok | 2:464c7e62d97d | 136 | { |
yfkwok | 17:5d8ff39a0e49 | 137 | // Fetch the information from Character file to display the character information |
yfkwok | 2:464c7e62d97d | 138 | if(select == 2){_c1.description(pad, lcd);} |
yfkwok | 2:464c7e62d97d | 139 | else if(select == 1){_s1.description(pad, lcd);} |
yfkwok | 2:464c7e62d97d | 140 | else if(select == 0){_b1.description(pad, lcd);} |
yfkwok | 2:464c7e62d97d | 141 | } |