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
Diff: Game_one/Object_files/Object.cpp
- Revision:
- 2:464c7e62d97d
- Child:
- 16:4e49f5cb972e
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Game_one/Object_files/Object.cpp Wed Apr 03 03:06:00 2019 +0000 @@ -0,0 +1,82 @@ +#include "Object.h" + +Object::Object() +{ + +} + +Object::~Object() +{ + +} + +void Object::init(int speed) +{ + _speed = speed; + + int position = rand() % 3; // randomise initial direction. + + // 4 possibilities. Get random modulo and set velocities accordingly + if (position == 0) { + _x = -9; + _y = 1; + } else if (position == 1) { + _x = -9; + _y = 16; + } else if (position == 2) { + _x = -9; + _y = 32; + } +} + +void Object::draw(N5110 &lcd) +{ + static int Object_data[] = { + 1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0, + 1,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, + 1,1,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0, + 1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,1,0, + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, + 1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,1, + 1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,1, + 1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,1, + 1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,1, + 1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,1, + 1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,1, + 1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,1, + 0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,1, + 0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,1, + 0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,1, + 0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1 + }; + + lcd.drawSprite(_x, _y, 16, 17, Object_data); +} + +void Object::update() +{ + _x += _speed; +} + +void Object::set_velocity(int speed) +{ + _speed = speed; +} + +int Object::get_velocity() +{ + int speed = _speed; + return speed; +} + +Vector2D Object::get_pos() +{ + Vector2D p = {_x,_y}; + return p; +} + +void Object::set_pos(Vector2D p) +{ + _x = p.x; + _y = p.y; +} \ No newline at end of file