Ben Evans / Mbed 2 deprecated Defender_Game

Dependencies:   mbed

People/People.cpp

Committer:
evanso
Date:
2020-05-14
Revision:
33:7fedd8029473
Child:
34:85ccc16f24d2

File content as of revision 33:7fedd8029473:

#include "People.h"

const int k_people_sprite[5][4] = {
    { 0,1,1,0,},
    { 1,1,1,1,},
    { 1,1,1,1,},
    { 0,1,1,0,},
    { 0,1,1,0,},
};

People::People() {

}
 
People::~People() {
    
}

void People::init(Gamepad &pad, int position_x_start) {
    position_x_ = position_x_start;
    position_y_ = 43;
}

void People::draw_people(N5110 &lcd, Direction d_){
    position_x_ += calc_people_movement(d_);
    lcd.drawSprite(position_x_, position_y_, 5, 4, (int*)k_people_sprite);
}

int People::calc_people_movement(Direction d_){  
    // moves the people in oposite direction to spaceship when it's position is 
    // at min and max x positions and joystick has direction     
    if (d_ == W || d_ == NW || d_ == SW){ 
        return 2;
    }else if (d_ == E || d_ == NE || d_ == SE){ 
        return -2; 
    }else {
        return 0;
    }
}