diff --git a/assets/barrel.png b/assets/barrel.png new file mode 100644 index 0000000..e6c8fcb Binary files /dev/null and b/assets/barrel.png differ diff --git a/assets/can.png b/assets/can.png new file mode 100644 index 0000000..b209036 Binary files /dev/null and b/assets/can.png differ diff --git a/assets/candle.png b/assets/candle.png new file mode 100644 index 0000000..9b39fbc Binary files /dev/null and b/assets/candle.png differ diff --git a/assets/clock.png b/assets/clock.png new file mode 100644 index 0000000..a3c329f Binary files /dev/null and b/assets/clock.png differ diff --git a/assets/house_int.png b/assets/house_int.png new file mode 100644 index 0000000..fde43e2 Binary files /dev/null and b/assets/house_int.png differ diff --git a/assets/log_pile.png b/assets/log_pile.png new file mode 100644 index 0000000..c2bc58e Binary files /dev/null and b/assets/log_pile.png differ diff --git a/assets/nightstand.png b/assets/nightstand.png new file mode 100644 index 0000000..0590361 Binary files /dev/null and b/assets/nightstand.png differ diff --git a/assets/pool_table.png b/assets/pool_table.png new file mode 100644 index 0000000..3da681b Binary files /dev/null and b/assets/pool_table.png differ diff --git a/assets/rug0.png b/assets/rug0.png new file mode 100644 index 0000000..eac7302 Binary files /dev/null and b/assets/rug0.png differ diff --git a/assets/rug1.png b/assets/rug1.png new file mode 100644 index 0000000..2da8398 Binary files /dev/null and b/assets/rug1.png differ diff --git a/assets/saloon_int.png b/assets/saloon_int.png new file mode 100644 index 0000000..70891a6 Binary files /dev/null and b/assets/saloon_int.png differ diff --git a/assets/skull.png b/assets/skull.png new file mode 100644 index 0000000..329c693 Binary files /dev/null and b/assets/skull.png differ diff --git a/assets/table.png b/assets/table.png new file mode 100644 index 0000000..466464c Binary files /dev/null and b/assets/table.png differ diff --git a/code/first.c b/code/first.c index d9fc917..2c67567 100644 --- a/code/first.c +++ b/code/first.c @@ -95,9 +95,10 @@ int main(int argc, char **argv) camera->farp = 1000.0f; game->draw.camera = camera; - World *world = LoadWorld(arena); + World *world = M_ArenaPush(arena, World);//LoadWorld(arena); game->world = world; world->arena = arena; + world->navMesh = &TestNavMesh; world->random = Random_Seed(29237489723847); world->npcCount = 2; for(U32 i = 0; i < world->npcCount; i++) { @@ -134,7 +135,85 @@ int main(int argc, char **argv) world->player.bulletsLoaded = PLAYER_BULLET_COUNT; world->player.reloadTimer = 0; world->player.currentArea = 0; + for(int i =0; i< 4200; i++) { + world->map[i] = map[i]; + } + + world->tileTypes[0].rotation=0; + world->tileTypes[0].collision=false; + world->tileTypes[0].tile=D_ImageHandle(&game->draw, S("tile_dirt_0")); + world->tileTypes[1].rotation=0, + world->tileTypes[1].collision=false, + world->tileTypes[1].tile=D_ImageHandle(&game->draw, S("path_middle")); + world->tileTypes[2].rotation=0; + world->tileTypes[2].collision=false; + world->tileTypes[2].tile=D_ImageHandle(&game->draw, S("path_middle_edge")); + world->tileTypes[3].rotation=PI_F32/2; + world->tileTypes[3].collision=false; + world->tileTypes[3].tile=D_ImageHandle(&game->draw, S("path_middle_edge")); + world->tileTypes[4].rotation=PI_F32; + world->tileTypes[4].collision=false; + world->tileTypes[4].tile=D_ImageHandle(&game->draw, S("path_middle_edge")); + world->tileTypes[5].rotation=-PI_F32/2; + world->tileTypes[5].collision=false; + world->tileTypes[5].tile=D_ImageHandle(&game->draw, S("path_middle_edge")); + world->tileTypes[6].rotation=0; + world->tileTypes[6].collision=false; + world->tileTypes[6].tile=D_ImageHandle(&game->draw, S("path_middle")); + world->tileTypes[7].rotation=PI_F32/2; + world->tileTypes[7].collision=false; + world->tileTypes[7].tile=D_ImageHandle(&game->draw, S("path_middle")); + world->tileTypes[8].rotation=-PI_F32; + world->tileTypes[8].collision=false; + world->tileTypes[8].tile=D_ImageHandle(&game->draw, S("path_middle")); + world->tileTypes[9].rotation=-PI_F32/2; + world->tileTypes[9].collision=false; + world->tileTypes[9].tile=D_ImageHandle(&game->draw, S("path_middle")); + world->tileTypes[10].rotation=0; + world->tileTypes[10].collision=false; + world->tileTypes[10].tile=D_ImageHandle(&game->draw, S("path_corner")); + world->tileTypes[11].rotation=PI_F32/2; + world->tileTypes[11].collision=false; + world->tileTypes[11].tile=D_ImageHandle(&game->draw, S("path_corner")); + world->tileTypes[12].rotation=-PI_F32/2; + world->tileTypes[12].collision=false; + world->tileTypes[12].tile=D_ImageHandle(&game->draw, S("path_corner")); + world->tileTypes[13].rotation=PI_F32; + world->tileTypes[13].collision=false; + world->tileTypes[13].tile=D_ImageHandle(&game->draw, S("path_corner")); + world->tileTypes[14].rotation=0; + world->tileTypes[14].collision=false; + world->tileTypes[14].tile=D_ImageHandle(&game->draw, S("tile_dirt_1")); + + world->propTypes[0].assetHandle=D_ImageHandle(&game->draw, S("rug0")); + world->propTypes[0].scale=1; + world->propTypes[1].assetHandle=D_ImageHandle(&game->draw, S("rug1")); + world->propTypes[1].scale=1; + world->propTypes[2].assetHandle=D_ImageHandle(&game->draw, S("skull")); + world->propTypes[2].scale=1; + world->propTypes[3].assetHandle=D_ImageHandle(&game->draw, S("table")); + world->propTypes[3].scale=1; + world->propTypes[4].assetHandle=D_ImageHandle(&game->draw, S("barrel")); + world->propTypes[4].scale=1; + world->propTypes[5].assetHandle=D_ImageHandle(&game->draw, S("can")); + world->propTypes[5].scale=1; + world->propTypes[6].assetHandle=D_ImageHandle(&game->draw, S("candle")); + world->propTypes[6].scale=1; + world->propTypes[7].assetHandle=D_ImageHandle(&game->draw, S("clock")); + world->propTypes[7].scale=1; + world->propTypes[8].assetHandle=D_ImageHandle(&game->draw, S("log_pile")); + world->propTypes[8].scale=1; + world->propTypes[9].assetHandle=D_ImageHandle(&game->draw, S("nightstand")); + world->propTypes[9].scale=1; + world->propTypes[10].assetHandle=D_ImageHandle(&game->draw, S("pool_table")); + world->propTypes[10].scale=1; + 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; } + game->editor.enabled = true; + game->editor.mode = G_EDITOR_MODE_TILE; D_Animation animation; @@ -164,13 +243,84 @@ int main(int argc, char **argv) V2F((F32) width, (F32) height) )); game->world->mouseProjected = V2F(projection.x, projection.y); - ProcessEvents(&e, game->world); + if(e.type==SDL_EVENT_MOUSE_MOTION) { + game->editor.cursor = V2F(projection.x, projection.y); + } + if (!game->editor.enabled) { + ProcessEvents(&e, game->world); + } else { + if(e.type==SDL_EVENT_MOUSE_BUTTON_DOWN && e.button.button == SDL_BUTTON_LEFT) { + switch(game->editor.mode){ + case G_EDITOR_MODE_TILE: { + F32 tilex = (S32)(game->editor.cursor.x+TILE_SIZE/2); + F32 tiley = (S32)(game->editor.cursor.y+TILE_SIZE/2); + game->world->map[(S32)tilex + (S32)tiley * 96] = game->editor.currentAsset; + break; + } + case G_EDITOR_MODE_PROP: { + game->world->props[game->world->propCount].propType = game->editor.currentAsset; + game->world->props[game->world->propCount].area = game->editor.currentLevel; + game->world->props[game->world->propCount].pos = game->editor.cursor; + game->world->propCount++; + break; + } + } + } + } + if (e.type == SDL_EVENT_KEY_DOWN) { + switch(e.key.key) { + case SDLK_F10: { + game->editor.enabled = !game->editor.enabled; + break; + } + case SDLK_RIGHT: { + game->editor.currentAsset = Min(game->editor.currentAsset+1, 64); + break; + } + case SDLK_LEFT: { + game->editor.currentAsset = Max(game->editor.currentAsset-1, 0); + break; + } + case SDLK_A: { + game->camera.p.x -= 5; + break; + } + case SDLK_D: { + game->camera.p.x += 5; + break; + } + case SDLK_W: { + game->camera.p.y -= 5; + break; + } + case SDLK_S: { + game->camera.p.y += 5; + break; + } + case SDLK_UP: { + game->editor.currentLevel++; + game->world->player.currentArea++; + break; + } + case SDLK_DOWN: { + game->editor.currentLevel--; + game->world->player.currentArea--; + break; + } + case SDLK_SPACE: { + game->editor.mode = (game->editor.mode + 1) % 4; + break; + } + } + } } - UpdateWorld(1.0f / 60.0f, game->world); - D_AnimationUpdate(&animation, 1.0f / 250.0f); - game->camera.p.x = game->world->player.pos.x; - game->camera.p.y = game->world->player.pos.y; + if(!game->editor.enabled) { + UpdateWorld(1.0f / 60.0f, game->world); + game->camera.p.x = game->world->player.pos.x; + game->camera.p.y = game->world->player.pos.y; + } + D_AnimationUpdate(&animation, 1.0f / 250.0f); int w, h; SDL_GetWindowSizeInPixels(window, &w, &h); @@ -208,14 +358,34 @@ int main(int argc, char **argv) D_Begin(&game->draw, frame, D_MAX_RECTS); - //RenderWorld(game->world, &game->draw); -// D_Rect(&game->draw, 0.0f, 0.0f, .texture = D_ImageHandle(&game->draw, S("saloon_ext")), .scale = 4.0f); -// D_Rect(&game->draw, -8.0f, 0.0f, .texture = 2, .scale = 2.0f); -// D_Rect(&game->draw, 6.0f, 0.0f, .texture = 3); + RenderWorld(game->world, &game->draw); R2f aframe = D_AnimationFrame(&animation); D_Rect(&game->draw, 0, 0, .texture = animation.id, .uv = aframe, .flags = D_RECT_UV_ASPECT); + if(game->editor.enabled) { + G_Editor editor = game->editor; + F32 tilex = floor(editor.cursor.x+TILE_SIZE/2); + F32 tiley = floor(editor.cursor.y+TILE_SIZE/2); + switch(game->editor.mode) { + case G_EDITOR_MODE_TILE: { + World_Tile asset = game->world->tileTypes[editor.currentAsset]; + D_Rect(&game->draw, tilex, tiley, .texture=asset.tile, .angle=asset.rotation); + break; + } + case G_EDITOR_MODE_PROP: { + World_PropType prop = game->world->propTypes[editor.currentAsset]; + D_Rect(&game->draw, editor.cursor.x, editor.cursor.y, .texture=prop.assetHandle, .scale=prop.scale); + break; + } + case G_EDITOR_MODE_HITBOX: { + break; + } + case G_EDITOR_MODE_POI: { + break; + } + } + } D_End(&game->draw, frame); vk.CmdEndRendering(cmd); diff --git a/code/game/core.h b/code/game/core.h index 163c71a..a589c54 100644 --- a/code/game/core.h +++ b/code/game/core.h @@ -13,6 +13,25 @@ struct G_Camera { Mat4x4FInv proj; }; +#define TILE_SIZE 1.0 + +typedef enum G_EDITOR_MODE G_EDITOR_MODE; +enum G_EDITOR_MODE { + G_EDITOR_MODE_TILE, + G_EDITOR_MODE_PROP, + G_EDITOR_MODE_HITBOX, + G_EDITOR_MODE_POI, +}; + +typedef struct G_Editor G_Editor; +struct G_Editor { + bool enabled; + U32 currentLevel; + S32 currentAsset; + G_EDITOR_MODE mode; + V2f cursor; +}; + typedef struct G_State G_State; struct G_State { M_Arena *arena; @@ -20,6 +39,7 @@ struct G_State { D_Context draw; G_Camera camera; + G_Editor editor; World *world; }; diff --git a/code/game/impl/world.c b/code/game/impl/world.c index f47525a..0385f92 100644 --- a/code/game/impl/world.c +++ b/code/game/impl/world.c @@ -37,10 +37,24 @@ void ProcessEvents(SDL_Event *event, World *world) } void RenderWorld(World *world, D_Context *draw) { - World_Tile tileTypes[] = {dirt, middlePath, middlePathEdgeTop, middlePathEdgeRight, middlePathEdgeBottom, middlePathEdgeLeft, middlePathCornerTopLeft, middlePathCornerTopRight, middlePathCornerBottomRight, middlePathCornerTurnBottomLeft}; - for (int i = 0; i < 4800; i++) - { - D_Rect(draw, (F32) (i % 96), (F32) (i / 96), .texture = tileTypes[map[i]].tile, .angle = (F32) tileTypes[map[i]].rotation); + 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) { + D_Rect( + draw, + world->props[i].pos.x, + world->props[i].pos.y, + .texture = world->propTypes[world->props[i].propType].assetHandle, + .scale = world->propTypes[world->props[i].propType].scale, + ); + } } for(U32 i = 0; i < world->npcCount; i++) { NPC npc = world->npcs[i]; diff --git a/code/game/map.h b/code/game/map.h index 56efae5..84bd2ee 100644 --- a/code/game/map.h +++ b/code/game/map.h @@ -1,17 +1,6 @@ #include "world.h" - -World_Tile dirt = {.rotation=0,.collision=false,.tile=16};//0 -World_Tile middlePath = {.rotation=0,.collision=false,.tile=6};//1 -World_Tile middlePathEdgeTop = {.rotation=0,.collision=false,.tile=7};//2 -World_Tile middlePathEdgeRight = {.rotation=PI_F32/2,.collision=false,.tile=7};//3 -World_Tile middlePathEdgeBottom = {.rotation=PI_F32,.collision=false,.tile=7};//4 -World_Tile middlePathEdgeLeft = {.rotation=-PI_F32/2,.collision=false,.tile=7};//5 -World_Tile middlePathCornerTopLeft = {.rotation=0,.collision=false,.tile=5};//6 -World_Tile middlePathCornerTopRight = {.rotation=PI_F32/2,.collision=false,.tile=5};//7 -World_Tile middlePathCornerBottomRight = {.rotation=-PI_F32,.collision=false,.tile=5};//8 -World_Tile middlePathCornerTurnBottomLeft = {.rotation=-PI_F32/2,.collision=false,.tile=5};//9 -int map[] = { +U32 map[] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,1,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,1,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,1,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, @@ -62,4 +51,4 @@ int map[] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,1,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,1,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,1,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,1,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,1,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,1,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -}; \ No newline at end of file +}; diff --git a/code/game/world.h b/code/game/world.h index 7720a01..9877bd5 100644 --- a/code/game/world.h +++ b/code/game/world.h @@ -9,20 +9,29 @@ enum World_Area { WORLD_AREA_OUTSIDE = (1 << 0), WORLD_AREA_SALOON = (1 << 1), - WORLD_PATH_MIDDLE_EDGE = (1 << 2), - WORLD_PATH_MIDDLE = (1 << 3), - WORLD_PATH_CORNER = (1 << 4), - WORLD_PATH_CORNER_EDGE = (1 << 5), }; typedef struct World_Tile World_Tile; -struct World_Tile -{ - World_Area tile; +struct World_Tile { + U32 tile; double rotation; bool collision; }; +typedef struct World_PropType World_PropType; +struct World_PropType { + U32 assetHandle; + F32 scale; +}; + +typedef struct World_Prop World_Prop; +struct World_Prop +{ + U32 propType; + World_Area area; + V2f pos; +}; + typedef struct World World; #include "player.h" #include "npc.h" @@ -35,6 +44,12 @@ struct World { NavMesh *navMesh; Random random; V2f mouseProjected; + World_Tile tileTypes[64]; + U32 map[4800]; + + World_PropType propTypes[64]; + U32 propCount; + World_Prop props[256]; //// Player Player player;