A game for Lab 4 of ECE 4180
Dependencies: 4DGL-uLCD-SE LSM9DS1_Library SDFileSystem mbed-rtos mbed wave_player
Diff: Player.cpp
- Revision:
- 0:6a49493943be
- Child:
- 3:27889fffc2f7
diff -r 000000000000 -r 6a49493943be Player.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Player.cpp Thu Mar 10 20:10:35 2016 +0000 @@ -0,0 +1,56 @@ +#include "Player.h" + +#define WIDTH 10 +#define HEIGHT 10 + +Player::Player(uLCD_4DGL* screenInit, InputHandler* input, int startX, int startY) +{ + screen = screenInit; + x = startX; + y = startY; + lastX = x; + lastY = y; + + inputManager = input; +} + +void Player::update() +{ + float xAccel = inputManager->getXAccel() * 4; + float yAccel = inputManager->getYAccel() * 4; + + int speedX = (int)(xAccel + (xAccel > 0 ? 0.5 : -0.5)) ; // Maximum Speed of 4 + int speedY = (int)(yAccel + (yAccel > 0 ? 0.5 : -0.5)) ; // Maximum Speed of 4 + + x += speedX; + y += speedY; +} + +void Player::draw() +{ + screen_mutex.lock(); + screen->filled_circle(lastX, lastY, WIDTH/2, BLACK); + screen->filled_circle(x, y, HEIGHT/2, GREEN); + screen_mutex.unlock(); +} + +int Player::getX() +{ + return x; +} + +int Player::getY() +{ + return y; +} + +int Player::getWidth() +{ + return WIDTH; +} + +int Player::getHeight() +{ + return HEIGHT; +} + \ No newline at end of file