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@32:58def659f463, 2019-05-08 (annotated)
- Committer:
- yfkwok
- Date:
- Wed May 08 15:14:55 2019 +0000
- Revision:
- 32:58def659f463
- Parent:
- 17:5d8ff39a0e49
08/05/2019 - Commit before moving majority sprites in main to Grad
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 | 32:58def659f463 | 28 | _c1.draw_cha1_sprite(60, _pos_cy, lcd); // Draw Charmander's sprite at position (60, 5) |
yfkwok | 32:58def659f463 | 29 | _s1.draw_cha1_sprite(32, _pos_sy, lcd); // Draw Squirtle's sprite at position (32, 9) |
yfkwok | 32:58def659f463 | 30 | _b1.draw_cha1_sprite(4, _pos_by, lcd); // Draw Bulbasaur's sprite at position (4, 13) |
yfkwok | 32:58def659f463 | 31 | lcd.drawRect(_pos_x, _pos_y, 25, 25, FILL_TRANSPARENT); //Draw selection box dependent on which Pokemon is currently being selected |
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,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fkwok | 11:5a6b9dffd78a | 43 | {1,0,0,0,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,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 | 32:58def659f463 | 49 | lcd.drawSprite(5, 33, 15, 69, (int*)instruct_data); // Draw the instruction for choosing to read information or start the game |
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 | 32:58def659f463 | 55 | update_select(pad); // Update the position of the selection box according to joystick input |
yfkwok | 32:58def659f463 | 56 | update_animation_b(pad); // Update the animation of Bulbasaur if it is being selected |
yfkwok | 32:58def659f463 | 57 | update_animation_c(pad); // Update the animation of Charmander if it is being selected |
yfkwok | 32:58def659f463 | 58 | update_animation_s(pad); // Update the animation of Squirtle if it is being selected |
yfkwok | 32:58def659f463 | 59 | update_alt(); // Update the alt parameter to alter the sprites of the characters |
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 | int Start::get_select(Vector2D p) |
yfkwok | 2:464c7e62d97d | 107 | { |
yfkwok | 17:5d8ff39a0e49 | 108 | // Return a value to represent the character that is being selected by the selection box |
yfkwok | 2:464c7e62d97d | 109 | int select = 0; |
yfkwok | 2:464c7e62d97d | 110 | int x = p.x; |
yfkwok | 2:464c7e62d97d | 111 | if(x == 2) {select = 0;} |
yfkwok | 2:464c7e62d97d | 112 | else if(x == 30) {select = 1;} |
yfkwok | 2:464c7e62d97d | 113 | else if(x == 58) {select = 2;} |
yfkwok | 2:464c7e62d97d | 114 | return select; |
yfkwok | 2:464c7e62d97d | 115 | } |
yfkwok | 2:464c7e62d97d | 116 | |
yfkwok | 2:464c7e62d97d | 117 | void Start::intro(int select,Gamepad &pad, N5110 &lcd) |
yfkwok | 2:464c7e62d97d | 118 | { |
yfkwok | 32:58def659f463 | 119 | // Fetch the files from Character file to display the character information |
yfkwok | 2:464c7e62d97d | 120 | if(select == 2){_c1.description(pad, lcd);} |
yfkwok | 2:464c7e62d97d | 121 | else if(select == 1){_s1.description(pad, lcd);} |
yfkwok | 2:464c7e62d97d | 122 | else if(select == 0){_b1.description(pad, lcd);} |
yfkwok | 2:464c7e62d97d | 123 | } |