code: added new things
parent
2040984666
commit
f60cb28d00
Binary file not shown.
BIN
art/gen/coal.png
BIN
art/gen/coal.png
Binary file not shown.
Before Width: | Height: | Size: 778 B After Width: | Height: | Size: 824 B |
Binary file not shown.
After Width: | Height: | Size: 5.7 KiB |
|
@ -46,6 +46,7 @@ Texture2D texgen_build_sprite_fallback(asset_id id) {
|
|||
|
||||
// NOTE(zaklaus): devices
|
||||
case ASSET_CHEST: return LoadTexEco("chest");
|
||||
case ASSET_FURNACE: return LoadTexEco("furnace");
|
||||
|
||||
default: return GenColorEco(PINK); break;
|
||||
}
|
||||
|
|
|
@ -252,3 +252,34 @@ void DrawRectangleLinesEco(float posX, float posY, float width, float height, Co
|
|||
rlVertex2f(posX + 1, posY + 1);
|
||||
rlEnd();
|
||||
}
|
||||
|
||||
static inline
|
||||
void DrawSpriteTextureEco(Texture2D texture, Vector3 position, float width, float height, float length, Color color) {
|
||||
float x = position.x;
|
||||
float y = position.y;
|
||||
float z = position.z;
|
||||
|
||||
Vector3 rotationAxis = {1.0f, 0.f, 0.f};
|
||||
|
||||
// NOTE: Plane is always created on XZ ground
|
||||
rlSetTexture(texture.id);
|
||||
|
||||
rlPushMatrix();
|
||||
rlTranslatef(position.x, position.y, position.z);
|
||||
rlRotatef(25.f, rotationAxis.x, rotationAxis.y, rotationAxis.z);
|
||||
rlScalef(width, height, length);
|
||||
|
||||
rlBegin(RL_QUADS);
|
||||
rlColor4ub(color.r, color.g, color.b, color.a);
|
||||
|
||||
// Top Face
|
||||
rlNormal3f(0.0f, 1.0f, 0.0f); // Normal Pointing Up
|
||||
rlTexCoord2f(0.0f, 0.0f); rlVertex3f(-0.5f, 0.0f, -0.5f); // Top Left Of The Texture and Quad
|
||||
rlTexCoord2f(0.0f, 1.0f); rlVertex3f(-0.5f, 0.0f, 0.5f); // Bottom Left Of The Texture and Quad
|
||||
rlTexCoord2f(1.0f, 1.0f); rlVertex3f(0.5f, 0.0f, 0.5f); // Bottom Right Of The Texture and Quad
|
||||
rlTexCoord2f(1.0f, 0.0f); rlVertex3f(0.5f, 0.0f, -0.5f); // Top Right Of The Texture and Quad
|
||||
rlEnd();
|
||||
rlPopMatrix();
|
||||
|
||||
rlSetTexture(0);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
static Camera2D render_camera;
|
||||
static Camera3D render_camera;
|
||||
static float zoom_overlay_tran = 0.0f;
|
||||
static float cam_zoom = 1.5f;
|
||||
|
||||
#define CAM_OVERLAY_ZOOM_LEVEL 0.15f
|
||||
#define ALPHA(x) ColorAlpha(x, data->tran_time)
|
||||
|
@ -9,7 +10,7 @@ float zpl_to_degrees(float);
|
|||
|
||||
void DrawNametag(const char* name, uint64_t key, entity_view *data, float x, float y) {
|
||||
float size = 16.f;
|
||||
float font_size = lerp(4.0f, 32.0f, 0.5f/(float)render_camera.zoom);
|
||||
float font_size = lerp(4.0f, 32.0f, 0.5f/1.0f);//(float)render_camera.zoom);
|
||||
float font_spacing = 1.1f;
|
||||
float title_bg_offset = 4;
|
||||
float fixed_title_offset = 8.f;
|
||||
|
@ -26,6 +27,8 @@ void DEBUG_draw_ground(uint64_t key, entity_view * data) {
|
|||
case EKIND_CHUNK: {
|
||||
world_view *view = game_world_view_get_active();
|
||||
float size = (float)(view->chunk_size * WORLD_BLOCK_SIZE);
|
||||
float half_size = size / 2.0f;
|
||||
float half_block_size = (float)(WORLD_BLOCK_SIZE >> 1);
|
||||
float offset = 0.0;
|
||||
|
||||
float x = data->x * size + offset;
|
||||
|
@ -35,13 +38,28 @@ void DEBUG_draw_ground(uint64_t key, entity_view * data) {
|
|||
float scale = (size)/(float)(tex.texture.width);
|
||||
tex.texture.width *= (int32_t)scale;
|
||||
tex.texture.height *= (int32_t)scale;
|
||||
DrawTextureRec(tex.texture, (Rectangle){0, 0, size, -size}, (Vector2){x, y}, ColorAlpha(WHITE, data->tran_time));
|
||||
// DrawTextureRec(tex.texture, (Rectangle){0, 0, size, -size}, (Vector2){x, y}, ColorAlpha(WHITE, data->tran_time));
|
||||
DrawCubeTexture(tex.texture, (Vector3){x+half_size, 0.0f, y+half_size}, size, 0.01f, size, WHITE);
|
||||
|
||||
for (size_t ty = 0; ty < view->chunk_size; ty++) {
|
||||
for (size_t tx = 0; tx < view->chunk_size; tx++) {
|
||||
block_id blk_id = data->outer_blocks[(ty*view->chunk_size)+tx];
|
||||
if (blk_id != 0) {
|
||||
DrawTextureRec(GetBlockImage(blk_id), ASSET_SRC_RECT(), (Vector2){x+tx*WORLD_BLOCK_SIZE, y+ty*WORLD_BLOCK_SIZE}, ColorAlpha(WHITE, data->tran_time));
|
||||
// DrawTextureRec(GetBlockImage(blk_id), ASSET_SRC_RECT(), (Vector2){x+tx*WORLD_BLOCK_SIZE, y+ty*WORLD_BLOCK_SIZE}, ColorAlpha(WHITE, data->tran_time));
|
||||
DrawCubeTexture(GetBlockImage(blk_id), (Vector3){x + tx*WORLD_BLOCK_SIZE+half_block_size, 32.0f, y + ty*WORLD_BLOCK_SIZE+half_block_size}, 64, 0.01f, 64, WHITE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int by = 0; by < 16; by++) {
|
||||
for (int bx = 0; bx < 16; bx++) {
|
||||
switch (blocks_get_flags(data->blocks[by*16+bx])) {
|
||||
case BLOCK_FLAG_COLLISION:{
|
||||
DrawCubeWires((Vector3){x + bx*WORLD_BLOCK_SIZE+half_block_size, 34.f, y + by*WORLD_BLOCK_SIZE+half_block_size}, 64, 66, 64, BLUE);
|
||||
}break;
|
||||
case BLOCK_FLAG_HAZARD:{
|
||||
DrawCubeWires((Vector3){x + bx*WORLD_BLOCK_SIZE+half_block_size, 16.667f, y + by*WORLD_BLOCK_SIZE+half_block_size}, 64, 33, 64, RED);
|
||||
}break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -72,7 +90,12 @@ void DEBUG_draw_overlay(uint64_t key, entity_view * data) {
|
|||
extern bool inv_is_open;
|
||||
|
||||
void DEBUG_draw_entities(uint64_t key, entity_view * data) {
|
||||
world_view *view = game_world_view_get_active();
|
||||
float size = 16.f;
|
||||
uint16_t ground_offset = 30;
|
||||
float bl_size = (float)(view->chunk_size * WORLD_BLOCK_SIZE);
|
||||
float half_size = bl_size / 2.0f;
|
||||
float half_block_size = (float)(WORLD_BLOCK_SIZE >> 1);
|
||||
|
||||
switch (data->kind) {
|
||||
case EKIND_DEMO_NPC: {
|
||||
|
@ -86,7 +109,8 @@ void DEBUG_draw_entities(uint64_t key, entity_view * data) {
|
|||
float y = data->y;
|
||||
float health = (data->hp / data->max_hp);
|
||||
DrawNametag("Player", key, data, x, y);
|
||||
DrawCircleEco(x, y, size, ColorAlpha(YELLOW, data->tran_time));
|
||||
// DrawCircleEco(x, y, size, ColorAlpha(YELLOW, data->tran_time));
|
||||
DrawSphere((Vector3){x,ground_offset,y}, size, ColorAlpha(YELLOW, data->tran_time));
|
||||
|
||||
if (data->has_items && !data->inside_vehicle) {
|
||||
float ix = data->x;
|
||||
|
@ -109,7 +133,24 @@ void DEBUG_draw_entities(uint64_t key, entity_view * data) {
|
|||
case EKIND_ITEM: {
|
||||
float x = data->x - 32.f;
|
||||
float y = data->y - 32.f;
|
||||
DrawTexturePro(GetSpriteTexture2D(assets_find(data->asset)), ASSET_SRC_RECT(), ASSET_DST_RECT(x,y), (Vector2){0.5f,0.5f}, 0.0f, ALPHA(WHITE));
|
||||
// DrawTexturePro(GetSpriteTexture2D(assets_find(data->asset)), ASSET_SRC_RECT(), ASSET_DST_RECT(x,y), (Vector2){0.5f,0.5f}, 0.0f, ALPHA(WHITE));
|
||||
// DrawCubeTexture(GetSpriteTexture2D(assets_find(data->asset)), (Vector3){x + half_block_size, 32.0f, y + half_block_size}, 64, 0.01f, 64, WHITE);
|
||||
DrawSpriteTextureEco(GetSpriteTexture2D(assets_find(data->asset)), (Vector3){x + half_block_size, half_block_size/2, y + half_block_size}, 32, 0.01f, 32, WHITE);
|
||||
|
||||
if (data->quantity > 1) {
|
||||
DrawTextEco(zpl_bprintf("%d", data->quantity), x, y, 10, ALPHA(RAYWHITE), 0.0f);
|
||||
}
|
||||
|
||||
if (data->durability < 1.0f) {
|
||||
DrawRectangleEco(x, y+32, 4, 32, BlendColor(RED, GREEN, data->durability));
|
||||
DrawRectangleEco(x, y+32, 4, 32*(1.0f-data->durability), ColorAlpha(BLACK, data->tran_time));
|
||||
}
|
||||
}break;
|
||||
case EKIND_DEVICE: {
|
||||
float x = data->x - 32.f;
|
||||
float y = data->y - 32.f;
|
||||
// DrawTexturePro(GetSpriteTexture2D(assets_find(data->asset)), ASSET_SRC_RECT(), ASSET_DST_RECT(x,y), (Vector2){0.5f,0.5f}, 0.0f, ALPHA(WHITE));
|
||||
DrawSpriteTextureEco(GetSpriteTexture2D(assets_find(data->asset)), (Vector3){x + half_block_size, half_block_size/2, y + half_block_size}, 64, 0.01f, 64, WHITE);
|
||||
|
||||
if (data->quantity > 1) {
|
||||
DrawTextEco(zpl_bprintf("%d", data->quantity), x, y, 10, ALPHA(RAYWHITE), 0.0f);
|
||||
|
@ -156,17 +197,28 @@ void DEBUG_draw_entities_low(uint64_t key, entity_view * data) {
|
|||
}
|
||||
|
||||
void renderer_draw(void) {
|
||||
render_camera.offset = (Vector2){(float)(screenWidth >> 1), (float)(screenHeight >> 1)};
|
||||
render_camera.zoom = zpl_lerp(render_camera.zoom, target_zoom, GetFrameTime()*2.9978f);
|
||||
cam_zoom = zpl_min(zpl_lerp(cam_zoom, target_zoom, GetFrameTime()*2.18f), 9.98f);
|
||||
camera_update();
|
||||
|
||||
camera game_camera = camera_get();
|
||||
render_camera.target = (Vector2){(float)game_camera.x, (float)game_camera.y};
|
||||
zoom_overlay_tran = zpl_lerp(zoom_overlay_tran, (target_zoom <= CAM_OVERLAY_ZOOM_LEVEL) ? 1.0f : 0.0f, GetFrameTime()*2.0f);
|
||||
#if 1
|
||||
render_camera.position = (Vector3){(float)game_camera.x, 260.0f*(10.0f-cam_zoom), (float)game_camera.y+50.0f*(10.0f-cam_zoom/2.0f)};
|
||||
render_camera.target = (Vector3){(float)game_camera.x, 0.0f, (float)game_camera.y};
|
||||
#else
|
||||
UpdateCamera(&render_camera);
|
||||
#endif
|
||||
|
||||
// render_camera.offset = (Vector2){(float)(screenWidth >> 1), (float)(screenHeight >> 1)};
|
||||
// render_camera.zoom = zpl_lerp(render_camera.zoom, target_zoom, GetFrameTime()*2.9978f);
|
||||
// camera_update();
|
||||
|
||||
// camera game_camera = camera_get();
|
||||
// render_camera.target = (Vector2){(float)game_camera.x, (float)game_camera.y};
|
||||
// zoom_overlay_tran = zpl_lerp(zoom_overlay_tran, (target_zoom <= CAM_OVERLAY_ZOOM_LEVEL) ? 1.0f : 0.0f, GetFrameTime()*2.0f);
|
||||
|
||||
|
||||
ClearBackground(GetColor(0x222034));
|
||||
BeginMode2D(render_camera);
|
||||
BeginMode3D(render_camera);
|
||||
game_world_view_active_entity_map(DEBUG_draw_ground);
|
||||
game_world_view_active_entity_map(DEBUG_draw_entities_low);
|
||||
game_world_view_active_entity_map(DEBUG_draw_entities);
|
||||
|
@ -174,18 +226,22 @@ void renderer_draw(void) {
|
|||
if (zoom_overlay_tran > 0.02f) {
|
||||
game_world_view_active_entity_map(DEBUG_draw_overlay);
|
||||
}
|
||||
EndMode2D();
|
||||
EndMode3D();
|
||||
}
|
||||
|
||||
float renderer_zoom_get(void) {
|
||||
return render_camera.zoom;
|
||||
return 1.0f;//render_camera.zoom;
|
||||
}
|
||||
|
||||
void renderer_init(void) {
|
||||
render_camera.target = (Vector2){0.0f,0.0f};
|
||||
render_camera.offset = (Vector2){(float)(screenWidth >> 1), (float)(screenHeight >> 1)};
|
||||
render_camera.rotation = 0.0f;
|
||||
render_camera.zoom = 2.9f;
|
||||
// render_camera.target = (Vector2){0.0f,0.0f};
|
||||
// render_camera.offset = (Vector2){(float)(screenWidth >> 1), (float)(screenHeight >> 1)};
|
||||
// render_camera.rotation = 0.0f;
|
||||
// render_camera.zoom = 2.9f;
|
||||
|
||||
render_camera.up = (Vector3){0.0f,0.0f,-1.0f};
|
||||
render_camera.fovy = 45.f;
|
||||
render_camera.projection = CAMERA_PERSPECTIVE;
|
||||
|
||||
// NOTE(zaklaus): Paint the screen before we load the game
|
||||
// TODO(zaklaus): Render a cool loading screen background maybe? :wink: :wink:
|
||||
|
@ -208,7 +264,7 @@ void renderer_shutdown(void) {
|
|||
}
|
||||
|
||||
void renderer_debug_draw(void) {
|
||||
BeginMode2D(render_camera);
|
||||
BeginMode3D(render_camera);
|
||||
debug_draw_queue *que = debug_draw_samples();
|
||||
|
||||
for (size_t i = 0; i < que->num_entries; i += 1) {
|
||||
|
@ -244,16 +300,16 @@ void renderer_debug_draw(void) {
|
|||
}
|
||||
}
|
||||
|
||||
EndMode2D();
|
||||
EndMode3D();
|
||||
}
|
||||
|
||||
void renderer_draw_single(float x, float y, asset_id id, Color color) {
|
||||
BeginMode2D(render_camera);
|
||||
BeginMode3D(render_camera);
|
||||
|
||||
x -= 32.0f;
|
||||
y -= 32.0f;
|
||||
|
||||
DrawTexturePro(GetSpriteTexture2D(assets_find(id)), ASSET_SRC_RECT(), ASSET_DST_RECT(x,y), (Vector2){0.5f,0.5f}, 0.0f, color);
|
||||
|
||||
EndMode2D();
|
||||
EndMode3D();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue