ELEC2645 (2018/19) / Mbed 2 deprecated el17arm

Dependencies:   mbed

Sprites/Sprites.h

Committer:
el17arm
Date:
2019-04-24
Revision:
49:9bea7089b657
Parent:
45:bad704c546d4
Child:
50:65ba437510f8

File content as of revision 49:9bea7089b657:

#ifndef SPRITES_H
#define SPRITES_H

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

/** Sprites Class
@author Andrew Milner University of Leeds
@brief Draws sprites and sets all collision rules 
@date April 2019
*/ 

/////////// All sprite bitmaps////////////////

// right facing miner bitmap
const int miner_right[24] =   {
        
        1,1,1,
        1,1,0,
        1,1,1,
        0,1,0,
        1,1,1,
        1,1,1,
        0,1,0,
        0,1,1,

    };
// left facing miner bitmap
const int miner_left[24] =   {
        
        1,1,1,
        0,1,1,
        1,1,1,
        0,1,0,
        1,1,1,
        1,1,1,
        0,1,0,
        1,1,0,
    };
// enemy bitmap
const int enemy[15] =   {
        
        1,1,1,
        1,0,1,
        1,1,1,
        0,1,0,
        1,1,1,
    };
// key bitmap
const int key[12] =   {
        
        1,1,0,0,
        1,0,1,1,
        1,1,0,1,
    };
// blank bitmap to show key collected
const int key_collected[12] =   {
        
        0,0,0,0,
        0,0,0,0,
        0,0,0,0,
    };
// trap bitmap
const int spike[9] =   {
        
        1,0,1,
        0,1,0,
        1,0,1,
    };
// solid block bitmap
const int solid_block[18] =   {
        
        1,1,1,1,1,1,
        1,0,1,1,0,1,
        1,1,1,1,1,1,
    };
// level exit bitmap
const int door[30] = {
        
        1,1,1,1,1,
        1,0,1,0,1,
        1,1,0,1,1,
        1,0,1,0,1,
        1,1,0,1,1,
        1,0,1,0,1,
};

/////////structs for sprite parameters and collision detection//////////////

/** Keys position struct */

struct keyed {
    bool key[5];  /**< initialise key flag array identifies each key individually */
    double kx[5]; /**< key x position*/
    double ky[5]; /**< key y position*/
};
/** Enemy position and movement struct */
struct enemies_init {
    bool eflag[5];  /**< initialise enemy flag array identifies each key individually */
    double ex[5];   /**< enemy x position */
    double ey[5];   /**< enemy y position */
    int counter[5]; /**< enemy counter, counts pixels moved */
    int distance[5];/**< distance enemy will travel before turning round */
};
/** Solid blocks struct */
struct Solid_blocks_init {
    double bx[5];   /**< block x position array identifies each block individually */
    double by[5];   /**< block y position array */
    bool collision[5]; /**< collision indicator for each individual block */

};
/////////////structs for populating up to 6 levels//////////////////
/** Enemy location for each level */
struct Enemies {
    double ex[5]; /**< enemy x positions for each level */
    double ey[5]; /**< enemy y positions for each level */
    int c[5];     /**< enemy counters for each level */
    int d[5];     /**< enemy travel distances for each level */
    double v[5];  /**< varies enemies velocity */
};

struct Traps {
    double tx[5];   /**< traps x positions for each level */
    double ty[5];   /**< traps y positions for each level */
};

struct Keys {
    double kx[5];   /**< keys x positions for each level */
    double ky[5];   /**< keys y positions for each level */
};

struct Solid_blocks {
    double bx[5];   /**< blocks x positions for each level */
    double by[5];   /**< blocks y positions for each level */
};

struct Soft_blocks {
    double sx1[5];  /**< sinking blocks x1 positions for each level */
    double sy[5];   /**< sinking blocks y positions for each level */
    int sx2[5];     /**< sinking blocks x2 (length) positions for each level */
};

struct Level_exit {
    double lx[5];   /**< Exit x position for each level */
    double ly[5];   /**< Exit y position for each level */
};

class Sprites
{

public:
    /** constructor
    */
    Sprites();
 /** deconstructor
 */ 
    ~Sprites();
 /** gets x and y position of player
 */
    Vector2D get_pos();
 /** States starting position of player
 @param x position
 @param y position
 */
    void miner_init(int x, int y);
    void miner_move(Direction d, N5110 &lcd);
    void miner_draw(N5110 &lcd);
    void miner_gravity(N5110 &lcd);
    void miner_jump(N5110 &lcd, Gamepad &pad);
    void miner_land(N5110 &lcd);
    
    void enemy_init(int i, int x, int y, int d);
    void enemy_move(int i, double v, N5110 &lcd);
    bool enemy_collision(int i);
    
    void key_collect(int k, int x, int y, N5110 &lcd, Gamepad &pad);
    int keys_collected();
    
    bool trap(int x, int y, N5110 &lcd);
    void blocks(Direction d, int i, int x, int y, N5110 &lcd);
    bool block_collision();
    void soft_blocks(int x, int y, int z, N5110 &lcd);
    
    bool exit_level(int x, int y, N5110 &lcd);
    
    keyed _k;
    enemies_init _enem; 
    


private:

    int _direction;
    int _gravity;
    bool _jump;
    int _y;
    int _x;
    bool _j_flag;
    int _j_counter;
    
    bool block[5];
    bool right_collision;
    bool left_collision;
    
    bool _collision;
    int _keys;
    

    Solid_blocks_init _b;
       
};
#endif