ELEC2645 (2019/20) / Mbed 2 deprecated ELEC2645_Project_el18jkeo

Dependencies:   mbed

Ship/Ship.cpp

Committer:
josh_ohara
Date:
2020-03-22
Revision:
5:e5bb95fb308b
Parent:
4:18a1fc4c38e0
Child:
6:5bea67cc96f9

File content as of revision 5:e5bb95fb308b:

#include "Ship.h"

void Ship::init(int y, int height, int width)
{
    X = WIDTH/2 + width/2;
    Y = HEIGHT - height;
    height = Height;
    width = Width;
    Speed = 0.5;
}

void Ship::draw(N5110 &lcd)
{
    lcd.drawRect(X,Y,Width,Height,FILL_BLACK);
}

void Ship::update(Direction d,float mag)
{
    Speed = int(mag*10.0f);  

    if (d == E) {
        X+=Speed;
    } else if (d == NE) {
        X+=0.5*Speed;
    } else if (d == SE) {
        X+=0.5*Speed;
    } else if (d == W) {
        X-=Speed;
    } else if (d == NW) {
        X-=0.5*Speed;
    } else if (d == SW) {
        X-=0.5*Speed;
    }
    
    if (X < 1) {
        X = 1;
    }
    if (X > HEIGHT - Height - 1) {
        X = HEIGHT - Height - 1;
    }
}

Vector2D Ship::get_position() {
    Vector2D p = {X,Y};
    return p;    
}

int Ship::get_height() {
    int height = Height;
    return height;
}

int Ship::get_width() {
    int width = Width;
    return width;
}

//void Ship::set_life(bool l) {
  //  Life = l;
//}