ELEC2645 (2018/19) / Mbed 2 deprecated el17ttds

Dependencies:   mbed N5110_tf

Map/Map.cpp

Committer:
el17ttds
Date:
2019-05-07
Revision:
4:3446009e2f38
Parent:
3:3d35ab70b565
Child:
6:e8c03f264ffc

File content as of revision 4:3446009e2f38:

#include "Map.h"

Map::Map() {

}

void Map::init(int width, int height, int swidth, int sheight) {  // initialises map dimensions
    _swidth = swidth;
    _sheight = sheight;
    _width = width;
    _height = height;
    _w = 0;
    _h = 0;
}

void Map::write(int x1, int y1) {  // uses origin of top left corner to create the map

    _x1 = x1;
    _x2 = _x1 + _width + (_swidth / 2);
    _y1 = y1;
    _y2 = _y1 + _height + (_sheight / 2);
    map_parameters();
}

void Map::map_parameters() {
  horizontal();
  veritical();
}

void Map::horizontal() {
  if (_x1 < -(_swidth / 2)) {
      _x1_pos = -1;
  } else if (_x1 < 0) {
      _x1_pos = 0;
      _w = (_swidth / 2) + _x1;
  } else {
      _x1_pos = 0;
      _w = _swidth / 2;
  }
  if (_x2 < (_swidth / 2)) {
    _x2 = (_swidth / 2);
    // _x1 = -100; do this in Engine
  }
}

void Map::veritical() {
  if (_y1 < -(_sheight / 2)) {
      _y1_pos = -1;
  } else if (_y1 < 0) {
      _y1_pos = 0;
      _h = (_sheight / 2) + _y1;
  } else {
      _y1_pos = 0;
      _h = _sheight / 2;
  }
  if (_y2 < (_sheight / 2)) {
    _y2 = (_sheight / 2);
    // _y1 = -100; do this in Engine
  }
}

void Map::draw(N5110 &lcd) {

    lcd.drawRect(_x1_pos,0,_w,_sheight,FILL_BLACK);
    lcd.drawRect(0,_y1_pos,_swidth,_h,FILL_BLACK);
    lcd.drawRect(0,_y2,_swidth,_sheight / 2,FILL_BLACK);
    lcd.drawRect(_x2,0,_swidth / 2,_sheight,FILL_BLACK);
}