Initial publish
Dependencies: mbed
Fork of el17dg by
game/game.cpp
- Committer:
- Noximilien
- Date:
- 2019-03-04
- Revision:
- 5:2b9181bc5c89
- Parent:
- 4:02c63aaa2df9
- Child:
- 6:100b46be4bea
File content as of revision 5:2b9181bc5c89:
#include "mbed.h" #include "N5110.h" #include "Gamepad.h" #include "models.h" #include "main.h" #include "game.h" //int x_ship_origin = 0; //int y_ship_origin = 24; int x_ship_pos = 0; int y_ship_pos = 24; const int ship_step_incremetion = 2; bool Game::updateAndDraw() { shipMovment(); lcd.drawSprite(x_ship_pos, y_ship_pos, spaceship1_width, spaceship1_height, spaceShip1); /*char buffer[4]; sprintf(buffer,"%i\n",(int)(x_dir.read()*84)); printf(buffer);*/ bool want_to_pause = false; if (gamepad.check_event(gamepad.START_PRESSED)){ want_to_pause = true; } return want_to_pause; } void Game::shipMovment(){ // The position of the ship if(x_ship_pos <= 48 && x_ship_pos >= 0){ if(x_dir.read() > 0.6f){ x_ship_pos -= ship_step_incremetion; } else if(x_dir.read() < 0.4f){ x_ship_pos += ship_step_incremetion; } } else if (x_ship_pos <= 48){ x_ship_pos = 0;} //Limits for x direction border IMPROVE IF POSSIBLE. else { x_ship_pos = 48;} if (y_ship_pos <= (47 - spaceship1_height) && y_ship_pos >= 0){ if(y_dir.read() > 0.6f){ y_ship_pos -= ship_step_incremetion; } else if(y_dir.read() < 0.4f){ y_ship_pos += ship_step_incremetion; } } else if (y_ship_pos >= (47 - spaceship1_height)){ y_ship_pos = 47 - spaceship1_height;} //Limits for y direction border IMPROVE IF POSSIBLE. else if (y_ship_pos < 0){ y_ship_pos = 0;} } void Game::shipFire(){ //if (gamepad.check_event(gamepad.B_PRESSED){ //} }