ELEC2645 (2018/19) / Mbed 2 deprecated el17m2h_public

Dependencies:   mbed

Committer:
el17m2h
Date:
Wed May 08 21:11:35 2019 +0000
Revision:
29:15e9640646b7
Parent:
26:d16a5b1e0ace
Child:
32:83f410c433c2
Changed the enemy file so that it has functions to make it update its position or make it disappear from the screen. The floors h file includes the enemy, and depending on its position it updates it or not.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
el17m2h 4:8ec314f806ae 1 #ifndef DOODLER_H
el17m2h 4:8ec314f806ae 2 #define DOODLER_H
el17m2h 4:8ec314f806ae 3
el17m2h 4:8ec314f806ae 4 #include "mbed.h"
el17m2h 4:8ec314f806ae 5 #include "N5110.h"
el17m2h 4:8ec314f806ae 6 #include "Gamepad.h"
el17m2h 5:8814d6de77d0 7
el17m2h 24:67dc71a8f009 8 /** Doodler's class
el17m2h 29:15e9640646b7 9 @brief Class for the doodler
el17m2h 24:67dc71a8f009 10 @author Melissa Hartmann
el17m2h 24:67dc71a8f009 11 @date May 2019
el17m2h 24:67dc71a8f009 12 */
el17m2h 29:15e9640646b7 13 class Doodler
el17m2h 29:15e9640646b7 14 {
el17m2h 4:8ec314f806ae 15 public:
el17m2h 4:8ec314f806ae 16 Doodler();
el17m2h 4:8ec314f806ae 17 ~Doodler();
el17m2h 29:15e9640646b7 18 /**
el17m2h 26:d16a5b1e0ace 19 @brief Defines the initial position of the doodler
el17m2h 24:67dc71a8f009 20 @param float position_x uses float since the velocity will be added, which is not an integer.
el17m2h 24:67dc71a8f009 21 @param float position_y uses float since the velocity will be added, which is not an integer.
el17m2h 29:15e9640646b7 22 @param double velocity_y needs to be double in order for it to decelerate to a small value that
el17m2h 26:d16a5b1e0ace 23 approaches zero.
el17m2h 29:15e9640646b7 24 @details The intial position of the doodler is at the centre of the screen and the values are
el17m2h 29:15e9640646b7 25 gotten from the Engine class. It also defines the gravity as a positive vale greater than 1
el17m2h 26:d16a5b1e0ace 26 and the up object as a negative vale less than 1.
el17m2h 24:67dc71a8f009 27 */
el17m2h 23:9be87557b89a 28 void init(float position_x, float position_y, double velocity_y);
el17m2h 29:15e9640646b7 29
el17m2h 29:15e9640646b7 30 /**
el17m2h 24:67dc71a8f009 31 @brief Prints the doodler into the LCD screen
el17m2h 24:67dc71a8f009 32 @param N5110 &lcd
el17m2h 24:67dc71a8f009 33 @details The function draws a sprite of 13 x 15 bits that shows the image of the doodler
el17m2h 24:67dc71a8f009 34 */
el17m2h 29:15e9640646b7 35 void draw(N5110 &lcd);
el17m2h 29:15e9640646b7 36
el17m2h 29:15e9640646b7 37 /**
el17m2h 24:67dc71a8f009 38 @brief Updates the position of the doodler
el17m2h 26:d16a5b1e0ace 39 @param Direction d is gotten from the user input of the joystick and determines the movement of
el17m2h 29:15e9640646b7 40 the doodler in the x-direction. It moves left/right if the joystick directs left/right at an angle
el17m2h 26:d16a5b1e0ace 41 or not.
el17m2h 29:15e9640646b7 42 @param float mag is used to accelerate the movement of the doodler in the x-direction since it
el17m2h 26:d16a5b1e0ace 43 moves 5 frames * the magnitude of the joystick.
el17m2h 29:15e9640646b7 44 @details The function checks the doodler does not leave the screen rectangle (30 x 83) in the
el17m2h 29:15e9640646b7 45 x-direction and checks the direction of the velocity to keep adding or substructing a value in
el17m2h 26:d16a5b1e0ace 46 the y-direction (depending on if it is jumping or falling)
el17m2h 24:67dc71a8f009 47 */
el17m2h 17:74de8c17ddac 48 void update(Direction d, float mag);
el17m2h 29:15e9640646b7 49
el17m2h 29:15e9640646b7 50 /**
el17m2h 29:15e9640646b7 51 @brief Function to check the doodler's y-coodinate velocity
el17m2h 29:15e9640646b7 52 @details The function checks the current velocity of the doodler and depending on its direction
el17m2h 29:15e9640646b7 53 (positive or negative) it will decide if the doodler's updated velocity will remain the same or
el17m2h 29:15e9640646b7 54 change direction (jump). If the velocity is positive, it means it is currently jumping, so it
el17m2h 29:15e9640646b7 55 should continue doing so but in a decreasing velocity (decelerating), which is why it is
el17m2h 29:15e9640646b7 56 multiplied times the _up constant (value less than 1). If the velocity is negative it means
el17m2h 29:15e9640646b7 57 it is falling downwards and increasing in velocity (accelerating). This is done by multiplying the
el17m2h 29:15e9640646b7 58 current velocity by the gravity constant value (greater than 1). Finally, if the velocity is 0, it
el17m2h 26:d16a5b1e0ace 59 means it has completely decelerated upwards and so it should begin to fall. To do so, the velocity
el17m2h 25:f122e1862cd1 60 is given the value of gravity (which is a positive value).
el17m2h 24:67dc71a8f009 61 */
el17m2h 29:15e9640646b7 62 void check_velocity();
el17m2h 29:15e9640646b7 63
el17m2h 29:15e9640646b7 64 /**
el17m2h 24:67dc71a8f009 65 @brief Returns the current doodler's velocity in the x-axis
el17m2h 24:67dc71a8f009 66 @details Gets the current value in the doodler's class for the doodler's velocity in the x-axis
el17m2h 24:67dc71a8f009 67 */
el17m2h 10:e1d2289705ef 68 float get_velocity_x();
el17m2h 29:15e9640646b7 69
el17m2h 29:15e9640646b7 70 /**
el17m2h 24:67dc71a8f009 71 @brief Returns the current doodler's velocity in the y-axis
el17m2h 29:15e9640646b7 72 @details Gets the current value in the doodler's class for the doodler's velocity in the y-axis. It is a
el17m2h 29:15e9640646b7 73 double value since the y-velocity is a double type.
el17m2h 24:67dc71a8f009 74 */
el17m2h 10:e1d2289705ef 75 double get_velocity_y();
el17m2h 29:15e9640646b7 76
el17m2h 29:15e9640646b7 77 /**
el17m2h 24:67dc71a8f009 78 @brief Returns the current doodler's position in the x-axis
el17m2h 24:67dc71a8f009 79 @details Gets the current value in the doodler's class for the doodler's position in the x-axis
el17m2h 24:67dc71a8f009 80 */
el17m2h 29:15e9640646b7 81 float get_position_x();
el17m2h 29:15e9640646b7 82
el17m2h 29:15e9640646b7 83 /**
el17m2h 24:67dc71a8f009 84 @brief Returns the current doodler's position in the y-axis
el17m2h 24:67dc71a8f009 85 @details Gets the current value in the doodler's class for the doodler's position in the y-axis
el17m2h 24:67dc71a8f009 86 */
el17m2h 29:15e9640646b7 87 float get_position_y();
el17m2h 29:15e9640646b7 88
el17m2h 29:15e9640646b7 89 /**
el17m2h 26:d16a5b1e0ace 90 @brief Sets the doodler's velocity in the Doodler's class to equal the inputed parameters
el17m2h 29:15e9640646b7 91 @param float vel_x
el17m2h 24:67dc71a8f009 92 @param float vel_y
el17m2h 29:15e9640646b7 93 @details The function sets the doodler's velocity in the doodler's class by making the current
el17m2h 26:d16a5b1e0ace 94 velocity equal to the inputed parameters
el17m2h 24:67dc71a8f009 95 */
el17m2h 14:529f798adae4 96 void set_velocity(float vel_x, double vel_y);
el17m2h 29:15e9640646b7 97
el17m2h 25:f122e1862cd1 98 /**
el17m2h 26:d16a5b1e0ace 99 @brief Sets the doodler's position in the Doodler's class to equal the inputed parameters
el17m2h 29:15e9640646b7 100 @param float pos_x
el17m2h 25:f122e1862cd1 101 @param float pos_y
el17m2h 29:15e9640646b7 102 @details The function sets the doodler's position in the doodler's class by making the current
el17m2h 26:d16a5b1e0ace 103 position equal the inputed parameters
el17m2h 24:67dc71a8f009 104 */
el17m2h 14:529f798adae4 105 void set_position(float pos_x, float pos_y);
el17m2h 29:15e9640646b7 106
el17m2h 4:8ec314f806ae 107 private:
el17m2h 14:529f798adae4 108 float _position_x;
el17m2h 14:529f798adae4 109 float _position_y;
el17m2h 10:e1d2289705ef 110 float _velocity_x;
el17m2h 10:e1d2289705ef 111 double _velocity_y;
el17m2h 10:e1d2289705ef 112 double _gravity;
el17m2h 10:e1d2289705ef 113 double _up;
el17m2h 4:8ec314f806ae 114 };
el17m2h 4:8ec314f806ae 115 #endif