#pragma once /* Set this to WINDOWS for Windows, UNIX for Linux, BSD, etc. */ #define UNIX /* This is needed to allow fopen, fread, etc. */ #ifdef WINDOWS #define _CRT_SECURE_NO_WARNINGS #define M_PI 3.141592653 #endif /* General-purpose C includes */ #include #include /* General-purpose C++ includes */ #include #include #include /* Data Structures */ #include #include /* OpenGL Loader */ #ifdef UNIX #include // glad on Windows #else #include #endif /* OpenGL Includes */ #include #include #include #include /* Tiny obj loader - loads Wavefront .obj files */ #include "tiny_obj_loader.h" /* Provides stbi_image to load textures */ #include "stb_image.h" using namespace std; using namespace glm; struct globals { float height = 800; float width = 1280; float gravity = 0.02f; float jump_speed = 0.5f; bool shutdown = false; vec3 player_position; float heading = 0.0; float elevation = 0.0; float vertical_speed = 0.0; float player_height = 1.5; float move_margin = 0.4f; float runspeed = 0.8f; float walkspeed = 0.2f; bool forward = false; bool backward = false; bool left = false; bool right = false; bool run = false; bool release_cursor = false; }; vec3 get_lookat_point(int direction = 0, float r = 0.0); char* get_source(const char *filename); class GameObject { public: /* Identifiers for OpenGL resources */ unsigned int v_attrib; unsigned int tc_attrib; unsigned int vp_uniform; unsigned int program; unsigned int vbuf; unsigned int ebuf; unsigned int tex; unsigned int element_count; unsigned int models_buffer; /* Properties related to initialization. Set these when initializing an object */ string object_file, texture_file, vertex_shader, fragment_shader; bool flip_yz = false; string name; GameObject() { object_file = "objects/cube.obj"; vertex_shader = "shaders/vertex_shader.glsl"; fragment_shader = "shaders/fragment_shader.glsl"; } /* Properties not related to OpenGL */ vector models; bool visible = true; void add_location(vec3 location); bool init(); void draw(mat4 vp); virtual void movement(float) {}; // takes the number of milliseconds since the last run virtual void trigger_action(size_t instance, int action) {} }; class SolidObject : public GameObject { public: /* Stuff we actually used */ virtual ssize_t is_inside(vec3 point, float margin) {return false;} virtual float get_top(size_t instance); virtual float get_bottom(size_t instance); virtual float get_topbottom(size_t instance, bool); /* Stuff we haven't used yet */ bool collision = false; bool blocks_player = false; void collided(GameObject& other, size_t our_instance, size_t other_instance); //some_format get_hit_box(); bool is_over(); /* Vector of sizes of instance? Or are all the instances the same size? */ /* Something for bouncing? */ }; #ifdef MAIN globals g; vector game_objects; vector solid_objects; #else extern globals g; extern vector game_objects; extern vector solid_objects; #endif struct vertex { float x, y, z, u, v; }; bool operator==(const vertex& a, const vertex& o); ostream& operator<<(ostream& out, vec3 v); #define PLAYER_ON_OBJECT 1 #define ACTIVATE 2 /* Other objects that aren't base classes go next */ #include "misc_objects.h" GameObject* add_object(GameObject *new_object, string name, bool solid = false); void load_level();