#ifndef PLAYER_HPP #define PLAYER_HPP #include "math.hpp" #include "world.hpp" typedef enum{Walking, Flying, Falling} StandingMode; class Player{ public: //This box goes around the player and is used //to see if a player hits a block Vector3f hitBox[8] = { Vector3f(-0.25,-1.6,-0.25), Vector3f(-0.25,-1.6,0.25), Vector3f(0.25,-1.6,-0.25), Vector3f(0.25,-1.6,0.25), Vector3f(-0.25,0.2,-0.25), Vector3f(-0.25,0.2,0.25), Vector3f(0.25,0.2,-0.25), Vector3f(0.25,0.2,0.25) }; StandingMode standingMode; void checkFalling(World& world){ if(standingMode==Flying)return; if(world.GetBlock(Vector3i(hitBox[0]+pos+Vector3f(0,-0.1,0)))==AIR&& world.GetBlock(Vector3i(hitBox[1]+pos+Vector3f(0,-0.1,0)))==AIR&& world.GetBlock(Vector3i(hitBox[2]+pos+Vector3f(0,-0.1,0)))==AIR&& world.GetBlock(Vector3i(hitBox[3]+pos))==AIR){ standingMode=Falling; }else if(ySpeed<=0){ standingMode=Walking; ySpeed=0; } if(standingMode==Falling){ if(!move(Vector3f(0,ySpeed,0),world,false)&& ySpeed <=0){ standingMode=Walking; ySpeed=0; } ySpeed-=0.01; } } float ySpeed=0; int hotbarSelected=0; //Position Vector3f pos; //Direction that the camera is facing float yaw,pitch; Vector3i facingBlock; Vector3i newBlock;//where a new block would be placed bool isFacingBlock; void findFacingBlock(World* world); bool isValidPos(Vector3f pos, World& world); bool move(Vector3f movement, World& world,bool alwaysMove); bool isAllowedToPlaceBlock(Vector3i blockPos); }; #endif