Add input logic for building

This commit is contained in:
2023-11-22 09:56:20 +01:00
parent 433b012715
commit 783db8ba90
4 changed files with 214 additions and 72 deletions

View File

@@ -4,12 +4,34 @@
#include <breeze.h>
#include <flecs.h>
typedef enum InputState {
typedef enum InputType {
INPUT_NONE,
INPUT_PLACING,
INPUT_DRAGGING,
INPUT_BUILDING,
INPUT_SELECTED_UNITS,
INPUT_SELECTED_OBJECT,
INPUT_SELECTED_BUILDING,
} InputType;
typedef struct InputState {
InputType state;
// Input mapping
MouseButton LMB;
MouseButton RMB;
MouseButton MMB;
KeyboardKey ESC;
f32 DRAG_LIMIT;
// Common
Vector2 mouseDown;
Vector2 mouseDownWorld;
f32 mouseDownElapsed;
// INPUT_BUILDING
int building;
bool buildingCanPlace;
TilePosition buildingPos;
TileSize buildingSize;
// SELECTED_UNITS
// SELECTED_OBJECTS
// SELECTED_BUILDING
} InputState;
typedef struct Game {
@@ -21,15 +43,7 @@ typedef struct Game {
BzSpatialGrid *entityGrid;
f32 frameDuration;
ecs_entity_t entity;
struct {
InputState state;
int building;
bool buildingCanPlace;
TilePosition buildingPos;
TileSize buildingSize;
Vector2 mouseDown;
f32 mouseDownElapsed;
} input;
InputState input;
struct {
i64 wood;
i64 iron;