Ikenna Adrian Ozoemena 201157039
Dependencies: mbed
Weapons/Weapons.cpp@40:90c7a893d513, 2019-05-07 (annotated)
- Committer:
- ikenna1
- Date:
- Tue May 07 10:01:34 2019 +0000
- Revision:
- 40:90c7a893d513
- Parent:
- 39:7824f9080f59
- Child:
- 42:ee13e1d103d8
- Child:
- 43:500b8cff3715
Add Orion ship weapons ; Gives a weapon that tracks the movements of enemy ship to the Orion
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ikenna1 | 9:241a1a7d8527 | 1 | #include "Weapons.h" |
ikenna1 | 23:0301effce801 | 2 | DigitalIn A_button(PTB9); |
ikenna1 | 9:241a1a7d8527 | 3 | |
ikenna1 | 9:241a1a7d8527 | 4 | Weapons::Weapons() |
ikenna1 | 9:241a1a7d8527 | 5 | { |
ikenna1 | 9:241a1a7d8527 | 6 | |
ikenna1 | 9:241a1a7d8527 | 7 | } |
ikenna1 | 9:241a1a7d8527 | 8 | |
ikenna1 | 9:241a1a7d8527 | 9 | Weapons::~Weapons() |
ikenna1 | 9:241a1a7d8527 | 10 | { |
ikenna1 | 9:241a1a7d8527 | 11 | |
ikenna1 | 9:241a1a7d8527 | 12 | } |
ikenna1 | 9:241a1a7d8527 | 13 | |
ikenna1 | 9:241a1a7d8527 | 14 | //Obtains the player position coordinates in the initialisation stage. |
ikenna1 | 9:241a1a7d8527 | 15 | void Weapons::init(int ship_xpos, int ship_ypos, int ship_width) |
ikenna1 | 9:241a1a7d8527 | 16 | { |
ikenna1 | 9:241a1a7d8527 | 17 | //printf("ship x, ship y = %d , %d \n", playerx, playery); |
ikenna1 | 9:241a1a7d8527 | 18 | _ship_xpos = ship_xpos + (ship_width/2); |
ikenna1 | 9:241a1a7d8527 | 19 | _ship_ypos = ship_ypos; |
ikenna1 | 9:241a1a7d8527 | 20 | |
ikenna1 | 9:241a1a7d8527 | 21 | } |
ikenna1 | 40:90c7a893d513 | 22 | void Weapons::draw(N5110 &lcd,Gamepad &pad,int shipno,Vector2D closest_enemy ) |
ikenna1 | 22:8cad70085883 | 23 | { |
ikenna1 | 22:8cad70085883 | 24 | if(shipno == 0) { |
ikenna1 | 22:8cad70085883 | 25 | _velocity.x = 0; //Projectile doesn't move sideways. |
ikenna1 | 39:7824f9080f59 | 26 | _velocity.y = -7; //Projectile moves upwards on screen. |
ikenna1 | 22:8cad70085883 | 27 | |
ikenna1 | 22:8cad70085883 | 28 | //resets once projectile reaches top of screen |
ikenna1 | 22:8cad70085883 | 29 | if(_y <= -1) { |
ikenna1 | 22:8cad70085883 | 30 | reset= 0; |
ikenna1 | 9:241a1a7d8527 | 31 | } |
ikenna1 | 9:241a1a7d8527 | 32 | |
ikenna1 | 22:8cad70085883 | 33 | if(reset == 0) { |
ikenna1 | 22:8cad70085883 | 34 | _x = _ship_xpos; |
ikenna1 | 22:8cad70085883 | 35 | _y = _ship_ypos; |
ikenna1 | 22:8cad70085883 | 36 | reset = reset+1; |
ikenna1 | 9:241a1a7d8527 | 37 | } |
ikenna1 | 22:8cad70085883 | 38 | lcd.drawRect(_x,_y,1,4,FILL_BLACK); |
ikenna1 | 22:8cad70085883 | 39 | // printf("Ship x and y pos, reset = %d , %d ,%d \n", _ship_xpos, _ship_ypos, reset); |
ikenna1 | 22:8cad70085883 | 40 | } |
ikenna1 | 22:8cad70085883 | 41 | if(shipno == 1) { |
ikenna1 | 23:0301effce801 | 42 | if((A_button) == true) { |
ikenna1 | 24:ab821bfeb383 | 43 | // while((A_button) == true) { |
ikenna1 | 24:ab821bfeb383 | 44 | pad.tone(2000,0.1); |
ikenna1 | 26:a53d41adf40b | 45 | lcd.drawRect(_ship_xpos - 1, 0,3,_ship_ypos + 6,FILL_BLACK); |
ikenna1 | 24:ab821bfeb383 | 46 | wait(0.1); |
ikenna1 | 23:0301effce801 | 47 | //} |
ikenna1 | 23:0301effce801 | 48 | } |
ikenna1 | 22:8cad70085883 | 49 | } |
ikenna1 | 40:90c7a893d513 | 50 | if(shipno == 2) { |
ikenna1 | 40:90c7a893d513 | 51 | float rangex = (abs(_ship_xpos - closest_enemy.x)); |
ikenna1 | 40:90c7a893d513 | 52 | float rangey = (abs(_ship_ypos - closest_enemy.y)); |
ikenna1 | 40:90c7a893d513 | 53 | int distance = floor((rangex+rangey)/2); |
ikenna1 | 40:90c7a893d513 | 54 | if((A_button) == true && distance < 15) { |
ikenna1 | 40:90c7a893d513 | 55 | lcd.drawLine(_ship_xpos + 2,_ship_ypos + 2,closest_enemy.x + 2,closest_enemy.y + 2,FILL_BLACK); |
ikenna1 | 27:f99249e727fd | 56 | } |
ikenna1 | 40:90c7a893d513 | 57 | } |
ikenna1 | 14:88ca5b1a111a | 58 | } |
ikenna1 | 9:241a1a7d8527 | 59 | |
ikenna1 | 22:8cad70085883 | 60 | void Weapons::update() |
ikenna1 | 9:241a1a7d8527 | 61 | { |
ikenna1 | 9:241a1a7d8527 | 62 | _x = _x + _velocity.x; |
ikenna1 | 9:241a1a7d8527 | 63 | _y = _y + _velocity.y; |
ikenna1 | 9:241a1a7d8527 | 64 | } |
ikenna1 | 9:241a1a7d8527 | 65 | |
ikenna1 | 9:241a1a7d8527 | 66 | |
ikenna1 | 9:241a1a7d8527 | 67 | |
ikenna1 | 24:ab821bfeb383 | 68 | Vector2D Weapons::get_pos(int shipno) |
ikenna1 | 9:241a1a7d8527 | 69 | { |
ikenna1 | 24:ab821bfeb383 | 70 | if(shipno == 0) { |
ikenna1 | 24:ab821bfeb383 | 71 | Vector2D pos = {_x,_y}; |
ikenna1 | 24:ab821bfeb383 | 72 | return pos; |
ikenna1 | 24:ab821bfeb383 | 73 | } |
ikenna1 | 9:241a1a7d8527 | 74 | } |
ikenna1 | 9:241a1a7d8527 | 75 | |
ikenna1 | 26:a53d41adf40b | 76 | void Weapons::set_pos(int xpos, int ypos) |
ikenna1 | 9:241a1a7d8527 | 77 | { |
ikenna1 | 26:a53d41adf40b | 78 | _x = xpos; |
ikenna1 | 26:a53d41adf40b | 79 | _y = ypos; |
ikenna1 | 9:241a1a7d8527 | 80 | } |