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@9:241a1a7d8527, 2019-04-09 (annotated)
- Committer:
- ikenna1
- Date:
- Tue Apr 09 05:14:07 2019 +0000
- Revision:
- 9:241a1a7d8527
- Child:
- 14:88ca5b1a111a
Had to work on this in another folder as this one got corrupted for some reason but it works once the name is changed so will work on it with name changed. New features include Menu class and Weapons class
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ikenna1 | 9:241a1a7d8527 | 1 | #include "Weapons.h" |
ikenna1 | 9:241a1a7d8527 | 2 | |
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 | 9:241a1a7d8527 | 25 | void Weapons::draw(N5110 &lcd) |
ikenna1 | 9:241a1a7d8527 | 26 | { |
ikenna1 | 9:241a1a7d8527 | 27 | /* |
ikenna1 | 9:241a1a7d8527 | 28 | The ship x position does not seem to be updating we need to pass the _ship_xpos froreset the ship class to here |
ikenna1 | 9:241a1a7d8527 | 29 | _ship_xpos = ship._ship_xpos |
ikenna1 | 9:241a1a7d8527 | 30 | _ship_ypos = ship._ship_ypos |
ikenna1 | 9:241a1a7d8527 | 31 | */ |
ikenna1 | 9:241a1a7d8527 | 32 | _velocity.x = 0; //Projectile doesn't move sideways. |
ikenna1 | 9:241a1a7d8527 | 33 | _velocity.y = -1; //Projectile moves upwards on screen. |
ikenna1 | 9:241a1a7d8527 | 34 | |
ikenna1 | 9:241a1a7d8527 | 35 | //resets once projectile reaches top of screen |
ikenna1 | 9:241a1a7d8527 | 36 | if(_y <= -1){ |
ikenna1 | 9:241a1a7d8527 | 37 | reset= 0; |
ikenna1 | 9:241a1a7d8527 | 38 | } |
ikenna1 | 9:241a1a7d8527 | 39 | |
ikenna1 | 9:241a1a7d8527 | 40 | if(reset == 0){ |
ikenna1 | 9:241a1a7d8527 | 41 | _x = _ship_xpos; |
ikenna1 | 9:241a1a7d8527 | 42 | _y = _ship_ypos; |
ikenna1 | 9:241a1a7d8527 | 43 | reset = reset+1; |
ikenna1 | 9:241a1a7d8527 | 44 | } |
ikenna1 | 9:241a1a7d8527 | 45 | lcd.drawRect(_x,_y,1,4,FILL_BLACK); |
ikenna1 | 9:241a1a7d8527 | 46 | // printf("Ship x and y pos, reset = %d , %d ,%d \n", _ship_xpos, _ship_ypos, reset); |
ikenna1 | 9:241a1a7d8527 | 47 | |
ikenna1 | 9:241a1a7d8527 | 48 | } |
ikenna1 | 9:241a1a7d8527 | 49 | |
ikenna1 | 9:241a1a7d8527 | 50 | void Weapons::update() |
ikenna1 | 9:241a1a7d8527 | 51 | { |
ikenna1 | 9:241a1a7d8527 | 52 | _x = _x + _velocity.x; |
ikenna1 | 9:241a1a7d8527 | 53 | _y = _y + _velocity.y; |
ikenna1 | 9:241a1a7d8527 | 54 | } |
ikenna1 | 9:241a1a7d8527 | 55 | |
ikenna1 | 9:241a1a7d8527 | 56 | |
ikenna1 | 9:241a1a7d8527 | 57 | |
ikenna1 | 9:241a1a7d8527 | 58 | Vector2D Weapons::get_pos() |
ikenna1 | 9:241a1a7d8527 | 59 | { |
ikenna1 | 9:241a1a7d8527 | 60 | Vector2D pos = {_x,_y}; |
ikenna1 | 9:241a1a7d8527 | 61 | return pos; |
ikenna1 | 9:241a1a7d8527 | 62 | } |
ikenna1 | 9:241a1a7d8527 | 63 | |
ikenna1 | 9:241a1a7d8527 | 64 | void Weapons::set_pos(Vector2D p) |
ikenna1 | 9:241a1a7d8527 | 65 | { |
ikenna1 | 9:241a1a7d8527 | 66 | _x = p.x; |
ikenna1 | 9:241a1a7d8527 | 67 | _y = p.y; |
ikenna1 | 9:241a1a7d8527 | 68 | } |