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

Committer:
yfkwok
Date:
Sat Apr 20 15:20:43 2019 +0000
Revision:
16:4e49f5cb972e
Parent:
2:464c7e62d97d
20/04/2019 - Update documentation for Game 1 Classes and Score

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yfkwok 2:464c7e62d97d 1 #include "Game_one_cha.h"
yfkwok 2:464c7e62d97d 2
yfkwok 2:464c7e62d97d 3 Game_one_cha::Game_one_cha()
yfkwok 2:464c7e62d97d 4 {
yfkwok 2:464c7e62d97d 5
yfkwok 2:464c7e62d97d 6 }
yfkwok 2:464c7e62d97d 7
yfkwok 2:464c7e62d97d 8 Game_one_cha::~Game_one_cha()
yfkwok 2:464c7e62d97d 9 {
yfkwok 2:464c7e62d97d 10
yfkwok 2:464c7e62d97d 11 }
yfkwok 2:464c7e62d97d 12
yfkwok 2:464c7e62d97d 13 void Game_one_cha::init(int x)
yfkwok 2:464c7e62d97d 14 {
yfkwok 16:4e49f5cb972e 15 _x = x; // x position fixed
yfkwok 2:464c7e62d97d 16 _y = HEIGHT/2 - 9; //y initial position at mid-point of screen
yfkwok 2:464c7e62d97d 17 _speed = 1; // default speed
yfkwok 2:464c7e62d97d 18 _score = 0; // start score from zero
yfkwok 2:464c7e62d97d 19 }
yfkwok 2:464c7e62d97d 20
yfkwok 2:464c7e62d97d 21 void Game_one_cha::draw(N5110 &lcd, int cha)
yfkwok 2:464c7e62d97d 22 {
yfkwok 16:4e49f5cb972e 23 if(cha == 1){_s1.draw_cha1_sprite(_x, _y, lcd);} // draw sprite for Squirtle in year 1
yfkwok 16:4e49f5cb972e 24 else if(cha == 2){_s1.draw_cha2_sprite(_x, _y, lcd);} // draw sprite for Wartortle in year 2
yfkwok 16:4e49f5cb972e 25 else if(cha == 3){_s1.draw_cha3_sprite(_x, _y, lcd);} // draw sprite for Blastoise in year 3
yfkwok 2:464c7e62d97d 26 }
yfkwok 2:464c7e62d97d 27
yfkwok 2:464c7e62d97d 28 void Game_one_cha::draw_alt(N5110 &lcd, int cha)
yfkwok 2:464c7e62d97d 29 {
yfkwok 16:4e49f5cb972e 30 if(cha == 1){_s1.draw_cha1_alt_sprite(_x, _y, lcd);} // draw alternative sprite for Squirtle
yfkwok 16:4e49f5cb972e 31 else if(cha == 2){_s1.draw_cha2_alt_sprite(_x, _y, lcd);} // draw alternative sprite for Wartortle
yfkwok 16:4e49f5cb972e 32 else if(cha == 3){_s1.draw_cha3_alt_sprite(_x, _y, lcd);} // draw alternative sprite for Blastoise
yfkwok 2:464c7e62d97d 33 }
yfkwok 2:464c7e62d97d 34
yfkwok 2:464c7e62d97d 35 void Game_one_cha::update(Direction d,float mag)
yfkwok 2:464c7e62d97d 36 {
yfkwok 16:4e49f5cb972e 37 _speed = int(mag*10.0f); // set the scale for speed
yfkwok 2:464c7e62d97d 38
yfkwok 2:464c7e62d97d 39 // update y value depending on direction of movement
yfkwok 2:464c7e62d97d 40 // North is decrement as origin is at the top-left so decreasing moves up
yfkwok 2:464c7e62d97d 41 if (d == N) {_y-=_speed;}
yfkwok 2:464c7e62d97d 42 else if (d == S) {_y+=_speed;}
yfkwok 2:464c7e62d97d 43
yfkwok 2:464c7e62d97d 44 // check the y origin to ensure that the character doesn't go off screen
yfkwok 2:464c7e62d97d 45 if (_y < 1) {_y = 1;}
yfkwok 2:464c7e62d97d 46 if (_y > HEIGHT - 18) {_y = HEIGHT - 18;}
yfkwok 2:464c7e62d97d 47 }
yfkwok 2:464c7e62d97d 48
yfkwok 2:464c7e62d97d 49 void Game_one_cha::add_score()
yfkwok 2:464c7e62d97d 50 {
yfkwok 16:4e49f5cb972e 51 _score++; // add up the score for the player for each success coin collection
yfkwok 2:464c7e62d97d 52 }
yfkwok 2:464c7e62d97d 53
yfkwok 2:464c7e62d97d 54 int Game_one_cha::get_score()
yfkwok 2:464c7e62d97d 55 {
yfkwok 16:4e49f5cb972e 56 return _score; // return score for the player
yfkwok 2:464c7e62d97d 57 }
yfkwok 2:464c7e62d97d 58
yfkwok 2:464c7e62d97d 59 Vector2D Game_one_cha::get_pos()
yfkwok 2:464c7e62d97d 60 {
yfkwok 16:4e49f5cb972e 61 Vector2D p = {_x,_y}; // return position of the player
yfkwok 2:464c7e62d97d 62 return p;
yfkwok 2:464c7e62d97d 63 }