feat: Hitbox drawing
This commit is contained in:
BIN
assets/house.png
Normal file
BIN
assets/house.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.3 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 7.1 KiB After Width: | Height: | Size: 8.2 KiB |
34
code/first.c
34
code/first.c
@@ -134,7 +134,7 @@ int main(int argc, char **argv)
|
|||||||
world->player.pos.y = 0;
|
world->player.pos.y = 0;
|
||||||
world->player.bulletsLoaded = PLAYER_BULLET_COUNT;
|
world->player.bulletsLoaded = PLAYER_BULLET_COUNT;
|
||||||
world->player.reloadTimer = 0;
|
world->player.reloadTimer = 0;
|
||||||
world->player.currentArea = 0;
|
world->player.currentArea = WORLD_AREA_OUTSIDE;
|
||||||
for(int i =0; i< 4200; i++) {
|
for(int i =0; i< 4200; i++) {
|
||||||
world->map[i] = map[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].assetHandle=D_ImageHandle(&game->draw, S("saloon_ext"));
|
||||||
world->propTypes[11].scale=6.875f;
|
world->propTypes[11].scale=6.875f;
|
||||||
world->propTypes[12].assetHandle=D_ImageHandle(&game->draw, S("saloon_int"));
|
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;
|
world->propTypes[12].scale=6.875f;
|
||||||
}
|
}
|
||||||
game->editor.enabled = true;
|
game->editor.enabled = true;
|
||||||
game->editor.mode = G_EDITOR_MODE_TILE;
|
game->editor.mode = G_EDITOR_MODE_TILE;
|
||||||
|
game->editor.currentLevel = WORLD_AREA_OUTSIDE;
|
||||||
|
|
||||||
|
|
||||||
D_Animation animation;
|
D_Animation animation;
|
||||||
@@ -264,9 +269,23 @@ int main(int argc, char **argv)
|
|||||||
game->world->propCount++;
|
game->world->propCount++;
|
||||||
break;
|
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) {
|
if (e.type == SDL_EVENT_KEY_DOWN) {
|
||||||
switch(e.key.key) {
|
switch(e.key.key) {
|
||||||
case SDLK_F10: {
|
case SDLK_F10: {
|
||||||
@@ -311,6 +330,13 @@ int main(int argc, char **argv)
|
|||||||
game->editor.mode = (game->editor.mode + 1) % 4;
|
game->editor.mode = (game->editor.mode + 1) % 4;
|
||||||
break;
|
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;
|
VkCommandBuffer cmd = frame->cmd;
|
||||||
|
|
||||||
VkClearValue clear_colour;
|
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[1] = 0.0f;
|
||||||
clear_colour.color.float32[2] = 0.0f;
|
clear_colour.color.float32[2] = 0.0f;
|
||||||
clear_colour.color.float32[3] = 1.0f;
|
clear_colour.color.float32[3] = 1.0f;
|
||||||
@@ -379,6 +405,10 @@ int main(int argc, char **argv)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case G_EDITOR_MODE_HITBOX: {
|
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;
|
break;
|
||||||
}
|
}
|
||||||
case G_EDITOR_MODE_POI: {
|
case G_EDITOR_MODE_POI: {
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ struct G_Editor {
|
|||||||
S32 currentAsset;
|
S32 currentAsset;
|
||||||
G_EDITOR_MODE mode;
|
G_EDITOR_MODE mode;
|
||||||
V2f cursor;
|
V2f cursor;
|
||||||
|
V2f dragStart;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct G_State G_State;
|
typedef struct G_State G_State;
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ void ProcessEvents(SDL_Event *event, World *world)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void RenderWorld(World *world, D_Context *draw) {
|
void RenderWorld(World *world, D_Context *draw) {
|
||||||
|
if(world->player.currentArea == WORLD_AREA_OUTSIDE) {
|
||||||
for (int i = 0; i < 4800; i++) {
|
for (int i = 0; i < 4800; i++) {
|
||||||
D_Rect(
|
D_Rect(
|
||||||
draw,
|
draw,
|
||||||
@@ -45,6 +46,7 @@ void RenderWorld(World *world, D_Context *draw) {
|
|||||||
.angle = (F32) world->tileTypes[world->map[i]].rotation,
|
.angle = (F32) world->tileTypes[world->map[i]].rotation,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
for (int i = 0; i < world->propCount; i++) {
|
for (int i = 0; i < world->propCount; i++) {
|
||||||
if(world->props[i].area == world->player.currentArea) {
|
if(world->props[i].area == world->player.currentArea) {
|
||||||
D_Rect(
|
D_Rect(
|
||||||
|
|||||||
@@ -50,6 +50,8 @@ struct World {
|
|||||||
World_PropType propTypes[64];
|
World_PropType propTypes[64];
|
||||||
U32 propCount;
|
U32 propCount;
|
||||||
World_Prop props[256];
|
World_Prop props[256];
|
||||||
|
U32 hitboxCount;
|
||||||
|
AABB hitboxes[4096];
|
||||||
|
|
||||||
//// Player
|
//// Player
|
||||||
Player player;
|
Player player;
|
||||||
|
|||||||
Reference in New Issue
Block a user