basic inventory (doesn't save)
This commit is contained in:
parent
2ce46f188b
commit
8ccfe726fc
6 changed files with 87 additions and 29 deletions
55
main.c
55
main.c
|
@ -13,6 +13,7 @@
|
|||
#include "cubes.h"
|
||||
#include "gen.h"
|
||||
#include "gl.h"
|
||||
#include "inv.h"
|
||||
#include "linmath.h"
|
||||
#include "stb_image.h"
|
||||
|
||||
|
@ -52,6 +53,12 @@ static const char *fragment_shader_text =
|
|||
"}\n";
|
||||
|
||||
int isCursor = 0;
|
||||
double cx = 0;
|
||||
double cy = 0;
|
||||
int fr = 0;
|
||||
vec3 pos;
|
||||
struct item *inv;
|
||||
int slot;
|
||||
|
||||
static void key_callback(GLFWwindow *window, int key, int scancode, int action,
|
||||
int mods) {
|
||||
|
@ -63,22 +70,23 @@ static void key_callback(GLFWwindow *window, int key, int scancode, int action,
|
|||
glfwSetInputMode(window, GLFW_CURSOR,
|
||||
isCursor ? GLFW_CURSOR_NORMAL : GLFW_CURSOR_DISABLED);
|
||||
}
|
||||
if (key == GLFW_KEY_Q && action == GLFW_PRESS) {
|
||||
slot = (slot + 9) % 10;
|
||||
}
|
||||
if (key == GLFW_KEY_E && action == GLFW_PRESS) {
|
||||
slot = (slot + 1) % 10;
|
||||
}
|
||||
}
|
||||
|
||||
double cx = 0;
|
||||
double cy = 0;
|
||||
int fr = 0;
|
||||
vec3 pos;
|
||||
|
||||
void mouse_button_callback(GLFWwindow *window, int button, int action,
|
||||
int mods) {
|
||||
if (button == GLFW_MOUSE_BUTTON_RIGHT && action == GLFW_PRESS) {
|
||||
fr = 1;
|
||||
control_rclick(cx, cy, pos);
|
||||
control_rclick(cx, cy, pos, inv, slot);
|
||||
}
|
||||
if (button == GLFW_MOUSE_BUTTON_LEFT && action == GLFW_PRESS) {
|
||||
fr = 1;
|
||||
control_lclick(cx, cy, pos);
|
||||
control_lclick(cx, cy, pos, inv);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -128,6 +136,8 @@ void *render_chunks(void *args) {
|
|||
#define WinMain main
|
||||
|
||||
int main(void) {
|
||||
inv = calloc(10, sizeof(struct item));
|
||||
|
||||
if (!glfwInit())
|
||||
exit(EXIT_FAILURE);
|
||||
|
||||
|
@ -359,12 +369,27 @@ int main(void) {
|
|||
cubes_rect(textO, &iz, -0.5, 0.5, -0.5, 0.5, 1, 0, 6);
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
for (int x = 0; x < 3; x++) {
|
||||
int dig = (int)(inv[i].count / (pow(10, x))) % 10;
|
||||
|
||||
dig = (dig + 9) % 10;
|
||||
|
||||
iz += 6;
|
||||
cubes_rect(cubeO, &iz, ((i - 4.5) * 2.5) + 0.5 - ((x + 1) * 0.5),
|
||||
((i - 4.5) * 2.5) + 1 - ((x + 1) * 0.5), -10, -10.5, 0, 0,
|
||||
0);
|
||||
cubes_rect(textO, &iz, 0, 0, 0, 0, 1, (dig + 3) % 6, (dig + 3) / 6 + 6);
|
||||
}
|
||||
iz += 6;
|
||||
cubes_rect(cubeO, &iz, ((i - 4.5) * 2.5) - 1, ((i - 4.5) * 2.5) + 1, -11,
|
||||
-9, 0, 1, 6);
|
||||
cubes_rect(textO, &iz, ((i - 4.5) * 2.5) - 1, ((i - 4.5) * 2.5) + 1, -11,
|
||||
-9, 1, 1, 6);
|
||||
-9, 0, 0, 0);
|
||||
cubes_rect(textO, &iz, 0, 0, 0, 0, 1, (slot == i) ? 1 : 2, 6);
|
||||
iz += 6;
|
||||
cubes_rect(cubeO, &iz, ((i - 4.5) * 2.5) - 0.5, ((i - 4.5) * 2.5) + 0.5,
|
||||
-10.5, -9.5, 0, 0, 0);
|
||||
cubes_rect(textO, &iz, 0, 0, 0, 0, 1, inv[i].id - 1, 0);
|
||||
}
|
||||
iz += 6;
|
||||
|
||||
mat4x4_identity(v);
|
||||
mat4x4_ortho(p, -ratio * 15, ratio * 15, -1.f * 15, 1.f * 15, 1.0f, -1.0f);
|
||||
|
@ -374,15 +399,15 @@ int main(void) {
|
|||
glUniformMatrix4fv(mvp_location, 1, GL_FALSE, (const GLfloat *)&mvp);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer[1]);
|
||||
glBufferSubData(GL_ARRAY_BUFFER, CTRI_ALL,
|
||||
(long)6 * 11 * sizeof(struct v3f), &textO[iz2]);
|
||||
glBufferSubData(GL_ARRAY_BUFFER, CTRI_ALL, (iz - iz2) * sizeof(struct v3f),
|
||||
&textO[iz2]);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer[0]);
|
||||
glBufferSubData(GL_ARRAY_BUFFER, CTRI_ALL,
|
||||
(long)6 * 11 * sizeof(struct v3f), &cubeO[iz2]);
|
||||
glBufferSubData(GL_ARRAY_BUFFER, CTRI_ALL, (iz - iz2) * sizeof(struct v3f),
|
||||
&cubeO[iz2]);
|
||||
|
||||
glBindVertexArray(vertex_array);
|
||||
|
||||
glDrawArrays(GL_TRIANGLES, CBLOCK_ALL * 18, 6 * 11);
|
||||
glDrawArrays(GL_TRIANGLES, CBLOCK_ALL * 18, (iz - iz2));
|
||||
}
|
||||
|
||||
if (fp) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue