-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
80 lines (80 loc) · 66.4 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#define MAX_MODELS 57
#define MOVE_SPEED 3.3f
#define STRAFE_SPEED 2.2f
#define MONSTER_SPEED 1.2f
#define MAX_MONSTER 19
#define YESINPUT lock_mouse == 1 && jspause == 0
#define NOINPUT lock_mouse == 0 || jspause == 1
#define PAUSE_CHECK ((json == 0 && lock_mouse == 1) || (json == 1 && jspause == 0 && lock_mouse == 1))
#define FAR_DISTANCE 100.f
#define updateModelView();mMul(&modelview,&model,&view);glUniformMatrix4fv(modelview_id,1,GL_FALSE,(float*)&modelview.m[0][0]);
#define PI 3.14159265359f
#define d2PI 1.57079632679f
#define DEG2RAD 0.01745329251f
#define uint GLuint
#include <math.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_opengles2.h>
GLint projection_id;GLint modelview_id;GLint position_id;GLint normal_id;GLint color_id;GLint lightpos_id;GLint ambient_id;GLint saturate_id;GLint specular_id;GLint hsv_id;GLint opacity_id;GLint lightness_id;typedef struct{float x,y,z,w;} vec;typedef struct {float m[4][4];} mat;mat projection, view, model, modelview;typedef struct{GLuint vid;GLuint iid;GLuint cid;GLuint nid;GLuint itp;GLuint ni;GLuint nv;GLfloat *vertices, *normals;GLubyte *colors;vec pos;GLfloat rad;GLfloat rsq;} ESModel;void esBind(const GLenum target, GLuint* buffer, const void* data, const GLsizeiptr datalen, const GLenum usage){glGenBuffers(1, buffer);glBindBuffer(target, *buffer);glBufferData(target, datalen, data, usage);}GLuint esRand(const GLuint min, const GLuint max){return (rand()%(max+1-min))+min;}GLfloat esRandFloat(const GLfloat min, const GLfloat max){static GLfloat rrndmax = 1.f/(GLfloat)RAND_MAX;return (((GLfloat)rand()) * rrndmax) * (max-min) + min;}ESModel esModelArray[MAX_MODELS];uint esModelArray_index = 0;uint esBoundModel = 0;void esBindModel(const uint id){glBindBuffer(GL_ARRAY_BUFFER, esModelArray[id].vid);glVertexAttribPointer(position_id, 3, GL_FLOAT, GL_FALSE, 0, 0);glEnableVertexAttribArray(position_id);glBindBuffer(GL_ARRAY_BUFFER, esModelArray[id].nid);glVertexAttribPointer(normal_id, 3, GL_FLOAT, GL_FALSE, 0, 0);glEnableVertexAttribArray(normal_id);glBindBuffer(GL_ARRAY_BUFFER, esModelArray[id].cid);glVertexAttribPointer(color_id, 3, GL_UNSIGNED_BYTE, GL_TRUE, 0, 0);glEnableVertexAttribArray(color_id);glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, esModelArray[id].iid);esBoundModel = id;}void esRenderModel(){glDrawElements(GL_TRIANGLES, esModelArray[esBoundModel].ni, esModelArray[esBoundModel].itp, 0);}void esBindRender(const uint id){glBindBuffer(GL_ARRAY_BUFFER, esModelArray[id].vid);glVertexAttribPointer(position_id, 3, GL_FLOAT, GL_FALSE, 0, 0);glEnableVertexAttribArray(position_id);glBindBuffer(GL_ARRAY_BUFFER, esModelArray[id].nid);glVertexAttribPointer(normal_id, 3, GL_FLOAT, GL_FALSE, 0, 0);glEnableVertexAttribArray(normal_id);glBindBuffer(GL_ARRAY_BUFFER, esModelArray[id].cid);glVertexAttribPointer(color_id, 3, GL_UNSIGNED_BYTE, GL_TRUE, 0, 0);glEnableVertexAttribArray(color_id);glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, esModelArray[id].iid);glDrawElements(GL_TRIANGLES, esModelArray[id].ni, esModelArray[id].itp, 0);}void esBindRenderS(const uint id){glBindBuffer(GL_ARRAY_BUFFER, esModelArray[id].vid);glVertexAttribPointer(position_id, 3, GL_FLOAT, GL_FALSE, 0, 0);glEnableVertexAttribArray(position_id);glBindBuffer(GL_ARRAY_BUFFER, esModelArray[id].nid);glVertexAttribPointer(normal_id, 3, GL_FLOAT, GL_FALSE, 0, 0);glEnableVertexAttribArray(normal_id);glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, esModelArray[id].iid);glDrawElements(GL_TRIANGLES, esModelArray[id].ni, esModelArray[id].itp, 0);}const GLchar* v1 = "#version 100\nuniform mat4 modelview;\nuniform mat4 projection;\nuniform vec3 color;\nuniform float ambient;\nuniform float saturate;\nuniform float opacity;\nuniform vec3 lightpos;\nattribute vec4 position;\nattribute vec3 normal;\nvarying vec3 vertPos;\nvarying vec3 vertNorm;\nvarying vec3 vertCol;\nvarying float vertAmb;\nvarying float vertSat;\nvarying float vertOpa;\nvarying vec3 vlightPos;\nvoid main()\n{\nvec4 vertPos4 = modelview * position;\nvertPos = vertPos4.xyz / vertPos4.w;\nvertNorm = vec3(modelview * vec4(normal, 0.0));\nvertCol = color;\nvertAmb = ambient;\nvertSat = saturate;\nvertOpa = opacity;\nvlightPos = lightpos;\ngl_Position = projection * vertPos4;\n}\n";const GLchar* v2 = "#version 100\nuniform mat4 modelview;\nuniform mat4 projection;\nuniform float ambient;\nuniform float saturate;\nuniform float opacity;\nuniform vec3 lightpos;\nattribute vec4 position;\nattribute vec3 normal;\nattribute vec3 color;\nvarying vec3 vertPos;\nvarying vec3 vertNorm;\nvarying vec3 vertCol;\nvarying float vertAmb;\nvarying float vertSat;\nvarying float vertOpa;\nvarying vec3 vlightPos;\nvoid main()\n{\nvec4 vertPos4 = modelview * position;\nvertPos = vertPos4.xyz / vertPos4.w;\nvertNorm = vec3(modelview * vec4(normal, 0.0));\nvertCol = color;\nvertAmb = ambient;\nvertSat = saturate;\nvertOpa = opacity;\nvlightPos = lightpos;\ngl_Position = projection * vertPos4;\n}\n";const GLchar* f1 = "#version 100\nprecision highp float;\nvarying vec3 vertPos;\nvarying vec3 vertNorm;\nvarying vec3 vertCol;\nvarying float vertAmb;\nvarying float vertSat;\nvarying float vertOpa;\nvarying vec3 vlightPos;\nvoid main()\n{\nvec3 lightDir = normalize(vlightPos - vertPos);\nfloat lambertian = min(max(dot(lightDir, normalize(vertNorm)), 0.0), vertSat);\ngl_FragColor = vec4((vertCol*vertAmb) + (vertCol*lambertian), vertOpa);\n}\n";const GLchar* v3 = "#version 100\nuniform mat4 modelview;\nuniform mat4 projection;\nuniform float ambient;\nuniform float specular;\nuniform vec3 hsv;\nuniform float opacity;\nuniform vec3 lightpos;\nattribute vec4 position;\nattribute vec3 normal;\nattribute vec3 color;\nvarying vec3 vertPos;\nvarying vec3 vertNorm;\nvarying vec3 vertCol;\nvarying float vertAmb;\nvarying float vertSpec;\nvarying float vertOpa;\nvarying vec3 vlightPos;\nvec3 rgb2hsv(vec3 c)\n{\nvec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\nvec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));\nvec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));\nfloat d = q.x - min(q.w, q.y);\nfloat e = 1.0e-10;\nreturn vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);\n}\nvec3 hsv2rgb(vec3 c)\n{\nvec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\nvec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);\nreturn c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);\n}\nvoid main()\n{\nvec4 vertPos4 = modelview * position;\nvertPos = vertPos4.xyz / vertPos4.w;\nvertNorm = vec3(modelview * vec4(normal, 0.0));\nvertCol = rgb2hsv(color);\nvertCol += hsv;\nvertCol = hsv2rgb(vertCol);\nvertAmb = ambient;\nvertSpec = specular;\nvertOpa = opacity;\nvlightPos = lightpos;\ngl_Position = projection * vertPos4;\n}\n";const GLchar* f2 = "#version 100\nprecision highp float;\nvarying vec3 vertPos;\nvarying vec3 vertNorm;\nvarying vec3 vertCol;\nvarying float vertAmb;\nvarying float vertSpec;\nvarying float vertOpa;\nvarying vec3 vlightPos;\nvoid main()\n{\nvec3 lightDir = normalize(vlightPos - vertPos);\nvec3 viewDir = normalize(-vertPos);\nvec3 reflectDir = reflect(-lightDir, vertNorm);\nfloat lumosity = dot(lightDir, vertNorm);\nvec3 specular = vertCol;\nfloat specAngle = max(dot(reflectDir, viewDir), 0.0);\nspecular += pow(specAngle, 4.0) * (vertCol*vertSpec);\ngl_FragColor = vec4(((vertCol*vertAmb) + max(specular * lumosity, 0.0)) * clamp(1.0 - (length(vertPos)*0.175), 0.0, 1.0), vertOpa);\n}\n";GLuint shdLambertSolid;GLint shdLambertSolid_position;GLint shdLambertSolid_projection;GLint shdLambertSolid_modelview;GLint shdLambertSolid_lightpos;GLint shdLambertSolid_color;GLint shdLambertSolid_normal;GLint shdLambertSolid_ambient;GLint shdLambertSolid_saturate;GLint shdLambertSolid_opacity;GLuint shdLambert;GLint shdLambert_position;GLint shdLambert_projection;GLint shdLambert_modelview;GLint shdLambert_lightpos;GLint shdLambert_color;GLint shdLambert_normal;GLint shdLambert_ambient;GLint shdLambert_saturate;GLint shdLambert_opacity;GLuint shdLambertD;GLint shdLambertD_position;GLint shdLambertD_projection;GLint shdLambertD_modelview;GLint shdLambertD_lightpos;GLint shdLambertD_color;GLint shdLambertD_normal;GLint shdLambertD_ambient;GLint shdLambertD_hsv;GLint shdLambertD_specular;GLint shdLambertD_opacity;void makeLambertSolid(){GLuint vertexShader = glCreateShader(GL_VERTEX_SHADER);glShaderSource(vertexShader, 1, &v1, NULL);glCompileShader(vertexShader);GLuint fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);glShaderSource(fragmentShader, 1, &f1, NULL);glCompileShader(fragmentShader);shdLambertSolid = glCreateProgram();glAttachShader(shdLambertSolid, vertexShader);glAttachShader(shdLambertSolid, fragmentShader);glLinkProgram(shdLambertSolid);shdLambertSolid_position = glGetAttribLocation(shdLambertSolid, "position");shdLambertSolid_normal = glGetAttribLocation(shdLambertSolid, "normal");shdLambertSolid_projection = glGetUniformLocation(shdLambertSolid, "projection");shdLambertSolid_modelview = glGetUniformLocation(shdLambertSolid, "modelview");shdLambertSolid_lightpos = glGetUniformLocation(shdLambertSolid, "lightpos");shdLambertSolid_color = glGetUniformLocation(shdLambertSolid, "color");shdLambertSolid_ambient = glGetUniformLocation(shdLambertSolid, "ambient");shdLambertSolid_saturate = glGetUniformLocation(shdLambertSolid, "saturate");shdLambertSolid_opacity = glGetUniformLocation(shdLambertSolid, "opacity");}void makeLambert(){GLuint vertexShader = glCreateShader(GL_VERTEX_SHADER);glShaderSource(vertexShader, 1, &v2, NULL);glCompileShader(vertexShader);GLuint fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);glShaderSource(fragmentShader, 1, &f1, NULL);glCompileShader(fragmentShader);shdLambert = glCreateProgram();glAttachShader(shdLambert, vertexShader);glAttachShader(shdLambert, fragmentShader);glLinkProgram(shdLambert);shdLambert_position = glGetAttribLocation(shdLambert, "position");shdLambert_normal = glGetAttribLocation(shdLambert, "normal");shdLambert_color = glGetAttribLocation(shdLambert, "color");shdLambert_projection = glGetUniformLocation(shdLambert, "projection");shdLambert_modelview = glGetUniformLocation(shdLambert, "modelview");shdLambert_lightpos = glGetUniformLocation(shdLambert, "lightpos");shdLambert_ambient = glGetUniformLocation(shdLambert, "ambient");shdLambert_saturate = glGetUniformLocation(shdLambert, "saturate");shdLambert_opacity = glGetUniformLocation(shdLambert, "opacity");}void makeLambertD(){GLuint vertexShader = glCreateShader(GL_VERTEX_SHADER);glShaderSource(vertexShader, 1, &v3, NULL);glCompileShader(vertexShader);GLuint fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);glShaderSource(fragmentShader, 1, &f2, NULL);glCompileShader(fragmentShader);shdLambertD = glCreateProgram();glAttachShader(shdLambertD, vertexShader);glAttachShader(shdLambertD, fragmentShader);glLinkProgram(shdLambertD);shdLambertD_position = glGetAttribLocation(shdLambertD, "position");shdLambertD_normal = glGetAttribLocation(shdLambertD, "normal");shdLambertD_color = glGetAttribLocation(shdLambertD, "color");shdLambertD_projection = glGetUniformLocation(shdLambertD, "projection");shdLambertD_modelview = glGetUniformLocation(shdLambertD, "modelview");shdLambertD_lightpos = glGetUniformLocation(shdLambertD, "lightpos");shdLambertD_ambient = glGetUniformLocation(shdLambertD, "ambient");shdLambertD_specular = glGetUniformLocation(shdLambertD, "specular");shdLambertD_hsv = glGetUniformLocation(shdLambertD, "hsv");shdLambertD_opacity = glGetUniformLocation(shdLambertD, "opacity");}void shadeLambertSolid(GLint* position, GLint* iprojection, GLint* imodelview, GLint* lightpos, GLint* normal, GLint* color, GLint* ambient, GLint* saturate, GLint* opacity){*position = shdLambertSolid_position;*iprojection = shdLambertSolid_projection;*imodelview = shdLambertSolid_modelview;*lightpos = shdLambertSolid_lightpos;*color = shdLambertSolid_color;*normal = shdLambertSolid_normal;*ambient = shdLambertSolid_ambient;*saturate = shdLambertSolid_saturate;*opacity = shdLambertSolid_opacity;glUseProgram(shdLambertSolid);}void shadeLambert(GLint* position, GLint* iprojection, GLint* imodelview, GLint* lightpos, GLint* normal, GLint* color, GLint* ambient, GLint* saturate, GLint* opacity){*position = shdLambert_position;*iprojection = shdLambert_projection;*imodelview = shdLambert_modelview;*lightpos = shdLambert_lightpos;*color = shdLambert_color;*normal = shdLambert_normal;*ambient = shdLambert_ambient;*saturate = shdLambert_saturate;*opacity = shdLambert_opacity;glUseProgram(shdLambert);}void shadeLambertD(GLint* position, GLint* iprojection, GLint* imodelview, GLint* lightpos, GLint* normal, GLint* color, GLint* ambient, GLint* specular, GLint* hsv, GLint* opacity){*position = shdLambertD_position;*iprojection = shdLambertD_projection;*imodelview = shdLambertD_modelview;*lightpos = shdLambertD_lightpos;*color = shdLambertD_color;*normal = shdLambertD_normal;*ambient = shdLambertD_ambient;*specular = shdLambertD_specular;*hsv = shdLambertD_hsv;*opacity = shdLambertD_opacity;glUseProgram(shdLambertD);}int srandfq = 5234;static inline void srandf(const int seed){srandfq = seed;}static inline float randfc(){srandfq *= 16807;return ((float)(srandfq)) * 4.6566129e-010f;}void vNorm(vec* v){const float len = 1.f/sqrtf(v->x*v->x + v->y*v->y + v->z*v->z);v->x *= len;v->y *= len;v->z *= len;}void vCross(vec* r, const vec v1, const vec v2){r->x = (v1.y * v2.z) - (v2.y * v1.z);r->y = -((v1.x * v2.z) - (v2.x * v1.z));r->z = (v1.x * v2.y) - (v2.x * v1.y);}void vSub(vec* r, const vec v1, const vec v2){r->x = v1.x - v2.x;r->y = v1.y - v2.y;r->z = v1.z - v2.z;}void vAdd(vec* r, const vec v1, const vec v2){r->x = v1.x + v2.x;r->y = v1.y + v2.y;r->z = v1.z + v2.z;}void vMulS(vec* r, const vec v1, const float v2){r->x = v1.x * v2;r->y = v1.y * v2;r->z = v1.z * v2;}void mIdent(mat *m){memset(m, 0x0, sizeof(mat));m->m[0][0] = 1.0f;m->m[1][1] = 1.0f;m->m[2][2] = 1.0f;m->m[3][3] = 1.0f;}void mMul(mat *r, const mat *a, const mat *b){mat tmp;for(int i = 0; i < 4; i++){tmp.m[i][0] = (a->m[i][0] * b->m[0][0]) +(a->m[i][1] * b->m[1][0]) +(a->m[i][2] * b->m[2][0]) +(a->m[i][3] * b->m[3][0]) ;tmp.m[i][1] = (a->m[i][0] * b->m[0][1]) +(a->m[i][1] * b->m[1][1]) +(a->m[i][2] * b->m[2][1]) +(a->m[i][3] * b->m[3][1]) ;tmp.m[i][2] = (a->m[i][0] * b->m[0][2]) +(a->m[i][1] * b->m[1][2]) +(a->m[i][2] * b->m[2][2]) +(a->m[i][3] * b->m[3][2]) ;tmp.m[i][3] = (a->m[i][0] * b->m[0][3]) +(a->m[i][1] * b->m[1][3]) +(a->m[i][2] * b->m[2][3]) +(a->m[i][3] * b->m[3][3]) ;}memcpy(r, &tmp, sizeof(mat));}void mScale(mat *r, const float x, const float y, const float z){r->m[0][0] *= x;r->m[0][1] *= x;r->m[0][2] *= x;r->m[0][3] *= x;r->m[1][0] *= y;r->m[1][1] *= y;r->m[1][2] *= y;r->m[1][3] *= y;r->m[2][0] *= z;r->m[2][1] *= z;r->m[2][2] *= z;r->m[2][3] *= z;}void mScale1(mat *r, const float s){mScale(r, s, s, s);}void mTranslate(mat *r, const float x, const float y, const float z){r->m[3][0] += (r->m[0][0] * x + r->m[1][0] * y + r->m[2][0] * z);r->m[3][1] += (r->m[0][1] * x + r->m[1][1] * y + r->m[2][1] * z);r->m[3][2] += (r->m[0][2] * x + r->m[1][2] * y + r->m[2][2] * z);r->m[3][3] += (r->m[0][3] * x + r->m[1][3] * y + r->m[2][3] * z);}void mRotate(mat *r, const float radians, float x, float y, float z){const float mag = 1.f/sqrtf(x * x + y * y + z * z);const float sinAngle = sinf(radians);const float cosAngle = cosf(radians);if(mag > 0.0f){x *= mag;y *= mag;z *= mag;const float xx = x * x;const float yy = y * y;const float zz = z * z;const float xy = x * y;const float yz = y * z;const float zx = z * x;const float xs = x * sinAngle;const float ys = y * sinAngle;const float zs = z * sinAngle;const float oneMinusCos = 1.0f - cosAngle;mat rotMat;rotMat.m[0][0] = (oneMinusCos * xx) + cosAngle;rotMat.m[0][1] = (oneMinusCos * xy) - zs;rotMat.m[0][2] = (oneMinusCos * zx) + ys;rotMat.m[0][3] = 0.0F;rotMat.m[1][0] = (oneMinusCos * xy) + zs;rotMat.m[1][1] = (oneMinusCos * yy) + cosAngle;rotMat.m[1][2] = (oneMinusCos * yz) - xs;rotMat.m[1][3] = 0.0F;rotMat.m[2][0] = (oneMinusCos * zx) - ys;rotMat.m[2][1] = (oneMinusCos * yz) + xs;rotMat.m[2][2] = (oneMinusCos * zz) + cosAngle;rotMat.m[2][3] = 0.0F;rotMat.m[3][0] = 0.0F;rotMat.m[3][1] = 0.0F;rotMat.m[3][2] = 0.0F;rotMat.m[3][3] = 1.0F;mMul(r, &rotMat, r);}}void mRotX(mat *r, const float radians){const float s = sinf(radians);const float c = cosf(radians);const mat t = { c, 0.f, s, 0.f,0.f, 1.f, 0.f, 0.f,-s, 0.f, c, 0.f,0.f, 0.f, 0.f, 1.f };mMul(r, &t, r);}void mRotY(mat *r, const float radians){const float s = sinf(radians);const float c = cosf(radians);const mat t = { 1.f, 0.f, 0.f, 0.f,0.f, c, -s, 0.f,0.f, s, c, 0.f,0.f, 0.f, 0.f, 1.f };mMul(r, &t, r);}void mRotZ(mat *r, const float radians){const float s = sinf(radians);const float c = cosf(radians);const mat t = { c, -s, 0.f, 0.f,s, c, 0.f, 0.f,0.f, 0.f, 1.f, 0.f,0.f, 0.f, 0.f, 1.f };mMul(r, &t, r);}void mFrustum(mat *r, const float left, const float right, const float bottom, const float top, const float nearZ, const float farZ){const float dX = right - left;const float dY = top - bottom;const float dZ = farZ - nearZ;const float rdX = 1.f/dX;const float rdY = 1.f/dY;const float rdZ = 1.f/dZ;mat frust;if(nearZ <= 0.0f || farZ <= 0.0f || dX <= 0.0f || dY <= 0.0f || dZ <= 0.0f)return;frust.m[0][0] = 2.0f * nearZ * rdX;frust.m[0][1] = frust.m[0][2] = frust.m[0][3] = 0.0f;frust.m[1][1] = 2.0f * nearZ * rdY;frust.m[1][0] = frust.m[1][2] = frust.m[1][3] = 0.0f;frust.m[2][0] = (right + left) * rdX;frust.m[2][1] = (top + bottom) * rdY;frust.m[2][2] = -(nearZ + farZ) * rdZ;frust.m[2][3] = -1.0f;frust.m[3][2] = -2.0f * nearZ * farZ * rdZ;frust.m[3][0] = frust.m[3][1] = frust.m[3][3] = 0.0f;mMul(r, &frust, r);}void mPerspective(mat *r, const float fovy, const float aspect, const float nearZ, const float farZ){float frustumW, frustumH;frustumH = tanf(fovy * 0.00872664625f) * nearZ;frustumW = frustumH * aspect;mFrustum(r, -frustumW, frustumW, -frustumH, frustumH, nearZ, farZ);}void mGetViewZ(vec *r, const mat matrix){r->x = -matrix.m[0][2];r->y = -matrix.m[1][2];r->z = -matrix.m[2][2];}void mGetViewX(vec *r, const mat matrix){r->x = -matrix.m[0][0];r->y = -matrix.m[1][0];r->z = -matrix.m[2][0];}void mGetViewY(vec *r, const mat matrix){r->x = -matrix.m[0][1];r->y = -matrix.m[1][1];r->z = -matrix.m[2][1];}void mSetPos(mat *r, const vec pos){r->m[3][0] = pos.x;r->m[3][1] = pos.y;r->m[3][2] = pos.z;}void mSetRotX(mat *r, const float radians){const float s = sinf(radians);const float c = cosf(radians);r->m[0][0] = c;r->m[0][1] = 0.f;r->m[0][2] = s;r->m[0][3] = 0.f;r->m[1][0] = 0.f;r->m[1][1] = 1.f;r->m[1][2] = 0.f;r->m[1][3] = 0.f;r->m[2][0] = -s;r->m[2][1] = 0.f;r->m[2][2] = c;r->m[2][3] = 0.f;}void mSetRotY(mat *r, const float radians){const float s = sinf(radians);const float c = cosf(radians);r->m[0][0] = 1.f;r->m[0][1] = 0.f;r->m[0][2] = 0.f;r->m[0][3] = 0.f;r->m[1][0] = 0.f;r->m[1][1] = c;r->m[1][2] = -s;r->m[1][3] = 0.f;r->m[2][0] = 0.f;r->m[2][1] = s;r->m[2][2] = c;r->m[2][3] = 0.f;}void mSetRotZ(mat *r, const float radians){const float s = sinf(radians);const float c = cosf(radians);r->m[0][0] = c;r->m[0][1] = -s;r->m[0][2] = 0.f;r->m[0][3] = 0.f;r->m[1][0] = s;r->m[1][1] = c;r->m[1][2] = 0.f;r->m[1][3] = 0.f;r->m[2][0] = 0.f;r->m[2][1] = 0.f;r->m[2][2] = 1.f;r->m[2][3] = 0.f;}
#include "floor.h"
#include "wall.h"
#include "hand.h"
#include "gun.h"
#include "blast.h"
#include "prot.h"
#include "brain.h"
#include "sign.h"
#include "dead.h"
#include "c1.h"
#include "c2.h"
#include "c3.h"
#include "c4.h"
#include "c5.h"
#include "c6.h"
#include "c7.h"
#include "c8.h"
#include "c9.h"
#include "c10.h"
#include "c11.h"
#include "c12.h"
#include "c13.h"
#include "c14.h"
#include "c15.h"
#include "c16.h"
#include "c17.h"
#include "c18.h"
#include "c19.h"
#include "b1.h"
#include "b2.h"
#include "b3.h"
#include "b4.h"
#include "b5.h"
#include "b6.h"
#include "b7.h"
#include "b8.h"
#include "b9.h"
#include "b10.h"
#include "b11.h"
#include "b12.h"
#include "b13.h"
#include "b14.h"
#include "h1.h"
#include "h2.h"
#include "h3.h"
#include "h4.h"
#include "h5.h"
#include "h6.h"
#include "h7.h"
#include "h8.h"
#include "h9.h"
#include "h10.h"
#include "h11.h"
#include "h12.h"
#include "h13.h"
#include "h14.h"
#include "blood.h"
const unsigned char icon[]="\377\377\377\000\377\377\377\000\377\377\377\000\377\377\377\000\377\377\377\000\377\377\377\000\377\377\377\000\377\377\377\000\377\377\377\000\377\377\377\000\377\377\377\000\377\377\377\000\377\377\377\000\377\377\377\000\377\377\377\000\377\377\377\000\377\377\377\000\377\377\377\000\377\377\377\000\377\377\377\000\377\377\377\000,),\036\065/\064_)$(@-'*E\070\061\065`-&*\040\000\000\000\001\377\377\377\000\377\377\377\000\377\377\377\000\377\377\377\000\377\377\377\000\377\377\377\000\377\377\377\000\071\061\067\061cT]\214uak\325\226\177\214\365aMT\345XHO\350\223{\211\367\205my\330jWa\225I;@<\377\377\377\000\377\377\377\000\377\377\377\000\377\377\377\000\377\377\377\000C<@`wdn\360\224y\205\377\210ku\377\254\220\235\377jTX\377RBH\377\251\213\232\377\244\200\212\377\226{\210\377\215v\177\370m[]t\000\000\000\001\377\377\377\000\377\377\377\000\070/\063>hV^\372\213ox\377\231\200\213\377\207pz\377\223x\203\377o[_\377VIO\377\245\206\221\377\226w\177\377\244\207\221\377\252\213\224\377\220v|\377M=@U\377\377\377\000\014\010\011\005TEJ\234pZc\377sX`\377\207lv\377\241\206\221\377\236}\206\377x_b\377^MR\377\244\206\220\377\242\210\224\377\242\201\206\377\250\205\211\377\242\200\206\377t_c\266.\060.\011,$&\025bMS\321kSY\377{bk\377\205hq\377\210q{\377\260\222\234\377wWY\377VAE\377\246\210\222\377\245\204\214\377\214jl\377\252\212\213\377\242\201\201\377\217op\345C:<--'-(`KQ\332gMR\377cLR\377\200fo\377\177dl\377\243\177\211\377mLL\377F\064\067\377\233z\202\377\236uz\377\231z}\377\242\202\203\377\203aa\377y[]\343\066-\060\067\064,\062QfQX\355\\EH\377tX_\377wT\\\377\212bj\377\241y\200\377pSU\377P?E\377\227qw\377\232rw\377\240|\177\377\253\204\205\377\227np\377\200ci\357\071\062\066U(##\060^KP\342^EH\377[=>\377oNR\377qPU\377{UZ\377[??\377E//\377wQT\377\177]`\377\201]_\377sKK\377\214aa\377\212km\343<\066\066\064\014\011\005\017WCG\310kPU\377XGG\377ebh\377mkr\377xeg\377,!\037\377\035\023\022\377]OR\377dbi\377urv\377jQP\377\206_^\377y\\\\\305\033\025\024\015\000\000\000\003O>C\226nQW\377]UW\377_mu\377epw\377\207\202\204\377O?<\377/#\"\377dfj\377dqz\377gpu\377\201sr\377\217oo\377hRV\204\000\000\000\001\377\377\377\000\065*\062\040E\061\063\270WJJ\377^]a\377PQW\377j[[\377N\070\065\375>-,\373d[[\377XZ_\377SQU\377gUR\377_IH\267;.\061\030\377\377\377\000\377\377\377\000\377\377\377\000\000\000\000\011A\066\066dG:\067\330J:\066\372R><\317\064%\"P%\035\035=F\071\067\275H:\067\370K:\067\341Q?=r\000\000\000\011\377\377\377\000\377\377\377\000\377\377\377\000\377\377\377\000\377\377\377\000\377\377\377\000!\031\024()\040\033W\032\025\024\034\377\377\377\000\377\377\377\000\002\000\000\017%\035\032P/&!/\377\377\377\000\377\377\377\000\377\377\377\000\377\377\377\000\377\377\377\000\377\377\377\000\377\377\377\000\377\377\377\000\377\377\377\000\377\377\377\000\377\377\377\000\377\377\377\000\377\377\377\000\377\377\377\000\377\377\377\000\377\377\377\000\377\377\377\000\377\377\377\000\377\377\377\000\377\377\377\000";void timestamp(char* ts){const time_t tt=time(0);strftime(ts,16,"%H:%M:%S",localtime(&tt));}const char appTitle[]="Silentrooms Blood Thirst";SDL_Window* wnd;SDL_GLContext glc;SDL_Surface* s_icon = NULL;uint winw=1024, winh=768, ks[6]={0};float t=0.f, dt=0.f, lt=0.f, fc=0.f, lfct=0.f, aspect, ww, wh, rww, rwh;float tsx=0, tsy=0, tdx=0, tdy=0;SDL_Joystick* js = NULL;float jsc = 0.f;uint jspause = 0;uint json = 0;float DRAW_DISTANCE = 36.f;uint lock_mouse = 0;float sens = 0.003f;int xd=0, yd=0;float mx=0, lx=0;float xrot = 0.f;vec lookx, looky, lookz;float sv = d2PI;const float level_floor[] = {-4,0,-4,1,-4,2,-4,-1,-4,-2,-4,-3,-2,-3,-2,-2,-2,-1,-2,2,-2,1,-2,0,0,0,0,1,0,-1,0,-2,1,-1,1,0,-4,-4,-4,3,-3,3,-3,-4,4,3,4,-4,4,-3,4,-2,4,-1,4,2,4,1,4,0,-2,-4,-2,3,2,3,2,-4,2,0,2,1,2,2,2,-1,2,-2,2,-3,3,-4,3,3,-1,-4,1,-4,0,-4,1,3,-1,3,0,3,-1,-1,-1,0,-1,-2,1,-2,1,1,-1,1,-2,-5,0,-5,0,-6,2,-5,2,-6,-2,-6,-3,-6,-4,-6,3,-6,4,-6,4,-7,4,-8,4,-9,-4,-7,-4,-8,-4,-9,-3,-9,-2,-9,-1,-9,0,-9,1,-9,2,-9,3,-9,-2,-7,-1,-7,0,-7,1,-7,2,-7,0,-8,-2,4,-2,5,-2,6,0,5,0,4,0,6,0,7,0,8,2,4,2,5,2,6,2,8,1,6,-1,6,-3,5,-4,5,3,5,4,5,4,6,4,7,4,8,3,8,1,8,-1,8,-2,8,-3,8,-4,8,-4,7,-4,6,6,6,6,7,6,8,7,8,8,8,9,8,11,8,13,8,14,8,14,7,14,6,14,5,13,5,6,5,7,5,9,6,11,6,12,8,12,6,12,5,12,4,10,8,10,7,10,6,10,4,10,5,8,6,8,5,8,4,10,-8,12,-7,11,-7,10,-7,9,-7,8,-7,13,-9,12,-9,10,-9,9,-9,8,-9,7,-9,6,-9,6,-8,6,-7,14,-9,14,-8,14,-7,14,-6,13,-6,6,-6,7,-6,8,-6,12,-6,12,-5,10,-6,10,-5,8,-5,9,1,11,1,11,-2,9,-2,9,0,9,-1,10,3,9,3,11,3,10,-4,11,-4,9,-4,13,3,13,-4,12,-3,12,-2,12,-1,12,2,12,1,12,0,12,-4,12,3,8,3,8,-4,14,0,14,1,14,2,14,-1,14,-2,14,-3,14,-4,14,3,7,-4,7,3,6,3,6,-4,11,0,11,-1,10,-2,10,-1,10,1,10,0,8,0,8,1,8,2,8,-1,8,-2,8,-3,6,-3,6,-2,6,-1,6,2,6,1,6,0,5,0,5,-1,-14,6,-14,7,-14,8,-13,8,-12,8,-11,8,-9,8,-7,8,-6,8,-6,7,-6,6,-6,5,-7,5,-14,5,-13,5,-11,6,-9,6,-8,8,-8,6,-8,5,-8,4,-10,8,-10,7,-10,6,-10,4,-10,5,-12,6,-12,5,-12,4,-10,-8,-8,-7,-9,-7,-10,-7,-11,-7,-12,-7,-7,-9,-8,-9,-9,-9,-10,-9,-11,-9,-12,-9,-13,-9,-14,-9,-14,-8,-6,-9,-6,-8,-6,-7,-6,-6,-7,-6,-14,-6,-13,-6,-12,-6,-8,-6,-8,-5,-10,-6,-10,-5,-12,-5,-11,1,-9,1,-9,-2,-11,-2,-11,0,-11,-1,-10,3,-11,3,-9,3,-10,-4,-9,-4,-11,-4,-7,3,-7,-4,-8,-3,-8,-2,-8,-1,-8,2,-8,1,-8,0,-8,-4,-8,3,-12,3,-12,-4,-6,0,-6,1,-6,2,-6,-1,-6,-2,-6,-3,-6,-4,-6,3,-13,-4,-13,3,-14,3,-14,-4,-9,0,-9,-1,-10,-2,-10,-1,-10,1,-10,0,-12,0,-12,1,-12,2,-12,-1,-12,-2,-12,-3,-14,-3,-14,-2,-14,-1,-14,2,-14,1,-14,0,-5,-8,-5,-7,-5,12,-5,11,-14,19,-14,20,-14,21,-14,18,-14,17,-14,16,-12,16,-12,17,-12,18,-12,20,-12,19,-10,17,-9,18,-9,19,-14,15,-14,22,-13,22,-13,15,-6,22,-6,15,-6,16,-6,17,-6,18,-6,21,-6,20,-6,19,-12,15,-12,22,-8,22,-8,15,-8,19,-8,20,-8,18,-8,17,-8,16,-7,15,-7,22,-11,15,-9,15,-10,15,-9,22,-11,22,-10,22,-11,18,-11,19,-11,17,-9,17,-9,20,-11,20,-12,14,-10,14,-10,13,-8,14,-8,13,-12,13,-13,13,-14,13,-7,13,-6,13,-6,12,-6,11,-6,10,-14,12,-14,11,-14,10,-13,10,-12,10,-11,10,-10,10,-9,10,-8,10,-7,10,-12,12,-11,12,-10,12,-9,12,-8,12,-10,11,-12,23,-12,24,-12,25,-10,24,-10,23,-10,25,-10,26,-10,27,-8,23,-8,24,-8,25,-8,27,-9,25,-11,25,-13,24,-14,24,-7,24,-6,24,-6,25,-6,26,-6,27,-7,27,-9,27,-11,27,-12,27,-13,27,-14,27,-14,26,-14,25,5,18,5,19,6,19,6,20,6,21,6,18,6,17,6,16,8,16,8,17,8,18,8,21,8,20,8,19,10,19,10,20,10,18,10,17,11,19,6,15,6,22,7,15,14,22,14,15,14,16,14,17,14,18,14,21,14,20,14,19,8,15,8,22,12,22,12,15,12,19,12,20,12,21,12,18,12,17,12,16,13,15,9,15,11,15,10,15,10,22,9,19,9,17,11,17,8,14,10,14,10,13,12,14,12,13,8,13,7,13,6,13,13,13,14,13,14,12,14,11,14,10,6,12,6,11,6,10,7,10,8,10,9,10,10,10,11,10,12,10,13,10,8,12,9,12,10,12,11,12,12,12,10,11,8,23,8,24,8,25,10,24,10,23,10,25,10,26,10,27,12,23,12,24,12,25,12,27,11,25,9,25,6,24,14,24,14,25,14,26,14,27,13,27,11,27,9,27,8,27,7,27,6,27,6,26,6,25,-4,25,-4,26,-4,27,-3,27,-2,27,-1,27,1,27,3,27,4,27,4,26,4,25,4,24,3,24,-4,24,-3,24,-1,25,1,25,2,27,2,25,2,24,2,23,0,27,0,26,0,25,0,23,0,24,-2,25,-2,24,-2,23,0,11,2,12,1,12,0,12,-1,12,-2,12,3,10,2,10,1,10,0,10,-1,10,-2,10,-3,10,-4,10,-4,11,-4,12,4,10,4,11,4,12,4,13,3,13,-4,13,-3,13,-2,13,2,13,2,14,0,13,0,14,-2,14,-1,20,1,20,1,17,-1,17,-1,19,0,22,-1,22,1,22,0,15,1,15,-1,15,3,22,3,15,2,16,2,17,2,18,2,21,2,20,2,19,2,15,2,22,-2,22,-2,15,4,19,4,20,4,21,4,18,4,17,4,16,4,15,4,22,-3,15,-3,22,-4,22,-4,15,1,19,1,18,0,17,0,20,-2,19,-2,20,-2,21,-2,17,-2,16,-4,16,-4,17,-4,18,-4,21,-4,20,-4,19,-5,-26,-5,-27,-14,-19,-14,-18,-14,-17,-14,-20,-14,-21,-14,-22,-12,-22,-12,-21,-12,-20,-12,-17,-12,-18,-12,-19,-9,-20,-9,-19,-14,-23,-14,-16,-13,-16,-13,-23,-6,-16,-6,-23,-6,-22,-6,-21,-6,-20,-6,-17,-6,-18,-6,-19,-12,-23,-12,-16,-8,-16,-8,-23,-8,-19,-8,-18,-8,-17,-8,-20,-8,-21,-8,-22,-7,-23,-7,-16,-11,-23,-9,-23,-10,-23,-9,-16,-11,-16,-10,-16,-11,-20,-11,-19,-11,-21,-9,-21,-9,-18,-11,-18,-12,-24,-10,-24,-10,-25,-8,-24,-8,-25,-12,-25,-13,-25,-14,-25,-7,-25,-6,-25,-6,-26,-6,-27,-6,-28,-14,-26,-14,-27,-14,-28,-13,-28,-12,-28,-11,-28,-10,-28,-9,-28,-8,-28,-7,-28,-12,-26,-11,-26,-10,-26,-9,-26,-8,-26,-10,-27,-12,-15,-12,-14,-12,-13,-10,-14,-10,-15,-10,-13,-10,-12,-10,-11,-8,-15,-8,-14,-8,-13,-8,-11,-9,-13,-11,-13,-13,-14,-14,-14,-7,-14,-6,-14,-6,-13,-6,-12,-6,-11,-7,-11,-9,-11,-11,-11,-12,-11,-13,-11,-14,-11,-14,-12,-14,-13,5,-20,5,-19,6,-19,6,-18,6,-17,6,-20,6,-21,6,-22,8,-22,8,-21,8,-20,8,-17,8,-18,8,-19,10,-19,10,-18,10,-20,10,-21,11,-20,11,-19,6,-23,6,-16,7,-16,7,-23,14,-16,14,-23,14,-22,14,-21,14,-20,14,-17,14,-18,14,-19,8,-23,8,-16,12,-16,12,-23,12,-19,12,-18,12,-17,12,-20,12,-21,12,-22,13,-23,13,-16,9,-23,11,-23,10,-23,11,-16,10,-16,9,-20,9,-19,9,-21,11,-21,11,-18,9,-18,8,-24,10,-24,10,-25,12,-24,12,-25,8,-25,7,-25,6,-25,13,-25,14,-25,14,-26,14,-27,14,-28,6,-26,6,-27,6,-28,7,-28,8,-28,9,-28,10,-28,11,-28,12,-28,13,-28,8,-26,9,-26,10,-26,11,-26,12,-26,10,-27,8,-14,8,-13,10,-14,10,-15,10,-13,10,-12,10,-11,12,-15,12,-14,12,-13,12,-11,9,-13,7,-14,6,-14,13,-14,14,-14,14,-13,14,-12,14,-11,13,-11,11,-11,9,-11,8,-11,7,-11,6,-11,6,-12,6,-13,-4,-13,-4,-12,-4,-11,-3,-11,-2,-11,-1,-11,1,-11,3,-11,4,-11,4,-12,4,-13,4,-14,3,-14,-4,-14,-3,-14,-1,-13,1,-13,2,-11,2,-13,2,-14,2,-15,0,-11,0,-12,0,-13,0,-15,-2,-13,-2,-14,-2,-15,0,-27,2,-26,1,-26,0,-26,-1,-26,-2,-26,3,-28,2,-28,1,-28,0,-28,-1,-28,-2,-28,-3,-28,-4,-28,-4,-27,-4,-26,4,-28,4,-27,4,-26,4,-25,3,-25,-4,-25,-3,-25,-2,-25,2,-25,2,-24,0,-24,-2,-24,-1,-18,1,-18,1,-21,-1,-21,-1,-19,-1,-20,0,-16,-1,-16,1,-16,0,-23,1,-23,-1,-23,3,-23,2,-22,2,-21,2,-20,2,-17,2,-18,2,-19,2,-23,2,-16,-2,-16,-2,-23,4,-19,4,-18,4,-17,4,-20,4,-21,4,-22,4,-23,4,-16,-3,-23,-3,-16,-4,-16,-4,-23,1,-19,1,-20,0,-20,0,-19,-2,-19,-2,-18,-2,-17,-2,-20,-2,-21,-2,-22,-4,-22,-4,-21,-4,-20,-4,-17,-4,-18,-4,-19,27,-23,34,-16,34,-23,34,-22,34,-21,34,-20,34,-17,34,-18,34,-19,28,-23,28,-16,32,-16,32,-23,32,-19,32,-18,32,-17,32,-21,32,-22,33,-23,33,-16,29,-23,31,-23,30,-23,31,-16,30,-16,29,-20,29,-21,31,-21,31,-18,28,-24,30,-24,30,-25,32,-25,28,-25,27,-25,26,-25,33,-25,34,-25,34,-26,34,-27,34,-28,26,-26,26,-27,26,-28,27,-28,28,-28,30,-28,31,-28,32,-28,28,-26,29,-26,30,-26,31,-26,32,-26,30,-27,28,-14,28,-13,30,-14,30,-15,30,-13,30,-12,30,-11,32,-15,32,-14,32,-13,32,-11,31,-13,29,-13,27,-14,26,-14,33,-14,34,-14,34,-12,34,-11,33,-11,31,-11,29,-11,28,-11,27,-11,26,-11,26,-12,36,-13,36,-12,36,-11,37,-11,38,-11,39,-11,41,-11,43,-11,44,-11,44,-12,44,-13,44,-14,43,-14,36,-14,37,-14,39,-13,41,-13,42,-11,42,-13,42,-14,42,-15,40,-11,40,-12,40,-13,40,-15,40,-14,38,-13,38,-14,38,-15,40,-27,42,-26,41,-26,40,-26,39,-26,38,-26,43,-28,42,-28,41,-28,40,-28,39,-28,38,-28,37,-28,36,-28,36,-27,36,-26,44,-28,44,-27,44,-26,44,-25,43,-25,36,-25,37,-25,38,-25,42,-25,42,-24,40,-25,40,-24,38,-24,39,-18,41,-18,41,-21,39,-21,39,-19,39,-20,40,-16,39,-16,41,-16,40,-23,41,-23,39,-23,43,-16,43,-23,42,-22,42,-21,42,-20,42,-17,42,-18,42,-19,42,-23,42,-16,38,-16,38,-23,44,-19,44,-18,44,-17,44,-20,44,-21,44,-22,44,-23,44,-16,37,-23,37,-16,36,-16,36,-23,41,-19,41,-20,40,-21,40,-20,40,-18,40,-19,38,-19,38,-18,38,-17,38,-20,38,-21,38,-22,36,-22,36,-21,36,-20,36,-17,36,-18,36,-19,35,-19,35,-20,16,-13,16,-12,16,-11,17,-11,18,-11,19,-11,21,-11,23,-11,24,-11,24,-12,24,-13,24,-14,23,-14,16,-14,17,-14,19,-13,21,-13,22,-11,22,-13,22,-14,22,-15,20,-11,20,-12,20,-13,20,-15,20,-14,18,-13,18,-14,18,-15,20,-27,22,-26,21,-26,20,-26,19,-26,18,-26,23,-28,22,-28,21,-28,20,-28,19,-28,18,-28,17,-28,16,-28,16,-27,16,-26,24,-28,24,-27,24,-26,24,-25,23,-25,16,-25,17,-25,18,-25,22,-25,22,-24,20,-25,20,-24,18,-24,19,-18,21,-18,21,-21,19,-21,19,-19,19,-20,20,-16,19,-16,21,-16,20,-23,21,-23,19,-23,23,-16,23,-23,22,-22,22,-21,22,-20,22,-17,22,-18,22,-19,22,-23,22,-16,18,-16,18,-23,24,-19,24,-18,24,-17,24,-20,24,-21,24,-22,24,-23,24,-16,17,-23,17,-16,16,-16,16,-23,21,-19,21,-20,20,-21,20,-20,20,-18,20,-19,18,-19,18,-18,18,-17,18,-20,18,-21,18,-22,16,-22,16,-21,16,-20,16,-17,16,-18,16,-19,25,-27,25,-26,26,19,26,20,26,21,26,18,26,17,26,16,28,16,28,17,28,18,28,21,28,20,28,19,30,19,30,20,30,18,30,17,31,18,31,19,26,15,26,22,27,22,27,15,34,22,34,15,34,16,34,17,34,18,34,21,34,20,34,19,28,15,28,22,32,22,32,15,32,19,32,20,32,21,32,18,32,17,32,16,33,15,33,22,29,15,31,15,30,15,31,22,29,22,30,22,29,18,29,19,29,17,31,17,31,20,29,20,28,14,30,14,30,13,32,14,32,13,28,13,27,13,26,13,33,13,34,13,34,12,34,11,34,10,26,12,26,11,26,10,27,10,29,10,30,10,31,10,32,10,33,10,28,12,29,12,30,12,31,12,32,12,30,11,28,23,28,24,28,25,30,24,30,23,30,25,30,26,30,27,32,23,32,24,32,25,32,27,31,25,29,25,27,24,26,24,33,24,34,24,34,25,34,26,34,27,33,27,31,27,29,27,28,27,27,27,26,27,26,26,26,25,36,25,36,26,36,27,37,27,38,27,39,27,41,27,43,27,44,27,44,26,44,25,44,24,43,24,36,24,37,24,39,25,41,25,42,27,42,25,42,24,42,23,40,27,40,26,40,25,40,23,40,24,38,25,38,24,38,23,40,11,42,12,41,12,40,12,39,12,38,12,43,10,42,10,41,10,40,10,39,10,38,10,36,10,36,11,36,12,44,10,44,11,44,12,44,13,43,13,36,13,38,13,42,13,42,14,40,13,40,14,38,14,39,20,41,20,41,17,39,17,39,19,39,18,40,22,39,22,41,22,40,15,41,15,39,15,43,22,43,15,42,16,42,17,42,18,42,21,42,20,42,19,42,15,42,22,38,22,38,15,44,19,44,20,44,21,44,18,44,17,44,16,44,15,44,22,37,22,36,22,36,15,41,19,41,18,40,17,40,20,38,19,38,20,38,21,38,18,38,17,38,16,36,16,36,17,36,18,36,21,36,20,36,19,35,19,35,18,16,25,16,26,16,27,17,27,18,27,19,27,21,27,23,27,24,27,24,26,24,25,24,24,23,24,16,24,17,24,19,25,21,25,22,27,22,25,22,24,22,23,20,27,20,26,20,25,20,23,20,24,18,25,18,24,18,23,20,11,22,12,21,12,20,12,19,12,18,12,23,10,22,10,21,10,20,10,19,10,18,10,17,10,16,10,16,11,16,12,24,10,24,11,24,12,24,13,23,13,16,13,17,13,18,13,22,13,22,14,20,13,20,14,18,14,19,20,21,20,21,17,19,17,19,19,19,18,20,22,19,22,21,22,20,15,21,15,19,15,23,22,23,15,22,16,22,17,22,18,25,-7,25,-8,16,0,16,1,16,2,16,-1,16,-2,16,-3,18,-3,18,-2,18,-1,18,2,18,1,18,0,20,0,20,1,20,-1,20,-2,21,-1,21,0,16,-4,16,3,17,3,17,-4,24,3,24,-4,24,-3,24,-2,24,-1,24,2,24,1,24,0,18,-4,18,3,22,3,22,-4,22,0,22,1,22,2,22,-1,22,-2,22,-3,23,-4,23,3,19,-4,21,-4,20,-4,21,3,19,3,20,3,19,-1,19,0,19,-2,21,-2,21,1,19,1,18,-5,20,-5,20,-6,22,-5,22,-6,18,-6,17,-6,16,-6,23,-6,24,-6,24,-7,24,-8,24,-9,16,-7,16,-8,16,-9,17,-9,18,-9,19,-9,20,-9,21,-9,22,-9,23,-9,18,-7,19,-7,20,-7,21,-7,22,-7,20,-8,18,4,18,5,18,6,20,5,20,4,20,6,20,7,20,8,22,4,22,5,22,6,22,8,21,6,19,6,17,5,16,5,23,5,24,5,24,6,24,7,24,8,23,8,21,8,19,8,18,8,17,8,16,8,16,7,16,6,35,-1,35,0,36,0,36,1,36,2,36,-1,36,-2,36,-3,38,-3,38,-2,38,-1,38,2,38,1,38,0,40,0,40,1,40,-1,40,-2,41,-1,41,0,36,-4,36,3,37,3,37,-4,44,3,44,-4,44,-3,44,-2,44,-1,44,2,44,1,44,0,38,-4,38,3,42,3,42,-4,42,0,42,1,42,-1,42,-2,43,-4,43,3,39,-4,41,-4,40,-4,41,3,39,3,40,3,39,-2,39,1,38,-5,40,-5,40,-6,42,-5,42,-6,38,-6,37,-6,36,-6,43,-6,44,-6,44,-7,44,-8,44,-9,36,-7,36,-8,36,-9,37,-9,38,-9,39,-9,40,-9,41,-9,42,-9,43,-9,38,-7,39,-7,40,-7,41,-7,42,-7,40,-8,38,4,38,5,38,6,40,6,40,7,40,8,42,4,42,5,42,6,41,6,39,6,36,5,44,5,44,6,44,7,44,8,43,8,37,8,36,8,36,7,36,6,26,6,26,7,26,8,27,8,29,8,31,8,33,8,34,8,34,7,34,6,34,5,33,5,26,5,27,5,29,6,31,6,32,8,32,6,32,5,32,4,30,8,30,7,30,6,30,4,30,5,28,6,28,5,28,4,30,-8,32,-7,31,-7,30,-7,29,-7,28,-7,33,-9,32,-9,31,-9,30,-9,29,-9,28,-9,27,-9,26,-9,26,-8,26,-7,34,-9,34,-8,34,-7,34,-6,26,-19,33,-6,26,-18,26,-17,26,-20,26,-21,26,-22,28,-22,28,-21,28,-20,28,-17,28,-18,26,-6,28,-19,30,-19,30,-18,30,-20,30,-21,31,-19,26,-23,26,-16,27,-16,27,-6,28,-6,32,-6,32,-5,30,-6,30,-5,28,-5,29,1,31,1,31,-2,29,-2,29,0,29,-1,30,3,29,3,31,3,30,-4,31,-4,29,-4,33,3,33,-4,32,-3,32,-2,32,-1,32,2,32,1,32,0,32,-4,32,3,28,3,28,-4,34,0,34,1,34,2,34,-1,34,-2,34,-3,34,-4,34,3,27,-4,27,3,26,3,26,-4,31,0,31,-1,30,-2,30,-1,30,1,30,0,28,0,28,1,28,2,28,-1,28,-2,28,-3,26,-3,26,-2,26,-1,26,2,26,1,22,20,22,19,22,15,26,0,22,22,18,22,18,15,24,19,24,20,24,21,24,18,24,17,24,16,24,15,24,22,17,15,17,22,16,22,16,15,21,19,21,18,20,17,20,18,20,20,20,19,18,19,18,20,18,18,18,17,18,16,16,16,16,17,16,18,16,21,16,20,16,19,25,11,25,12,43,19,43,18,12,-12,13,-12,13,-13,13,-10,0,-10,-6,-10,-14,9,0,9,-3,-20,-3,-19,3,19,3,18,-3,16,-3,21,2,11,-2,11,-5,16,-5,21,5,27,-8,26,7,23,6,23,10,21,9,21,11,21,7,21,13,17,13,21,13,19,10,16,7,19,7,17,9,23,11,23,13,23,14,23,12,26,8,26,7,25,13,25,5,-16,7,-15,-14,4,-13,-10,28,-10,35,-27,39,2,41,2,40,-3,41,-3,39,-3,40,2,37,0,37,-1,41,-5,39,-5,44,4,36,4,38,8,38,9,42,8,25,24,20,21,11,9,27,9,36,14,37,10,21,-10,23,-10,22,-12,18,-12,17,-10,19,-10,18,-8,22,-8,-13,21,-13,20,15,24,15,12,24,9,15,-4,15,-14};const uint floor_size = 4114;const float level_wall[] = {-5,1,-5,0,-3,1,-3,0,5,1,3,0,3,2,3,1,-3,2,1,2,0,2,-1,2,-4,4,-3,4,4,4,3,4,1,4,-1,4,-1,5,1,5,5,4,5,5,-5,3,-5,4,-5,5,-5,2,5,3,5,2,5,6,5,7,-5,6,-5,9,-5,8,-5,7,-3,6,3,6,1,7,3,7,-4,9,-1,9,-2,9,-3,9,2,9,3,9,4,9,5,9,1,9,2,7,5,8,-3,7,-2,7,-1,7,-1,-8,-2,-8,-3,-8,5,-9,2,-8,1,-10,5,-10,4,-10,3,-10,2,-10,-3,-10,-2,-10,-1,-10,-4,-10,3,-8,1,-8,3,-7,-3,-7,-5,-9,-5,-10,5,-8,5,-7,5,-3,5,-4,-5,-3,-5,-6,-5,-5,-5,-4,5,-6,5,-5,1,-6,-1,-6,-1,-5,1,-5,3,-5,4,-5,-3,-5,-4,-5,-1,-3,0,-3,1,-3,-3,-3,3,-2,3,-3,3,-1,5,-2,-3,-1,-3,-2,-5,-1,-5,-2,7,-2,7,-1,15,-1,15,-2,13,-1,13,-3,13,-2,7,-3,11,-3,10,-3,9,-3,6,-5,7,-5,14,-5,13,-5,11,-5,9,-5,9,-6,11,-6,15,-5,15,-6,15,-3,15,-7,15,-8,7,-7,13,-7,11,-8,13,-8,6,-10,10,-10,9,-10,8,-10,7,-10,12,-10,14,-10,15,-10,11,-10,12,-8,15,-9,7,-8,8,-8,9,-8,9,7,8,7,7,7,15,8,12,7,15,9,14,9,13,9,12,9,7,9,8,9,9,9,10,9,6,9,13,7,11,7,13,6,7,6,15,7,15,6,15,2,15,3,15,5,15,4,11,5,9,5,9,4,11,4,13,4,14,4,7,4,6,4,9,2,10,2,11,2,7,2,13,1,13,2,13,0,15,1,15,0,7,0,7,1,-15,-2,-15,-1,-13,-2,-13,-1,-7,-1,-7,-3,-7,-2,-13,-3,-9,-3,-10,-3,-11,-3,-14,-5,-13,-5,-6,-5,-7,-5,-9,-5,-11,-5,-11,-6,-9,-6,-15,-4,-15,-5,-15,-6,-15,-3,-15,-7,-15,-10,-15,-9,-15,-8,-13,-7,-7,-7,-9,-8,-7,-8,-14,-10,-10,-10,-11,-10,-12,-10,-8,-10,-7,-10,-9,-10,-8,-8,-13,-8,-12,-8,-11,-8,-11,7,-12,7,-13,7,-8,7,-9,9,-6,9,-7,9,-8,9,-13,9,-12,9,-11,9,-10,9,-7,7,-9,7,-7,6,-13,6,-15,7,-15,8,-15,9,-15,6,-15,2,-15,5,-15,4,-15,3,-9,5,-11,5,-11,4,-9,4,-7,4,-6,4,-13,4,-11,2,-10,2,-9,2,-13,2,-7,1,-7,2,-7,0,-13,0,-13,1,-15,0,-15,1,-15,20,-15,19,-13,19,-7,19,-7,21,-7,20,-9,21,-10,21,-11,21,-14,23,-13,23,-6,23,-7,23,-9,23,-11,23,-11,24,-9,24,-15,22,-15,23,-15,24,-15,21,-15,25,-15,28,-15,27,-15,26,-13,25,-7,25,-9,26,-7,26,-14,28,-10,28,-11,28,-12,28,-13,28,-8,28,-7,28,-6,28,-9,28,-13,26,-12,26,-11,26,-11,11,-12,11,-13,11,-8,11,-7,11,-9,11,-7,12,-13,12,-15,11,-15,10,-15,12,-15,16,-15,13,-15,14,15,19,15,20,15,23,-15,15,-9,13,-11,13,-11,14,15,22,15,21,15,25,15,26,-9,14,-7,14,-6,14,-13,14,6,28,10,28,9,28,8,28,-5,17,-5,18,-3,17,-3,18,-14,14,5,17,3,16,3,17,7,28,12,28,1,16,0,16,-1,16,13,28,-4,14,-3,14,4,14,3,14,1,14,-1,14,-1,13,1,13,5,14,5,13,-5,15,-5,14,-5,13,5,15,5,16,5,12,5,11,-5,10,-3,12,3,12,1,11,3,11,5,10,-3,11,-1,11,-1,26,-2,26,-3,26,2,26,1,28,5,28,4,28,3,28,2,28,-3,28,-2,28,-1,28,0,28,-4,28,3,26,1,26,3,25,-3,25,-5,26,-5,27,-5,28,-5,25,5,26,5,25,5,21,5,22,-5,24,-5,23,-5,22,5,24,5,23,1,24,-1,24,-1,23,1,23,3,23,4,23,-3,23,-4,23,14,28,-1,21,0,21,1,21,15,28,11,28,3,20,3,21,5,20,-11,16,-3,19,-3,20,-5,19,-5,20,15,27,9,11,8,11,7,11,15,10,12,11,13,11,11,11,13,12,7,12,-10,16,-9,16,-13,16,-7,17,15,11,15,16,15,15,-7,16,-7,18,-13,18,-13,17,15,13,15,14,11,13,9,13,9,14,11,14,13,14,14,14,7,14,6,14,15,17,15,18,-15,18,-15,17,-15,-18,-15,-19,-13,-18,-13,-19,-7,-19,-7,-17,-7,-18,-13,-17,-9,-17,-10,-17,-11,-17,-14,-15,-13,-15,-6,-15,-7,-15,-9,-15,-11,-15,-11,-14,-9,-14,-15,-16,-15,-15,-15,-14,-15,-17,-15,-13,-15,-11,-15,-12,-13,-13,-7,-13,-9,-12,-7,-12,-8,-12,-13,-12,-12,-12,-11,-12,-11,-27,-12,-27,-13,-27,-8,-27,-9,-29,-6,-29,-7,-29,-8,-29,-13,-29,-12,-29,-11,-29,-10,-29,-14,-29,-7,-27,-9,-27,-7,-26,-13,-26,-15,-27,-15,-28,-15,-29,-15,-26,-15,-22,-15,-25,-15,-24,7,-18,7,-19,15,-19,15,-18,13,-19,13,-17,13,-18,7,-17,11,-17,10,-17,9,-17,6,-15,8,-15,14,-15,13,-15,11,-15,9,-15,9,-14,11,-14,15,-15,-15,-23,-9,-25,-11,-25,-11,-24,15,-16,15,-17,15,-13,15,-12,-9,-24,-7,-24,-6,-24,-13,-24,7,-13,11,-12,-5,-21,-5,-20,-3,-21,-14,-24,5,-21,3,-20,3,-22,3,-21,-3,-22,1,-22,0,-22,-1,-22,-4,-24,-3,-24,4,-24,3,-24,1,-24,-1,-24,-1,-25,1,-25,5,-24,5,-25,-5,-23,-5,-24,-5,-25,-5,-22,5,-23,5,-22,5,-26,5,-27,-5,-29,-5,-28,-3,-26,3,-26,1,-27,3,-27,-4,-29,0,-29,-1,-29,-2,-29,-3,-29,2,-29,3,-29,4,-29,5,-29,1,-29,2,-27,5,-28,-3,-27,-2,-27,-1,-27,-1,-12,-2,-12,-3,-12,5,-11,2,-12,3,-12,1,-12,3,-13,-3,-13,-5,-12,-5,-11,-5,-13,5,-12,5,-13,5,-17,-5,-17,-5,-14,-5,-15,-5,-16,5,-14,5,-15,1,-14,-1,-14,-1,-15,1,-15,3,-15,4,-15,-3,-15,-4,-15,-1,-17,0,-17,1,-17,-3,-17,3,-18,3,-17,3,-19,5,-18,-11,-22,-3,-18,-5,-19,-5,-18,15,-11,7,-12,8,-12,9,-12,9,-27,8,-27,7,-27,15,-28,12,-27,11,-29,15,-29,14,-29,13,-29,12,-29,7,-29,8,-29,9,-29,10,-29,6,-29,13,-27,11,-27,13,-26,7,-26,-10,-22,-9,-22,-13,-22,-7,-21,15,-27,15,-26,15,-22,15,-23,-7,-22,-7,-20,-13,-20,-13,-21,15,-25,15,-24,11,-25,9,-25,9,-24,11,-24,13,-24,14,-24,7,-24,6,-24,9,-22,10,-22,11,-22,7,-22,13,-21,13,-22,13,-20,15,-21,15,-20,7,-20,7,-21,-15,-20,-15,-21,37,-21,37,-20,45,-20,45,-21,43,-20,43,-22,43,-21,37,-22,41,-22,40,-22,39,-22,36,-24,37,-24,44,-24,43,-24,41,-24,39,-24,39,-25,41,-25,45,-24,45,-25,17,-21,17,-20,23,-20,23,-22,45,-23,45,-22,45,-26,45,-27,23,-21,17,-22,21,-22,20,-22,37,-26,43,-26,41,-27,43,-27,36,-29,40,-29,39,-29,38,-29,37,-29,42,-29,43,-29,44,-29,45,-29,41,-29,42,-27,45,-28,37,-27,38,-27,39,-27,39,-12,38,-12,37,-12,45,-11,42,-12,25,-18,25,-19,27,-18,27,-19,19,-22,35,-18,33,-19,33,-17,33,-18,27,-17,31,-17,30,-17,29,-17,26,-15,27,-15,34,-15,33,-15,31,-15,29,-15,29,-14,31,-14,35,-15,35,-14,25,-16,25,-15,25,-14,25,-17,35,-16,35,-17,35,-13,35,-12,25,-13,25,-11,25,-12,27,-13,33,-13,31,-12,33,-12,32,-12,35,-11,27,-12,28,-12,29,-12,29,-27,28,-27,27,-27,35,-28,32,-27,31,-29,35,-29,34,-29,33,-29,32,-29,27,-29,28,-29,29,-29,30,-29,26,-29,33,-27,31,-27,33,-26,27,-26,25,-28,25,-29,35,-26,35,-22,35,-23,25,-22,25,-25,25,-24,25,-23,35,-25,35,-24,31,-25,29,-25,29,-24,31,-24,33,-24,34,-24,27,-24,26,-24,29,-22,30,-22,31,-22,27,-22,33,-21,33,-22,33,-20,35,-21,16,-24,27,-20,27,-21,25,-20,25,-21,43,-12,41,-12,43,-13,37,-13,17,-24,24,-24,23,-24,21,-24,45,-12,45,-13,45,-17,45,-16,19,-24,19,-25,21,-25,45,-14,45,-15,41,-14,39,-14,39,-15,41,-15,43,-15,44,-15,37,-15,36,-15,39,-17,40,-17,41,-17,37,-17,43,-18,43,-17,43,-19,45,-18,45,-19,37,-19,37,-18,17,-26,23,-26,21,-27,23,-27,16,-29,20,-29,19,-29,18,-29,17,-29,22,-29,23,-29,24,-29,21,-29,22,-27,17,-27,18,-27,19,-27,19,-12,17,-12,23,-12,21,-12,23,-13,17,-13,21,-14,19,-14,19,-15,21,-15,23,-15,24,-15,17,-15,16,-15,19,-17,20,-17,21,-17,17,-17,23,-18,23,-17,23,-19,17,-19,17,-18,37,17,37,18,45,18,45,17,43,16,43,17,37,16,41,16,40,16,39,16,37,14,44,14,43,14,41,14,39,14,39,13,41,13,45,14,45,13,17,17,17,18,23,18,23,16,45,15,45,16,45,12,45,11,23,17,17,16,21,16,20,16,37,12,43,12,41,11,43,11,42,11,45,10,37,11,38,11,39,11,39,26,38,26,37,26,45,27,42,26,25,20,25,19,27,20,27,19,19,16,35,20,33,19,33,21,33,20,41,28,45,28,27,21,31,21,30,21,29,21,44,28,26,23,27,23,34,23,33,23,31,23,29,23,29,24,31,24,35,23,35,24,25,22,25,23,25,21,35,22,35,21,35,25,35,26,25,25,25,28,25,27,25,26,27,25,33,25,31,26,33,26,26,28,30,28,29,28,28,28,27,28,32,28,33,28,34,28,35,28,31,28,32,26,35,27,27,26,28,26,29,26,29,11,28,11,27,11,35,10,32,11,33,11,31,11,33,12,27,12,25,10,35,11,35,12,35,16,35,15,25,16,25,13,25,14,25,15,35,13,35,14,31,13,29,13,29,14,31,14,33,14,34,14,27,14,26,14,43,28,29,16,30,16,31,16,27,16,42,28,37,28,33,17,33,16,33,18,35,17,16,14,27,18,27,17,25,18,25,17,38,28,39,28,40,28,36,28,43,26,41,26,43,25,37,25,17,14,24,14,23,14,21,14,45,26,45,25,45,21,45,22,19,14,19,13,21,13,45,24,45,23,41,24,39,24,39,23,41,23,43,23,44,23,37,23,36,23,39,21,40,21,41,21,37,21,43,20,43,21,45,20,45,19,37,19,37,20,17,12,23,12,21,11,23,11,22,11,17,11,18,11,19,11,19,26,18,26,17,26,22,26,21,28,24,28,23,28,22,28,17,28,18,28,19,28,20,28,16,28,23,26,21,26,23,25,17,25,21,24,19,24,19,23,21,23,23,23,24,23,17,23,16,23,19,21,21,21,17,21,23,20,23,21,23,19,17,19,17,20,17,1,17,0,23,0,23,2,23,1,17,2,21,2,20,2,19,2,16,4,17,4,24,4,23,4,21,4,19,4,19,5,21,5,17,6,23,6,21,7,23,7,16,9,20,9,19,9,18,9,17,9,22,9,23,9,21,9,22,7,17,7,18,7,19,7,19,-8,17,-8,24,-10,22,-10,18,-10,20,-10,16,-10,23,-8,21,-8,23,-7,17,-7,37,1,45,0,45,1,43,0,43,2,43,1,37,2,37,4,43,4,41,4,39,4,39,5,41,5,45,4,45,5,21,-6,19,-6,19,-5,45,3,45,2,45,6,45,7,21,-5,23,-5,24,-5,17,-5,37,6,43,6,41,7,43,7,36,9,40,9,39,9,25,-2,25,-1,27,-2,27,-1,16,-5,35,-2,33,-1,33,-3,33,-2,37,9,42,9,27,-3,31,-3,30,-3,29,-3,43,9,26,-5,27,-5,34,-5,33,-5,31,-5,29,-5,29,-6,31,-6,35,-5,35,-6,25,-4,25,-5,25,-6,25,-3,35,-4,35,-3,35,-7,35,-8,25,-10,25,-9,27,-7,33,-7,31,-8,33,-8,26,-10,30,-10,29,-10,27,-10,32,-10,33,-10,34,-10,35,-10,31,-10,32,-8,35,-9,27,-8,28,-8,29,-8,29,7,28,7,27,7,35,8,32,7,31,9,35,9,34,9,33,9,32,9,28,9,29,9,30,9,26,9,33,7,31,7,33,6,27,6,25,7,25,8,25,9,25,6,35,7,35,6,35,2,35,3,25,2,25,5,25,4,25,3,35,5,35,4,31,5,29,5,29,4,31,4,33,4,34,4,27,4,26,4,44,9,29,2,30,2,31,2,27,2,45,9,41,9,33,1,33,2,33,0,35,1,19,-3,27,0,27,1,25,0,25,1,42,7,45,8,37,7,38,7,39,7,39,-8,38,-8,37,-8,45,-9,42,-8,41,-10,45,-10,44,-10,43,-10,42,-10,37,-10,38,-10,39,-10,40,-10,36,-10,43,-8,41,-8,43,-7,37,-7,20,-3,21,-3,17,-3,23,-2,45,-8,45,-7,45,-3,45,-4,23,-3,23,-1,17,-1,17,-2,45,-6,45,-5,41,-6,39,-6,43,-5,44,-5,37,-5,36,-5,37,-3,43,-2,43,-3,43,-1,45,-2,45,-1,37,-2,40,18,40,19,11,-13,7,16,13,16,11,16,9,16,9,18,11,18,13,18,7,18,7,20,13,20,11,20,9,20,9,22,11,22,13,22,7,22,7,24,13,24,11,24,9,24,9,26,11,26,13,26,7,26,0,-14,0,-25,0,-18,0,-17,0,-21,3,-16,9,-16,11,-9,-2,18,-1,18,0,19,0,18,-14,-7,34,-13,26,-13,33,-28,29,-28,28,-15,29,-16,29,-18,29,-19,32,-20,31,-20,32,-24,42,-3,42,2,41,-2,41,1,39,-1,39,0,40,5,40,4,41,8,39,8,43,5,37,5,22,21,18,21,-10,-21,-10,-20,-10,-19,-10,-18,28,8,28,10,37,15,37,13,-10,20,-10,19,-10,18,-12,21,-8,21};const uint wall_size = 2964;float px=0.f, py=0.f;float fx=0.f, fy=0.f;float caught=0.f;float winst = 0.f;float ga = 0.f;uint prot = 0;uint protc = 0;float prota = 0.f;uint pid;float pix, piy;float ft = 0.f;float rm = 0.f;float rmb = 0.f;float cx[MAX_MONSTER], cy[MAX_MONSTER], lcx[MAX_MONSTER], lcy[MAX_MONSTER], cdx[MAX_MONSTER], cdy[MAX_MONSTER];float cnt[MAX_MONSTER];uint cm[MAX_MONSTER];float cds[MAX_MONSTER];void updateWindowSize(int width, int height){winw = width, winh = height;ww = (float)winw, wh = (float)winh;rww = 1.f/ww, rwh = 1.f/wh;glViewport(0, 0, winw, winh);aspect = ww / wh;mIdent(&projection);mPerspective(&projection, 60.f, aspect, 0.01f, FAR_DISTANCE);glUniformMatrix4fv(projection_id, 1, GL_FALSE, (float*)&projection.m[0][0]);}void activateJOY(){json=1;puts("!! Gamepad / Joystick ACTIVATED, mouse disabled until game restart.");}uint insideFrustum(const float x, const float y){const float xm = px+x, ym = py+y;const float d = xm*xm + ym*ym;if(d > 1.f && (xm*lookz.x) + (ym*lookz.y) <= 0.f){return 0;}if(d < DRAW_DISTANCE){return 1;}else{return 0;}return 0;}void resetMonster(uint i){float d = 42.f, tcx, tcy;do{const uint pi = esRand(0, 2053)*2;tcx = level_floor[pi], tcy = level_floor[pi+1];const float xm = px+tcx;const float ym = py+tcy;d = xm*xm + ym*ym;}while(d < 36.f);cx[i] = tcx, cy[i] = tcy;lcx[i] = cx[i], lcy[i] = cy[i];cdx[i]=1, cdy[i]=0;cnt[i] = t+1.f;cm[i] = 0;cds[i] = 0.f;}void retargetStraglers(){for(uint i=0; i < MAX_MONSTER; i++){if(cds[i] != 0.f){continue;}const float xm = px+cx[i];const float ym = py+cy[i];float d = xm*xm + ym*ym;if(d > 81.f){float tcx, tcy;do{const uint pi = esRand(0, 2053)*2;tcx = level_floor[pi], tcy = level_floor[pi+1];const float xm = px+tcx;const float ym = py+tcy;d = xm*xm + ym*ym;}while(d < 36.f || d > 81.f);cx[i] = tcx, cy[i] = tcy;lcx[i] = cx[i], lcy[i] = cy[i];cds[i] = 0.f;}}}void resetGame(uint mode){glClearColor(0.f, 0.f, 0.f, 0.f);if(mode == 1){char strts[16];timestamp(&strts[0]);printf("[%s] Game Reset.\n", strts);}else if(mode == 2){char strts[16];timestamp(&strts[0]);printf("[%s] You died.\n", strts);}px=0.f, py=0.f;fx=0.f, fy=0.f;pid = 28;caught = 0.f;xrot = 0.f;ft = 0.f;prot=0;protc=0;prota=0.f;float d = 42.f, tx, ty;do{const uint pi = esRand(0, 2053)*2;tx = level_floor[pi], ty = level_floor[pi+1];const float xm = px+tx;const float ym = py+ty;d = xm*xm + ym*ym;}while(d < 36.f);pix = tx, piy = ty;for(uint i=0; i < MAX_MONSTER; i++){resetMonster(i);}SDL_SetWindowTitle(wnd, appTitle);}void doAttack(){float nlx = lookz.x, nly = lookz.y;const float len = 1.f/sqrtf(nlx*nlx + nly*nly);nlx *= len, nly *= len;int sid = -1;float dist = 99999.f;for(uint i = 0; i < MAX_MONSTER; i++){if(cds[i] != 0.f){continue;}const float xm = px+cx[i], ym = py+cy[i];const float d = xm*xm + ym*ym;if(d < 0.42f){sid=i;dist=d;break;}else if(d < 16.f){const float len = 1.f/sqrtf(d);const float ex = xm*len, ey = ym*len;const float dot = (nlx * ex) + (nly * ey);if(dot > 0.94f && d < dist){sid=i;dist=d;}}}if(sid != -1){cds[sid] = t;protc++;if(protc >= 4){prot=1;protc=0;}}else{const float xm = px+pix, ym = py+piy;const float d = xm*xm + ym*ym;if(d < 16.f && ft == 0.f){const float len = 1.f/sqrtf(d);const float ex = xm*len, ey = ym*len;const float dot = (nlx * ex) + (nly * ey);if(dot > 0.94f && ft == 0.f){ft = t+1.f;rm = 0.f;rmb = 0.f;}}}ga=t;}void main_loop(){fc++;t=((float)SDL_GetTicks())*0.001f,dt=t-lt,lt=t;SDL_Event event;while(SDL_PollEvent(&event)){switch(event.type){case SDL_WINDOWEVENT:{if(event.window.event == SDL_WINDOWEVENT_RESIZED){updateWindowSize(event.window.data1, event.window.data2);}}break;case SDL_KEYDOWN:{if(NOINPUT){return;}const SDL_Keycode key = event.key.keysym.sym;if( key == SDLK_LEFT || key == SDLK_a){ks[0]=1;}else if(key == SDLK_RIGHT || key == SDLK_d){ks[1]=1;}else if(key == SDLK_UP || key == SDLK_w){ks[2]=1;}else if(key == SDLK_DOWN || key == SDLK_s){ks[3]=1;}else if(key == SDLK_j) {ks[4]=1;}else if(key == SDLK_l) {ks[5]=1;}else if(key == SDLK_SPACE && caught == 0.f && ga == 0.f){doAttack();}else if(key == SDLK_1){sens = 0.0001f;}else if(key == SDLK_2){sens = 0.0003f;}else if(key == SDLK_3){sens = 0.0006f;}else if(key == SDLK_4){sens = 0.0012f;}else if(key == SDLK_5){sens = 0.0022f;}else if(key == SDLK_6){sens = 0.006f;}else if(key == SDLK_7){sens = 0.012f;}else if(key == SDLK_8){sens = 0.03f;}else if(key == SDLK_9){sens = 0.06f;}else if(key == SDLK_0){sens = 0.003f;}else if(key == SDLK_e){xrot += PI;}else if(key == SDLK_f){if(t-lfct > 2.0){ char strts[16];timestamp(&strts[0]); printf("[%s] FPS: %g\n", strts, fc/(t-lfct)); lfct = t; fc = 0;}}else if(key == SDLK_r){resetGame(1);}else if(key == SDLK_ESCAPE){lock_mouse = 0;SDL_GetRelativeMouseState(&xd, &yd);SDL_SetRelativeMouseMode(SDL_FALSE);}}break;case SDL_KEYUP:{if(NOINPUT){return;}const SDL_Keycode key = event.key.keysym.sym;if( key == SDLK_LEFT || key == SDLK_a){ks[0]=0;}else if(key == SDLK_RIGHT || key == SDLK_d){ks[1]=0;}else if(key == SDLK_UP || key == SDLK_w){ks[2]=0;}else if(key == SDLK_DOWN || key == SDLK_s){ks[3]=0;}else if(key == SDLK_j) {ks[4]=0;}else if(key == SDLK_l) {ks[5]=0;}}break;case SDL_MOUSEBUTTONDOWN:{if(event.button.button == SDL_BUTTON_LEFT){if(lock_mouse == 0){ if(json == 1){jspause = 0;} lock_mouse = 1; SDL_GetRelativeMouseState(&xd, &yd); SDL_SetRelativeMouseMode(SDL_TRUE);}else if(caught == 0.f && ga == 0.f){doAttack();}}else if(event.button.button == SDL_BUTTON_RIGHT){xrot += PI;}}break;case SDL_QUIT:{SDL_FreeSurface(s_icon);SDL_GL_DeleteContext(glc);SDL_DestroyWindow(wnd);SDL_Quit();exit(0);}break;}}if(js == NULL){if(t > jsc){const uint nj = SDL_NumJoysticks();if(nj >= 1){js = SDL_JoystickOpen(0);puts("!! Gamepad / Joystick detected.");}jsc = t + 6.f;}}else{if(YESINPUT){if(caught == 0.f){const float nj0 = -(((float)SDL_JoystickGetAxis(js, 0)) / 32768.f);const float nj1 = -(((float)SDL_JoystickGetAxis(js, 1)) / 32768.f);if(json == 0){if(fabsf(nj0) > 0.1f || fabsf(nj1) > 0.1f){activateJOY();}}if(fabsf(nj0) > 0.1f || fabsf(nj1) > 0.1f){float ttdx = nj0 * 7.f;float ttdy = nj1 * 10.f;if(ttdx > STRAFE_SPEED){ttdx = STRAFE_SPEED;}else if(ttdx < -STRAFE_SPEED){ttdx = -STRAFE_SPEED;}if(ttdy > MOVE_SPEED){ttdy = MOVE_SPEED;}else if(ttdy < -MOVE_SPEED){ttdy = -MOVE_SPEED;}px -= lookx.x * ttdx * dt, py -= lookx.y * ttdx * dt;px -= lookz.x * ttdy * dt, py -= lookz.y * ttdy * dt;}}if(caught == 0.f && ga == 0.f && (SDL_JoystickGetAxis(js, 2) > 0 || SDL_JoystickGetAxis(js, 5) > 0 || SDL_JoystickGetButton(js, 0) == 1)){doAttack();}else if(SDL_JoystickGetButton(js, 3) == 1){static float nt = 0.f;if(t > nt){resetGame(1);nt = t+0.333f;}}else if(caught == 0.f && (SDL_JoystickGetButton(js, 1) == 1 || SDL_JoystickGetButton(js, 4) == 1 || SDL_JoystickGetButton(js, 5) == 1)){static float nt = 0.f;if(t > nt){xrot += PI;nt = t+0.2f;}}}if(SDL_JoystickGetButton(js, 2) == 1 && lock_mouse == 1){static float nt = 0.f;if(t > nt){jspause=1-jspause;nt = t+0.333f;}}}if(caught == 0.f){float fms = MOVE_SPEED;if(ks[0]==1){px -= lookx.x * STRAFE_SPEED * dt, py -= lookx.y * STRAFE_SPEED * dt; fms=STRAFE_SPEED;}else if(ks[1]==1){px += lookx.x * STRAFE_SPEED * dt, py += lookx.y * STRAFE_SPEED * dt; fms=STRAFE_SPEED;}if(ks[2]==1){px -= lookz.x * fms * dt, py -= lookz.y * fms * dt;}else if(ks[3]==1){px += lookz.x * fms * dt, py += lookz.y * fms * dt;}if(ks[4]==1){xrot += 3.f*dt;}else if(ks[5]==1){xrot -= 3.f*dt;}}if(json == 1 && YESINPUT){const float nj3 = -(((float)SDL_JoystickGetAxis(js, 3)) / 32768.f);if(fabsf(nj3) > 0.1f){xrot += nj3*3.33f*dt;}}else if(json == 0 && lock_mouse == 1){SDL_GetRelativeMouseState(&xd, &yd);xrot -= xd*sens;}mIdent(&view);if(caught != 0.f){const float dc = caught-t;mRotate(&view, d2PI, 1.f, 0.f, 0.f);mRotate(&view, xrot, 0.f, 0.f, 1.f);mRotate(&view, -d2PI+(dc*0.523598767f), 0.f, 1.f, 0.f);mTranslate(&view, px, py, -0.5f + (0.4f-(dc*0.133333333f)));if(dc < 0.f){resetGame(2);}}else{mRotate(&view, d2PI, 1.f, 0.f, 0.f);mRotate(&view, xrot, 0.f, 0.f, 1.f);mTranslate(&view, px, py, -0.5f);}mGetViewZ(&lookz, view);mGetViewY(&looky, view);mGetViewX(&lookx, view);{const float xm = px+pix, ym = py+piy;const float d = xm*xm + ym*ym;if(d < 0.6f){const float len = 1.f/sqrtf(d);const float ex = xm*len, ey = ym*len;const float dl = 0.6f-d;px += ex*dl, py += ey*dl;}}{static float nt = 0.f;if(t > nt){retargetStraglers();nt = t+3.f;}}glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);shadeLambertD(&position_id, &projection_id, &modelview_id, &lightpos_id, &normal_id, &color_id, &ambient_id, &specular_id, &hsv_id, &opacity_id);glUniform1f(specular_id, 0.63f);glUniform1f(ambient_id, 0.26f);glUniform3f(hsv_id, (px+py)*0.01f, 0.f, 0.f);glUniformMatrix4fv(projection_id, 1, GL_FALSE, (float*)&projection.m[0][0]);esBindModel(1);for(uint i = 0; i < floor_size; i+=2){if(insideFrustum(level_floor[i], level_floor[i+1]) == 1){mIdent(&model);mSetPos(&model, (vec){level_floor[i], level_floor[i+1], 0.f});updateModelView();esRenderModel();}}esBindModel(0);for(uint i = 0; i < wall_size; i+=2){const float xd = px+level_wall[i], yd = py+level_wall[i+1];const float fxd = fabsf(xd), fyd = fabsf(yd);const uint xif = fxd < 0.6f, yif = fyd < 0.6f;if(xif && yif){if(xif && fxd > fyd){if(xd < 0.f){px -= 0.6f+xd;} else{px += 0.6f-xd;}}if(yif && fyd > fxd){if(yd < 0.f){py -= 0.6f+yd;} else{py += 0.6f-yd;}}}if(insideFrustum(level_wall[i], level_wall[i+1]) == 1){mIdent(&model);mSetPos(&model, (vec){level_wall[i], level_wall[i+1], 0.f});updateModelView();esRenderModel();}}glUniform3f(hsv_id, 0.f, 0.f, 0.f);float highred = 16.f;for(uint i=0; i < MAX_MONSTER; i++){if(cds[i] == 0.f){if(PAUSE_CHECK && caught == 0.f){if(cm[i] == 1){cdx[i] = cx[i]+px, cdy[i] = cy[i]+py;const float len = 1.f/sqrtf(cdx[i]*cdx[i] + cdy[i]*cdy[i]);cdx[i] *= len;cdy[i] *= len;cx[i] -= cdx[i]*MONSTER_SPEED*dt, cy[i] -= cdy[i]*MONSTER_SPEED*dt;}else{cx[i] -= cdx[i]*MOVE_SPEED*dt, cy[i] -= cdy[i]*MOVE_SPEED*dt;}}if(PAUSE_CHECK && caught == 0.f){const float xm = px+cx[i];const float ym = py+cy[i];const float d = xm*xm + ym*ym;if(d < 16.f){if(d < highred){highred = d;}}if(d < 0.3f){if(prot == 1){ cds[i] = t; protc=0; if(prota == 0.f){prota=t+1.f;}}else{caught=t+3.f;}}}for(uint j=0; j < MAX_MONSTER; j++){if(j == i || cds[j] != 0.f){continue;}const float xm = cx[j]-cx[i];const float ym = cy[j]-cy[i];const float d = xm*xm + ym*ym;if(d < 0.3f){cds[i] = t;}}if(PAUSE_CHECK && t > cnt[i] && caught == 0.f){const float xm = cx[i]-lcx[i];const float ym = cy[i]-lcy[i];const float d = xm*xm + ym*ym;cm[i] = d > 1.f;if(cm[i] == 0){const uint rd = esRand(0, 3); if(rd == 0){cdx[i]= 1.f, cdy[i]= 0.f;}else if(rd == 1){cdx[i]=-1.f, cdy[i]= 0.f;}else if(rd == 2){cdx[i]= 0.f, cdy[i]= 1.f;}else if(rd == 3){cdx[i]= 0.f, cdy[i]=-1.f;}}lcx[i] = cx[i];lcy[i] = cy[i];cnt[i] = t+esRand(1.f, 3.f);}if(-cx[i] < -45.f || -cx[i] > 15.f || -cy[i] < -28.f || -cy[i] > 29.f){resetMonster(i);}for(uint j=0; j < wall_size; j+=2){const float colb = 0.8f;const float xd = cx[i]-level_wall[j], yd = cy[i]-level_wall[j+1];const float fxd = fabsf(xd), fyd = fabsf(yd);const uint xif = fxd < colb, yif = fyd < colb;if(xif && yif){if(xif && fxd > fyd){ if(xd < 0.f){cx[i] -= colb+xd;} else{cx[i] += colb-xd;}}if(yif && fyd > fxd){ if(yd < 0.f){cy[i] -= colb+yd;} else{cy[i] += colb-yd;}}}}}if(insideFrustum(cx[i], cy[i]) == 1){mIdent(&model);mSetPos(&model, (vec){cx[i], cy[i], 0.f});static const vec up_norm = (vec){0.f, 0.f, 1.f};const vec dir_norm = (vec){cdx[i], cdy[i], 0.f};vec c;vCross(&c, up_norm, dir_norm);vNorm(&c);vec rup;vCross(&rup, dir_norm, c);model.m[0][0] = c.x;model.m[0][1] = c.y;model.m[0][2] = c.z;model.m[2][0] = rup.x;model.m[2][1] = rup.y;model.m[2][2] = rup.z;model.m[1][0] = -dir_norm.x;model.m[1][1] = -dir_norm.y;model.m[1][2] = -dir_norm.z;if(cds[i] != 0.f){cdx[i] = cx[i]+px, cdy[i] = cy[i]+py;const float len = 1.f/sqrtf(cdx[i]*cdx[i] + cdy[i]*cdy[i]);cdx[i] *= len;cdy[i] *= len;const float dd = (t-cds[i])*6.f;if(dd > d2PI){resetMonster(i);}mRotY(&model, -dd);}updateModelView();esBindRender(9+i);if(cds[i] != 0.f){float dd = t-cds[i];if(dd > 1.f){dd = 1.f;}mRotZ(&model, t*4.f);mScale1(&model, 1.f+(dd*3.333333333f));updateModelView();glUniform1f(opacity_id, (0.3f-dd)*3.333333333f);glEnable(GL_BLEND);esBindRender(56);glDisable(GL_BLEND);}}}if(insideFrustum(pix, piy) == 1){mIdent(&model);vec dirn = (vec){-px, -py, 0.f};const vec origin = (vec){pix, piy, 0.f};vSub(&dirn, dirn, origin);vNorm(&dirn);static const vec up = (vec){0.f, 0.f, -1.f};vec c;vCross(&c, up, dirn);vNorm(&c);vec rup;vCross(&rup, dirn, c);model.m[0][0] = c.x;model.m[0][1] = c.y;model.m[0][2] = c.z;model.m[2][0] = -rup.x;model.m[2][1] = -rup.y;model.m[2][2] = -rup.z;model.m[1][0] = dirn.x;model.m[1][1] = dirn.y;model.m[1][2] = dirn.z;model.m[3][0] = origin.x;model.m[3][1] = origin.y;model.m[3][2] = origin.z;if(ft != 0.f){const float ftd = ft-t;rm += (1.f-ftd)*16.5f*dt;rmb += (1.5f-ftd)*16.5f*dt;mRotZ(&model, rm);if(ftd <= 0.f){ft = 0.f;pid++;if(pid > 41){pid = 28;}float d2 = 42.f, tx, ty;do{const uint pi = esRand(0, 2053)*2;tx = level_floor[pi], ty = level_floor[pi+1];const float xm = px+tx;const float ym = py+ty;d2 = xm*xm + ym*ym;}while(d2 < 36.f);pix = tx, piy = ty;mSetPos(&model, (vec){pix, piy, 0.f});}updateModelView();glUniform1f(opacity_id, ftd);glEnable(GL_BLEND);esBindRender(pid);shadeLambertSolid(&position_id, &projection_id, &modelview_id, &lightpos_id, &normal_id, &color_id, &ambient_id, &saturate_id, &opacity_id);glUniform3f(color_id, 255.f, 0.f, 0.f);glUniform1f(ambient_id, 0.26f);glUniform1f(saturate_id, 1.0f);glUniform1f(opacity_id, ftd);glUniformMatrix4fv(projection_id, 1, GL_FALSE, (float*)&projection.m[0][0]);vec bp = (vec){pix, piy, 0.3f};const uint po = 27; if(pid == po+1) {bp.z = 0.32f;}else if(pid == po+2) {bp.z = 0.21f;}else if(pid == po+3) {bp.z = 0.33f;}else if(pid == po+4) {bp.z = 0.30f;}else if(pid == po+5) {bp.z = 0.21f;}else if(pid == po+6) {bp.z = 0.31f;}else if(pid == po+7) {bp.z = 0.16f;}else if(pid == po+8) {bp.z = 0.28f;}else if(pid == po+9) {bp.z = 0.21f;}else if(pid == po+10){bp.z = 0.33f;}else if(pid == po+11){bp.z = 0.43f;}else if(pid == po+12){bp.z = 0.43f;}else if(pid == po+13){bp.z = 0.27f;}else if(pid == po+14){bp.z = 0.27f;}mIdent(&model);mSetPos(&model, bp);mRotY(&model, -90.f*DEG2RAD);mRotX(&model, -rmb);mScale1(&model, 0.6f);updateModelView();esBindRenderS(4);mIdent(&model);mSetPos(&model, bp);mRotY(&model, -90.f*DEG2RAD);mScale1(&model, 0.6f);updateModelView();esBindRenderS(4);glDisable(GL_BLEND);shadeLambertD(&position_id, &projection_id, &modelview_id, &lightpos_id, &normal_id, &color_id, &ambient_id, &specular_id, &hsv_id, &opacity_id);glUniform1f(specular_id, 0.63f);glUniform1f(ambient_id, 0.26f);glUniform3f(hsv_id, 0.f, 0.f, 0.f);glUniformMatrix4fv(projection_id, 1, GL_FALSE, (float*)&projection.m[0][0]);}else{updateModelView();esBindRender(pid);esBindRender(pid+14);}}if(px*px + py*py < 36.f){if(insideFrustum(0.f, 1.43f) == 1){mIdent(&model);mSetPos(&model, (vec){0.f, 1.43f, 0.f});updateModelView();esBindRender(7);}}if(caught == 0){shadeLambert(&position_id, &projection_id, &modelview_id, &lightpos_id, &normal_id, &color_id, &ambient_id, &saturate_id, &opacity_id);glUniform1f(ambient_id, 0.26f);glUniform1f(saturate_id, 1.0f);glUniformMatrix4fv(projection_id, 1, GL_FALSE, (float*)&projection.m[0][0]);}{const float uxi = pix - fx;const float uyi = piy - fy;fx += uxi*0.3f*dt;fy += uyi*0.3f*dt;float height = 5.5f;const float xm = px+fx;const float ym = py+fy;const float d = xm*xm + ym*ym;if(d < 196.f){height -= 4.f-(d*0.020408163f);}mIdent(&model);vec dirn = (vec){-px, -py, 0.5f};const vec origin = (vec){fx, fy, height};vSub(&dirn, dirn, origin);vNorm(&dirn);static const vec up = (vec){0.f, 0.f, -1.f};vec c;vCross(&c, up, dirn);vNorm(&c);vec rup;vCross(&rup, dirn, c);model.m[0][0] = c.x;model.m[0][1] = c.y;model.m[0][2] = c.z;model.m[2][0] = -rup.x;model.m[2][1] = -rup.y;model.m[2][2] = -rup.z;model.m[1][0] = dirn.x;model.m[1][1] = dirn.y;model.m[1][2] = dirn.z;model.m[3][0] = origin.x;model.m[3][1] = origin.y;model.m[3][2] = origin.z;updateModelView();esBindRender(6);}if(caught == 0.f){glClear(GL_DEPTH_BUFFER_BIT);{const float td = t-ga;if(ga != 0.f){if(td < 0.62f){vec ld = lookz;ld.z = 0.f;vMulS(&ld, ld, 1.5f);vec np = (vec){-px, -py, 0.5f};vAdd(&np, np, ld);mIdent(&model);mSetPos(&model, (vec){np.x, np.y, 0.16f});mSetRotZ(&model, -xrot);mRotX(&model, 4.8f*td);updateModelView();glUniform1f(opacity_id, 1.f-(td*1.219512195f));glEnable(GL_BLEND);esBindRender(4);glDisable(GL_BLEND);}}static float kp1 = 3.8f;static float kp2 = -0.8f;static float kp3 = 8.8f;static float bob = 0.f;vec ld = lookz;vMulS(&ld, ld, 1.f);vec np = (vec){-px, -py, 0.5f};vAdd(&np, np, ld);mIdent(&model);static float lpx=0.f, lpy=0.f;if(fabsf(lpx-px) > 0.03f || fabsf(lpy-py) > 0.03f){mSetPos(&model, (vec){np.x, np.y, 0.1f+sinf(bob)*0.03f});bob += dt*6.f;static float nt = 0.f;if(t > nt){lpx=px,lpy=py;nt = t+0.1f;}}else{mSetPos(&model, (vec){np.x, np.y, 0.1f+sinf(bob)*0.03f});bob += dt;}mSetRotZ(&model, -xrot);if(ga != 0.f){if(td < 0.16f){mRotY(&model, -0.03f - (kp1*td));mRotZ(&model, kp2*td);mRotX(&model, kp3*td);}else if(td >= 0.16f && td <= 0.32f){const float rtd = 0.16f - (td-0.16f);mRotY(&model, -0.03f - (kp1*rtd));mRotZ(&model, kp2*rtd);mRotX(&model, kp3*rtd);}else if(td > 0.62f){ga = 0.f;kp1 = esRandFloat(1.f, 3.8f);kp2 = esRandFloat(-0.8f, 0.8f);kp3 = esRandFloat(-8.8f, 8.8f);}}updateModelView();esBindRender(3);if(prot==1){if(prota != 0.f){const float d = 1.f-(prota-t);if(d >= 3.f){prota=0.f;prot=0;}vec np = (vec){-px, -py, 0.1f+sinf(bob)*0.03f};vec inc;vMulS(&inc, lookz, 1.f+d);vAdd(&np, np, inc);mIdent(&model);mSetPos(&model, np);mSetRotZ(&model, -xrot);mScale1(&model, d*3.f);updateModelView();glClear(GL_DEPTH_BUFFER_BIT);glUniform1f(opacity_id, ((prota+2)-t)*0.5f);glEnable(GL_BLEND);esBindRender(5);glDisable(GL_BLEND);}else{esBindRender(5);}}}{float dx = px+pix;float dy = py+piy;const float len = 1.f/sqrtf(dx*dx + dy*dy);dx *= len, dy *= len;vec ld = lookz;ld.z = 0.f;vMulS(&ld, ld, 6.6f);vec np = (vec){-px, -py, 0.f};vAdd(&np, np, ld);mIdent(&model);mSetPos(&model, (vec){np.x, np.y, 3.f});static const vec up_norm = (vec){0.f, 0.f, 1.f};const vec dir_norm = (vec){-dx, -dy, 0.f};vec c;vCross(&c, up_norm, dir_norm);vNorm(&c);vec rup;vCross(&rup, dir_norm, c);model.m[0][0] = c.x;model.m[0][1] = c.y;model.m[0][2] = c.z;model.m[2][0] = rup.x;model.m[2][1] = rup.y;model.m[2][2] = rup.z;model.m[1][0] = -dir_norm.x;model.m[1][1] = -dir_norm.y;model.m[1][2] = -dir_norm.z;const float hr = (1.f-(0.0625f*highred))*0.35f;if(hr > 0.01f){mRotZ(&model, randfc()*hr);}updateModelView();glClear(GL_DEPTH_BUFFER_BIT);esBindRender(2);}}else{mIdent(&model);mSetPos(&model, (vec){-px, -py, 0.f});updateModelView();esBindRender(8);}SDL_GL_SwapWindow(wnd);}int main(int argc, char** argv){printf("Welcome to The Silentrooms Blood Thirst.\n");printf("https://Silentrooms.itch.io/\n");printf("----\n");int msaa = 16;if(argc >= 2){msaa = atoi(argv[1]);}printf("One command line argument, msaa 0-16.\n");printf("e.g; ./silentrooms 16\n");printf("----\n");printf("- DESKTOP:\n");printf("ESCAPE to release mouse lock.\n");printf("Arrow Keys or WASD to Move Around.\n");printf("Mouse Move to Look Around.\n");printf("Left Click to Shoot.\n");printf("Right Click to 180 degree turn.\n");printf("----\n");printf("- KEYBOARD:\n");printf("WASD = Move.\n");printf("J/L = Look Left/Right.\n");printf("SPACE = Shoot.\n");printf("E = 180 degree turn.\n");printf("R = Reset game.\n");printf("1-9 = Adjusts mouse sensitivity.\n");printf("0 = Resets mouse sensitivity.\n");printf("----\n");printf("Supports the XBOX gamepad.\n");printf("----\n");printf("d1baed295c13b4b96f6ed2735a732bec\n");printf("----\n");SDL_version compiled;SDL_version linked;SDL_VERSION(&compiled);SDL_GetVersion(&linked);printf("Compiled against SDL version %u.%u.%u.\n", compiled.major, compiled.minor, compiled.patch);printf("Linked against SDL version %u.%u.%u.\n", linked.major, linked.minor, linked.patch);printf("----\n");if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_EVENTS|SDL_INIT_JOYSTICK) < 0){printf("ERROR: SDL_Init(): %s\n", SDL_GetError());return 1;}if(msaa > 0){SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, msaa);}SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);wnd = SDL_CreateWindow(appTitle, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, winw, winh, SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);while(wnd == NULL){msaa--;if(msaa == 0){printf("ERROR: SDL_CreateWindow(): %s\n", SDL_GetError());return 1;}SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, msaa);wnd = SDL_CreateWindow(appTitle, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, winw, winh, SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);}SDL_GL_SetSwapInterval(1);glc = SDL_GL_CreateContext(wnd);s_icon = SDL_CreateRGBSurfaceWithFormat(0, 16, 16, 32, SDL_PIXELFORMAT_RGBA32);memcpy(s_icon->pixels, (Uint32*)&icon, s_icon->pitch*16);SDL_SetWindowIcon(wnd, s_icon);if(glc == NULL){printf("ERROR: SDL_GL_CreateContext(): %s\n", SDL_GetError());return 1;}register_wall();register_floor();register_hand();register_gun();register_blast();register_prot();register_brain();register_sign();register_dead();register_c1();register_c2();register_c3();register_c4();register_c5();register_c6();register_c7();register_c8();register_c9();register_c10();register_c11();register_c12();register_c13();register_c14();register_c15();register_c16();register_c17();register_c18();register_c19();register_b1();register_b2();register_b3();register_b4();register_b5();register_b6();register_b7();register_b8();register_b9();register_b10();register_b11();register_b12();register_b13();register_b14();register_h1();register_h2();register_h3();register_h4();register_h5();register_h6();register_h7();register_h8();register_h9();register_h10();register_h11();register_h12();register_h13();register_h14();register_blood();makeLambert();makeLambertD();makeLambertSolid();glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);glClearColor(0.f, 0.f, 0.f, 0.f);glEnable(GL_CULL_FACE);glEnable(GL_DEPTH_TEST);shadeLambertD(&position_id, &projection_id, &modelview_id, &lightpos_id, &normal_id, &color_id, &ambient_id, &specular_id, &hsv_id, &opacity_id);glUniform1f(specular_id, 0.63f);glUniform1f(ambient_id, 0.26f);updateWindowSize(winw, winh);srand(time(0));srandf(time(0));resetGame(0);while(1){main_loop();}return 0;}