Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed Gamepad N5110 mbed-rtos
EnemyBeam/EnemyBeam2.cpp@0:d9cf94b41df3, 2019-05-09 (annotated)
- Committer:
- RexRoshan
- Date:
- Thu May 09 09:49:35 2019 +0000
- Revision:
- 0:d9cf94b41df3
Documentation has been completed and the code has been slightly modified
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
RexRoshan | 0:d9cf94b41df3 | 1 | #include "EnemyBeam2.h" |
RexRoshan | 0:d9cf94b41df3 | 2 | |
RexRoshan | 0:d9cf94b41df3 | 3 | EnemyBeam2::EnemyBeam2() |
RexRoshan | 0:d9cf94b41df3 | 4 | { |
RexRoshan | 0:d9cf94b41df3 | 5 | |
RexRoshan | 0:d9cf94b41df3 | 6 | } |
RexRoshan | 0:d9cf94b41df3 | 7 | |
RexRoshan | 0:d9cf94b41df3 | 8 | EnemyBeam2::~EnemyBeam2() |
RexRoshan | 0:d9cf94b41df3 | 9 | { |
RexRoshan | 0:d9cf94b41df3 | 10 | |
RexRoshan | 0:d9cf94b41df3 | 11 | } |
RexRoshan | 0:d9cf94b41df3 | 12 | |
RexRoshan | 0:d9cf94b41df3 | 13 | void EnemyBeam2::init(int size,int a, int b ,int c, int d) // initialising beam for the first and second enemy in the second stage |
RexRoshan | 0:d9cf94b41df3 | 14 | { |
RexRoshan | 0:d9cf94b41df3 | 15 | _size = size; // size of the beam |
RexRoshan | 0:d9cf94b41df3 | 16 | _x = _size; // length of the beam |
RexRoshan | 0:d9cf94b41df3 | 17 | _y = _size; // height of the beam |
RexRoshan | 0:d9cf94b41df3 | 18 | _a = a; // x position of the first enemy beam |
RexRoshan | 0:d9cf94b41df3 | 19 | _b = b + 5; // y position of the first enemy beam |
RexRoshan | 0:d9cf94b41df3 | 20 | _c = c; // x position of the second enemy beam |
RexRoshan | 0:d9cf94b41df3 | 21 | _d = d; // y position of the second enemy beam |
RexRoshan | 0:d9cf94b41df3 | 22 | } |
RexRoshan | 0:d9cf94b41df3 | 23 | |
RexRoshan | 0:d9cf94b41df3 | 24 | void EnemyBeam2::draw(N5110 &lcd) |
RexRoshan | 0:d9cf94b41df3 | 25 | { |
RexRoshan | 0:d9cf94b41df3 | 26 | // draws the first enemy beam of the second stage |
RexRoshan | 0:d9cf94b41df3 | 27 | lcd.drawRect(_a,_b,_x,_y,FILL_BLACK); |
RexRoshan | 0:d9cf94b41df3 | 28 | // draws the second enemy beam of the second stage |
RexRoshan | 0:d9cf94b41df3 | 29 | lcd.drawRect(_c,_d,_x,_y,FILL_BLACK); |
RexRoshan | 0:d9cf94b41df3 | 30 | } |
RexRoshan | 0:d9cf94b41df3 | 31 | |
RexRoshan | 0:d9cf94b41df3 | 32 | void EnemyBeam2::update() |
RexRoshan | 0:d9cf94b41df3 | 33 | { |
RexRoshan | 0:d9cf94b41df3 | 34 | _speed = 5.0; // the speed of the beam moving is set at 5 |
RexRoshan | 0:d9cf94b41df3 | 35 | |
RexRoshan | 0:d9cf94b41df3 | 36 | _a-=_speed; // moves the first enemy beam in the negative x direction |
RexRoshan | 0:d9cf94b41df3 | 37 | _c-=_speed; // moves the second enemy beam in the negative x direction |
RexRoshan | 0:d9cf94b41df3 | 38 | |
RexRoshan | 0:d9cf94b41df3 | 39 | // the y direction is kept constant |
RexRoshan | 0:d9cf94b41df3 | 40 | |
RexRoshan | 0:d9cf94b41df3 | 41 | } |
RexRoshan | 0:d9cf94b41df3 | 42 | |
RexRoshan | 0:d9cf94b41df3 | 43 | Vector2D EnemyBeam2::get_pos_21() |
RexRoshan | 0:d9cf94b41df3 | 44 | { |
RexRoshan | 0:d9cf94b41df3 | 45 | // gets the position of the first enemy beam |
RexRoshan | 0:d9cf94b41df3 | 46 | Vector2D b = {_a,_b}; |
RexRoshan | 0:d9cf94b41df3 | 47 | return b; |
RexRoshan | 0:d9cf94b41df3 | 48 | } |
RexRoshan | 0:d9cf94b41df3 | 49 | |
RexRoshan | 0:d9cf94b41df3 | 50 | Vector2D EnemyBeam2::get_pos_22() |
RexRoshan | 0:d9cf94b41df3 | 51 | { |
RexRoshan | 0:d9cf94b41df3 | 52 | // gets the position of the second enemy beam |
RexRoshan | 0:d9cf94b41df3 | 53 | Vector2D c = {_c,_d}; |
RexRoshan | 0:d9cf94b41df3 | 54 | return c; |
RexRoshan | 0:d9cf94b41df3 | 55 | } |
RexRoshan | 0:d9cf94b41df3 | 56 | |
RexRoshan | 0:d9cf94b41df3 | 57 | void EnemyBeam2::set_pos_21(Vector2D p) |
RexRoshan | 0:d9cf94b41df3 | 58 | { |
RexRoshan | 0:d9cf94b41df3 | 59 | // sets the position of the first enemy beam |
RexRoshan | 0:d9cf94b41df3 | 60 | _a = p.x ; |
RexRoshan | 0:d9cf94b41df3 | 61 | _b = p.y ; |
RexRoshan | 0:d9cf94b41df3 | 62 | } |
RexRoshan | 0:d9cf94b41df3 | 63 | |
RexRoshan | 0:d9cf94b41df3 | 64 | void EnemyBeam2::set_pos_22(Vector2D p) |
RexRoshan | 0:d9cf94b41df3 | 65 | { |
RexRoshan | 0:d9cf94b41df3 | 66 | // sets the position of the second enemy beam |
RexRoshan | 0:d9cf94b41df3 | 67 | _c = p.x ; |
RexRoshan | 0:d9cf94b41df3 | 68 | _d = p.y ; |
RexRoshan | 0:d9cf94b41df3 | 69 | } |