test avoid bulled game

Dependencies:   C12832_lcd LCD_fonts mbed mbed-rtos

Person.cpp

Committer:
kaku_jyoko
Date:
2016-12-13
Revision:
39:e8d6dd3c75c7
Parent:
18:0f6f2aa2339d
Child:
40:ec5c1b305b9a

File content as of revision 39:e8d6dd3c75c7:

#include "point.h"
#include "models.h"

Person::Person(){
    p.x = DEFAULT_X;
    p.y = DEFAULT_Y;
    jump_count = 0;
    jump_time = 0;
}

point Person::update(int h){
    int height = LCD_Y - h - 1;
    if(jump_time > 0){
        //while jumpping
        p.y -= JUMP_SIZE;
        jump_time--; 
    }else{
        //while down or go
        if(isGround(height)){
            //while go
            jump_count = 0;
        }else{
            //while down
            p.y += JUMP_SIZE;
        }
    }
    return p;
}

point Person::jump(){
    //start jump
    if(jump_count < MAX_JUMP_COUNT){
        p.y -= JUMP_SIZE;
        jump_time = MAX_JUMP_TIME;
        jump_count++;
    }
    return p;
}

bool Person::isGround(int height){
    printf("height: %d, person: %d \n", height, p.y + PERSON_SIZE - 1);
    return height == (p.y + PERSON_SIZE - 1);
}