ELEC2645 (2018/19) / Mbed 2 deprecated el17m2h_public

Dependencies:   mbed

Doodler/Doodler.h

Committer:
el17m2h
Date:
2019-05-08
Revision:
24:67dc71a8f009
Parent:
23:9be87557b89a
Child:
25:f122e1862cd1

File content as of revision 24:67dc71a8f009:

#ifndef DOODLER_H
#define DOODLER_H

#include "mbed.h"
#include "N5110.h"
#include "Gamepad.h"

/** Doodler's class
@brief Class for the doodler 
@author Melissa Hartmann
@date May 2019
*/
class Doodler{
public:
    Doodler();
    ~Doodler();
    /** 
    @brief Defines the initial position of the bullet
    @param float position_x uses float since the velocity will be added, which is not an integer.
    @param float position_y uses float since the velocity will be added, which is not an integer.
    @param double velocity_y needs to be double in order for it to decelerate to a small value that approaches zero.
    @details The intial position of the doodler is at the centre of the screen and the values are gotten from the Engine class. It also defines the gravity as a positive vale greater than 1 and the up object as a negative vale less than 1.
    */
    void init(float position_x, float position_y, double velocity_y);
    
    /** 
    @brief Prints the doodler into the LCD screen
    @param N5110 &lcd
    @details The function draws a sprite of 13 x 15 bits that shows the image of the doodler
    */
    void draw(N5110 &lcd);    
    
    /** 
    @brief Updates the position of the doodler
    @param Direction d is gotten from the user input of the joystick and determines the movement of the doodler in the x-direction. It moves left/right if the joystick directs left/right at an angle or not.
    @param float mag is used to accelerate the movement of the doodler in the x-direction since it moves 5 frames * the magnitude of the joystick.
    @details The function checks the doodler does not leave the screen rectangle (30 x 83) in the 
    x-direction and checks the direction of the velocity to keep adding or substructing a value in the y-direction (depending on if it is jumping or falling)
    */
    void update(Direction d, float mag);
    
    /** 
    @brief Check velocity 
    @details The function checks the velocity of the 
    if ((double)_velocity_y > 0.00){ // no jump 
        _velocity_y = (double)_velocity_y*(double)_gravity; // falls accelerating 
    } else if ( (double)_velocity_y == 0.00){
        _velocity_y = (double)_gravity; 
    } else if ((double)_velocity_y < 0.00){ 
        _velocity_y = -((double)_velocity_y * (double)_up); // jumps decelerating upwards (0<_up<1 so _velocity.y reaches 0)
        if (fabs((double)_velocity_y) < 0.008){ // decelerated completely
            _velocity_y = 0.00;
    */
    void check_velocity();  
    
    /** 
    @brief Returns the current doodler's velocity in the x-axis
    @details Gets the current value in the doodler's class for the doodler's velocity in the x-axis
    */
    float get_velocity_x();
    
    /** 
    @brief Returns the current doodler's velocity in the y-axis
    @details Gets the current value in the doodler's class for the doodler's velocity in the y-axis. It is a double value since the y-velocity is a double type. 
    */
    double get_velocity_y();
    
    /** 
    @brief Returns the current doodler's position in the x-axis
    @details Gets the current value in the doodler's class for the doodler's position in the x-axis
    */
    float get_position_x(); 
    
    /** 
    @brief Returns the current doodler's position in the y-axis
    @details Gets the current value in the doodler's class for the doodler's position in the y-axis
    */
    float get_position_y(); 
    
    /** 
    @brief 
    @param float vel_x 
    @param float vel_y
    @details 
    */
    void set_velocity(float vel_x, double vel_y);
    
    /** 
    @brief 
    @param 
    @param 
    @details 
    */
    void set_position(float pos_x, float pos_y);
    
private:
    float _position_x;
    float _position_y;
    float _velocity_x;
    double _velocity_y;
    double _gravity;
    double _up;
};
#endif