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
Diff: Ship/Ship.cpp
- Revision:
- 6:8473dacbeb65
- Parent:
- 5:bb6edc5b5be3
- Child:
- 9:241a1a7d8527
--- a/Ship/Ship.cpp Tue Mar 05 07:08:57 2019 +0000 +++ b/Ship/Ship.cpp Tue Mar 05 09:57:55 2019 +0000 @@ -1,5 +1,4 @@ #include "Ship.h" - Ship::Ship() { @@ -9,7 +8,7 @@ { } -/* data needed for first ship: basic +// data needed for first ship: basic const int basic[6][9] = { { 0,0,0,0,1,0,0,0,0 }, { 0,0,0,1,1,1,0,0,0 }, @@ -18,58 +17,59 @@ { 1,0,1,1,0,1,1,0,1 }, { 0,1,1,1,1,1,1,1,0 }, }; +/* int basic_width = 9; int basic_height = 6; int basic_speed = 5; */ // Set basic ship to be default -void ship::init(int ship_speed,int ship_width,int ship_height,int ship_xpos,int ship_ypos,const int ship_shape) +void Ship::init(int ship_speed,int ship_width,int ship_height,int ship_xpos,int ship_ypos) { _ship_speed = ship_speed; _ship_width = ship_width; _ship_height = ship_height; _ship_xpos = ship_xpos; _ship_xpos = ship_ypos; - _ship_shape[_ship_height][_ship_width] = ship_shape; +// _ship_shape[_ship_height][_ship_width] = ship_shape; } // Draw the ship ***Note: figure out how to change ship type e.g from basic to devotion -void ship::draw_ship(N5110 &lcd) +void Ship::draw_ship(N5110 &lcd) { lcd.drawSprite(_ship_xpos,_ship_ypos,6,9,(int *)basic); } -void ship::update_ship(int x_joystick,int y_joystick) +void Ship::update_ship(int x_joystick,int y_joystick) { // Do not move sprite until joystick is moved reasonably if(-0.25 > x_joystick || x_joystick > 0.25 || -0.25 > y_joystick || y_joystick > 0.25) { // Dont let sprite move out of screen - if(_ship_xpos > (84 - (1.5 * ship_width))) { + if(_ship_xpos > (84 - (1.5 * _ship_width))) { if(x_joystick < -0.25) { - _ship_xpos = _ship_xpos + (x_joystick*ship_speed); + _ship_xpos = _ship_xpos + (x_joystick*_ship_speed); } - } else if(_ship_xpos < (0.5 *ship_width)) { + } else if(_ship_xpos < (0.5 *_ship_width)) { if(x_joystick > 0.25) { - _ship_xpos = _ship_xpos + (x_joystick*ship_speed); + _ship_xpos = _ship_xpos + (x_joystick*_ship_speed); } } else { - _ship_xpos = _ship_xpos + (x_joystick*ship_speed); + _ship_xpos = _ship_xpos + (x_joystick*_ship_speed); } if(_ship_ypos > 1) { if(y_joystick > 0.25) { - _ship_ypos = _ship_ypos - (y_joystick*ship_speed); + _ship_ypos = _ship_ypos - (y_joystick*_ship_speed); } } - if(_ship_ypos < (48 - ship_height)) { + if(_ship_ypos < (48 - _ship_height)) { if(y_joystick < -0.25) { - _ship_ypos = _ship_ypos - (y_joystick*ship_speed); + _ship_ypos = _ship_ypos - (y_joystick*_ship_speed); } } } } // returns the current ship position on screen as a vector -Vector2D ship::get_pos() +Vector2D Ship::get_pos() { Vector2D ship_pos = {_ship_xpos,_ship_ypos}; return ship_pos; @@ -77,4 +77,5 @@ /****Note: if you make all the ships the same size, you could then creare a enum for them ship.[ enum class Ship {basic, devotion}; ] then, you can declare a new variable belonging to the enum Ship, ship. then to set a ships sprite simply use the variable to test if -the ship is correct and create an if function to draw the appropriate ship \ No newline at end of file +the ship is correct and create an if function to draw the appropriate ship +*/ \ No newline at end of file