basic inventory (doesn't save)

This commit is contained in:
onezplpl 2024-07-19 21:14:40 -04:00
parent 2ce46f188b
commit 8ccfe726fc
No known key found for this signature in database
GPG key ID: 7EC026A136F9EEC3
6 changed files with 87 additions and 29 deletions

View file

@ -1,8 +1,8 @@
#include "cubes.h"
#include "gen.h"
#include "inv.h"
#include "linmath.h"
#include <GLFW/glfw3.h>
#include <stdio.h>
int is_space;
@ -66,9 +66,9 @@ struct v3f control_handler(double cx, double cy, vec3 pos, vec3 dir_temp,
for (int a = -2; a < 0; a++) {
off[1] = a;
for (int b = -1; b < 1; b++) {
off[0] = (b + 0.5)*0.95;
off[0] = (b + 0.5) * 0.95;
for (int c = -1; c < 1; c++) {
off[2] = (c + 0.5)*0.95;
off[2] = (c + 0.5) * 0.95;
col = col || gen_cube(pos[0] + off[0], pos[1] + off[1], pos[2] + off[2],
chunk, 0, -1);
}
@ -82,9 +82,9 @@ struct v3f control_handler(double cx, double cy, vec3 pos, vec3 dir_temp,
off[1] = -2;
for (int b = -1; b < 1; b++) {
off[0] = (b + 0.5)*0.95;
off[0] = (b + 0.5) * 0.95;
for (int c = -1; c < 1; c++) {
off[2] = (c + 0.5)*0.95;
off[2] = (c + 0.5) * 0.95;
col = col || gen_cube(pos[0] + off[0], pos[1] + off[1], pos[2] + off[2],
chunk, 0, -1);
}
@ -152,7 +152,7 @@ struct v3f control_rtrace(double cx, double cy, vec3 pos, int mode) {
return out_pos;
}
void control_lclick(double cx, double cy, vec3 pos) {
void control_lclick(double cx, double cy, vec3 pos, struct item *inv) {
struct v3f highlighted = control_rtrace(cx, cy, pos, 1);
struct chunk placeChunk;
int cube = gen_cube(highlighted.pos[0], highlighted.pos[1],
@ -163,16 +163,39 @@ void control_lclick(double cx, double cy, vec3 pos) {
return;
gen_cube(highlighted.pos[0], highlighted.pos[1], highlighted.pos[2],
placeChunk, 0, 0);
for (int i = 0; i < 10; i++) {
if (inv[i].id == 0) {
inv[i].id = cube;
inv[i].count = 0;
}
if (inv[i].id == cube) {
inv[i].count++;
break;
}
}
}
void control_rclick(double cx, double cy, vec3 pos) {
void control_rclick(double cx, double cy, vec3 pos, struct item *inv, int slot) {
struct v3f highlighted = control_rtrace(cx, cy, pos, 0);
struct chunk placeChunk;
int cube = gen_cube(highlighted.pos[0], highlighted.pos[1],
highlighted.pos[2], placeChunk, 0, -1);
if (cube != 0 ||
(fabs(highlighted.pos[0] - pos[0]) < 1 && fabs(highlighted.pos[1] - pos[1] + 0.5) < 1.5 && fabs(highlighted.pos[2] - pos[2]) < 1))
if (cube != 0 || (fabs(highlighted.pos[0] - pos[0]) < 1 &&
fabs(highlighted.pos[1] - pos[1] + 0.5) < 1.5 &&
fabs(highlighted.pos[2] - pos[2]) < 1))
return;
gen_cube(highlighted.pos[0], highlighted.pos[1], highlighted.pos[2],
placeChunk, 0, 1);
placeChunk, 0, inv[slot].id);
for (int i = 0; i < 10; i++) {
if (inv[i].id == inv[slot].id) {
inv[i].count--;
if (inv[i].count == 0) {
inv[i].id = 0;
inv[i].count = 0;
}
break;
}
}
}