Johnathan Chin / Mbed 2 deprecated Lab5

Dependencies:   4DGL-uLCD-SE PinDetect mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers AbstractAsteroid.cpp Source File

AbstractAsteroid.cpp

00001 #include "AbstractAsteroid.h"
00002 
00003 int asteroidErase[ASTEROID_WIDTH * ASTEROID_HEIGHT] = {
00004  _,_,_,_,_,_,_,_,_,_,_,_,_,_,_,
00005  _,_,_,_,_,_,_,_,_,_,_,_,_,_,_,
00006  _,_,_,_,_,_,_,_,_,_,_,_,_,_,_,
00007  _,_,_,_,_,_,_,_,_,_,_,_,_,_,_,
00008  _,_,_,_,_,_,_,_,_,_,_,_,_,_,_,
00009  _,_,_,_,_,_,_,_,_,_,_,_,_,_,_,
00010  _,_,_,_,_,_,_,_,_,_,_,_,_,_,_,
00011  _,_,_,_,_,_,_,_,_,_,_,_,_,_,_,
00012  _,_,_,_,_,_,_,_,_,_,_,_,_,_,_,
00013  _,_,_,_,_,_,_,_,_,_,_,_,_,_,_,
00014  _,_,_,_,_,_,_,_,_,_,_,_,_,_,_,
00015  _,_,_,_,_,_,_,_,_,_,_,_,_,_,_
00016 };
00017 
00018 int AbstractAsteroid::getXPath() const {
00019     return xPath;
00020 }
00021 
00022 int AbstractAsteroid::getYPath() const {
00023     return yPath;
00024 }
00025 
00026 int AbstractAsteroid::getSpeed() const {
00027     return speed;
00028 }
00029 
00030 void AbstractAsteroid::setXPath(int xPath) {
00031     this->xPath = xPath;
00032 }
00033 
00034 void AbstractAsteroid::setYPath(int yPath) {
00035     this->yPath = yPath;
00036 }
00037 
00038 void AbstractAsteroid::setSpeed(int speed) {
00039     this->speed = speed;
00040 }
00041 
00042 
00043 void AbstractAsteroid::draw() {
00044     uLCD.BLIT(getX() - (ASTEROID_WIDTH / 2), getY() - (ASTEROID_HEIGHT / 2),
00045         ASTEROID_WIDTH, ASTEROID_HEIGHT, getSprite());
00046 }
00047 
00048 void AbstractAsteroid::update() {
00049     uLCD.BLIT(getX() - (ASTEROID_WIDTH / 2), getY() - (ASTEROID_HEIGHT / 2),
00050         ASTEROID_WIDTH, ASTEROID_HEIGHT, asteroidErase);
00051     setX(getSpeed() * (getX() + getXPath()));
00052     setY(getSpeed() * (getY() + getYPath()));
00053     int leftBound = getX() - (ASTEROID_WIDTH / 2);
00054     int topBound = getY() - (ASTEROID_HEIGHT / 2);
00055     int rightBound = getX() + (ASTEROID_WIDTH / 2);
00056     int bottomBound = getY() + (ASTEROID_WIDTH / 2);
00057     if (leftBound < 1 + (getWidth() / 2) || topBound < 1 + (getHeight()  / 2)
00058         || rightBound > 127 - (getWidth() / 2)
00059         || bottomBound > 127 - (getHeight() / 2)) {
00060         setDestroyed(true);
00061     } 
00062 }