Add weapons

This commit is contained in:
2024-01-06 19:54:22 +01:00
parent dbc0ce5981
commit f667614cfe
398 changed files with 1209 additions and 66 deletions

View File

@@ -313,6 +313,7 @@ static void renderGame(Game *game, float dt) {
// Entities
bzArrayClear(game->drawData);
ecs_iter_t it = ecs_query_iter(ECS, game->drawQuery);
ecs_entity_t worker = 0;
while (ecs_iter_next(&it)) {
Position *p = ecs_field(&it, Position, 1);
Size *s = ecs_field(&it, Size, 2);
@@ -320,6 +321,9 @@ static void renderGame(Game *game, float dt) {
TextureRegion *t = ecs_field(&it, TextureRegion, 4);
for (i32 i = 0; i < it.count; i++) {
Rectangle dst = {p[i].x, p[i].y, s[i].x, s[i].y};
if (dst.width == 10 && dst.height == 10) {
worker = it.entities[i];
}
Vector2 origin = {dst.width * 0.5f, dst.height};
dst.x += origin.x - dst.width * 0.5f;
dst.y += origin.y - dst.height * 0.5f;
@@ -327,8 +331,8 @@ static void renderGame(Game *game, float dt) {
// Fixes texture bleeding issue
src.x += 0.01f;
src.y += 0.01f;
src.width -= 0.01f;
src.height -= 0.01f;
src.width -= 0.02f;
src.height -= 0.02f;
if (t[i].flipX) src.width *= -1.0f;
if (t[i].flipY) src.height *= -1.0f;
bzArrayPush(game->drawData, (DrawData) {
@@ -346,6 +350,32 @@ static void renderGame(Game *game, float dt) {
DrawData draw = game->drawData[i];
DrawTexturePro(draw.tex, draw.src, draw.dst, draw.origin, draw.rotation, WHITE);
}
Vector2 target = GetMousePosition();
target = GetScreenToWorld2D(target, game->camera);
static f32 elapsed = 0;
static bool attack = false;
static Vector2 lockedTarget;
if (!attack && IsMouseButtonPressed(0)) {
attack = true;
lockedTarget = target;
elapsed = 0;
}
elapsed += dt * 2;
elapsed = Clamp(elapsed, 0, 1.0f);
attack = false;
if (worker && false) {
Position *pos = ecs_get_mut(ECS, worker, Position);
DrawCircle(pos->x, pos->y, 2.0f, BLUE);
Vector2 attackVector = Vector2Subtract(lockedTarget, *pos);
attackVector = Vector2Normalize(attackVector);
attackVector = Vector2Scale(attackVector, 2.0f);
DrawLine(pos->x, pos->y, pos->x + attackVector.x, pos->y + attackVector.y, RED);
Rotation *rot = ecs_get_mut(ECS, worker, Rotation);
f32 targetRot = Vector2Angle(*pos, lockedTarget);
targetRot += 25 * DEG2RAD;
*rot = targetRot * bzEase(BZ_EASE_IN_BACK, elapsed);
bzLogInfo("%.2f", Vector2Angle(*pos, lockedTarget) * RAD2DEG);
}
ecs_progress(ECS, dt);
ecs_enable(ECS, renderDebugPathSystem, game->debugDraw.path);