1052 lines
28 KiB
C
1052 lines
28 KiB
C
#include <linux/input.h>
|
||
#include <sys/types.h>
|
||
#include <sys/stat.h>
|
||
#include <fcntl.h>
|
||
#include <stdio.h>
|
||
#include <unistd.h>
|
||
#include <GL/glut.h>
|
||
#include <string.h>
|
||
|
||
#include <GL/gl.h>
|
||
#include <GLFW/glfw3.h>
|
||
#include <GL/freeglut.h>
|
||
|
||
#include <locale.h>
|
||
|
||
#include <pthread.h>
|
||
|
||
|
||
|
||
int bat = 1000;
|
||
struct color_struct{
|
||
float R, G, B;
|
||
|
||
}color;
|
||
|
||
#define STB_IMAGE_IMPLEMENTATION
|
||
#include "stb_image.h"
|
||
float k, k_2;
|
||
float width, height;
|
||
#define WIDTH 17
|
||
#define HEIGHT 35
|
||
struct map_struct{
|
||
int itom;
|
||
int wall;
|
||
|
||
} mape[HEIGHT][WIDTH];
|
||
struct inventory_struct{
|
||
int oil, locator, sphere;
|
||
|
||
} inventory;
|
||
|
||
struct player_str{
|
||
int x;
|
||
int y;
|
||
} player;
|
||
#include "Lavirint_generator.h"
|
||
int fd;
|
||
struct input_event ev;
|
||
float cub[][2] = {
|
||
{0,0},
|
||
{1,0},
|
||
{1,1},
|
||
{0,1}
|
||
};
|
||
float player_matrix[][2] = {
|
||
{0.2,0.2},
|
||
{0.8,0.2},
|
||
{0.8,0.8},
|
||
{0.2,0.8}
|
||
};
|
||
|
||
#define max(a,b) \
|
||
({ __typeof__ (a) _a = (a); \
|
||
__typeof__ (b) _b = (b); \
|
||
_a > _b ? _a : _b; })
|
||
|
||
#define min(a,b) \
|
||
({ __typeof__ (a) _a = (a); \
|
||
__typeof__ (b) _b = (b); \
|
||
_a < _b ? _a : _b; })
|
||
|
||
|
||
void glTexParam(){
|
||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);// GL_CLAMP
|
||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);// GL_REPEAT
|
||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);// GL_NEAREST
|
||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);// GL_LINEAR
|
||
}
|
||
unsigned int texsture, texsture_text, texsture_oil, texsture_locator, texsture_sphere;
|
||
void texsture_add(){
|
||
int x = 2, y = 2;// y x
|
||
struct {unsigned char r,g,b,a;} data[y][x];
|
||
memset(data, 0,sizeof(data));
|
||
data[1][0].r = 0;
|
||
data[1][0].b = 0;
|
||
data[1][0].g = 0;
|
||
|
||
data[0][1].r = 0;
|
||
data[0][1].b = 0;
|
||
data[0][1].g = 0;
|
||
|
||
data[0][0].r = 255;
|
||
data[0][0].b = 255;
|
||
data[0][0].g = 255;
|
||
|
||
data[1][1].r = 255;
|
||
data[1][1].b = 255;
|
||
data[1][1].g = 255;
|
||
//data = (data *) malloc(sizeof(data));
|
||
/*
|
||
int b;
|
||
for (int i1=0;i1 != 2;i1++){
|
||
for (int iaa=i1;iaa < 4;iaa+=2){
|
||
for (int ia=i1;ia < 4;ia+=2){
|
||
if (i1%2) b = 255;
|
||
else b = 0;
|
||
data[iaa][ia].r = b;
|
||
data[iaa][ia].b = b;
|
||
data[iaa][ia].g = b;
|
||
}
|
||
|
||
}
|
||
}
|
||
*/
|
||
|
||
|
||
|
||
glGenTextures(1, &texsture);
|
||
glBindTexture(GL_TEXTURE_2D, texsture);
|
||
glTexParam();
|
||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, x, y,
|
||
0, GL_RGBA, GL_UNSIGNED_BYTE, data);
|
||
glBindTexture(GL_TEXTURE_2D,0);
|
||
//delete &data;
|
||
}
|
||
|
||
GLuint index_SZT[] = {0,1,2, 0,2,3 ,4,5,6, 4,6,7};
|
||
float texCoord_2[] = {0,1, 1,1, 1,0, 0,0};
|
||
float texCoord_3[] = {0,16, 16,16, 16,0, 0,0};
|
||
float rectTex[] = {0,1, 1,1, 1,0, 0,0};
|
||
|
||
|
||
void texsture_text_add(){
|
||
//printf("cnt: %i\n", cnt);
|
||
//printf("x: %i y: %i\n", x, y);
|
||
int x, y, cnt;// y x //TEST_kord.png
|
||
{
|
||
unsigned char *data = stbi_load("Verdana.png", &x, &y, &cnt, 0);
|
||
glGenTextures(1, &texsture_text);
|
||
glBindTexture(GL_TEXTURE_2D, texsture_text);
|
||
glTexParam();
|
||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, x, y,
|
||
0, GL_RGBA, GL_UNSIGNED_BYTE, data);
|
||
glBindTexture(GL_TEXTURE_2D,0);
|
||
}
|
||
{
|
||
unsigned char *data = stbi_load("oil.png", &x, &y, &cnt, 0);
|
||
glGenTextures(1, &texsture_oil);
|
||
glBindTexture(GL_TEXTURE_2D, texsture_oil);
|
||
glTexParam();
|
||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, x, y,
|
||
0, GL_RGBA, GL_UNSIGNED_BYTE, data);
|
||
glBindTexture(GL_TEXTURE_2D,0);
|
||
}
|
||
{
|
||
unsigned char *data = stbi_load("locator.png", &x, &y, &cnt, 0);
|
||
glGenTextures(1, &texsture_locator);
|
||
glBindTexture(GL_TEXTURE_2D, texsture_locator);
|
||
glTexParam();
|
||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, x, y,
|
||
0, GL_RGBA, GL_UNSIGNED_BYTE, data);
|
||
glBindTexture(GL_TEXTURE_2D,0);
|
||
}
|
||
{
|
||
unsigned char *data = stbi_load("sphere.png", &x, &y, &cnt, 0);
|
||
glGenTextures(1, &texsture_sphere);
|
||
glBindTexture(GL_TEXTURE_2D, texsture_sphere);
|
||
glTexParam();
|
||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, x, y,
|
||
0, GL_RGBA, GL_UNSIGNED_BYTE, data);
|
||
glBindTexture(GL_TEXTURE_2D,0);
|
||
}
|
||
}
|
||
|
||
void eee(){
|
||
glLoadIdentity();
|
||
//glOrtho(0,1, 0,25/11, -1,1);
|
||
glOrtho(-1.0f, 1.0f * width / height, -1.0f, 1.0f * height / width, -1.0f, 1.0f);
|
||
//glOrtho(-1.0f * width / height, 1.0f * width / height, -1.0f, 1.0f, -1.0f, 1.0f);
|
||
//glOrtho(-1.0f * width / height, -1.0f, 1.0f * width / height, 1.0f, -1.0f, 1.0f);
|
||
//glOrtho(-k,k, -1,1, -1,1);
|
||
//glTranslatef(float(segment->y)/8-1,float(segment->x)/8-1,0);
|
||
//glOrtho(0,1, 0,1, -1,1);
|
||
glOrtho(0,HEIGHT, 0,HEIGHT, -1,1);
|
||
glTranslatef(2,3,0);
|
||
glTranslatef(-1*(player.x-HEIGHT/2), -1*(player.y-WIDTH/2), 0.0f);
|
||
}
|
||
|
||
void render_figure(int x, int y){
|
||
eee();
|
||
//glTranslatef(-1*(player.x-HEIGHT/2), -1*(player.y-WIDTH/2), 0.0f);
|
||
glTranslatef(x,y,0);
|
||
glVertexPointer(2, GL_FLOAT, 0 , &cub);
|
||
glEnableClientState(GL_VERTEX_ARRAY);
|
||
//glBindTexture(GL_TEXTURE_2D, texsture);
|
||
//glTexCoordPointer(2, GL_FLOAT, 0, texCoord_2);
|
||
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
||
//glDrawElements(GL_TRIANGLES, 4, GL_UNSIGNED_INT, &index_SZT);
|
||
//glBindTexture(GL_TEXTURE_2D,0);
|
||
}
|
||
void render_player(int x, int y){
|
||
eee();
|
||
//glColor3f(color.R,color.G,color.B);
|
||
glColor3f(1.0f,0.0f,0.0f);
|
||
glTranslatef(x,y,0);
|
||
glVertexPointer(2, GL_FLOAT, 0 , &player_matrix);
|
||
glEnableClientState(GL_VERTEX_ARRAY);
|
||
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
||
glColor3f(0.0f,0.0f,0.0f);
|
||
}
|
||
GLuint index_L[] = {1,2,3, 3,0,1};
|
||
void render_light(int x, int y){
|
||
eee();
|
||
//glTranslatef(-1*(player.x-HEIGHT/2), -1*(player.y-WIDTH/2), 0.0f);
|
||
glColor3f(color.R,color.G,color.B);
|
||
glTranslatef(x,y,0);
|
||
glVertexPointer(2, GL_FLOAT, 0 , &cub);
|
||
glEnableClientState(GL_VERTEX_ARRAY);
|
||
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
||
glColor3f(0.0f,0.0f,0.0f);
|
||
|
||
}
|
||
void render_light_2(int x, int y){
|
||
eee();
|
||
//glTranslatef(-1*(player.x-HEIGHT/2), -1*(player.y-WIDTH/2), 0.0f);
|
||
glColor3f(color.R,color.G,color.B);
|
||
glEnable(GL_TEXTURE_2D);
|
||
glTranslatef(x,y,1);
|
||
glVertexPointer(2, GL_FLOAT, 0 , &cub);
|
||
glEnableClientState(GL_VERTEX_ARRAY);
|
||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||
|
||
glEnableClientState(GL_VERTEX_ARRAY);
|
||
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, &index_L);
|
||
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
||
glBindTexture(GL_TEXTURE_2D,0);
|
||
|
||
glBindTexture(GL_TEXTURE_2D, texsture);
|
||
glTexCoordPointer(2, GL_FLOAT, 0, texCoord_3);
|
||
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
||
glBindTexture(GL_TEXTURE_2D,0);
|
||
glColor3f(0.0f,0.0f,0.0f);
|
||
}
|
||
void render_oil(int x, int y){
|
||
eee();
|
||
glEnable(GL_TEXTURE_2D);
|
||
glTranslatef(x,y,0);
|
||
glEnableClientState(GL_VERTEX_ARRAY);
|
||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||
glVertexPointer(2, GL_FLOAT, 0 , &player_matrix);
|
||
glBindTexture(GL_TEXTURE_2D, texsture_oil);
|
||
glTexCoordPointer(2, GL_FLOAT, 0, texCoord_2);
|
||
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
||
glBindTexture(GL_TEXTURE_2D,0);
|
||
|
||
/*
|
||
glColor3f(1.0f,1.0f,1.0f);
|
||
glTranslatef(x,y,0);
|
||
glVertexPointer(2, GL_FLOAT, 0 , &cub);
|
||
glEnableClientState(GL_VERTEX_ARRAY);
|
||
glBindTexture(GL_TEXTURE_2D, texsture_oil);
|
||
glTexCoordPointer(2, GL_FLOAT, 0, texCoord_2);
|
||
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
||
glBindTexture(GL_TEXTURE_2D,0);
|
||
glColor3f(0.0f,0.0f,0.0f);
|
||
*/
|
||
}
|
||
void render_flash(int x, int y){
|
||
eee();
|
||
glEnable(GL_TEXTURE_2D);
|
||
glTranslatef(x,y,0);
|
||
glEnableClientState(GL_VERTEX_ARRAY);
|
||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||
glVertexPointer(2, GL_FLOAT, 0 , &cub);
|
||
glBindTexture(GL_TEXTURE_2D, texsture_locator);
|
||
glTexCoordPointer(2, GL_FLOAT, 0, texCoord_2);
|
||
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
||
glBindTexture(GL_TEXTURE_2D,0);
|
||
}
|
||
void render_sphere(int x, int y){
|
||
eee();
|
||
glEnable(GL_TEXTURE_2D);
|
||
glTranslatef(x,y,0);
|
||
glEnableClientState(GL_VERTEX_ARRAY);
|
||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||
glVertexPointer(2, GL_FLOAT, 0 , &cub);
|
||
glBindTexture(GL_TEXTURE_2D, texsture_sphere);
|
||
glTexCoordPointer(2, GL_FLOAT, 0, texCoord_2);
|
||
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
||
glBindTexture(GL_TEXTURE_2D,0);
|
||
}
|
||
void texst_number_render(int numbr){
|
||
glBindTexture(GL_TEXTURE_2D, texsture_text);
|
||
glTexCoordPointer(2, GL_FLOAT, 0, rectTex);
|
||
for (int i = 1000;i!=0; i/=10){
|
||
static float charSize = 1/16.0;
|
||
int x = numbr / i % 10, y = 3;
|
||
struct{
|
||
float left,rite,top,bottom;
|
||
} rct;
|
||
rct.left = x * charSize;
|
||
rct.rite = rct.left + charSize;
|
||
rct.top = y * charSize;
|
||
rct.bottom = rct.top + charSize;
|
||
rectTex[0] = rectTex[6] = rct.left;
|
||
rectTex[2] = rectTex[4] = rct.rite;
|
||
rectTex[1] = rectTex[3] = rct.bottom;
|
||
rectTex[5] = rectTex[7] = rct.top;
|
||
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
||
glTranslatef(1,0,0);
|
||
}
|
||
|
||
}
|
||
void texst_render(char *text){
|
||
glBindTexture(GL_TEXTURE_2D, texsture_text);
|
||
glTexCoordPointer(2, GL_FLOAT, 0, rectTex);
|
||
while(*text){
|
||
|
||
static float charSize = 1/16.0;
|
||
char c = *text;
|
||
int x = c & 0b1111, y = c >> 4;
|
||
struct{
|
||
float left,rite,top,bottom;
|
||
} rct;
|
||
rct.left = x * charSize;
|
||
rct.rite = rct.left + charSize;
|
||
rct.top = y * charSize;
|
||
rct.bottom = rct.top + charSize;
|
||
rectTex[0] = rectTex[6] = rct.left;
|
||
rectTex[2] = rectTex[4] = rct.rite;
|
||
rectTex[1] = rectTex[3] = rct.bottom;
|
||
rectTex[5] = rectTex[7] = rct.top;
|
||
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
||
text++;
|
||
glTranslatef(1,0,0);
|
||
|
||
}
|
||
}
|
||
|
||
void render_ui(){
|
||
|
||
//glLoadIdentity();
|
||
//glOrtho(0,1, 0,25/11, -1,1);
|
||
//glOrtho(-1.0f, 1.0f * width / height, -1.0f, 1.0f * height / width, -1.0f, 1.0f);
|
||
//glOrtho(-1.0f * width / height, 1.0f * width / height, -1.0f, 1.0f, -1.0f, 1.0f);
|
||
//glOrtho(-1.0f * width / height, -1.0f, 1.0f * width / height, 1.0f, -1.0f, 1.0f);
|
||
//glOrtho(-k,k, -1,1, -1,1);
|
||
//glTranslatef(float(segment->y)/8-1,float(segment->x)/8-1,0);
|
||
//glOrtho(0,1, 0,1, -1,1);
|
||
//glOrtho(0,HEIGHT, 0,HEIGHT, -1,1);
|
||
glTranslatef(2,0,0);
|
||
glEnable(GL_TEXTURE_2D);
|
||
glTranslatef(1,1,0);
|
||
glColor3f(color.R,color.G,color.B);
|
||
|
||
glEnableClientState(GL_VERTEX_ARRAY);
|
||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||
glVertexPointer(2, GL_FLOAT, 0 , &cub);
|
||
|
||
glBindTexture(GL_TEXTURE_2D, texsture_locator);
|
||
glTexCoordPointer(2, GL_FLOAT, 0, texCoord_2);
|
||
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
||
glTranslatef(1,0,0);
|
||
|
||
|
||
//inventory.locator = 345;
|
||
|
||
|
||
|
||
texst_render("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> : ");
|
||
texst_number_render(inventory.locator);
|
||
|
||
//glLoadIdentity();
|
||
//glOrtho(-1.0f, 1.0f * width / height, -1.0f, 1.0f * height / width, -1.0f, 1.0f);
|
||
//glOrtho(0,HEIGHT, 0,HEIGHT, -1,1);
|
||
glTranslatef(2,1,0);
|
||
|
||
glBindTexture(GL_TEXTURE_2D, texsture_oil);
|
||
glTexCoordPointer(2, GL_FLOAT, 0, texCoord_2);
|
||
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
||
glTranslatef(1,0,0);
|
||
texst_render("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: ");
|
||
texst_number_render(inventory.oil);
|
||
|
||
//glLoadIdentity();
|
||
//glOrtho(-1.0f, 1.0f * width / height, -1.0f, 1.0f * height / width, -1.0f, 1.0f);
|
||
//glOrtho(0,HEIGHT, 0,HEIGHT, -1,1);
|
||
glTranslatef(2,2,0);
|
||
|
||
glBindTexture(GL_TEXTURE_2D, texsture_sphere);
|
||
glTexCoordPointer(2, GL_FLOAT, 0, texCoord_2);
|
||
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
||
glTranslatef(1,0,0);
|
||
texst_render("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> : ");
|
||
texst_number_render(inventory.sphere);
|
||
|
||
|
||
glBindTexture(GL_TEXTURE_2D, texsture_sphere);
|
||
glTexCoordPointer(2, GL_FLOAT, 0, texCoord_2);
|
||
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
||
glTranslatef(1,0,0);
|
||
texst_render("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> : ");
|
||
texst_number_render(bat);
|
||
|
||
|
||
//inventory.locator = 10534;
|
||
//for (int i = 1;inventory.locator / i; i*=10){
|
||
|
||
|
||
glBindTexture(GL_TEXTURE_2D,0);
|
||
glColor3f(0.0f,0.0f,0.0f);
|
||
}
|
||
void render_ui_lo(){
|
||
glEnable(GL_TEXTURE_2D);
|
||
glColor3f(color.R,color.G,color.B);
|
||
|
||
glEnableClientState(GL_VERTEX_ARRAY);
|
||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||
glVertexPointer(2, GL_FLOAT, 0 , &cub);
|
||
}
|
||
|
||
void render_ui_locator(){
|
||
render_ui_lo();
|
||
//glPushMatrix();
|
||
|
||
glBindTexture(GL_TEXTURE_2D, texsture_locator);
|
||
glTexCoordPointer(2, GL_FLOAT, 0, texCoord_2);
|
||
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
||
glTranslatef(1,0,0);
|
||
texst_render("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ");
|
||
//glPopMatrix();
|
||
glTranslatef(-10,-1,0);
|
||
texst_number_render(inventory.locator);
|
||
}
|
||
void render_ui_oil(){
|
||
render_ui_lo();
|
||
|
||
glBindTexture(GL_TEXTURE_2D, texsture_oil);
|
||
glTexCoordPointer(2, GL_FLOAT, 0, texCoord_2);
|
||
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
||
glTranslatef(1,0,0);
|
||
texst_render("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ");
|
||
glTranslatef(-10,-1,0);
|
||
texst_number_render(inventory.oil);
|
||
glColor3f(0,0,0);
|
||
}
|
||
void render_ui_sphere(){
|
||
render_ui_lo();
|
||
|
||
glBindTexture(GL_TEXTURE_2D, texsture_sphere);
|
||
glTexCoordPointer(2, GL_FLOAT, 0, texCoord_2);
|
||
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
||
glTranslatef(1,0,0);
|
||
texst_render("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ");
|
||
glTranslatef(-10,-1,0);
|
||
texst_number_render(inventory.sphere);
|
||
}
|
||
void render_ui_battery(){
|
||
render_ui_lo();
|
||
|
||
glBindTexture(GL_TEXTURE_2D, texsture_sphere);
|
||
glTexCoordPointer(2, GL_FLOAT, 0, texCoord_2);
|
||
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
||
glTranslatef(1,0,0);
|
||
texst_render("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ");
|
||
glTranslatef(-10,-1,0);
|
||
texst_number_render(bat);
|
||
}
|
||
|
||
int x = 3, y = 10;
|
||
float BAC_COLOR = 1;
|
||
unsigned char triger = 1;
|
||
int debag = 0;
|
||
void render_rodar(){
|
||
render_light(player.x,player.y);
|
||
for (int g=1; g == -1 || g == 1;g-=2){
|
||
for (int ia=0; ia != 5 && ia != -5;ia+=g){
|
||
if (!mape[player.x][player.y+ia].wall){
|
||
render_light(player.x,player.y+ia);
|
||
}
|
||
else if (ia != 1 && ia != -1){
|
||
if(!mape[player.x+1][player.y+ia-g].wall){
|
||
render_light_2(player.x+1,player.y+ia-g);
|
||
if(!mape[player.x+2][player.y+ia-g].wall && (ia < 3 && ia > -3))render_light_2(player.x+2,player.y+ia-g);
|
||
}
|
||
if(!mape[player.x-1][player.y+ia-g].wall){
|
||
render_light_2(player.x-1,player.y+ia-g);
|
||
if(!mape[player.x-2][player.y+ia-g].wall && (ia < 3 && ia > -3))render_light_2(player.x-2,player.y+ia-g);
|
||
}
|
||
break;
|
||
}
|
||
else break;
|
||
}
|
||
for (int ia=0; ia != 5 && ia != -5;ia+=g){
|
||
if (!mape[player.x+ia][player.y].wall){
|
||
render_light(player.x+ia,player.y);
|
||
}
|
||
else if (ia != 1 && ia != -1) {
|
||
if(!mape[player.x+ia-g][player.y+1].wall){
|
||
render_light_2(player.x+ia-g,player.y+1);
|
||
if(!mape[player.x+ia-g][player.y+2].wall && (ia < 3 && ia > -3))render_light_2(player.x+ia-g,player.y+2);
|
||
}
|
||
if(!mape[player.x+ia-g][player.y-1].wall){
|
||
render_light_2(player.x+ia-g,player.y-1);
|
||
if(!mape[player.x+ia-g][player.y-2].wall && (ia < 3 && ia > -3))render_light_2(player.x+ia-g,player.y-2);
|
||
}
|
||
break;
|
||
}
|
||
else break;
|
||
}
|
||
}
|
||
/*
|
||
for (int i=1; i != 3; i++){
|
||
render_light(player.x-i,player.y);
|
||
render_light(player.x+i,player.y);
|
||
render_light(player.x,player.y-i);
|
||
render_light(player.x,player.y+i);
|
||
render_light(player.x-i,player.y-i);
|
||
render_light(player.x+i,player.y+i);
|
||
render_light(player.x+i,player.y-i);
|
||
render_light(player.x-i,player.y+i);
|
||
|
||
}
|
||
*/
|
||
}
|
||
void render_map(){
|
||
for (int x = 0;x != HEIGHT;x++){
|
||
for (int y = 0;y != WIDTH;y++){
|
||
if (mape[x][y].wall) render_figure(x,y);
|
||
if (mape[x][y].itom == 1 && !mape[player.x][player.y].wall) render_oil(x,y);
|
||
if (mape[x][y].itom == 2 && !mape[player.x][player.y].wall) render_flash(x,y);
|
||
if (mape[x][y].itom == 3 && !mape[player.x][player.y].wall) render_sphere(x,y);
|
||
}
|
||
}
|
||
}
|
||
float cub_AAA[][2] = {
|
||
{0,0},
|
||
{0,1},
|
||
|
||
{1,1},
|
||
{1,0}
|
||
};
|
||
float cub_AAA_2[][2] = {
|
||
{-1,-1},
|
||
{-1,1},
|
||
|
||
{1,1},
|
||
{1,-1}
|
||
};
|
||
GLuint index_L_AAA[] = {0,1, 1,2, 2,3, 3,0, 0,2, 1,3};
|
||
|
||
void ren(){
|
||
glLoadIdentity();
|
||
//glOrtho(-1.0f * height / width, 1.0f * width / height, -1.0f * width / height, 1.0f * width / height, -1.0f, 1.0f);
|
||
k = width / (float)height;
|
||
k_2 = (float)height / width;
|
||
glOrtho(-k,k, -1,1, -1,1);
|
||
//glOrtho(0,1, 0,5, -1,1);
|
||
//glOrtho(0, width, 0, height, -1.0f, 1.0f);
|
||
|
||
}
|
||
void render_teat(){
|
||
/*
|
||
glLineWidth(5);
|
||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||
glBindTexture(GL_TEXTURE_2D,0);
|
||
glEnableClientState(GL_VERTEX_ARRAY);
|
||
glVertexPointer(2, GL_FLOAT, 0 , &cub_AAA);
|
||
glDrawElements(GL_LINES, sizeof(index_L_AAA) / sizeof(GLuint), GL_UNSIGNED_INT, &index_L_AAA);
|
||
*/
|
||
}
|
||
void render_teat_2(){
|
||
glLineWidth(5);
|
||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||
glBindTexture(GL_TEXTURE_2D,0);
|
||
glEnableClientState(GL_VERTEX_ARRAY);
|
||
glVertexPointer(2, GL_FLOAT, 0 , &cub_AAA_2);
|
||
glDrawElements(GL_LINES, sizeof(index_L_AAA) / sizeof(GLuint), GL_UNSIGNED_INT, &index_L_AAA);
|
||
}
|
||
|
||
void render_GUI(){
|
||
ren();
|
||
//glOrtho(-k,k, -1,1, -1,1);
|
||
//glOrtho(0,1, 0,1, -1,1);
|
||
//glOrtho(0,0.5, 0,1, -1,1);
|
||
glOrtho(0,4, 0,8, -1,1);
|
||
|
||
render_teat();
|
||
|
||
glScalef(0.12,0.12,1);
|
||
glTranslatef(1,4,0);
|
||
//glOrtho(-k,1, -1,1, -1,1);
|
||
//glScalef(k,1,1);
|
||
//render_ui_locator();
|
||
//render_teat();
|
||
|
||
ren();
|
||
|
||
glOrtho(0,4, 0,8, -1,1);
|
||
glTranslatef(1,0,0);
|
||
render_teat();
|
||
glScalef(0.12,0.12,1);
|
||
glTranslatef(1,4,0);
|
||
render_ui_oil();
|
||
/*
|
||
ren();
|
||
glOrtho(0,4, 0,8, -1,1);
|
||
glTranslatef(2,0,0);
|
||
render_teat();
|
||
glScalef(0.12,0.12,1);
|
||
glTranslatef(1,4,0);
|
||
render_ui_sphere();
|
||
|
||
ren();
|
||
glOrtho(0,4, 0,8, -1,1);
|
||
glTranslatef(3,0,0);
|
||
render_teat();
|
||
glScalef(0.12,0.12,1);
|
||
glTranslatef(1,4,0);
|
||
render_ui_battery();
|
||
*/
|
||
glColor3f(0,0,0);
|
||
|
||
}
|
||
|
||
void render(){
|
||
// if (a >= 1 && triger) triger = 0;
|
||
// else if (a < 0 && !triger) triger = 1;
|
||
// if (triger) a = a + 0.001;
|
||
// else a = a - 0.01; glColor3f(color.R,color.G,color.B);
|
||
glClearColor(color.R-BAC_COLOR,color.G-BAC_COLOR,color.B-BAC_COLOR,0.0f);
|
||
if (debag == 1) glClearColor(0.0f,0.8f,0.0f,0.0f);
|
||
else if (debag == 2) glClearColor(0.1f,0.1f,0.1f,0.0f);
|
||
glEnable(GL_ALPHA_TEST);
|
||
glAlphaFunc(GL_GREATER, 0.1);
|
||
//glClearColor(0.1f,0.1f,0.1f,0.0f);
|
||
//glOrtho(-k,k, -1,1, -1,1);
|
||
glFlush();
|
||
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
|
||
//glutPostRedisplay();
|
||
//glfwSwapBuffers(window);
|
||
glPushMatrix();
|
||
//printf("SAS - %f\n", a);
|
||
|
||
//glColor3f(a,a,a);
|
||
float cellWidth = width / 4.0f; // 5 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
float cellHeight = height / 5.0f; // 4 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
float cubePosX = (0 + 0.5f) * cellWidth;
|
||
float cubePosY = (0 + 0.5f) * cellHeight;
|
||
|
||
float cubeSize = min(cellWidth, cellHeight) / 2.0f; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||
glColor3f(color.R,color.G,color.B);
|
||
|
||
render_rodar();
|
||
|
||
|
||
|
||
//render_ui();
|
||
//glTranslatef(player.x, player.y, 0.0f);
|
||
render_map();
|
||
render_player(player.x,player.y);
|
||
|
||
|
||
|
||
render_GUI();
|
||
//render_player(HEIGHT/2,WIDTH/2);
|
||
|
||
//
|
||
|
||
|
||
|
||
|
||
|
||
//glOrtho(-k,k, -1,1, -1,1);
|
||
//glScalef(0.2,0.2,1);
|
||
//glOrtho(-k,k, -1,1, -1,1);
|
||
//glScalef(0.5,0.5,1);
|
||
//glPushMatrix(); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
//glTranslatef(cubePosX, cubePosY, 0.0f);
|
||
//glScalef(k,k,1);
|
||
//glTranslatef((k-1)/2/2,0,0);
|
||
//glScalef(cubeSize, cubeSize, cubeSize);
|
||
//glTranslatef(k_2/k,0,0);
|
||
//glOrtho(-k,k, -1,1, -1,1);
|
||
|
||
|
||
/*
|
||
|
||
|
||
glTranslatef(1,1,0);
|
||
//glOrtho(0,1, 0,1, -1,1);
|
||
render_teat();
|
||
|
||
ren();
|
||
glOrtho(0,4, 0,5, -1,1);
|
||
glTranslatef(2,0,0);
|
||
render_teat();
|
||
*/
|
||
/*
|
||
render_ui_locator();
|
||
|
||
ren();
|
||
glOrtho(0,4, 0,5, -1,1);
|
||
//glScalef(2,2,1);
|
||
glTranslatef(2,0,0);
|
||
render_teat();
|
||
//glOrtho(0,4, 0,5, -1,1);
|
||
//glOrtho(0,1, 0,1, -1,1);
|
||
render_teat();
|
||
glTranslatef(-100,0,0);
|
||
render_ui_locator();
|
||
glTranslatef(1,0,0);
|
||
//glScissor(0,20, 0,20);
|
||
//glOrtho(1,3, 1,0.1, -1,1);
|
||
render_teat();
|
||
|
||
|
||
*/
|
||
|
||
|
||
|
||
//glTranslatef(1,0,0);
|
||
//glOrtho(0,10, 0,2, -1,1);
|
||
//glOrtho(0,100, 0,2, -1,1);
|
||
//glOrtho(0,2, 0,2, -1,1);
|
||
/*
|
||
ren();
|
||
render_ui_locator();
|
||
ren();
|
||
glTranslatef(0,1,0);
|
||
render_ui_oil();
|
||
ren();
|
||
glTranslatef(0,2,0);
|
||
render_ui_sphere();
|
||
ren();
|
||
glTranslatef(0,3,0);
|
||
render_ui_battery();
|
||
*/
|
||
|
||
|
||
|
||
|
||
|
||
//render_rodar();
|
||
//render_ui();
|
||
//render_map();
|
||
//render_player(player.x,player.y);
|
||
|
||
|
||
|
||
|
||
|
||
|
||
/*
|
||
for (int i = 0; i < HEIGHT; i++) {
|
||
for (int j = 0; j < WIDTH; j++){
|
||
printf(mape[i][j].wall ? "" : " ");
|
||
|
||
if (mape[i][j].wall) render_figure(i,j);
|
||
}
|
||
printf("\n");
|
||
}
|
||
printf("\n\n\n");
|
||
|
||
*/
|
||
/*
|
||
glBegin(GL_TRIANGLES);
|
||
glColor3f(1.0f,0.0f,0.0f); glVertex2f(0.0f,1.0f);
|
||
glColor3f(0.0f,1.0f,0.0f); glVertex2f(0.87f,-0.5f);
|
||
glColor3f(0.0f,0.0f,1.0f); glVertex2f(-0.87f,-0.5f);
|
||
glEnd();
|
||
*/
|
||
|
||
|
||
|
||
|
||
glLoadIdentity();
|
||
//glOrtho(-k,k, -1,1, -1,1);
|
||
|
||
|
||
glColor3f(1,1,1);
|
||
glDisableClientState(GL_VERTEX_ARRAY);
|
||
glDisableClientState(GL_COLOR_ARRAY);
|
||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||
//glutSwapBuffers();
|
||
glFlush();
|
||
usleep(1000000/144);
|
||
//read(fd, &ev, sizeof(struct input_event));
|
||
|
||
|
||
|
||
|
||
|
||
|
||
}
|
||
|
||
void* myThreadFun(void* vargp){
|
||
unsigned char a = 1, b = 1;
|
||
while (1){
|
||
bat--;
|
||
usleep(50000);
|
||
}
|
||
return NULL;
|
||
}
|
||
void handleInput(int button, int state,
|
||
int x, int y) {
|
||
printf("SAS: %i\n", button);
|
||
printf("SAS: %i\n", state);
|
||
printf("SAS: %i\n", x);
|
||
printf("SAS: %i\n", y);
|
||
//printf("SAS: %i\n", state);
|
||
}
|
||
|
||
void* fsp(void* vargp){
|
||
for (float i=1; i>0; i-=0.05){
|
||
printf("SAS\n");
|
||
BAC_COLOR=i;
|
||
usleep(10000);
|
||
}
|
||
for (float i=0; i<1; i+=0.01){
|
||
printf("SAS\n");
|
||
BAC_COLOR=i;
|
||
usleep(10000);
|
||
}
|
||
}
|
||
|
||
|
||
|
||
void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) {
|
||
if (action == GLFW_PRESS) {
|
||
printf("Key pressed: %d\n", key);
|
||
switch (key){
|
||
case 263 : printf("GLUT_KEY_LEFT %d\n",key) ;
|
||
if (!mape[player.x - 1][player.y].wall) player.x--;
|
||
break;
|
||
case 262 : printf("GLUT_KEY_RIGHT %d\n",key);
|
||
if (!mape[player.x + 1][player.y].wall) player.x++;
|
||
break;
|
||
case 265 : printf("GLUT_KEY_UP %d\n",key) ;
|
||
if (!mape[player.x][player.y + 1].wall) player.y++;
|
||
break;
|
||
case 264 : printf("GLUT_KEY_DOWN %d\n",key) ;
|
||
if (!mape[player.x][player.y - 1].wall) player.y--;
|
||
break;
|
||
case 32 : printf("GLUT_KEY %d\n",key) ;
|
||
pthread_t thread_id_2;
|
||
pthread_create(&thread_id_2, NULL, fsp, NULL);
|
||
break;
|
||
case 81 : printf("GLUT_KEY %d\n",key) ;
|
||
if (debag == 0) debag = 1;
|
||
else if (debag == 1) debag = 2;
|
||
else debag = 0;
|
||
break;
|
||
}
|
||
if (mape[player.x][player.y].itom == 2){
|
||
mape[player.x][player.y].itom = 0;
|
||
inventory.locator++;
|
||
}
|
||
if (mape[player.x][player.y].itom == 1){
|
||
mape[player.x][player.y].itom = 0;
|
||
inventory.oil++;
|
||
}
|
||
if (mape[player.x][player.y].itom == 3){
|
||
mape[player.x][player.y].itom = 0;
|
||
inventory.sphere++;
|
||
}
|
||
}
|
||
}
|
||
/*
|
||
void ChangeWindow(GLFWwindow* window, int width, int height){
|
||
printf("width: %i width: %i\n", width, height);
|
||
glViewport(0,0, width, height);
|
||
glLoadIdentity();
|
||
k = width / (float)height;
|
||
glOrtho(-k,k, -1,1, -1,1);
|
||
}
|
||
*/
|
||
void ChangeWindow(GLFWwindow* window, int _width33, int _height33) {
|
||
width = _width33;
|
||
height = _height33;
|
||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||
glViewport(0, 0, width, height);
|
||
|
||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
glMatrixMode(GL_PROJECTION);
|
||
glLoadIdentity();
|
||
//glOrtho(-1.0f * width / height, 1.0f * width / height, -1.0f, 1.0f, -1.0f, 1.0f);
|
||
glMatrixMode(GL_MODELVIEW);
|
||
//k = width / (float)height;
|
||
}
|
||
|
||
int main(int argc, char** argv) {
|
||
color.R = 1; //#FFA900 100%, 69%, 0%
|
||
color.G = 0.69; // 58%, 1%, 65% 51%, 2%, 66%
|
||
color.B = 0;
|
||
inventory.locator = 0;
|
||
setlocale(LC_ALL, "Russian");
|
||
glutInit(&argc, argv);
|
||
srand(time(NULL));
|
||
initMaze(mape);
|
||
//pthread_t thread_id_2;
|
||
//pthread_create(&thread_id_2, NULL, myThreadFun_2, NULL);
|
||
carveMaze(mape, 1, 1);
|
||
printMaze(mape);
|
||
//mape[5][5].player = 1;
|
||
player.x = 5;
|
||
player.y = 5;
|
||
|
||
|
||
|
||
int upper_bound = HEIGHT-2;
|
||
int upper_bound_2 = WIDTH-2;
|
||
// Set the lower bound for random numbers#define WIDTH 17
|
||
//#define HEIGHT 35
|
||
int lower_bound = 1;
|
||
|
||
// Loop through 10 times
|
||
for (int i = 0; i < HEIGHT*WIDTH/10; i++) {
|
||
// Generate a random number within the specified
|
||
// bounds
|
||
int value = rand() % (upper_bound - lower_bound + 1)
|
||
+ lower_bound;
|
||
int value_2 = rand() % (upper_bound_2 - lower_bound + 1)
|
||
+ lower_bound;
|
||
// Print the generated random value
|
||
printf("%d \n", value);
|
||
mape[value][value_2].wall = 0;
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
pthread_t thread_id;
|
||
pthread_create(&thread_id, NULL, myThreadFun, NULL);
|
||
|
||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> GLFW
|
||
if (!glfwInit()) {
|
||
return -1;
|
||
}
|
||
|
||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||
GLFWwindow* window = glfwCreateWindow(1200, 1200, "Hello world!", NULL, NULL);
|
||
if (!window) {
|
||
glfwTerminate();
|
||
return -1;
|
||
}
|
||
ChangeWindow(window, 1200, 1200);
|
||
|
||
glfwMakeContextCurrent(window);
|
||
|
||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
glfwSetKeyCallback(window, key_callback);
|
||
|
||
glfwSetFramebufferSizeCallback(window, ChangeWindow);
|
||
|
||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||
texsture_add();
|
||
texsture_text_add();
|
||
|
||
|
||
|
||
while (!glfwWindowShouldClose(window)) {
|
||
render(); // <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
|
||
glfwSwapBuffers(window); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
glfwPollEvents(); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
|
||
}
|
||
|
||
glfwDestroyWindow(window);
|
||
glfwTerminate();
|
||
return 0;
|
||
}
|
||
|
||
/*
|
||
int main(int argc, char** argv){
|
||
|
||
|
||
srand(time(NULL));
|
||
initMaze(mape);
|
||
//pthread_t thread_id_2;
|
||
//pthread_create(&thread_id_2, NULL, myThreadFun_2, NULL);
|
||
carveMaze(mape, 1, 1);
|
||
printMaze(mape);
|
||
//mape[5][5].player = 1;
|
||
player.x = 5;
|
||
player.y = 5;
|
||
|
||
|
||
|
||
fd = open(argv[1], O_RDONLY);
|
||
|
||
|
||
pthread_t thread_id;
|
||
pthread_create(&thread_id, NULL, myThreadFun, NULL);
|
||
//pthread_t thread_id_2;
|
||
//pthread_create(&thread_id_2, NULL, myThreadFun_2, NULL);
|
||
// //pthread_create(&tid, NULL, myThreadFun, NULL);
|
||
//pthread_join(thread_id, NULL);
|
||
|
||
glutInit(&argc, argv);
|
||
glutInitDisplayMode(GLUT_SINGLE);
|
||
glutInitWindowSize(1200, 1200);
|
||
glutInitWindowPosition(100, 100);
|
||
glutCreateWindow("Hello world!");
|
||
texsture_add();
|
||
|
||
|
||
|
||
glutDisplayFunc(render);
|
||
glutSpecialFunc(key_target);
|
||
glutTabletButtonFunc(handleInput);
|
||
//glutKeyboardFunc(key_callback);
|
||
|
||
//glutMouseFunc(TEST);
|
||
//glutPassiveMotionFunc(onMouseMove);
|
||
//glutReshapeFunc(ChangeWindow);
|
||
glutMainLoop();
|
||
|
||
|
||
return 0;
|
||
}
|
||
|
||
*/
|
||
|
||
|
||
|
||
|
||
|
||
/*
|
||
int main(int argc, char **argv)
|
||
{
|
||
int fd;
|
||
if(argc < 2) {
|
||
printf("usage: %s <device>\n", argv[0]);
|
||
return 1;
|
||
}
|
||
|
||
fd = open(argv[1], O_RDONLY);
|
||
struct input_event ev;
|
||
|
||
while (1)
|
||
{
|
||
read(fd, &ev, sizeof(struct input_event));
|
||
|
||
if(ev.type == 1)
|
||
printf("key %i state %i\n", ev.code, ev.value);
|
||
|
||
}
|
||
}
|
||
*/
|