Compare commits

...

4 Commits

Author SHA1 Message Date
Dominik Madarász 082c485eeb billboarding 2022-10-15 22:33:09 +02:00
Vladyslav Hrytsenko 76dd148671 added mega tree 2022-10-15 20:44:41 +03:00
Vladyslav Hrytsenko b8e27c9b0d updated furnace 2022-10-15 19:01:22 +03:00
Vladyslav Hrytsenko f60cb28d00 code: added new things 2022-10-15 15:52:20 +03:00
15 changed files with 394 additions and 28 deletions

Binary file not shown.

BIN
art/gen/bigtree.png 100644

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 778 B

After

Width:  |  Height:  |  Size: 824 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 652 B

BIN
art/gen/furnace.png 100644

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

View File

@ -141,6 +141,7 @@ static debug_item items[] = {
{ .kind = DITEM_BUTTON, .name = "spawn chest", .on_click = ActSpawnChest },
{ .kind = DITEM_BUTTON, .name = "spawn belt", .on_click = ActSpawnBelt },
{ .kind = DITEM_BUTTON, .name = "spawn furnace", .on_click = ActSpawnFurnace },
{ .kind = DITEM_BUTTON, .name = "spawn big tree", .on_click = ActSpawnBigTree },
{ .kind = DITEM_BUTTON, .name = "spawn demo blueprint", .on_click = ActSpawnDemoHouseItem },
{ .kind = DITEM_BUTTON, .name = "spawn random durability icemaker", .on_click = ActSpawnDurabilityTest },
{

View File

@ -85,6 +85,17 @@ ActSpawnFurnace(void) {
entity_set_position(e, dest->x, dest->y);
}
void
ActSpawnBigTree(void) {
ecs_entity_t e = item_spawn(ASSET_BIG_TREE, 32);
ecs_entity_t plr = camera_get().ent_id;
Position const* origin = ecs_get(world_ecs(), plr, Position);
Position * dest = ecs_get_mut(world_ecs(), e, Position);
*dest = *origin;
entity_set_position(e, dest->x, dest->y);
}
void
ActSpawnDemoHouseItem(void) {
ecs_entity_t e = item_spawn(ASSET_BLUEPRINT, 1);

View File

@ -21,6 +21,7 @@ Texture2D texgen_build_sprite_fallback(asset_id id) {
case ASSET_BLANK: return GenColorEco(WHITE); break;
case ASSET_BUILDMODE_HIGHLIGHT: return GenColorEco(WHITE); break;
case ASSET_BLOCK_FRAME: return GenFrameRect(); break;
case ASSET_BIG_TREE: return LoadTexEco("bigtree"); break;
// NOTE(zaklaus): items
case ASSET_COAL: return LoadTexEco("coal");
@ -46,6 +47,7 @@ Texture2D texgen_build_sprite_fallback(asset_id id) {
// NOTE(zaklaus): devices
case ASSET_CHEST: return LoadTexEco("chest");
case ASSET_FURNACE: return LoadTexEco("furnace-export");
default: return GenColorEco(PINK); break;
}

View File

@ -8,6 +8,7 @@ typedef enum {
ASSET_BLANK,
ASSET_BLOCK_FRAME,
ASSET_BUILDMODE_HIGHLIGHT,
ASSET_BIG_TREE,
// NOTE(zaklaus): entities
ASSET_PLAYER,

View File

@ -15,6 +15,8 @@ static asset assets[] = {
ASSET_TEX(ASSET_BLANK),
ASSET_TEX(ASSET_BLOCK_FRAME),
ASSET_TEX(ASSET_BUILDMODE_HIGHLIGHT),
ASSET_TEX(ASSET_BIG_TREE),
ASSET_TEX(ASSET_COAL),
ASSET_TEX(ASSET_CHEST),
ASSET_TEX(ASSET_FURNACE),

View File

@ -23,4 +23,5 @@ static item_desc items[] = {
ITEM_ENT(ASSET_CHEST, 32, ASSET_CHEST),
ITEM_ENT(ASSET_FURNACE, 32, ASSET_FURNACE),
ITEM_ENT(ASSET_BIG_TREE, 32, ASSET_FURNACE),
};

View File

@ -98,6 +98,8 @@ void platform_get_block_realpos(float *x, float *y){
entity_view *e = game_world_view_active_get_entity(cam.ent_id);
if (!e) return;
float zoom = renderer_zoom_get();
mpos.x = screenWidth-mpos.x;
mpos.y = screenHeight-mpos.y;
mpos.x -= screenWidth/2.0f;
mpos.y -= screenHeight/2.0f;
cam.x += mpos.x*(1.0f/zoom);

View File

@ -2,6 +2,7 @@
#include <math.h>
#include "platform/system.h"
#include "raylib.h"
#include "raymath.h"
#include "world/blocks.h"
#include "models/assets.h"
@ -252,3 +253,288 @@ 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);
}
static inline
void Draw3DRectangle(Camera camera, float x, float y, float z, float w, float h, Color tint)
{
rlPushMatrix();
// get the camera view matrix
Matrix mat = MatrixLookAt(camera.position, camera.target, camera.up);
// peel off just the rotation
Quaternion quat = QuaternionFromMatrix(mat);
mat = QuaternionToMatrix(quat);
// apply just the rotation
rlMultMatrixf(MatrixToFloat(mat));
Vector3 position = (Vector3){x,z,y};
position = Vector3Transform(position, MatrixInvert(mat));
rlTranslatef(position.x, position.y, position.z);
// draw the billboard
float width = w / 2;
float height = h / 2;
rlCheckRenderBatchLimit(6);
// draw quad
rlBegin(RL_QUADS);
rlColor4ub(tint.r, tint.g, tint.b, tint.a);
// Front Face
rlNormal3f(0.0f, 0.0f, 1.0f); // Normal Pointing Towards Viewer
rlVertex3f(-width, -height, 0); // Bottom Left Of The Texture and Quad
rlVertex3f(+width, -height, 0); // Bottom Right Of The Texture and Quad
rlVertex3f(+width, +height, 0); // Top Right Of The Texture and Quad
rlVertex3f(-width, +height, 0); // Top Left Of The Texture and Quad
rlEnd();
rlPopMatrix();
}
static inline
void Draw3DBillboardRec(Camera camera, Texture2D texture, Rectangle source, Vector3 position, Vector2 size, Color tint)
{
rlPushMatrix();
// get the camera view matrix
Matrix mat = MatrixLookAt(camera.position, camera.target, camera.up);
// peel off just the rotation
Quaternion quat = QuaternionFromMatrix(mat);
mat = QuaternionToMatrix(quat);
// apply just the rotation
rlMultMatrixf(MatrixToFloat(mat));
// translate backwards in the inverse rotated matrix to put the item where it goes in world space
position = Vector3Transform(position, MatrixInvert(mat));
rlTranslatef(position.x, position.y, position.z);
// draw the billboard
float width = size.x / 2;
float height = size.y / 2;
rlCheckRenderBatchLimit(6);
rlSetTexture(texture.id);
// draw quad
rlBegin(RL_QUADS);
rlColor4ub(tint.r, tint.g, tint.b, tint.a);
// Front Face
rlNormal3f(0.0f, 0.0f, 1.0f); // Normal Pointing Towards Viewer
rlTexCoord2f((float)source.x / texture.width, (float)(source.y + source.height) / texture.height);
rlVertex3f(-width, -height, 0); // Bottom Left Of The Texture and Quad
rlTexCoord2f((float)(source.x + source.width) / texture.width, (float)(source.y + source.height) / texture.height);
rlVertex3f(+width, -height, 0); // Bottom Right Of The Texture and Quad
rlTexCoord2f((float)(source.x + source.width) / texture.width, (float)source.y / texture.height);
rlVertex3f(+width, +height, 0); // Top Right Of The Texture and Quad
rlTexCoord2f((float)source.x / texture.width, (float)source.y / texture.height);
rlVertex3f(-width, +height, 0); // Top Left Of The Texture and Quad
rlEnd();
rlSetTexture(0);
rlPopMatrix();
}
static inline
void Draw3DBillboard(Camera camera, Texture2D texture, Vector3 position, float size, Color tint)
{
Draw3DBillboardRec(camera, texture, (Rectangle){ 0,0,(float)texture.width,(float)texture.height }, position, (Vector2){ size,size }, tint);
}
// Draw codepoint at specified position in 3D space
static void DrawTextCodepoint3D(Font font, int codepoint, Vector3 position, float fontSize, bool backface, Color tint)
{
// Character index position in sprite font
// NOTE: In case a codepoint is not available in the font, index returned points to '?'
int index = GetGlyphIndex(font, codepoint);
float scale = fontSize/(float)font.baseSize;
// Character destination rectangle on screen
// NOTE: We consider charsPadding on drawing
position.x += (float)(font.glyphs[index].offsetX - font.glyphPadding)/(float)font.baseSize*scale;
position.z += (float)(font.glyphs[index].offsetY - font.glyphPadding)/(float)font.baseSize*scale;
// Character source rectangle from font texture atlas
// NOTE: We consider chars padding when drawing, it could be required for outline/glow shader effects
Rectangle srcRec = { font.recs[index].x - (float)font.glyphPadding, font.recs[index].y - (float)font.glyphPadding,
font.recs[index].width + 2.0f*font.glyphPadding, font.recs[index].height + 2.0f*font.glyphPadding };
float width = (float)(font.recs[index].width + 2.0f*font.glyphPadding)/(float)font.baseSize*scale;
float height = (float)(font.recs[index].height + 2.0f*font.glyphPadding)/(float)font.baseSize*scale;
if (font.texture.id > 0)
{
const float x = 0.0f;
const float y = 0.0f;
const float z = 0.0f;
// normalized texture coordinates of the glyph inside the font texture (0.0f -> 1.0f)
const float tx = srcRec.x/font.texture.width;
const float ty = srcRec.y/font.texture.height;
const float tw = (srcRec.x+srcRec.width)/font.texture.width;
const float th = (srcRec.y+srcRec.height)/font.texture.height;
rlCheckRenderBatchLimit(4 + 4*backface);
rlSetTexture(font.texture.id);
rlPushMatrix();
rlTranslatef(position.x, position.y, position.z);
rlBegin(RL_QUADS);
rlColor4ub(tint.r, tint.g, tint.b, tint.a);
// Front Face
rlNormal3f(0.0f, 1.0f, 0.0f); // Normal Pointing Up
rlTexCoord2f(tx, ty); rlVertex3f(x, y, z); // Top Left Of The Texture and Quad
rlTexCoord2f(tx, th); rlVertex3f(x, y, z + height); // Bottom Left Of The Texture and Quad
rlTexCoord2f(tw, th); rlVertex3f(x + width, y, z + height); // Bottom Right Of The Texture and Quad
rlTexCoord2f(tw, ty); rlVertex3f(x + width, y, z); // Top Right Of The Texture and Quad
if (backface)
{
// Back Face
rlNormal3f(0.0f, -1.0f, 0.0f); // Normal Pointing Down
rlTexCoord2f(tx, ty); rlVertex3f(x, y, z); // Top Right Of The Texture and Quad
rlTexCoord2f(tw, ty); rlVertex3f(x + width, y, z); // Top Left Of The Texture and Quad
rlTexCoord2f(tw, th); rlVertex3f(x + width, y, z + height); // Bottom Left Of The Texture and Quad
rlTexCoord2f(tx, th); rlVertex3f(x, y, z + height); // Bottom Right Of The Texture and Quad
}
rlEnd();
rlPopMatrix();
rlSetTexture(0);
}
}
// Draw a 2D text in 3D space
static void DrawText3D(Font font, const char *text, Vector3 position, float fontSize, float fontSpacing, float lineSpacing, bool backface, Color tint)
{
int length = TextLength(text); // Total length in bytes of the text, scanned by codepoints in loop
float textOffsetY = 0.0f; // Offset between lines (on line break '\n')
float textOffsetX = 0.0f; // Offset X to next character to draw
float scale = fontSize/(float)font.baseSize;
for (int i = 0; i < length;)
{
// Get next codepoint from byte string and glyph index in font
int codepointByteCount = 0;
int codepoint = GetCodepoint(&text[i], &codepointByteCount);
int index = GetGlyphIndex(font, codepoint);
// NOTE: Normally we exit the decoding sequence as soon as a bad byte is found (and return 0x3f)
// but we need to draw all of the bad bytes using the '?' symbol moving one byte
if (codepoint == 0x3f) codepointByteCount = 1;
if (codepoint == '\n')
{
textOffsetY += scale + lineSpacing/(float)font.baseSize*scale;
textOffsetX = 0.0f;
}
else
{
if ((codepoint != ' ') && (codepoint != '\t'))
{
DrawTextCodepoint3D(font, codepoint, (Vector3){ position.x + textOffsetX, position.y, position.z + textOffsetY }, fontSize, backface, tint);
}
if (font.glyphs[index].advanceX == 0) textOffsetX += (float)(font.recs[index].width + fontSpacing)/(float)font.baseSize*scale;
else textOffsetX += (float)(font.glyphs[index].advanceX + fontSpacing)/(float)font.baseSize*scale;
}
i += codepointByteCount; // Move text bytes counter to next codepoint
}
}
// Measure a text in 3D. For some reason `MeasureTextEx()` just doesn't seem to work so i had to use this instead.
static Vector3 MeasureText3D(Font font, const char* text, float fontSize, float fontSpacing, float lineSpacing)
{
int len = TextLength(text);
int tempLen = 0; // Used to count longer text line num chars
int lenCounter = 0;
float tempTextWidth = 0.0f; // Used to count longer text line width
float scale = fontSize/(float)font.baseSize;
float textHeight = scale;
float textWidth = 0.0f;
int letter = 0; // Current character
int index = 0; // Index position in sprite font
for (int i = 0; i < len; i++)
{
lenCounter++;
int next = 0;
letter = GetCodepoint(&text[i], &next);
index = GetGlyphIndex(font, letter);
// NOTE: normally we exit the decoding sequence as soon as a bad byte is found (and return 0x3f)
// but we need to draw all of the bad bytes using the '?' symbol so to not skip any we set next = 1
if (letter == 0x3f) next = 1;
i += next - 1;
if (letter != '\n')
{
if (font.glyphs[index].advanceX != 0) textWidth += (font.glyphs[index].advanceX+fontSpacing)/(float)font.baseSize*scale;
else textWidth += (font.recs[index].width + font.glyphs[index].offsetX)/(float)font.baseSize*scale;
}
else
{
if (tempTextWidth < textWidth) tempTextWidth = textWidth;
lenCounter = 0;
textWidth = 0.0f;
textHeight += scale + lineSpacing/(float)font.baseSize*scale;
}
if (tempLen < lenCounter) tempLen = lenCounter;
}
if (tempTextWidth < textWidth) tempTextWidth = textWidth;
Vector3 vec = { 0 };
vec.x = tempTextWidth + (float)((tempLen - 1)*fontSpacing/(float)font.baseSize*scale); // Adds chars spacing to measure
vec.y = 0.25f;
vec.z = textHeight;
return vec;
}

View File

@ -61,10 +61,10 @@ void platform_input() {
{
float x=0.0f, y=0.0f;
uint8_t use, sprint, drop, ctrl, pick;
if (IsKeyDown(KEY_RIGHT) || IsKeyDown(KEY_D)) x += 1.0f;
if (IsKeyDown(KEY_LEFT) || IsKeyDown(KEY_A)) x -= 1.0f;
if (IsKeyDown(KEY_UP) || IsKeyDown(KEY_W)) y += 1.0f;
if (IsKeyDown(KEY_DOWN) || IsKeyDown(KEY_S)) y -= 1.0f;
if (IsKeyDown(KEY_RIGHT) || IsKeyDown(KEY_D)) x -= 1.0f;
if (IsKeyDown(KEY_LEFT) || IsKeyDown(KEY_A)) x += 1.0f;
if (IsKeyDown(KEY_UP) || IsKeyDown(KEY_W)) y -= 1.0f;
if (IsKeyDown(KEY_DOWN) || IsKeyDown(KEY_S)) y += 1.0f;
use = IsKeyPressed(KEY_SPACE);
sprint = IsKeyDown(KEY_LEFT_SHIFT) || IsKeyDown(KEY_RIGHT_SHIFT);
@ -77,6 +77,8 @@ void platform_input() {
mouse_pos.y /= screenHeight;
mouse_pos.x -= 0.5f;
mouse_pos.y -= 0.5f;
mouse_pos.x = screenWidth - mouse_pos.x;
mouse_pos.y = screenHeight - mouse_pos.y;
mouse_pos = Vector2Normalize(mouse_pos);
if (game_get_kind() == GAMEKIND_SINGLE && IsMouseButtonDown(MOUSE_MIDDLE_BUTTON)) {

View File

@ -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)
@ -8,17 +9,18 @@ float zpl_lerp(float,float,float);
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 size = 72.f;
float font_size = lerp(12.0f, 72.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;
float health = (data->hp / data->max_hp);
const char *title = TextFormat("%s %llu", name, key);
float title_w = MeasureTextEco(title, font_size, font_spacing);
DrawRectangleEco(x-title_w/2.f-title_bg_offset/2.f, y-size-font_size-fixed_title_offset, title_w+title_bg_offset, font_size, ColorAlpha(BLACK, data->tran_time));
DrawRectangleEco(x-title_w/2.f-title_bg_offset/2.f, y-size-fixed_title_offset, title_w*health+title_bg_offset, font_size*0.2f, ColorAlpha(RED, data->tran_time));
Draw3DRectangle(render_camera, x-title_w/2.f-title_bg_offset/2.f, y, size+font_size+fixed_title_offset, title_w+title_bg_offset, font_size, ColorAlpha(BLACK, data->tran_time));
Draw3DRectangle(render_camera, x-title_w/2.f-title_bg_offset/2.f, y, size+fixed_title_offset, title_w*health+title_bg_offset, font_size*0.2f, ColorAlpha(RED, data->tran_time));
DrawTextEco(title, x-title_w/2.f, y-size-font_size-fixed_title_offset, font_size, ColorAlpha(RAYWHITE, data->tran_time), font_spacing);
DrawText3D(GetFontDefault(), title, (Vector3){x-title_w/2.f, 64.f, y}, 24.f, 12.0f, 1.3f, true, WHITE);
}
void DEBUG_draw_ground(uint64_t key, entity_view * data) {
@ -26,6 +28,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 +39,29 @@ 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);
// DrawCubeWires((Vector3){x, 0.f, y}, WORLD_BLOCK_SIZE*view->chunk_size, 66, WORLD_BLOCK_SIZE*view->chunk_size, BLUE);
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 +92,13 @@ 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);
Texture2D sprite_tex = GetSpriteTexture2D(assets_find(data->asset));
switch (data->kind) {
case EKIND_DEMO_NPC: {
@ -86,7 +112,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 +136,23 @@ 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);
Draw3DBillboard(render_camera, sprite_tex, (Vector3){x + half_block_size, 32.0f, y + half_block_size}, 64.0f, 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;
Draw3DBillboard(render_camera, sprite_tex, (Vector3){x + half_block_size, 32.0f, y + half_block_size}, 64.0f, WHITE);
if (data->quantity > 1) {
DrawTextEco(zpl_bprintf("%d", data->quantity), x, y, 10, ALPHA(RAYWHITE), 0.0f);
@ -156,17 +199,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)+30.0f, (float)game_camera.y-50.0f*(10.0f-cam_zoom/2.0f)};
render_camera.target = (Vector3){(float)game_camera.x, 30.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 +228,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,1.0f,0.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 +266,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 +302,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();
}