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
Weapons/Weapons.cpp@26:a53d41adf40b, 2019-04-18 (annotated)
- Committer:
- ikenna1
- Date:
- Thu Apr 18 11:40:47 2019 +0000
- Revision:
- 26:a53d41adf40b
- Parent:
- 24:ab821bfeb383
- Child:
- 27:f99249e727fd
Changed the way collision functions work to now return a true or false value depending on if the collision occurred.;
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 | 9:241a1a7d8527 | 22 | |
| ikenna1 | 9:241a1a7d8527 | 23 | |
| ikenna1 | 9:241a1a7d8527 | 24 | |
| ikenna1 | 23:0301effce801 | 25 | void Weapons::draw(N5110 &lcd,Gamepad &pad,int shipno) |
| ikenna1 | 22:8cad70085883 | 26 | { |
| ikenna1 | 22:8cad70085883 | 27 | if(shipno == 0) { |
| ikenna1 | 22:8cad70085883 | 28 | _velocity.x = 0; //Projectile doesn't move sideways. |
| ikenna1 | 23:0301effce801 | 29 | _velocity.y = -5; //Projectile moves upwards on screen. |
| ikenna1 | 22:8cad70085883 | 30 | |
| ikenna1 | 22:8cad70085883 | 31 | //resets once projectile reaches top of screen |
| ikenna1 | 22:8cad70085883 | 32 | if(_y <= -1) { |
| ikenna1 | 22:8cad70085883 | 33 | reset= 0; |
| ikenna1 | 9:241a1a7d8527 | 34 | } |
| ikenna1 | 9:241a1a7d8527 | 35 | |
| ikenna1 | 22:8cad70085883 | 36 | if(reset == 0) { |
| ikenna1 | 22:8cad70085883 | 37 | _x = _ship_xpos; |
| ikenna1 | 22:8cad70085883 | 38 | _y = _ship_ypos; |
| ikenna1 | 22:8cad70085883 | 39 | reset = reset+1; |
| ikenna1 | 9:241a1a7d8527 | 40 | } |
| ikenna1 | 22:8cad70085883 | 41 | lcd.drawRect(_x,_y,1,4,FILL_BLACK); |
| ikenna1 | 22:8cad70085883 | 42 | // printf("Ship x and y pos, reset = %d , %d ,%d \n", _ship_xpos, _ship_ypos, reset); |
| ikenna1 | 22:8cad70085883 | 43 | } |
| ikenna1 | 22:8cad70085883 | 44 | if(shipno == 1) { |
| ikenna1 | 23:0301effce801 | 45 | if((A_button) == true) { |
| ikenna1 | 24:ab821bfeb383 | 46 | // while((A_button) == true) { |
| ikenna1 | 24:ab821bfeb383 | 47 | pad.tone(2000,0.1); |
| ikenna1 | 26:a53d41adf40b | 48 | lcd.drawRect(_ship_xpos - 1, 0,3,_ship_ypos + 6,FILL_BLACK); |
| ikenna1 | 24:ab821bfeb383 | 49 | wait(0.1); |
| ikenna1 | 23:0301effce801 | 50 | //} |
| ikenna1 | 23:0301effce801 | 51 | } |
| ikenna1 | 22:8cad70085883 | 52 | } |
| ikenna1 | 14:88ca5b1a111a | 53 | } |
| ikenna1 | 9:241a1a7d8527 | 54 | |
| ikenna1 | 22:8cad70085883 | 55 | |
| ikenna1 | 22:8cad70085883 | 56 | void Weapons::update() |
| ikenna1 | 9:241a1a7d8527 | 57 | { |
| ikenna1 | 9:241a1a7d8527 | 58 | _x = _x + _velocity.x; |
| ikenna1 | 9:241a1a7d8527 | 59 | _y = _y + _velocity.y; |
| ikenna1 | 9:241a1a7d8527 | 60 | } |
| ikenna1 | 9:241a1a7d8527 | 61 | |
| ikenna1 | 9:241a1a7d8527 | 62 | |
| ikenna1 | 9:241a1a7d8527 | 63 | |
| ikenna1 | 24:ab821bfeb383 | 64 | Vector2D Weapons::get_pos(int shipno) |
| ikenna1 | 9:241a1a7d8527 | 65 | { |
| ikenna1 | 24:ab821bfeb383 | 66 | if(shipno == 0) { |
| ikenna1 | 24:ab821bfeb383 | 67 | Vector2D pos = {_x,_y}; |
| ikenna1 | 24:ab821bfeb383 | 68 | return pos; |
| ikenna1 | 24:ab821bfeb383 | 69 | } |
| ikenna1 | 9:241a1a7d8527 | 70 | } |
| ikenna1 | 9:241a1a7d8527 | 71 | |
| ikenna1 | 26:a53d41adf40b | 72 | void Weapons::set_pos(int xpos, int ypos) |
| ikenna1 | 9:241a1a7d8527 | 73 | { |
| ikenna1 | 26:a53d41adf40b | 74 | _x = xpos; |
| ikenna1 | 26:a53d41adf40b | 75 | _y = ypos; |
| ikenna1 | 9:241a1a7d8527 | 76 | } |