ELEC2645 (2018/19) / Mbed 2 deprecated el17m2h_public

Dependencies:   mbed

Doodler/Doodler.cpp

Committer:
el17m2h
Date:
2019-04-13
Revision:
6:848d1e4c1a31
Parent:
5:8814d6de77d0
Child:
7:0d9cee90ab0d

File content as of revision 6:848d1e4c1a31:

#include "Doodler.h"

Doodler::Doodler(){
}
Doodler::~Doodler(){
}

void Doodler::init(int radius){
    
// initial position of doodler at middle 
    _x = (70/2)+6; // middle
    _y = 43; // if doodler is above the middle, the screen shifts up (floors shift down)
    _radius = radius;
    _speed =0.5; // default speed
}

void Doodler::draw(N5110 &lcd){
    lcd.drawCircle(_x, _y, _radius, FILL_BLACK);
}

void Doodler::update(Direction d, float mag){
    _speed = int(mag*10.0f);
    
    if (d == W){ // if direction is left
        _x-= _speed;
    } else if (d == E){
        _x+= _speed;
    }
// checking doodler does not leave screen:
    if (_x > WIDTH-4){ // right side
        _x = WIDTH-4;
    }
    if (_x < _radius){ // left side
        _x = _radius;
    }    
}

void Doodler::jump(){
    _y-= _speed; // (y max = 43, y min = 28)
    
    if ( _y < 28){
        _y+= _speed;
    }    
}

Vector2D Doodler::get_pos(){
    Vector2D p = {_x,_y};
    return p;
}