Skip to content
Snippets Groups Projects
Select Git revision
  • 2998d40135035a7239a951e08361bf5538bd1667
  • master default protected
2 results

structs.h

Blame
  • structs.h 3.21 KiB
    #ifndef SNAKE_STRUCTS
    #define SNAKE_STRUCTS
    
    /**
     * Enum, storing possible moving directions
     */
    typedef enum Direction{
        NONE = -1,
        UP = 0,
        RIGHT = 1,
        DOWN = 2,
        LEFT = 3,
    }Direction;
    
    /**
     * 2 dimensional integer vector
     * or position
     */
    typedef struct Vec2i{
        int x;
        int y;
    }Pos;
    
    /**
     * Storing snake linked list.
     * The head can count as a sentry (but it is storing data but cannot be removed...)
     */
    typedef struct snakeChain
    {
        /**
         * snake part distance from head. Feature wasn't added
         */
        int num;
        /**
         * Snake part's pos
         */
        struct Vec2i pos;
        /**
         * direction. Feature wasn't added
         */
        Direction dir;
        /**
         * Why do I have to document this. It is obvious
         */
        struct snakeChain *next;
    
    }snakeChain;
    
    /**
     * Storing 4 bytes for 1 utf-8 encoded character
     * *utf-8 does not always 4 bytes long, can be shorter...
     * 
     * If not using utf-8 encoding, the 1st byte will be used
     * 
     * in utf-8, the first bit can tell is it longer?
     * this is why I used union
     */
    typedef union unichar{
        int isUnicone : 1;
        struct{
            char c[4];
        }bytes;
    
    }unichar;
    
    /**
     * 1 1 by 2 chunk. Can store a boolean, is it a food chunk, or it's just a wall or air...
     * stores 2 unichar
     */
    typedef struct chunk