Drawing Debug functions moved to lib.h to clean things up
This commit is contained in:
parent
631940a6eb
commit
9dd7727c92
38
lib.h
38
lib.h
@ -42,3 +42,41 @@ typedef struct PointOrNone {
|
||||
Point point;
|
||||
} value;
|
||||
} PointOrNone;
|
||||
|
||||
|
||||
void D_DrawTextureRec(Texture2D texture, Rectangle source, Vector2 position, Color tint);
|
||||
void D_DrawTexturePro(Texture2D texture, Rectangle source, Rectangle dest, Vector2 origin, float rotation, Color tint);
|
||||
void D_DrawTextureV(Texture2D texture, Vector2 position, Color tint);
|
||||
#ifdef ENNIX_LIB_IMPLEMENTATION
|
||||
extern bool global_debug_mode;
|
||||
inline void D_DrawTextureV(Texture2D texture, Vector2 position, Color tint) {
|
||||
DrawTextureV(texture, position, tint);
|
||||
#ifdef DEBUG_MODE_ENABLED
|
||||
if (global_debug_mode) {
|
||||
Rectangle debug = {position.x,position.y,texture.width,texture.height};
|
||||
DrawRectangleLinesEx(debug, 1.0f, RED);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void D_DrawTextureRec(Texture2D texture, Rectangle source, Vector2 position, Color tint) {
|
||||
DrawTextureRec(texture, source, position, tint);
|
||||
#ifdef DEBUG_MODE_ENABLED
|
||||
if (global_debug_mode) {
|
||||
Rectangle debug = {position.x,position.y,source.width,source.height};
|
||||
DrawRectangleLinesEx(debug, 1.0f, RED);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void D_DrawTexturePro(Texture2D texture, Rectangle source, Rectangle dest, Vector2 origin, float rotation, Color tint) {
|
||||
DrawTexturePro(texture, source, dest, origin, rotation, tint);
|
||||
#ifdef DEBUG_MODE_ENABLED
|
||||
if (global_debug_mode) {
|
||||
Rectangle debug = {dest.x-origin.x,dest.y-origin.y,dest.width,dest.height};
|
||||
DrawRectangleLinesEx(debug, 1.0f, RED);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
61
main.c
61
main.c
@ -10,11 +10,15 @@
|
||||
#define MAX_ANIMATION_PLAYBACKS 64
|
||||
#define MAX_KNIGHTS 64
|
||||
|
||||
#define DEBUG_MODE_ENABLED
|
||||
|
||||
bool global_debug_mode;
|
||||
|
||||
#define ENNIX_LIB_IMPLEMENTATION
|
||||
#include "lib.h"
|
||||
#include "sprites.h"
|
||||
#include "game_data.h"
|
||||
|
||||
#define DEBUG_MODE_ENABLED
|
||||
|
||||
typedef enum KnightState {
|
||||
KNIGHT_IDLE = 0,
|
||||
KNIGHT_RUNNING = 1,
|
||||
@ -49,7 +53,6 @@ typedef struct {
|
||||
PointOrNone *target_points;
|
||||
SpriteAnimationPlayback* anim_playbacks;
|
||||
int anim_playbacks_count;
|
||||
bool debug_mode;
|
||||
} GameState;
|
||||
|
||||
typedef struct {
|
||||
@ -151,7 +154,7 @@ void Update(GameState *game, Camera2D *cam, float dt) {
|
||||
PlayAnimation(&game->anim_playbacks[0], game->anim_playbacks[0]);
|
||||
}
|
||||
if (IsKeyPressed(KEY_F1)) {
|
||||
game->debug_mode = !game->debug_mode;
|
||||
global_debug_mode = !global_debug_mode;
|
||||
}
|
||||
if (game->knight.state == KNIGHT_ATTACKING) {
|
||||
game->anim_playbacks[0].anim_id = ANIM_KNIGHT_ATTACK_SIDE1;
|
||||
@ -199,18 +202,7 @@ void Draw(const GameState *game, Assets assets, Camera2D cam, float dt) {
|
||||
}
|
||||
Vector2 pos = {32 * col + topx, 32 * row + topy};
|
||||
Rectangle src_rect = {32 * atlas_col, 32 * atlas_row, 32, 32};
|
||||
DrawTextureRec(assets.textures[0], src_rect, pos, WHITE);
|
||||
#ifdef DEBUG_MODE_ENABLED
|
||||
if (game->debug_mode) {
|
||||
Rectangle debug_frame = {
|
||||
pos.x,
|
||||
pos.y,
|
||||
src_rect.width,
|
||||
src_rect.height,
|
||||
};
|
||||
DrawRectangleLinesEx(debug_frame, 0.5f, RED);
|
||||
}
|
||||
#endif
|
||||
D_DrawTextureRec(assets.textures[0], src_rect, pos, WHITE);
|
||||
}
|
||||
}
|
||||
|
||||
@ -218,7 +210,7 @@ void Draw(const GameState *game, Assets assets, Camera2D cam, float dt) {
|
||||
Vector2 marker_pos = game->target_points[0].value.point;
|
||||
marker_pos.x -= assets.textures[3].width / 2;
|
||||
// marker_pos.y -= assets.textures[3].height / 2;
|
||||
DrawTextureV(assets.textures[3], marker_pos, WHITE);
|
||||
D_DrawTextureV(assets.textures[3], marker_pos, WHITE);
|
||||
}
|
||||
|
||||
for (int i = 0; i < game->anim_playbacks_count; i++) {
|
||||
@ -230,17 +222,11 @@ void Draw(const GameState *game, Assets assets, Camera2D cam, float dt) {
|
||||
if (game->knight.look_dir == DIR_LEFT) {
|
||||
src_rect.width = -abs((int)src_rect.width);
|
||||
}
|
||||
Vector2 pos = Vector2Subtract(game->knight.position, knight_origin);
|
||||
DrawTextureRec(assets.textures[1], src_rect, pos, WHITE);
|
||||
#ifdef DEBUG_MODE_ENABLED
|
||||
if (game->debug_mode) {
|
||||
Rectangle debug_frame = {
|
||||
pos.x,
|
||||
pos.y,
|
||||
anim->src_rect.width,
|
||||
anim->src_rect.height,
|
||||
};
|
||||
DrawRectangleLinesEx(debug_frame, 2.0f, RED);
|
||||
// Vector2 pos = Vector2Subtract(game->knight.position, knight_origin);
|
||||
Rectangle dest_rect = {game->knight.position.x, game->knight.position.y, 192, 192};
|
||||
D_DrawTexturePro(assets.textures[1], src_rect, dest_rect, knight_origin, 0.0f, WHITE);
|
||||
|
||||
if (game->selected_knight) {
|
||||
Vector2 kpos = game->knight.position;
|
||||
Rectangle knight_col_area = {
|
||||
kpos.x - knight_colrect_select.width / 2,
|
||||
@ -248,26 +234,14 @@ void Draw(const GameState *game, Assets assets, Camera2D cam, float dt) {
|
||||
knight_colrect_select.width,
|
||||
knight_colrect_select.height,
|
||||
};
|
||||
Color color = game->selected_knight == NULL ? RED : GREEN;
|
||||
DrawRectangleLinesEx(knight_col_area, 2.0f, color);
|
||||
// Color color = game->selected_knight == NULL ? RED : GREEN;
|
||||
DrawRectangleLinesEx(knight_col_area, 2.0f, GREEN);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
Vector2 world = GetScreenToWorld2D(GetMousePosition(), cam);
|
||||
Vector2 pointer_pos = Vector2Subtract(world, (Vector2){24, 19});
|
||||
DrawTextureV(assets.textures[2], pointer_pos, WHITE);
|
||||
#ifdef DEBUG_MODE_ENABLED
|
||||
if (game->debug_mode) {
|
||||
Rectangle debug_frame = {
|
||||
pointer_pos.x,
|
||||
pointer_pos.y,
|
||||
assets.textures[2].width,
|
||||
assets.textures[2].height,
|
||||
};
|
||||
DrawRectangleLinesEx(debug_frame, 2.0f, RED);
|
||||
}
|
||||
#endif
|
||||
D_DrawTextureV(assets.textures[2], pointer_pos, WHITE);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
@ -291,7 +265,6 @@ int main(void) {
|
||||
cam.zoom = 1.0f;
|
||||
|
||||
GameState game = {0};
|
||||
game.debug_mode = true;
|
||||
game.anim_playbacks = malloc(sizeof(SpriteAnimationPlayback) * MAX_ANIMATION_PLAYBACKS);
|
||||
game.anim_playbacks_count = 1;
|
||||
// First one is idle
|
||||
|
Loading…
x
Reference in New Issue
Block a user