implemented angles in sprite rendering, knifes has proper rotation based from direction of player

efd/v1
DavoSK 2023-02-02 18:59:49 +01:00
parent 3a9196d19a
commit c21cb39140
3 changed files with 6 additions and 2 deletions

View File

@ -48,7 +48,7 @@ entity_view* world_build_entity_view(int64_t e) {
view.vx = vel->x;
view.vy = vel->y;
}
const Rotation* rot = ecs_get(world_ecs(), e, Rotation);
if (rot) {
view.angle = rot->angle;

View File

@ -61,7 +61,7 @@ void renderer_draw_entry(uint64_t key, entity_view *data, game_world_render_entr
case EKIND_WEAPON: {
float x = data->x;
float y = data->y;
DrawSpriteEco(&main_sprite_sheet, data->frame, x, y, 0.0f, 2.0f, WHITE);
DrawSpriteEco(&main_sprite_sheet, data->frame, x, y, data->angle, 2.0f, WHITE);
} break;
case EKIND_DEVICE:{
float x = data->x - 32.f;

View File

@ -28,6 +28,10 @@ void WeaponKnifeMechanic(ecs_iter_t *it) {
.origin_x=pos[i].x,
.origin_y=pos[i].y
});
ecs_set(it->world, e, Rotation, {
.angle=zpl_to_degrees(zpl_arctan2(input[i].hx, input[i].hy))
});
ecs_set(it->world, e, Velocity, {
.x=input[i].hx*WEAPON_PROJECTILE_SPEED,