Josh Davy / Mbed 2 deprecated Flip

Dependencies:   mbed el17jd

Player/Player.cpp

Committer:
joshdavy
Date:
2019-04-17
Revision:
7:68e06dda79f7
Parent:
4:afbf3dd71403
Child:
8:21b6d4dbce44

File content as of revision 7:68e06dda79f7:

#include "Player.h"



Player::Player()
{
    _orientation = 1;
}

Player::~Player()
{

}

void Player::update(Gamepad &pad, Block blocks [],int number_of_blocks)
{
//    if orientation = 1 then
//        for block
//            if in x range of the block
//                if y - height is equal to block y
//                    then dont move down
//                else move down


    if (pad.check_event(Gamepad::L_PRESSED)) {
        _pos.x -= 2;
    }
    if (pad.check_event(Gamepad::R_PRESSED)) {
        _pos.x += 2;
    }
    if (pad.check_event(Gamepad::A_PRESSED)) {
        flip();
    }
    bool can_move_down = false;
    for (int i  = 0; i < number_of_blocks;i++) {
        if (_pos.x + _width > blocks[i].first.x && 
            _pos.x - _width < blocks[i].second.x) {
                
                if ( (_pos.y + _height) == blocks[i].first.y ) {
                    can_move_down = false;
                }
            }
        }
    
    if (can_move_down) {
        _pos.y += GRAVITY;
    }
    
    
       
}