![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
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/YouTube_files/YouTube.cpp@33:f7ec806e14b6, 2019-05-08 (annotated)
- Committer:
- yfkwok
- Date:
- Wed May 08 23:57:04 2019 +0000
- Revision:
- 33:f7ec806e14b6
- Parent:
- 26:c60becf3f840
09/05/19 - Inline comment added, functionalities complete, all Deoxygen comment added for classes
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yfkwok | 14:abe64fe0b6a5 | 1 | #include "YouTube.h" |
yfkwok | 14:abe64fe0b6a5 | 2 | |
yfkwok | 14:abe64fe0b6a5 | 3 | YouTube::YouTube() |
yfkwok | 14:abe64fe0b6a5 | 4 | { |
yfkwok | 14:abe64fe0b6a5 | 5 | |
yfkwok | 14:abe64fe0b6a5 | 6 | } |
yfkwok | 14:abe64fe0b6a5 | 7 | |
yfkwok | 14:abe64fe0b6a5 | 8 | YouTube::~YouTube() |
yfkwok | 14:abe64fe0b6a5 | 9 | { |
yfkwok | 14:abe64fe0b6a5 | 10 | |
yfkwok | 14:abe64fe0b6a5 | 11 | } |
yfkwok | 14:abe64fe0b6a5 | 12 | |
yfkwok | 33:f7ec806e14b6 | 13 | // Function to initiate the youtube icon |
yfkwok | 14:abe64fe0b6a5 | 14 | void YouTube::init(int speed) |
yfkwok | 14:abe64fe0b6a5 | 15 | { |
yfkwok | 19:903d67bb0dea | 16 | int position = rand() % 8; // randomise initial direction and position. |
yfkwok | 14:abe64fe0b6a5 | 17 | |
yfkwok | 19:903d67bb0dea | 18 | // 8 possibilities. Get random modulo and set velocities and position accordingly |
yfkwok | 14:abe64fe0b6a5 | 19 | if (position == 0) { |
yfkwok | 26:c60becf3f840 | 20 | _x = -32; |
yfkwok | 14:abe64fe0b6a5 | 21 | _y = 12; |
yfkwok | 14:abe64fe0b6a5 | 22 | _velocity.x = speed * 2; |
yfkwok | 14:abe64fe0b6a5 | 23 | _velocity.y = speed; |
yfkwok | 14:abe64fe0b6a5 | 24 | } else if (position == 1) { |
yfkwok | 14:abe64fe0b6a5 | 25 | _x = 20; |
yfkwok | 26:c60becf3f840 | 26 | _y = -11; |
yfkwok | 14:abe64fe0b6a5 | 27 | _velocity.x = speed * 2; |
yfkwok | 14:abe64fe0b6a5 | 28 | _velocity.y = speed *2; |
yfkwok | 14:abe64fe0b6a5 | 29 | } else if (position == 2) { |
yfkwok | 14:abe64fe0b6a5 | 30 | _x = 60; |
yfkwok | 26:c60becf3f840 | 31 | _y = -11; |
yfkwok | 14:abe64fe0b6a5 | 32 | _velocity.x = -speed * 2; |
yfkwok | 14:abe64fe0b6a5 | 33 | _velocity.y = speed *2; |
yfkwok | 14:abe64fe0b6a5 | 34 | } else if (position == 3) { |
yfkwok | 26:c60becf3f840 | 35 | _x = 84; |
yfkwok | 14:abe64fe0b6a5 | 36 | _y = 14; |
yfkwok | 14:abe64fe0b6a5 | 37 | _velocity.x = -speed * 3; |
yfkwok | 14:abe64fe0b6a5 | 38 | _velocity.y = speed; |
yfkwok | 14:abe64fe0b6a5 | 39 | } else if (position == 4) { |
yfkwok | 26:c60becf3f840 | 40 | _x = 84; |
yfkwok | 14:abe64fe0b6a5 | 41 | _y = 35; |
yfkwok | 14:abe64fe0b6a5 | 42 | _velocity.x = -speed * 3; |
yfkwok | 14:abe64fe0b6a5 | 43 | _velocity.y = -speed *2; |
yfkwok | 14:abe64fe0b6a5 | 44 | } else if (position == 5) { |
yfkwok | 14:abe64fe0b6a5 | 45 | _x = 60; |
yfkwok | 26:c60becf3f840 | 46 | _y = 48; |
yfkwok | 14:abe64fe0b6a5 | 47 | _velocity.x = -speed * 2; |
yfkwok | 14:abe64fe0b6a5 | 48 | _velocity.y = -speed *2; |
yfkwok | 14:abe64fe0b6a5 | 49 | } else if (position == 6) { |
yfkwok | 14:abe64fe0b6a5 | 50 | _x = 20; |
yfkwok | 26:c60becf3f840 | 51 | _y = 48; |
yfkwok | 14:abe64fe0b6a5 | 52 | _velocity.x = speed * 2; |
yfkwok | 14:abe64fe0b6a5 | 53 | _velocity.y = -speed *2; |
yfkwok | 14:abe64fe0b6a5 | 54 | } else if (position == 7) { |
yfkwok | 26:c60becf3f840 | 55 | _x = -32; |
yfkwok | 14:abe64fe0b6a5 | 56 | _y = 30; |
yfkwok | 14:abe64fe0b6a5 | 57 | _velocity.x = speed * 3; |
yfkwok | 14:abe64fe0b6a5 | 58 | _velocity.y = -speed *2; |
yfkwok | 14:abe64fe0b6a5 | 59 | } |
yfkwok | 14:abe64fe0b6a5 | 60 | } |
yfkwok | 14:abe64fe0b6a5 | 61 | |
yfkwok | 33:f7ec806e14b6 | 62 | // Draw the youtube icon depending on the updated position |
yfkwok | 14:abe64fe0b6a5 | 63 | void YouTube::draw(N5110 &lcd) |
yfkwok | 14:abe64fe0b6a5 | 64 | { |
yfkwok | 14:abe64fe0b6a5 | 65 | int YouTube_data[11][32] = { |
yfkwok | 14:abe64fe0b6a5 | 66 | {0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0}, |
yfkwok | 14:abe64fe0b6a5 | 67 | {1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}, |
yfkwok | 14:abe64fe0b6a5 | 68 | {1,0,1,0,1,0,1,1,1,0,1,0,1,0,1,0,0,0,1,0,1,0,1,0,0,1,1,0,0,0,1,1}, |
yfkwok | 14:abe64fe0b6a5 | 69 | {1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,1,0,1,1,0,1,0,1,0,1,0,1,0,1,1,1,1}, |
yfkwok | 14:abe64fe0b6a5 | 70 | {1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,1,0,1,1,0,1,0,1,0,1,0,1,0,1,1,1,1}, |
yfkwok | 14:abe64fe0b6a5 | 71 | {1,0,1,1,1,0,1,0,1,0,1,0,1,0,1,1,0,1,1,0,1,0,1,0,0,1,1,0,0,0,1,1}, |
yfkwok | 14:abe64fe0b6a5 | 72 | {1,0,0,1,0,0,1,0,1,0,1,0,1,0,1,1,0,1,1,0,1,0,1,0,1,0,1,0,1,1,1,1}, |
yfkwok | 14:abe64fe0b6a5 | 73 | {1,0,0,1,0,0,1,0,1,0,1,0,1,0,1,1,0,1,1,0,1,0,1,0,1,0,1,0,1,1,1,1}, |
yfkwok | 14:abe64fe0b6a5 | 74 | {1,0,0,1,0,0,1,1,1,0,1,1,1,0,1,1,0,1,1,0,0,0,1,0,0,1,1,0,0,0,1,1}, |
yfkwok | 14:abe64fe0b6a5 | 75 | {1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}, |
yfkwok | 14:abe64fe0b6a5 | 76 | {0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0}, |
yfkwok | 14:abe64fe0b6a5 | 77 | }; |
yfkwok | 14:abe64fe0b6a5 | 78 | |
yfkwok | 14:abe64fe0b6a5 | 79 | lcd.drawSprite(_x, _y, 11, 32, (int*)YouTube_data); |
yfkwok | 14:abe64fe0b6a5 | 80 | } |
yfkwok | 14:abe64fe0b6a5 | 81 | |
yfkwok | 33:f7ec806e14b6 | 82 | // Update the position of the youtube icon dependent on the speed |
yfkwok | 14:abe64fe0b6a5 | 83 | void YouTube::update() |
yfkwok | 14:abe64fe0b6a5 | 84 | { |
yfkwok | 14:abe64fe0b6a5 | 85 | _x += _velocity.x; |
yfkwok | 14:abe64fe0b6a5 | 86 | _y += _velocity.y; |
yfkwok | 14:abe64fe0b6a5 | 87 | } |
yfkwok | 14:abe64fe0b6a5 | 88 | |
yfkwok | 33:f7ec806e14b6 | 89 | // Function used to set the velocity of the youtube icon |
yfkwok | 14:abe64fe0b6a5 | 90 | void YouTube::set_velocity(Vector2D v) |
yfkwok | 14:abe64fe0b6a5 | 91 | { |
yfkwok | 14:abe64fe0b6a5 | 92 | _velocity.x = v.x; |
yfkwok | 14:abe64fe0b6a5 | 93 | _velocity.y = v.y; |
yfkwok | 14:abe64fe0b6a5 | 94 | } |
yfkwok | 14:abe64fe0b6a5 | 95 | |
yfkwok | 33:f7ec806e14b6 | 96 | // Function used to fetch the current velocity of the youtube icon |
yfkwok | 14:abe64fe0b6a5 | 97 | Vector2D YouTube::get_velocity() |
yfkwok | 14:abe64fe0b6a5 | 98 | { |
yfkwok | 14:abe64fe0b6a5 | 99 | Vector2D v = {_velocity.x,_velocity.y}; |
yfkwok | 14:abe64fe0b6a5 | 100 | return v; |
yfkwok | 14:abe64fe0b6a5 | 101 | } |
yfkwok | 14:abe64fe0b6a5 | 102 | |
yfkwok | 33:f7ec806e14b6 | 103 | // Function used to fetch the current position of the youtube icon |
yfkwok | 14:abe64fe0b6a5 | 104 | Vector2D YouTube::get_pos() |
yfkwok | 14:abe64fe0b6a5 | 105 | { |
yfkwok | 14:abe64fe0b6a5 | 106 | Vector2D p = {_x,_y}; |
yfkwok | 14:abe64fe0b6a5 | 107 | return p; |
yfkwok | 14:abe64fe0b6a5 | 108 | } |
yfkwok | 14:abe64fe0b6a5 | 109 | |
yfkwok | 33:f7ec806e14b6 | 110 | // Function used to set the current position of the youtube icon |
yfkwok | 14:abe64fe0b6a5 | 111 | void YouTube::set_pos(Vector2D p) |
yfkwok | 14:abe64fe0b6a5 | 112 | { |
yfkwok | 14:abe64fe0b6a5 | 113 | _x = p.x; |
yfkwok | 14:abe64fe0b6a5 | 114 | _y = p.y; |
yfkwok | 14:abe64fe0b6a5 | 115 | } |