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
Game_two/Character_files/Game_two_cha.cpp@21:704d938acf5d, 2019-04-28 (annotated)
- Committer:
- yfkwok
- Date:
- Sun Apr 28 18:04:23 2019 +0000
- Revision:
- 21:704d938acf5d
- Parent:
- 14:abe64fe0b6a5
- Child:
- 33:f7ec806e14b6
28/04/2019 - Bug fix
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yfkwok | 14:abe64fe0b6a5 | 1 | #include "Game_two_cha.h" |
yfkwok | 14:abe64fe0b6a5 | 2 | |
yfkwok | 14:abe64fe0b6a5 | 3 | Game_two_cha::Game_two_cha() |
yfkwok | 14:abe64fe0b6a5 | 4 | { |
yfkwok | 14:abe64fe0b6a5 | 5 | |
yfkwok | 14:abe64fe0b6a5 | 6 | } |
yfkwok | 14:abe64fe0b6a5 | 7 | |
yfkwok | 14:abe64fe0b6a5 | 8 | Game_two_cha::~Game_two_cha() |
yfkwok | 14:abe64fe0b6a5 | 9 | { |
yfkwok | 14:abe64fe0b6a5 | 10 | |
yfkwok | 14:abe64fe0b6a5 | 11 | } |
yfkwok | 14:abe64fe0b6a5 | 12 | |
yfkwok | 14:abe64fe0b6a5 | 13 | void Game_two_cha::init() |
yfkwok | 14:abe64fe0b6a5 | 14 | { |
yfkwok | 14:abe64fe0b6a5 | 15 | _x = WIDTH/2 - 9; //x position fixed |
yfkwok | 14:abe64fe0b6a5 | 16 | _y = HEIGHT/2 - 9; //y initial position at mid-point of screen |
yfkwok | 14:abe64fe0b6a5 | 17 | _speed = 1; // default speed |
yfkwok | 14:abe64fe0b6a5 | 18 | _score = 0; // start score from zero |
yfkwok | 14:abe64fe0b6a5 | 19 | } |
yfkwok | 14:abe64fe0b6a5 | 20 | |
yfkwok | 14:abe64fe0b6a5 | 21 | void Game_two_cha::draw(N5110 &lcd, int cha) |
yfkwok | 14:abe64fe0b6a5 | 22 | { |
yfkwok | 14:abe64fe0b6a5 | 23 | if(cha == 1){_c1.draw_cha1_sprite(_x, _y, lcd);} |
yfkwok | 14:abe64fe0b6a5 | 24 | else if(cha == 2){_c1.draw_cha2_sprite(_x, _y, lcd);} |
yfkwok | 14:abe64fe0b6a5 | 25 | else if(cha == 3){_c1.draw_cha3_sprite(_x, _y, lcd);} |
yfkwok | 14:abe64fe0b6a5 | 26 | } |
yfkwok | 14:abe64fe0b6a5 | 27 | |
yfkwok | 14:abe64fe0b6a5 | 28 | void Game_two_cha::draw_alt(N5110 &lcd, int cha) |
yfkwok | 14:abe64fe0b6a5 | 29 | { |
yfkwok | 14:abe64fe0b6a5 | 30 | if(cha == 1){_c1.draw_cha1_alt_sprite(_x, _y, lcd);} |
yfkwok | 14:abe64fe0b6a5 | 31 | else if(cha == 2){_c1.draw_cha2_alt_sprite(_x, _y, lcd);} |
yfkwok | 14:abe64fe0b6a5 | 32 | else if(cha == 3){_c1.draw_cha3_alt_sprite(_x, _y, lcd);} |
yfkwok | 14:abe64fe0b6a5 | 33 | } |
yfkwok | 14:abe64fe0b6a5 | 34 | |
yfkwok | 14:abe64fe0b6a5 | 35 | void Game_two_cha::update(Direction d,float mag) |
yfkwok | 14:abe64fe0b6a5 | 36 | { |
yfkwok | 14:abe64fe0b6a5 | 37 | _speed = int(mag*10.0f); // scale is arbitrary, could be changed in future |
yfkwok | 14:abe64fe0b6a5 | 38 | |
yfkwok | 14:abe64fe0b6a5 | 39 | // update y value depending on direction of movement |
yfkwok | 14:abe64fe0b6a5 | 40 | // North is decrement as origin is at the top-left so decreasing moves up |
yfkwok | 21:704d938acf5d | 41 | if (d == N) {_y-=-_speed*0.7;} |
yfkwok | 21:704d938acf5d | 42 | else if (d == NE) {_y-=-_speed*0.7; _x+=_speed;} |
yfkwok | 14:abe64fe0b6a5 | 43 | else if (d == E) {_x+=_speed;} |
yfkwok | 21:704d938acf5d | 44 | else if (d == SE) {_y+=-_speed*0.7; _x+=_speed;} |
yfkwok | 21:704d938acf5d | 45 | else if (d == S) {_y+=-_speed*0.7;} |
yfkwok | 21:704d938acf5d | 46 | else if (d == SW) {_y+=-_speed*0.7; _x-=_speed;} |
yfkwok | 14:abe64fe0b6a5 | 47 | else if (d == W) {_x-=_speed;} |
yfkwok | 21:704d938acf5d | 48 | else if (d == NW) {_y-=-_speed*0.7; _x-=_speed;} |
yfkwok | 14:abe64fe0b6a5 | 49 | |
yfkwok | 14:abe64fe0b6a5 | 50 | // check the y origin to ensure that the character doesn't go off screen |
yfkwok | 14:abe64fe0b6a5 | 51 | if (_y < 1) {_y = 1;} |
yfkwok | 14:abe64fe0b6a5 | 52 | if (_y > HEIGHT - 18) {_y = HEIGHT - 18;} |
yfkwok | 21:704d938acf5d | 53 | if (_x < 1) {_x = 1;} |
yfkwok | 21:704d938acf5d | 54 | if (_x > WIDTH - 18) {_x = WIDTH - 18;} |
yfkwok | 14:abe64fe0b6a5 | 55 | } |
yfkwok | 14:abe64fe0b6a5 | 56 | |
yfkwok | 14:abe64fe0b6a5 | 57 | void Game_two_cha::add_score() |
yfkwok | 14:abe64fe0b6a5 | 58 | { |
yfkwok | 14:abe64fe0b6a5 | 59 | _score++; |
yfkwok | 14:abe64fe0b6a5 | 60 | } |
yfkwok | 14:abe64fe0b6a5 | 61 | |
yfkwok | 14:abe64fe0b6a5 | 62 | int Game_two_cha::get_score() |
yfkwok | 14:abe64fe0b6a5 | 63 | { |
yfkwok | 14:abe64fe0b6a5 | 64 | return _score; |
yfkwok | 14:abe64fe0b6a5 | 65 | } |
yfkwok | 14:abe64fe0b6a5 | 66 | |
yfkwok | 14:abe64fe0b6a5 | 67 | Vector2D Game_two_cha::get_pos() |
yfkwok | 14:abe64fe0b6a5 | 68 | { |
yfkwok | 14:abe64fe0b6a5 | 69 | Vector2D p = {_x,_y}; |
yfkwok | 14:abe64fe0b6a5 | 70 | return p; |
yfkwok | 14:abe64fe0b6a5 | 71 | } |