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@14:abe64fe0b6a5, 2019-04-18 (annotated)
- Committer:
- yfkwok
- Date:
- Thu Apr 18 04:53:04 2019 +0000
- Revision:
- 14:abe64fe0b6a5
- Child:
- 21:704d938acf5d
18/04/2019 - Mini Game 2 Implementation
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 | 14:abe64fe0b6a5 | 41 | if (d == N) {_y-=_speed;} |
yfkwok | 14:abe64fe0b6a5 | 42 | else if (d == NE) {_y-=_speed; _x+=_speed;} |
yfkwok | 14:abe64fe0b6a5 | 43 | else if (d == E) {_x+=_speed;} |
yfkwok | 14:abe64fe0b6a5 | 44 | else if (d == SE) {_y+=_speed; _x+=_speed;} |
yfkwok | 14:abe64fe0b6a5 | 45 | else if (d == S) {_y+=_speed;} |
yfkwok | 14:abe64fe0b6a5 | 46 | else if (d == SW) {_y+=_speed; _x-=_speed;} |
yfkwok | 14:abe64fe0b6a5 | 47 | else if (d == W) {_x-=_speed;} |
yfkwok | 14:abe64fe0b6a5 | 48 | else if (d == NW) {_y-=_speed; _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 | 14:abe64fe0b6a5 | 53 | } |
yfkwok | 14:abe64fe0b6a5 | 54 | |
yfkwok | 14:abe64fe0b6a5 | 55 | void Game_two_cha::add_score() |
yfkwok | 14:abe64fe0b6a5 | 56 | { |
yfkwok | 14:abe64fe0b6a5 | 57 | _score++; |
yfkwok | 14:abe64fe0b6a5 | 58 | } |
yfkwok | 14:abe64fe0b6a5 | 59 | |
yfkwok | 14:abe64fe0b6a5 | 60 | int Game_two_cha::get_score() |
yfkwok | 14:abe64fe0b6a5 | 61 | { |
yfkwok | 14:abe64fe0b6a5 | 62 | return _score; |
yfkwok | 14:abe64fe0b6a5 | 63 | } |
yfkwok | 14:abe64fe0b6a5 | 64 | |
yfkwok | 14:abe64fe0b6a5 | 65 | Vector2D Game_two_cha::get_pos() |
yfkwok | 14:abe64fe0b6a5 | 66 | { |
yfkwok | 14:abe64fe0b6a5 | 67 | Vector2D p = {_x,_y}; |
yfkwok | 14:abe64fe0b6a5 | 68 | return p; |
yfkwok | 14:abe64fe0b6a5 | 69 | } |