inventory
This commit is contained in:
parent
b1e5a3c6fb
commit
d2416946d9
BIN
res/block.png
BIN
res/block.png
Binary file not shown.
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 9.6 KiB |
@ -261,8 +261,8 @@ void Batch2D::blockSprite(float x, float y, float w, float h, int atlasRes, int
|
||||
}
|
||||
|
||||
void Batch2D::rect(float x, float y, float w, float h,
|
||||
float u, float v, float tx, float ty,
|
||||
float r, float g, float b, float a){
|
||||
float u, float v, float tx, float ty,
|
||||
float r, float g, float b, float a){
|
||||
if (index + 6*VERTEX_SIZE >= capacity)
|
||||
render();
|
||||
vertex(x, y, u, v+ty, r,g,b,a);
|
||||
@ -274,6 +274,66 @@ void Batch2D::rect(float x, float y, float w, float h,
|
||||
vertex(x+w, y+h, u+tx, v, r,g,b,a);
|
||||
}
|
||||
|
||||
void Batch2D::rect(float x, float y, float w, float h,
|
||||
float r0, float g0, float b0,
|
||||
float r1, float g1, float b1,
|
||||
float r2, float g2, float b2,
|
||||
float r3, float g3, float b3,
|
||||
float r4, float g4, float b4, int sh){
|
||||
if (index + 30*VERTEX_SIZE >= capacity)
|
||||
render();
|
||||
vec2 v0 = vec2(x+h/2,y+h/2);
|
||||
vec2 v1 = vec2(x+w-sh,y);
|
||||
vec2 v2 = vec2(x+sh,y);
|
||||
vec2 v3 = vec2(x,y+sh);
|
||||
vec2 v4 = vec2(x,y+h-sh);
|
||||
vec2 v5 = vec2(x+sh,y+h);
|
||||
vec2 v6 = vec2(x+w-h/2,y+h/2);
|
||||
vec2 v7 = vec2(x+w-sh,y+h);
|
||||
vec2 v8 = vec2(x+w,y+h-sh);
|
||||
vec2 v9 = vec2(x+w,y+sh);
|
||||
|
||||
vertex(v0, vec2(0, 0), r1,g1,b1,1.0f);
|
||||
vertex(v6, vec2(0, 0), r1,g1,b1,1.0f);
|
||||
vertex(v1, vec2(0, 0), r1,g1,b1,1.0f);
|
||||
|
||||
vertex(v0, vec2(0, 0), r1,g1,b1,1.0f);
|
||||
vertex(v1, vec2(0, 0), r1,g1,b1,1.0f);
|
||||
vertex(v2, vec2(0, 0), r1,g1,b1,1.0f);
|
||||
|
||||
vertex(v0, vec2(0, 0), r0,g0,b0,1.0f);
|
||||
vertex(v2, vec2(0, 0), r0,g0,b0,1.0f);
|
||||
vertex(v3, vec2(0, 0), r0,g0,b0,1.0f);
|
||||
|
||||
vertex(v0, vec2(0, 0), r1,g1,b1,1.0f);
|
||||
vertex(v3, vec2(0, 0), r1,g1,b1,1.0f);
|
||||
vertex(v4, vec2(0, 0), r1,g1,b1,1.0f);
|
||||
|
||||
vertex(v0, vec2(0, 0), r2,g2,b2,1.0f);
|
||||
vertex(v4, vec2(0, 0), r2,g2,b2,1.0f);
|
||||
vertex(v5, vec2(0, 0), r2,g2,b2,1.0f);
|
||||
|
||||
vertex(v0, vec2(0, 0), r3,g3,b3,1.0f);
|
||||
vertex(v5, vec2(0, 0), r3,g3,b3,1.0f);
|
||||
vertex(v6, vec2(0, 0), r3,g3,b3,1.0f);
|
||||
|
||||
vertex(v6, vec2(0, 0), r3,g3,b3,1.0f);
|
||||
vertex(v5, vec2(0, 0), r3,g3,b3,1.0f);
|
||||
vertex(v7, vec2(0, 0), r3,g3,b3,1.0f);
|
||||
|
||||
vertex(v6, vec2(0, 0), r4,g4,b4,1.0f);
|
||||
vertex(v7, vec2(0, 0), r4,g4,b4,1.0f);
|
||||
vertex(v8, vec2(0, 0), r4,g4,b4,1.0f);
|
||||
|
||||
vertex(v6, vec2(0, 0), r3,g3,b3,1.0f);
|
||||
vertex(v8, vec2(0, 0), r3,g3,b3,1.0f);
|
||||
vertex(v9, vec2(0, 0), r3,g3,b3,1.0f);
|
||||
|
||||
vertex(v6, vec2(0, 0), r2,g2,b2,1.0f);
|
||||
vertex(v9, vec2(0, 0), r2,g2,b2,1.0f);
|
||||
vertex(v1, vec2(0, 0), r2,g2,b2,1.0f);
|
||||
}
|
||||
|
||||
void Batch2D::render() {
|
||||
mesh->reload(buffer, index / VERTEX_SIZE);
|
||||
mesh->draw(GL_TRIANGLES);
|
||||
|
||||
@ -49,8 +49,15 @@ public:
|
||||
|
||||
void rect(float x, float y, float w, float h);
|
||||
void rect(float x, float y, float w, float h,
|
||||
float u, float v, float tx, float ty,
|
||||
float r, float g, float b, float a);
|
||||
float u, float v, float tx, float ty,
|
||||
float r, float g, float b, float a);
|
||||
|
||||
void rect(float x, float y, float w, float h,
|
||||
float r0, float g0, float b0,
|
||||
float r1, float g1, float b1,
|
||||
float r2, float g2, float b2,
|
||||
float r3, float g3, float b3,
|
||||
float r4, float g4, float b4, int sh);
|
||||
void render();
|
||||
};
|
||||
|
||||
|
||||
@ -374,86 +374,62 @@ inline void _renderXBlock(std::vector<float>& buffer, int x, int y, int z, const
|
||||
|
||||
float uvsize = 1.0f/16.0f;
|
||||
|
||||
float lr = LIGHT(x,y,z, 0) / 15.0f;
|
||||
float lg = LIGHT(x,y,z, 1) / 15.0f;
|
||||
float lb = LIGHT(x,y,z, 2) / 15.0f;
|
||||
float ls = LIGHT(x,y,z, 3) / 15.0f;
|
||||
float lr = LIGHT(x,y,z, 0);
|
||||
float lg = LIGHT(x,y,z, 1);
|
||||
float lb = LIGHT(x,y,z, 2);
|
||||
float ls = LIGHT(x,y,z, 3);
|
||||
|
||||
float lr0 = (LIGHT(x,y-1,z,0) + lr*30) / 45.0f;
|
||||
float lr1 = (LIGHT(x,y+1,z,0) + lr*30) / 45.0f;
|
||||
float lr2 = (LIGHT(x,y+1,z,0) + lr*30) / 45.0f;
|
||||
float lr3 = (LIGHT(x,y-1,z,0) + lr*30) / 45.0f;
|
||||
float lr4 = (LIGHT(x,y-1,z,0) + lr*30) / 45.0f;
|
||||
float lr5 = (LIGHT(x,y+1,z,0) + lr*30) / 45.0f;
|
||||
float lr6 = (LIGHT(x,y+1,z,0) + lr*30) / 45.0f;
|
||||
float lr7 = (LIGHT(x,y-1,z,0) + lr*30) / 45.0f;
|
||||
float lr0 = (LIGHT(x,y-1,z,0) + lr*3) / 60.0f;
|
||||
float lr1 = (LIGHT(x,y+1,z,0) + lr*3) / 60.0f;
|
||||
|
||||
float lg0 = (LIGHT(x,y-1,z,1) + lg*30) / 45.0f;
|
||||
float lg1 = (LIGHT(x,y+1,z,1) + lg*30) / 45.0f;
|
||||
float lg2 = (LIGHT(x,y+1,z,1) + lg*30) / 45.0f;
|
||||
float lg3 = (LIGHT(x,y-1,z,1) + lg*30) / 45.0f;
|
||||
float lg4 = (LIGHT(x,y-1,z,1) + lg*30) / 45.0f;
|
||||
float lg5 = (LIGHT(x,y+1,z,1) + lg*30) / 45.0f;
|
||||
float lg6 = (LIGHT(x,y+1,z,1) + lg*30) / 45.0f;
|
||||
float lg7 = (LIGHT(x,y-1,z,1) + lg*30) / 45.0f;
|
||||
float lg0 = (LIGHT(x,y-1,z,1) + lg*3) / 60.0f;
|
||||
float lg1 = (LIGHT(x,y+1,z,1) + lg*3) / 60.0f;
|
||||
|
||||
float lb0 = (LIGHT(x,y-1,z,2) + lb*30) / 45.0f;
|
||||
float lb1 = (LIGHT(x,y+1,z,2) + lb*30) / 45.0f;
|
||||
float lb2 = (LIGHT(x,y+1,z,2) + lb*30) / 45.0f;
|
||||
float lb3 = (LIGHT(x,y-1,z,2) + lb*30) / 45.0f;
|
||||
float lb4 = (LIGHT(x,y-1,z,2) + lb*30) / 45.0f;
|
||||
float lb5 = (LIGHT(x,y+1,z,2) + lb*30) / 45.0f;
|
||||
float lb6 = (LIGHT(x,y+1,z,2) + lb*30) / 45.0f;
|
||||
float lb7 = (LIGHT(x,y-1,z,2) + lb*30) / 45.0f;
|
||||
float lb0 = (LIGHT(x,y-1,z,2) + lb*3) / 60.0f;
|
||||
float lb1 = (LIGHT(x,y+1,z,2) + lb*3) / 60.0f;
|
||||
|
||||
float ls0 = (LIGHT(x,y-1,z,3) + ls*30) / 45.0f;
|
||||
float ls1 = (LIGHT(x,y+1,z,3) + ls*30) / 45.0f;
|
||||
float ls2 = (LIGHT(x,y+1,z,3) + ls*30) / 45.0f;
|
||||
float ls3 = (LIGHT(x,y-1,z,3) + ls*30) / 45.0f;
|
||||
float ls4 = (LIGHT(x,y-1,z,3) + ls*30) / 45.0f;
|
||||
float ls5 = (LIGHT(x,y+1,z,3) + ls*30) / 45.0f;
|
||||
float ls6 = (LIGHT(x,y+1,z,3) + ls*30) / 45.0f;
|
||||
float ls7 = (LIGHT(x,y-1,z,3) + ls*30) / 45.0f;
|
||||
float ls0 = (LIGHT(x,y-1,z,3) + ls*3) / 60.0f;
|
||||
float ls1 = (LIGHT(x,y+1,z,3) + ls*3) / 60.0f;
|
||||
|
||||
{SETUP_UV(block->textureFaces[1]);
|
||||
|
||||
VERTEX(index, x-0.3535f+xs, y-0.5f, z-0.3535f+zs, u2,v1, lr0,lg0,lb0,ls0);
|
||||
VERTEX(index, x-0.3535f+xs, y+0.5f, z-0.3535f+zs, u2,v2, lr1,lg1,lb1,ls1);
|
||||
VERTEX(index, x+0.3535f+xs, y+0.5f, z+0.3535f+zs, u1,v2, lr2,lg2,lb2,ls2);
|
||||
VERTEX(index, x+0.3535f+xs, y+0.5f, z+0.3535f+zs, u1,v2, lr1,lg1,lb1,ls1);
|
||||
|
||||
VERTEX(index, x-0.3535f+xs, y-0.5f, z-0.3535f+zs, u2,v1, lr0,lg0,lb0,ls0);
|
||||
VERTEX(index, x+0.3535f+xs, y+0.5f, z+0.3535f+zs, u1,v2, lr2,lg2,lb2,ls2);
|
||||
VERTEX(index, x+0.3535f+xs, y-0.5f, z+0.3535f+zs, u1,v1, lr3,lg3,lb3,ls3);}
|
||||
VERTEX(index, x+0.3535f+xs, y+0.5f, z+0.3535f+zs, u1,v2, lr1,lg1,lb1,ls1);
|
||||
VERTEX(index, x+0.3535f+xs, y-0.5f, z+0.3535f+zs, u1,v1, lr0,lg0,lb0,ls0);}
|
||||
|
||||
{SETUP_UV(block->textureFaces[0]);
|
||||
|
||||
VERTEX(index, x-0.3535f+xs, y-0.5f, z-0.3535f+zs, u1,v1, lr0,lg0,lb0,ls0);
|
||||
VERTEX(index, x+0.3535f+xs, y+0.5f, z+0.3535f+zs, u2,v2, lr1,lg1,lb1,ls1);
|
||||
VERTEX(index, x-0.3535f+xs, y+0.5f, z-0.3535f+zs, u1,v2, lr2,lg2,lb2,ls2);
|
||||
VERTEX(index, x-0.3535f+xs, y+0.5f, z-0.3535f+zs, u1,v2, lr1,lg1,lb1,ls1);
|
||||
|
||||
VERTEX(index, x-0.3535f+xs, y-0.5f, z-0.3535f+zs, u1,v1, lr0,lg0,lb0,ls0);
|
||||
VERTEX(index, x+0.3535f+xs, y-0.5f, z+0.3535f+zs, u2,v1, lr3,lg3,lb3,ls3);
|
||||
VERTEX(index, x+0.3535f+xs, y-0.5f, z+0.3535f+zs, u2,v1, lr0,lg0,lb0,ls0);
|
||||
VERTEX(index, x+0.3535f+xs, y+0.5f, z+0.3535f+zs, u2,v2, lr1,lg1,lb1,ls1);}
|
||||
|
||||
{SETUP_UV(block->textureFaces[5]);
|
||||
|
||||
VERTEX(index, x-0.3535f+xs, y-0.5f, z+0.3535f+zs, u1,v1, lr4,lg4,lb4,ls4);
|
||||
VERTEX(index, x+0.3535f+xs, y+0.5f, z-0.3535f+zs, u2,v2, lr5,lg5,lb5,ls5);
|
||||
VERTEX(index, x-0.3535f+xs, y+0.5f, z+0.3535f+zs, u1,v2, lr6,lg6,lb6,ls6);
|
||||
VERTEX(index, x-0.3535f+xs, y-0.5f, z+0.3535f+zs, u1,v1, lr0,lg0,lb0,ls0);
|
||||
VERTEX(index, x+0.3535f+xs, y+0.5f, z-0.3535f+zs, u2,v2, lr1,lg1,lb1,ls1);
|
||||
VERTEX(index, x-0.3535f+xs, y+0.5f, z+0.3535f+zs, u1,v2, lr1,lg1,lb1,ls1);
|
||||
|
||||
VERTEX(index, x-0.3535f+xs, y-0.5f, z+0.3535f+zs, u1,v1, lr4,lg4,lb4,ls4);
|
||||
VERTEX(index, x+0.3535f+xs, y-0.5f, z-0.3535f+zs, u2,v1, lr7,lg7,lb7,ls7);
|
||||
VERTEX(index, x+0.3535f+xs, y+0.5f, z-0.3535f+zs, u2,v2, lr5,lg5,lb5,ls5);}
|
||||
VERTEX(index, x-0.3535f+xs, y-0.5f, z+0.3535f+zs, u1,v1, lr0,lg0,lb0,ls0);
|
||||
VERTEX(index, x+0.3535f+xs, y-0.5f, z-0.3535f+zs, u2,v1, lr0,lg0,lb0,ls0);
|
||||
VERTEX(index, x+0.3535f+xs, y+0.5f, z-0.3535f+zs, u2,v2, lr1,lg1,lb1,ls1);}
|
||||
|
||||
{SETUP_UV(block->textureFaces[4]);
|
||||
|
||||
VERTEX(index, x-0.3535f+xs, y-0.5f, z+0.3535f+zs, u2,v1, lr4,lg4,lb4,ls4);
|
||||
VERTEX(index, x-0.3535f+xs, y+0.5f, z+0.3535f+zs, u2,v2, lr5,lg5,lb5,ls5);
|
||||
VERTEX(index, x+0.3535f+xs, y+0.5f, z-0.3535f+zs, u1,v2, lr6,lg6,lb6,ls6);
|
||||
VERTEX(index, x-0.3535f+xs, y-0.5f, z+0.3535f+zs, u2,v1, lr0,lg0,lb0,ls0);
|
||||
VERTEX(index, x-0.3535f+xs, y+0.5f, z+0.3535f+zs, u2,v2, lr1,lg1,lb1,ls1);
|
||||
VERTEX(index, x+0.3535f+xs, y+0.5f, z-0.3535f+zs, u1,v2, lr1,lg1,lb1,ls1);
|
||||
|
||||
VERTEX(index, x-0.3535f+xs, y-0.5f, z+0.3535f+zs, u2,v1, lr4,lg4,lb4,ls4);
|
||||
VERTEX(index, x+0.3535f+xs, y+0.5f, z-0.3535f+zs, u1,v2, lr6,lg6,lb6,ls6);
|
||||
VERTEX(index, x+0.3535f+xs, y-0.5f, z-0.3535f+zs, u1,v1, lr7,lg7,lb7,ls7);}
|
||||
VERTEX(index, x-0.3535f+xs, y-0.5f, z+0.3535f+zs, u2,v1, lr0,lg0,lb0,ls0);
|
||||
VERTEX(index, x+0.3535f+xs, y+0.5f, z-0.3535f+zs, u1,v2, lr1,lg1,lb1,ls1);
|
||||
VERTEX(index, x+0.3535f+xs, y-0.5f, z-0.3535f+zs, u1,v1, lr0,lg0,lb0,ls0);}
|
||||
}
|
||||
|
||||
const float* VoxelRenderer::render(Chunk* chunk, const Chunk** chunks, size_t& size){
|
||||
|
||||
@ -56,8 +56,8 @@ void HudRenderer::drawDebug(Level* level, Assets* assets, int fps, bool occlusio
|
||||
batch->begin();
|
||||
font->draw(batch, L"chunks: "+std::to_wstring(chunks->chunksCount), 16, 16, STYLE_OUTLINE);
|
||||
font->draw(batch, std::to_wstring((int)player->camera->position.x), 10, 30, STYLE_OUTLINE);
|
||||
font->draw(batch, std::to_wstring((int)player->camera->position.y), 50, 30, STYLE_OUTLINE);
|
||||
font->draw(batch, std::to_wstring((int)player->camera->position.z), 90, 30, STYLE_OUTLINE);
|
||||
font->draw(batch, std::to_wstring((int)player->camera->position.y), 90, 30, STYLE_OUTLINE);
|
||||
font->draw(batch, std::to_wstring((int)player->camera->position.z), 170, 30, STYLE_OUTLINE);
|
||||
font->draw(batch, L"fps:", 16, 42, STYLE_OUTLINE);
|
||||
font->draw(batch, std::to_wstring(fps), 44, 42, STYLE_OUTLINE);
|
||||
font->draw(batch, L"occlusion: "+std::to_wstring(occlusion), 16, 54, STYLE_OUTLINE);
|
||||
@ -80,51 +80,115 @@ void HudRenderer::draw(Level* level, Assets* assets){
|
||||
Texture* sprite = assets->getTexture("slot");
|
||||
|
||||
if (!Events::_cursor_locked) {
|
||||
batch->texture(nullptr);
|
||||
batch->color = vec4(0.0f, 0.0f, 0.0f, 0.5f);
|
||||
batch->rect(0, 0, Window::width, Window::height);
|
||||
}
|
||||
|
||||
batch->color = vec4(1.0f);
|
||||
batch->texture(sprite);
|
||||
batch->sprite(16, uicamera->fov - 80, 64, 64, 16, 0, vec4(1.0f));
|
||||
// batch->texture(sprite);
|
||||
batch->texture(nullptr);
|
||||
// batch->sprite(Window::width/2-32, uicamera->fov - 80, 64, 64, 16, 0, vec4(1.0f));
|
||||
// batch->rect(Window::width/2-128-4, Window::height-80-4, 256+8, 64+8,
|
||||
// 0.85f, 0.85f, 0.85f, 0.95f, 0.95f, 0.95f,
|
||||
// 0.55f, 0.55f, 0.55f,
|
||||
// 0.45f, 0.45f, 0.45f, 0.7f, 0.7f, 0.7f, 2);
|
||||
batch->rect(Window::width/2-128-4, Window::height-80-4, 256+8, 64+8,
|
||||
0.95f, 0.95f, 0.95f, 0.85f, 0.85f, 0.85f,
|
||||
0.7f, 0.7f, 0.7f,
|
||||
0.55f, 0.55f, 0.55f, 0.45f, 0.45f, 0.45f, 4);
|
||||
batch->rect(Window::width/2-128, Window::height - 80, 256, 64,
|
||||
0.75f, 0.75f, 0.75f, 0.75f, 0.75f, 0.75f,
|
||||
0.75f, 0.75f, 0.75f,
|
||||
0.75f, 0.75f, 0.75f, 0.75f, 0.75f, 0.75f, 4);
|
||||
batch->rect(Window::width/2-32+2, Window::height - 80+2, 60, 60,
|
||||
0.45f, 0.45f, 0.45f, 0.55f, 0.55f, 0.55f,
|
||||
0.7f, 0.7f, 0.7f,
|
||||
0.85f, 0.85f, 0.85f, 0.95f, 0.95f, 0.95f, 2);
|
||||
batch->rect(Window::width/2-32+4, Window::height - 80+4, 56, 56,
|
||||
0.75f, 0.75f, 0.75f, 0.75f, 0.75f, 0.75f,
|
||||
0.75f, 0.75f, 0.75f,
|
||||
0.75f, 0.75f, 0.75f, 0.75f, 0.75f, 0.75f, 2);
|
||||
|
||||
|
||||
batch->texture(blocks);
|
||||
Player* player = level->player;
|
||||
{
|
||||
Block* cblock = Block::blocks[player->choosenBlock];
|
||||
if (cblock->model == BLOCK_MODEL_CUBE){
|
||||
batch->blockSprite(24, uicamera->fov - 72, 48, 48, 16, cblock->textureFaces, vec4(1.0f));
|
||||
batch->blockSprite(Window::width/2-24, uicamera->fov - 72, 48, 48, 16, cblock->textureFaces, vec4(1.0f));
|
||||
} else if (cblock->model == BLOCK_MODEL_X_SPRITE){
|
||||
batch->sprite(24, uicamera->fov - 72, 48, 48, 16, cblock->textureFaces[3], vec4(1.0f));
|
||||
batch->sprite(Window::width/2-24, uicamera->fov - 72, 48, 48, 16, cblock->textureFaces[3], vec4(1.0f));
|
||||
}
|
||||
}
|
||||
|
||||
if (!Events::_cursor_locked) {
|
||||
if (!Events::_cursor_locked) { //inventory
|
||||
int size = 48;
|
||||
int step = 70;
|
||||
int y = uicamera->fov - 72 - 70;
|
||||
int step = 64;
|
||||
int inv_wm = step*10;
|
||||
int inv_hm = step*8;
|
||||
int inv_w = inv_wm - (step - size);
|
||||
int inv_h = inv_hm - (step - size);
|
||||
int xs = (Window::width - inv_w + step)/2;
|
||||
int x = 0;
|
||||
int ys = (Window::height - inv_h + step)/2;
|
||||
int y = 0;
|
||||
vec4 tint = vec4(1.0f);
|
||||
int mx = Events::x;
|
||||
int my = Events::y;
|
||||
int count = (inv_w / step) * (inv_h / step) + 1;
|
||||
|
||||
for (unsigned i = 1; i < 256; i++) {
|
||||
//back
|
||||
batch->texture(nullptr);
|
||||
batch->color = vec4(0.0f, 0.0f, 0.0f, 0.3f);
|
||||
batch->rect(0, 0, Window::width, Window::height);
|
||||
batch->rect((Window::width - (inv_w)) / 2 - 4, (Window::height - (inv_h)) / 2 - 4, inv_w+8, inv_h+8,
|
||||
0.95f, 0.95f, 0.95f, 0.85f, 0.85f, 0.85f,
|
||||
0.7f, 0.7f, 0.7f,
|
||||
0.55f, 0.55f, 0.55f, 0.45f, 0.45f, 0.45f, 4);
|
||||
batch->rect((Window::width - (inv_w)) / 2, (Window::height - (inv_h)) / 2, inv_w, inv_h,
|
||||
0.75f, 0.75f, 0.75f, 0.75f, 0.75f, 0.75f,
|
||||
0.75f, 0.75f, 0.75f,
|
||||
0.75f, 0.75f, 0.75f, 0.75f, 0.75f, 0.75f, 4);
|
||||
|
||||
batch->color = vec4(0.35f, 0.35f, 0.35f, 1.0f);
|
||||
for (unsigned i = 1; i < count; i++) {
|
||||
x = xs + step * ((i-1) % (inv_w / step));
|
||||
y = ys + step * ((i-1) / (inv_w / step));
|
||||
// batch->rect(x-2, y-2, size+4, size+4);
|
||||
batch->rect(x-2, y-2, size+4, size+4,
|
||||
0.45f, 0.45f, 0.45f, 0.55f, 0.55f, 0.55f,
|
||||
0.7f, 0.7f, 0.7f,
|
||||
0.85f, 0.85f, 0.85f, 0.95f, 0.95f, 0.95f, 2);
|
||||
batch->rect(x, y, size, size,
|
||||
0.65f, 0.65f, 0.65f, 0.65f, 0.65f, 0.65f,
|
||||
0.65f, 0.65f, 0.65f,
|
||||
0.65f, 0.65f, 0.65f, 0.65f, 0.65f, 0.65f, 2);
|
||||
}
|
||||
|
||||
// batch->color = vec4(0.5f, 0.5f, 0.5f, 1.0f);
|
||||
// for (unsigned i = 1; i < count; i++) {
|
||||
// x = xs + step * ((i-1) % (inv_w / step));
|
||||
// y = ys + step * ((i-1) / (inv_w / step));
|
||||
// batch->rect(x, y, size, size);
|
||||
// }
|
||||
|
||||
//front
|
||||
batch->texture(blocks);
|
||||
for (unsigned i = 1; i < count; i++) {
|
||||
Block* cblock = Block::blocks[i];
|
||||
if (cblock == nullptr)
|
||||
break;
|
||||
x = 24 + (i-1) * step;
|
||||
y -= 72 * (x / (Window::width - step));
|
||||
x %= (Window::width - step);
|
||||
x = xs + step * ((i-1) % (inv_w / step));
|
||||
y = ys + step * ((i-1) / (inv_w / step));
|
||||
if (mx > x && mx < x + size && my > y && my < y + size) {
|
||||
tint.r *= 1.3f;
|
||||
tint.g *= 1.3f;
|
||||
tint.b *= 1.3f;
|
||||
tint.r *= 1.2f;
|
||||
tint.g *= 1.2f;
|
||||
tint.b *= 1.2f;
|
||||
if (Events::jclicked(GLFW_MOUSE_BUTTON_LEFT)) {
|
||||
player->choosenBlock = i;
|
||||
}
|
||||
// size = 50;
|
||||
} else
|
||||
{
|
||||
// size = 48;
|
||||
tint = vec4(1.0f);
|
||||
}
|
||||
|
||||
@ -138,9 +202,11 @@ void HudRenderer::draw(Level* level, Assets* assets){
|
||||
|
||||
batch->render();
|
||||
|
||||
Shader* crosshairShader = assets->getShader("crosshair");
|
||||
crosshairShader->use();
|
||||
crosshairShader->uniform1f("u_ar", (float)Window::height / (float)Window::width);
|
||||
crosshairShader->uniform1f("u_scale", 1.0f / ((float)Window::height / 1000.0f));
|
||||
crosshair->draw(GL_LINES);
|
||||
if (Events::_cursor_locked){
|
||||
Shader* crosshairShader = assets->getShader("crosshair");
|
||||
crosshairShader->use();
|
||||
crosshairShader->uniform1f("u_ar", (float)Window::height / (float)Window::width);
|
||||
crosshairShader->uniform1f("u_scale", 1.0f / ((float)Window::height / 1000.0f));
|
||||
crosshair->draw(GL_LINES);
|
||||
}
|
||||
}
|
||||
|
||||
@ -130,7 +130,7 @@ void mainloop(Level* level, Assets* assets) {
|
||||
if (Events::jpressed(GLFW_KEY_ESCAPE)){
|
||||
Window::setShouldClose(true);
|
||||
}
|
||||
if (Events::jpressed(GLFW_KEY_TAB)){
|
||||
if (Events::jpressed(GLFW_KEY_TAB) || Events::jpressed(GLFW_KEY_E)){
|
||||
Events::toggleCursor();
|
||||
}
|
||||
if (Events::jpressed(GLFW_KEY_O)){
|
||||
@ -178,7 +178,7 @@ int main() {
|
||||
if (status) return status;
|
||||
|
||||
std::cout << "-- loading world" << std::endl;
|
||||
vec3 playerPosition = vec3(0,150,-10);
|
||||
vec3 playerPosition = vec3(0,150,0);
|
||||
Camera* camera = new Camera(playerPosition, radians(90.0f));
|
||||
World* world = new World("world-1", "world/", 42);
|
||||
Player* player = new Player(playerPosition, 4.0f, camera);
|
||||
|
||||
@ -13,12 +13,14 @@ public:
|
||||
int textureFaces[6]; // -x,x, -y,y, -z,z
|
||||
unsigned char emission[3];
|
||||
unsigned char drawGroup = 0;
|
||||
unsigned char model = 1; // 0:None 1:Block 2:XSprite
|
||||
bool lightPassing = false;
|
||||
bool skyLightPassing = false;
|
||||
bool obstacle = true;
|
||||
bool selectable = true;
|
||||
bool breakable = true;
|
||||
unsigned char model = 1;
|
||||
float hitboxScale = 1;
|
||||
float hitboxY = 1;
|
||||
|
||||
Block(unsigned int id, int texture);
|
||||
};
|
||||
|
||||
@ -37,15 +37,16 @@ public:
|
||||
};
|
||||
|
||||
float calc_height(fnl_state *noise, int real_x, int real_z){
|
||||
float height = fnlGetNoise3D(noise, real_x*0.0125f*8,real_z*0.0125f*8, 0.0f);
|
||||
height += fnlGetNoise3D(noise, real_x*0.025f*8,real_z*0.025f*8, 0.0f)*0.5f;
|
||||
height += fnlGetNoise3D(noise, real_x*0.05f*8,real_z*0.05f*8, 0.0f)*0.25f;
|
||||
float height = 0;
|
||||
height += fnlGetNoise3D(noise, real_x*0.0125f*8-125567,real_z*0.0125f*8+3546, 0.0f);
|
||||
height += fnlGetNoise3D(noise, real_x*0.025f*8+4647,real_z*0.025f*8-3436, 0.0f)*0.5f;
|
||||
height += fnlGetNoise3D(noise, real_x*0.05f*8-834176,real_z*0.05f*8+23678, 0.0f)*0.25f;
|
||||
height += fnlGetNoise3D(noise,
|
||||
real_x*0.2f*8 + fnlGetNoise3D(noise, real_x*0.1f*8,real_z*0.1f*8, 0.0f)*50,
|
||||
real_z*0.2f*8 + fnlGetNoise3D(noise, real_x*0.1f*8+4363,real_z*0.1f*8, 0.0f)*50,
|
||||
real_x*0.2f*8 + fnlGetNoise3D(noise, real_x*0.1f*8-23557,real_z*0.1f*8-6568, 0.0f)*50,
|
||||
real_z*0.2f*8 + fnlGetNoise3D(noise, real_x*0.1f*8+4363,real_z*0.1f*8+4456, 0.0f)*50,
|
||||
0.0f)*0.1f;
|
||||
height += fnlGetNoise3D(noise, real_x*0.1f*8,real_z*0.1f*8, 0.0f)*0.125f;
|
||||
height += fnlGetNoise3D(noise, real_x*0.4f*8,real_z*0.4f*8, 0.0f)*0.0625f;
|
||||
height += fnlGetNoise3D(noise, real_x*0.1f*8-3465,real_z*0.1f*8+4534, 0.0f)*0.125f;
|
||||
height += fnlGetNoise3D(noise, real_x*0.4f*8+4565,real_z*0.4f*8+46456, 0.0f)*0.0625f;
|
||||
height += fnlGetNoise3D(noise, real_x*8,real_z*8, 0.0f)*0.03f*(fnlGetNoise3D(noise, -real_x*0.0125f*8-1000,real_z*0.0125f*8+2000, 0.0f)/2+0.5f);
|
||||
height *= fnlGetNoise3D(noise, real_x*0.0125f*8+1000,real_z*0.0125f*8+1000, 0.0f)/2+0.5f;
|
||||
height += 1.0f;
|
||||
@ -54,14 +55,15 @@ float calc_height(fnl_state *noise, int real_x, int real_z){
|
||||
}
|
||||
|
||||
float calc_height_faster(fnl_state *noise, int real_x, int real_z){
|
||||
float height = fnlGetNoise3D(noise, real_x*0.0125f*8,real_z*0.0125f*8, 0.0f);
|
||||
height += fnlGetNoise3D(noise, real_x*0.025f*8,real_z*0.025f*8, 0.0f)*0.5f;
|
||||
height += fnlGetNoise3D(noise, real_x*0.05f*8,real_z*0.05f*8, 0.0f)*0.25f;
|
||||
float height = 0;
|
||||
height += fnlGetNoise3D(noise, real_x*0.0125f*8-125567,real_z*0.0125f*8+3546, 0.0f);
|
||||
height += fnlGetNoise3D(noise, real_x*0.025f*8+4647,real_z*0.025f*8-3436, 0.0f)*0.5f;
|
||||
height += fnlGetNoise3D(noise, real_x*0.05f*8-834176,real_z*0.05f*8+23678, 0.0f)*0.25f;
|
||||
height += fnlGetNoise3D(noise,
|
||||
real_x*0.2f*8 + fnlGetNoise3D(noise, real_x*0.1f*8,real_z*0.1f*8, 0.0f)*50,
|
||||
real_z*0.2f*8 + fnlGetNoise3D(noise, real_x*0.1f*8+4363,real_z*0.1f*8, 0.0f)*50,
|
||||
real_x*0.2f*8 + fnlGetNoise3D(noise, real_x*0.1f*8-23557,real_z*0.1f*8-6568, 0.0f)*50,
|
||||
real_z*0.2f*8 + fnlGetNoise3D(noise, real_x*0.1f*8+4363,real_z*0.1f*8+4456, 0.0f)*50,
|
||||
0.0f)*0.1f;
|
||||
height += fnlGetNoise3D(noise, real_x*0.1f*8,real_z*0.1f*8, 0.0f)*0.125f;
|
||||
height += fnlGetNoise3D(noise, real_x*0.1f*8-3465,real_z*0.1f*8+4534, 0.0f)*0.125f;
|
||||
height *= fnlGetNoise3D(noise, real_x*0.0125f*8+1000,real_z*0.0125f*8+1000, 0.0f)/2+0.5f;
|
||||
height += 1.0f;
|
||||
height *= 64.0f;
|
||||
@ -142,10 +144,10 @@ void WorldGenerator::generate(voxel* voxels, int cx, int cz, int seed){
|
||||
}
|
||||
if (real_y <= 2)
|
||||
id = BLOCK_BEDROCK;
|
||||
if ((id == 0) && (real_y > 55) && ((int)(height + 0.5f) == real_y) && ((unsigned short)random() > 56000)){
|
||||
if ((id == 0) && (height > 55.5) && ((int)(height + 1) == real_y) && ((unsigned short)random() > 56000)){
|
||||
id = BLOCK_GRASS;
|
||||
}
|
||||
if ((id == 0) && (real_y > 55) && ((int)(height + 0.5f) == real_y) && ((unsigned short)random() > 64000)){
|
||||
if ((id == 0) && (height > 55.5) && ((int)(height + 1) == real_y) && ((unsigned short)random() > 64000)){
|
||||
id = BLOCK_FLOWER;
|
||||
}
|
||||
voxels[(y * CHUNK_D + z) * CHUNK_W + x].id = id;
|
||||
|
||||
@ -147,7 +147,7 @@ void WorldRenderer::draw(World* world, Camera* camera, bool occlusion){
|
||||
if (selectedBlock->model == 1){
|
||||
lineBatch->box(pos.x+0.5f, pos.y+0.5f, pos.z+0.5f, 1.005f,1.005f,1.005f, 0,0,0,0.5f);
|
||||
} else if (selectedBlock->model == 2){
|
||||
lineBatch->box(pos.x+0.4f, pos.y+0.3f, pos.z+0.4f, 0.805f,0.805f,0.805f, 0,0,0,0.5f);
|
||||
lineBatch->box(pos.x+0.5f, pos.y+0.35f, pos.z+0.5f, 0.805f,0.705f,0.805f, 0,0,0,0.5f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user