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