Nemesis game third enemy
Enemy3.cpp@4:bc02594c4902, 2017-05-03 (annotated)
- Committer:
- musallambseiso
- Date:
- Wed May 03 20:04:08 2017 +0000
- Revision:
- 4:bc02594c4902
- Parent:
- 3:ed7f3ee41871
Removed redundant code, perfected Doxygen, added inline comments.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
musallambseiso | 3:ed7f3ee41871 | 1 | #include "Enemy3.h" |
musallambseiso | 3:ed7f3ee41871 | 2 | |
musallambseiso | 3:ed7f3ee41871 | 3 | Enemy3::Enemy3() |
musallambseiso | 3:ed7f3ee41871 | 4 | { |
musallambseiso | 3:ed7f3ee41871 | 5 | } |
musallambseiso | 3:ed7f3ee41871 | 6 | |
musallambseiso | 3:ed7f3ee41871 | 7 | Enemy3::~Enemy3() |
musallambseiso | 3:ed7f3ee41871 | 8 | { |
musallambseiso | 4:bc02594c4902 | 9 | } |
musallambseiso | 3:ed7f3ee41871 | 10 | |
musallambseiso | 4:bc02594c4902 | 11 | |
musallambseiso | 4:bc02594c4902 | 12 | // Initializion method: |
musallambseiso | 3:ed7f3ee41871 | 13 | |
musallambseiso | 3:ed7f3ee41871 | 14 | void Enemy3::init(int speed) |
musallambseiso | 3:ed7f3ee41871 | 15 | { |
musallambseiso | 4:bc02594c4902 | 16 | _x = rand() % 63 + 84; // Starting x position is randomized off screen. Creates a random ship generation. |
musallambseiso | 4:bc02594c4902 | 17 | _y = 13; // Starting y position (fixed, third lane) |
musallambseiso | 3:ed7f3ee41871 | 18 | |
musallambseiso | 4:bc02594c4902 | 19 | _velocity.x = -speed; // Velocity is based on the speed, which is input when method is used. |
musallambseiso | 3:ed7f3ee41871 | 20 | _velocity.y = 0; |
musallambseiso | 3:ed7f3ee41871 | 21 | } |
musallambseiso | 3:ed7f3ee41871 | 22 | |
musallambseiso | 4:bc02594c4902 | 23 | |
musallambseiso | 4:bc02594c4902 | 24 | // Draws third enemy ship onto LCD: |
musallambseiso | 4:bc02594c4902 | 25 | |
musallambseiso | 3:ed7f3ee41871 | 26 | void Enemy3::draw(N5110 &lcd) |
musallambseiso | 3:ed7f3ee41871 | 27 | { |
musallambseiso | 3:ed7f3ee41871 | 28 | lcd.drawLine(_x,_y,_x,_y+5,1); |
musallambseiso | 3:ed7f3ee41871 | 29 | lcd.drawLine(_x-1,_y,_x-1,_y+5,1); |
musallambseiso | 3:ed7f3ee41871 | 30 | lcd.drawLine(_x-2,_y+1,_x-2,_y+4,1); |
musallambseiso | 3:ed7f3ee41871 | 31 | lcd.drawLine(_x-3,_y+1,_x-3,_y+4,1); |
musallambseiso | 3:ed7f3ee41871 | 32 | lcd.drawLine(_x-4,_y+2,_x-4,_y+3,1); |
musallambseiso | 3:ed7f3ee41871 | 33 | } |
musallambseiso | 3:ed7f3ee41871 | 34 | |
musallambseiso | 4:bc02594c4902 | 35 | |
musallambseiso | 4:bc02594c4902 | 36 | // Updates third enemy ship's position: |
musallambseiso | 4:bc02594c4902 | 37 | |
musallambseiso | 3:ed7f3ee41871 | 38 | void Enemy3::update() |
musallambseiso | 3:ed7f3ee41871 | 39 | { |
musallambseiso | 4:bc02594c4902 | 40 | // X and y positions depend on velocity: |
musallambseiso | 3:ed7f3ee41871 | 41 | _x += _velocity.x; |
musallambseiso | 3:ed7f3ee41871 | 42 | _y += _velocity.y; |
musallambseiso | 3:ed7f3ee41871 | 43 | } |
musallambseiso | 3:ed7f3ee41871 | 44 | |
musallambseiso | 4:bc02594c4902 | 45 | |
musallambseiso | 4:bc02594c4902 | 46 | // Obtains third enemy ship's current position: |
musallambseiso | 4:bc02594c4902 | 47 | |
musallambseiso | 3:ed7f3ee41871 | 48 | Vector2D Enemy3::get_pos() |
musallambseiso | 3:ed7f3ee41871 | 49 | { |
musallambseiso | 3:ed7f3ee41871 | 50 | Vector2D p = {_x,_y}; |
musallambseiso | 3:ed7f3ee41871 | 51 | return p; |
musallambseiso | 3:ed7f3ee41871 | 52 | } |