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_one/Coin_files/Coin.cpp
- Committer:
- yfkwok
- Date:
- 2019-05-09
- Revision:
- 34:3ddfaa217eca
- Parent:
- 16:4e49f5cb972e
File content as of revision 34:3ddfaa217eca:
#include "Coin.h" Coin::Coin() { } Coin::~Coin() { } void Coin::init(int speed) { _speed = speed; int position = rand() % 4; // randomise initial direction. // 4 possibilities. Get random modulo and set initial position accordingly if (position == 0) { _x = -9; _y = 1; } else if (position == 1) { _x = -9; _y = 12; } else if (position == 2) { _x = -9; _y = 24; } else { _x = -9; _y = 36; } } void Coin::draw(N5110 &lcd) { int coin_data[12][10] = { {0,0,0,1,1,1,1,0,0,0}, {0,0,1,1,0,0,0,1,0,0}, {0,1,1,0,0,0,0,0,1,0}, {0,1,1,0,0,1,0,0,1,0}, {1,1,0,0,1,0,1,0,0,1}, {1,1,0,0,1,0,1,0,0,1}, {1,1,0,0,1,0,1,0,0,1}, {1,1,0,0,1,0,1,0,0,1}, {0,1,1,0,0,1,0,0,1,0}, {0,1,1,0,0,0,0,0,1,0}, {0,0,1,1,0,0,0,1,0,0}, {0,0,0,1,1,1,1,0,0,0}, }; // Sprite for the coin object lcd.drawSprite(_x, _y, 12, 10, (int*)coin_data); } void Coin::update() { _x += _speed; } void Coin::set_velocity(int speed) { _speed = speed; } int Coin::get_velocity() { int speed = _speed; return speed; } Vector2D Coin::get_pos() { Vector2D p = {_x,_y}; return p; } void Coin::set_pos(Vector2D p) { _x = p.x; _y = p.y; }