diff --git a/assets/house.png b/assets/house.png new file mode 100644 index 0000000..1afc6f0 Binary files /dev/null and b/assets/house.png differ diff --git a/assets/saloon_int.png b/assets/saloon_int.png index 70891a6..d954c0a 100644 Binary files a/assets/saloon_int.png and b/assets/saloon_int.png differ diff --git a/code/first.c b/code/first.c index 2c67567..6272ef7 100644 --- a/code/first.c +++ b/code/first.c @@ -134,7 +134,7 @@ int main(int argc, char **argv) world->player.pos.y = 0; world->player.bulletsLoaded = PLAYER_BULLET_COUNT; world->player.reloadTimer = 0; - world->player.currentArea = 0; + world->player.currentArea = WORLD_AREA_OUTSIDE; for(int i =0; i< 4200; i++) { world->map[i] = map[i]; } @@ -210,10 +210,15 @@ int main(int argc, char **argv) world->propTypes[11].assetHandle=D_ImageHandle(&game->draw, S("saloon_ext")); world->propTypes[11].scale=6.875f; world->propTypes[12].assetHandle=D_ImageHandle(&game->draw, S("saloon_int")); + world->propTypes[12].scale=6.875f; + world->propTypes[11].assetHandle=D_ImageHandle(&game->draw, S("house")); + world->propTypes[11].scale=6.875f; + world->propTypes[12].assetHandle=D_ImageHandle(&game->draw, S("house_int")); world->propTypes[12].scale=6.875f; } game->editor.enabled = true; game->editor.mode = G_EDITOR_MODE_TILE; + game->editor.currentLevel = WORLD_AREA_OUTSIDE; D_Animation animation; @@ -264,9 +269,23 @@ int main(int argc, char **argv) game->world->propCount++; break; } + case G_EDITOR_MODE_HITBOX: { + game->editor.dragStart = game->editor.cursor; + break; + } } + } else if(e.type==SDL_EVENT_MOUSE_BUTTON_UP && e.button.button == SDL_BUTTON_LEFT && game->editor.mode == G_EDITOR_MODE_HITBOX) { + // Add hitbox + V2f topLeft = V2F(Min(game->editor.cursor.x, game->editor.dragStart.x), Min(game->editor.cursor.y, game->editor.dragStart.y)); + game->world->hitboxes[game->world->hitboxCount].pos = topLeft; + game->world->hitboxes[game->world->hitboxCount].size = V2F( + Abs(game->editor.cursor.x-game->editor.dragStart.x), + Abs(game->editor.cursor.y-game->editor.dragStart.y) + ); + game->world->hitboxCount++; } } + if (e.type == SDL_EVENT_KEY_DOWN) { switch(e.key.key) { case SDLK_F10: { @@ -311,6 +330,13 @@ int main(int argc, char **argv) game->editor.mode = (game->editor.mode + 1) % 4; break; } + case SDLK_U: { + switch(game->editor.mode) { + case G_EDITOR_MODE_PROP: {game->world->propCount--;} + case G_EDITOR_MODE_HITBOX: {game->world->hitboxCount--;} + } + break; + } } } } @@ -334,7 +360,7 @@ int main(int argc, char **argv) VkCommandBuffer cmd = frame->cmd; VkClearValue clear_colour; - clear_colour.color.float32[0] = 1.0f; + clear_colour.color.float32[0] = 0.0f; clear_colour.color.float32[1] = 0.0f; clear_colour.color.float32[2] = 0.0f; clear_colour.color.float32[3] = 1.0f; @@ -379,6 +405,10 @@ int main(int argc, char **argv) break; } case G_EDITOR_MODE_HITBOX: { + for(int i = 0; i < game->world->hitboxCount; i++) { + V2f centre = AABB_Centre(game->world->hitboxes[i]); + D_Rect(&game->draw, centre.x, centre.y, .texture=0, .dim=game->world->hitboxes[i].size, .flags=D_RECT_IGNORE_ASPECT); + } break; } case G_EDITOR_MODE_POI: { diff --git a/code/game/core.h b/code/game/core.h index a589c54..028266e 100644 --- a/code/game/core.h +++ b/code/game/core.h @@ -30,6 +30,7 @@ struct G_Editor { S32 currentAsset; G_EDITOR_MODE mode; V2f cursor; + V2f dragStart; }; typedef struct G_State G_State; diff --git a/code/game/impl/world.c b/code/game/impl/world.c index 0385f92..63757c3 100644 --- a/code/game/impl/world.c +++ b/code/game/impl/world.c @@ -37,13 +37,15 @@ void ProcessEvents(SDL_Event *event, World *world) } void RenderWorld(World *world, D_Context *draw) { - for (int i = 0; i < 4800; i++) { - D_Rect( - draw, - (F32) (i % 96), (F32) (i / 96), - .texture = world->tileTypes[world->map[i]].tile, - .angle = (F32) world->tileTypes[world->map[i]].rotation, - ); + if(world->player.currentArea == WORLD_AREA_OUTSIDE) { + for (int i = 0; i < 4800; i++) { + D_Rect( + draw, + (F32) (i % 96), (F32) (i / 96), + .texture = world->tileTypes[world->map[i]].tile, + .angle = (F32) world->tileTypes[world->map[i]].rotation, + ); + } } for (int i = 0; i < world->propCount; i++) { if(world->props[i].area == world->player.currentArea) { diff --git a/code/game/world.h b/code/game/world.h index 9877bd5..a9969a9 100644 --- a/code/game/world.h +++ b/code/game/world.h @@ -50,6 +50,8 @@ struct World { World_PropType propTypes[64]; U32 propCount; World_Prop props[256]; + U32 hitboxCount; + AABB hitboxes[4096]; //// Player Player player;