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
- Committer:
- ikenna1
- Date:
- 2019-04-10
- Revision:
- 14:88ca5b1a111a
- Parent:
- 9:241a1a7d8527
- Child:
- 22:8cad70085883
File content as of revision 14:88ca5b1a111a:
#include "Weapons.h" Weapons::Weapons() { } Weapons::~Weapons() { } //Obtains the player position coordinates in the initialisation stage. void Weapons::init(int ship_xpos, int ship_ypos, int ship_width) { //printf("ship x, ship y = %d , %d \n", playerx, playery); _ship_xpos = ship_xpos + (ship_width/2); _ship_ypos = ship_ypos; } void Weapons::draw(N5110 &lcd) { /* The ship x position does not seem to be updating we need to pass the _ship_xpos froreset the ship class to here _ship_xpos = ship._ship_xpos _ship_ypos = ship._ship_ypos */ _velocity.x = 0; //Projectile doesn't move sideways. _velocity.y = -1; //Projectile moves upwards on screen. //resets once projectile reaches top of screen if(_y <= -1){ reset= 0; } if(reset == 0){ _x = _ship_xpos; _y = _ship_ypos; reset = reset+1; } lcd.drawRect(_x,_y,1,4,FILL_BLACK); // printf("Ship x and y pos, reset = %d , %d ,%d \n", _ship_xpos, _ship_ypos, reset); } void Weapons::draw_i(N5110 &lcd) { // Make it so rectangle is drawn to top // Change button set up so the beam holds // use sprite if rectangle doesnt work well // add wait times in beween firing and make code to slow down ship lcd.drawRect(_ship_xpos - 2, 0,3,_ship_ypos + 6,FILL_BLACK); } void Weapons::update() { _x = _x + _velocity.x; _y = _y + _velocity.y; } Vector2D Weapons::get_pos() { Vector2D pos = {_x,_y}; return pos; } void Weapons::set_pos(Vector2D p) { _x = p.x; _y = p.y; }