Add cursors

This commit is contained in:
2024-01-28 15:58:20 +01:00
parent d0ad91d5b2
commit 6ee46da8ab
6 changed files with 318 additions and 117 deletions

File diff suppressed because one or more lines are too long

View File

@@ -37,6 +37,8 @@ static OwnerType getOwnerType(BzTileID tile) {
typedef enum TerrainType { typedef enum TerrainType {
TERRAIN_NONE = -1, TERRAIN_NONE = -1,
TERRAIN_GOLD_ORE, TERRAIN_GOLD_ORE,
TERRAIN_WHEAT_0,
TERRAIN_WHEAT_1,
TERRAIN_COUNT, TERRAIN_COUNT,
} TerrainType; } TerrainType;
@@ -792,25 +794,22 @@ static AnimationFrame entityGetAnimationFrame(EntityType entity, AnimType type,
typedef enum ItemType { typedef enum ItemType {
ITEM_NONE = -1, ITEM_NONE = -1,
ITEM_ARROW,
ITEM_AXE, ITEM_AXE,
ITEM_BATTLEAXE, ITEM_BATTLEAXE,
ITEM_BATTLEHAMMER,
ITEM_BOW, ITEM_BOW,
ITEM_CUTLASS, ITEM_CUTLASS,
ITEM_DAGGER, ITEM_DAGGER,
ITEM_FORK,
ITEM_GREATEAXE, ITEM_GREATEAXE,
ITEM_GREATSWORD, ITEM_GREATSWORD,
ITEM_HAMMER,
ITEM_IRON_SHIELD, ITEM_IRON_SHIELD,
ITEM_JAVLIN,
ITEM_MACE,
ITEM_PICKAXE, ITEM_PICKAXE,
ITEM_SHIELD, ITEM_SHIELD,
ITEM_SPEAR, ITEM_SPEAR,
ITEM_STAFF, ITEM_STAFF,
ITEM_SWORD, ITEM_SWORD,
ITEM_SYTHE, ITEM_SYTHE,
ITEM_TRIDENT,
ITEM_WOOD_SHIELD, ITEM_WOOD_SHIELD,
ITEM_COUNT, ITEM_COUNT,
} ItemType; } ItemType;
@@ -825,18 +824,15 @@ static BzTileID getItemTile(ItemType type) {
case ITEM_SHIELD: return 7937; case ITEM_SHIELD: return 7937;
case ITEM_IRON_SHIELD: return 7938; case ITEM_IRON_SHIELD: return 7938;
case ITEM_BOW: return 7939; case ITEM_BOW: return 7939;
case ITEM_JAVLIN: return 7942;
case ITEM_ARROW: return 7943;
case ITEM_SWORD: return 8192; case ITEM_SWORD: return 8192;
case ITEM_GREATSWORD: return 8193; case ITEM_GREATSWORD: return 8193;
case ITEM_CUTLASS: return 8194; case ITEM_CUTLASS: return 8194;
case ITEM_BATTLEAXE: return 8195; case ITEM_BATTLEAXE: return 8195;
case ITEM_GREATEAXE: return 8196; case ITEM_GREATEAXE: return 8196;
case ITEM_SYTHE: return 8197; case ITEM_SYTHE: return 8448;
case ITEM_MACE: return 8198; case ITEM_HAMMER: return 8450;
case ITEM_BATTLEHAMMER: return 8199; case ITEM_SPEAR: return 8451;
case ITEM_SPEAR: return 8200; case ITEM_FORK: return 8452;
case ITEM_TRIDENT: return 8201;
default: return -1; default: return -1;
} }
} }
@@ -1661,6 +1657,10 @@ static bool hasItemHandlePoint(BzTile tile) {
case 8199: case 8199:
case 8200: case 8200:
case 8201: case 8201:
case 8448:
case 8450:
case 8451:
case 8452:
return true; return true;
default: return false; default: return false;
} }
@@ -1686,6 +1686,10 @@ static Vector2 getItemHandlePoint(BzTile tile) {
case 8199: return (Vector2) {5, 11}; case 8199: return (Vector2) {5, 11};
case 8200: return (Vector2) {4, 12}; case 8200: return (Vector2) {4, 12};
case 8201: return (Vector2) {4, 12}; case 8201: return (Vector2) {4, 12};
case 8448: return (Vector2) {6, 9};
case 8450: return (Vector2) {5, 11};
case 8451: return (Vector2) {4, 12};
case 8452: return (Vector2) {4, 12};
default: return (Vector2) {0.0f, 0.0f}; default: return (Vector2) {0.0f, 0.0f};
} }
} }
@@ -1703,6 +1707,8 @@ static bool hasEntityHitBoxRec(BzTile tile) {
case 5891: case 5891:
case 6146: case 6146:
case 6147: case 6147:
case 6400:
case 6401:
case 6402: case 6402:
case 6403: case 6403:
case 6656: case 6656:
@@ -1728,6 +1734,8 @@ static Rectangle getEntityHitBoxRec(BzTile tile) {
case 5891: return (Rectangle) {6, 2, 4, 10}; case 5891: return (Rectangle) {6, 2, 4, 10};
case 6146: return (Rectangle) {6, 2, 4, 10}; case 6146: return (Rectangle) {6, 2, 4, 10};
case 6147: return (Rectangle) {6, 2, 4, 10}; case 6147: return (Rectangle) {6, 2, 4, 10};
case 6400: return (Rectangle) {4, 2, 8, 10};
case 6401: return (Rectangle) {4, 2, 8, 10};
case 6402: return (Rectangle) {6, 2, 4, 10}; case 6402: return (Rectangle) {6, 2, 4, 10};
case 6403: return (Rectangle) {6, 2, 4, 10}; case 6403: return (Rectangle) {6, 2, 4, 10};
case 6656: return (Rectangle) {6, 2, 4, 10}; case 6656: return (Rectangle) {6, 2, 4, 10};

View File

@@ -46,6 +46,8 @@ typedef struct InputState {
CURSOR_NONE, CURSOR_NONE,
CURSOR_COLLECT_WOOD, CURSOR_COLLECT_WOOD,
CURSOR_COLLECT_GOLD, CURSOR_COLLECT_GOLD,
CURSOR_FARM,
CURSOR_ATTACK
} cursor; } cursor;
// INPUT_BUILDING // INPUT_BUILDING

View File

@@ -94,7 +94,7 @@ void inputUnitAction(Game *game, InputState *input) {
input->cursor = CURSOR_COLLECT_GOLD; input->cursor = CURSOR_COLLECT_GOLD;
break; break;
case RES_FOOD: case RES_FOOD:
//input->cursor = CURSOR_COLLECT_FOOD; input->cursor = CURSOR_FARM;
break; break;
default:; default:;
} }
@@ -343,22 +343,37 @@ void drawPlayerInputUI() {
DrawRectangleLines(area.x, area.y, area.width, area.height, RED); DrawRectangleLines(area.x, area.y, area.width, area.height, RED);
} }
Vector2 point = input->mouseWorld;
Rectangle texRect = {0, 0, 0, 0};
switch (input->cursor) { switch (input->cursor) {
case CURSOR_COLLECT_WOOD: { case CURSOR_COLLECT_WOOD:
const Vector2 point = input->mouseWorld; texRect = getTextureRect(getItemTile(ITEM_AXE));
DrawCircle(point.x, point.y, 2.0f, RED);
DrawText("Collect wood", point.x, point.y, 10.0f, RED);
break; break;
} case CURSOR_COLLECT_GOLD:
case CURSOR_COLLECT_GOLD: { texRect = getTextureRect(getItemTile(ITEM_PICKAXE));
const Vector2 point = input->mouseWorld; break;
DrawCircle(point.x, point.y, 2.0f, RED); case CURSOR_FARM:
DrawText("Collect gold", point.x, point.y, 10.0f, RED); texRect = getTextureRect(getItemTile(ITEM_SYTHE));
break;
case CURSOR_ATTACK:
texRect = getTextureRect(getItemTile(ITEM_CUTLASS));
break; break;
}
default: break; default: break;
} }
if (texRect.width != 0 && texRect.height != 0) {
Texture tiles = game->tileset.tiles;
f32 size = 35.0 / game->camera.zoom;
Rectangle dst = {
point.x - size * 0.5f,
point.y - size * 0.5f,
size, size
};
point.y -= texRect.height;
DrawTexturePro(tiles, texRect, dst, Vector2Zero(), 0.0f, WHITE);
}
} }
ecs_entity_t queryEntity(BzSpatialGrid *entityGrid, Vector2 point, ecs_entity_t tag) { ecs_entity_t queryEntity(BzSpatialGrid *entityGrid, Vector2 point, ecs_entity_t tag) {

View File

@@ -7859,21 +7859,69 @@
}, },
{ {
"id":6400, "id":6400,
"objectgroup":
{
"draworder":"index",
"id":2,
"name":"",
"objects":[
{
"height":10,
"id":1,
"name":"hitbox",
"rotation":0,
"type":"",
"visible":true,
"width":8,
"x":4,
"y":4
}],
"opacity":1,
"type":"objectgroup",
"visible":true,
"x":0,
"y":0
},
"properties":[ "properties":[
{ {
"name":"terrain", "name":"terrain",
"type":"string", "type":"string",
"value":"" "value":""
}] }],
"type":"wheat_1"
}, },
{ {
"id":6401, "id":6401,
"objectgroup":
{
"draworder":"index",
"id":2,
"name":"",
"objects":[
{
"height":10,
"id":1,
"name":"hitbox",
"rotation":0,
"type":"",
"visible":true,
"width":8,
"x":4,
"y":4
}],
"opacity":1,
"type":"objectgroup",
"visible":true,
"x":0,
"y":0
},
"properties":[ "properties":[
{ {
"name":"terrain", "name":"terrain",
"type":"string", "type":"string",
"value":"" "value":""
}] }],
"type":"wheat_0"
}, },
{ {
"id":6402, "id":6402,
@@ -9768,24 +9816,16 @@
{ {
"animation":[ "animation":[
{ {
"duration":100, "duration":140,
"tileid":7939 "tileid":7939
}, },
{ {
"duration":180, "duration":140,
"tileid":7940 "tileid":7940
}, },
{ {
"duration":260, "duration":140,
"tileid":7941 "tileid":7684
},
{
"duration":100,
"tileid":7940
},
{
"duration":100,
"tileid":7939
}], }],
"id":7939, "id":7939,
"objectgroup": "objectgroup":
@@ -9837,11 +9877,6 @@
{ {
"id":7941, "id":7941,
"properties":[ "properties":[
{
"name":"item",
"type":"string",
"value":""
},
{ {
"name":"player", "name":"player",
"type":"int", "type":"int",
@@ -9875,17 +9910,11 @@
"y":0 "y":0
}, },
"properties":[ "properties":[
{
"name":"item",
"type":"string",
"value":""
},
{ {
"name":"player", "name":"player",
"type":"int", "type":"int",
"value":1 "value":1
}], }]
"type":"javlin"
}, },
{ {
"id":7943, "id":7943,
@@ -9914,17 +9943,11 @@
"y":0 "y":0
}, },
"properties":[ "properties":[
{
"name":"item",
"type":"string",
"value":""
},
{ {
"name":"player", "name":"player",
"type":"int", "type":"int",
"value":1 "value":1
}], }]
"type":"arrow"
}, },
{ {
"id":7944, "id":7944,
@@ -10330,17 +10353,11 @@
"y":0 "y":0
}, },
"properties":[ "properties":[
{
"name":"item",
"type":"string",
"value":""
},
{ {
"name":"player", "name":"player",
"type":"int", "type":"int",
"value":1 "value":1
}], }]
"type":"sythe"
}, },
{ {
"id":8198, "id":8198,
@@ -10369,17 +10386,11 @@
"y":0 "y":0
}, },
"properties":[ "properties":[
{
"name":"item",
"type":"string",
"value":""
},
{ {
"name":"player", "name":"player",
"type":"int", "type":"int",
"value":1 "value":1
}], }]
"type":"mace"
}, },
{ {
"id":8199, "id":8199,
@@ -10408,17 +10419,11 @@
"y":0 "y":0
}, },
"properties":[ "properties":[
{
"name":"item",
"type":"string",
"value":""
},
{ {
"name":"player", "name":"player",
"type":"int", "type":"int",
"value":1 "value":1
}], }]
"type":"battlehammer"
}, },
{ {
"id":8200, "id":8200,
@@ -10447,17 +10452,11 @@
"y":0 "y":0
}, },
"properties":[ "properties":[
{
"name":"item",
"type":"string",
"value":""
},
{ {
"name":"player", "name":"player",
"type":"int", "type":"int",
"value":1 "value":1
}], }]
"type":"spear"
}, },
{ {
"id":8201, "id":8201,
@@ -10484,14 +10483,7 @@
"visible":true, "visible":true,
"x":0, "x":0,
"y":0 "y":0
}, }
"properties":[
{
"name":"item",
"type":"string",
"value":""
}],
"type":"trident"
}, },
{ {
"id":8206, "id":8206,
@@ -10601,6 +10593,151 @@
"value":1 "value":1
}] }]
}, },
{
"id":8448,
"objectgroup":
{
"draworder":"index",
"id":2,
"name":"",
"objects":[
{
"height":0,
"id":1,
"name":"handle",
"point":true,
"rotation":0,
"type":"",
"visible":true,
"width":0,
"x":6,
"y":9
}],
"opacity":1,
"type":"objectgroup",
"visible":true,
"x":0,
"y":0
},
"properties":[
{
"name":"item",
"type":"string",
"value":""
}],
"type":"sythe"
},
{
"id":8449,
"properties":[
{
"name":"item",
"type":"string",
"value":""
}]
},
{
"id":8450,
"objectgroup":
{
"draworder":"index",
"id":2,
"name":"",
"objects":[
{
"height":0,
"id":1,
"name":"handle",
"point":true,
"rotation":0,
"type":"",
"visible":true,
"width":0,
"x":5,
"y":11
}],
"opacity":1,
"type":"objectgroup",
"visible":true,
"x":0,
"y":0
},
"properties":[
{
"name":"item",
"type":"string",
"value":""
}],
"type":"hammer"
},
{
"id":8451,
"objectgroup":
{
"draworder":"index",
"id":2,
"name":"",
"objects":[
{
"height":0,
"id":1,
"name":"handle",
"point":true,
"rotation":0,
"type":"",
"visible":true,
"width":0,
"x":4,
"y":12
}],
"opacity":1,
"type":"objectgroup",
"visible":true,
"x":0,
"y":0
},
"properties":[
{
"name":"item",
"type":"string",
"value":""
}],
"type":"spear"
},
{
"id":8452,
"objectgroup":
{
"draworder":"index",
"id":2,
"name":"",
"objects":[
{
"height":0,
"id":1,
"name":"handle",
"point":true,
"rotation":0,
"type":"",
"visible":true,
"width":0,
"x":4,
"y":12
}],
"opacity":1,
"type":"objectgroup",
"visible":true,
"x":0,
"y":0
},
"properties":[
{
"name":"item",
"type":"string",
"value":""
}],
"type":"fork"
},
{ {
"id":8453, "id":8453,
"properties":[ "properties":[

View File

@@ -2892,15 +2892,21 @@
<property name="player" type="int" value="0"/> <property name="player" type="int" value="0"/>
</properties> </properties>
</tile> </tile>
<tile id="6400"> <tile id="6400" type="wheat_1">
<properties> <properties>
<property name="terrain" value=""/> <property name="terrain" value=""/>
</properties> </properties>
<objectgroup draworder="index" id="2">
<object id="1" name="hitbox" x="4" y="4" width="8" height="10"/>
</objectgroup>
</tile> </tile>
<tile id="6401"> <tile id="6401" type="wheat_0">
<properties> <properties>
<property name="terrain" value=""/> <property name="terrain" value=""/>
</properties> </properties>
<objectgroup draworder="index" id="2">
<object id="1" name="hitbox" x="4" y="4" width="8" height="10"/>
</objectgroup>
</tile> </tile>
<tile id="6402"> <tile id="6402">
<properties> <properties>
@@ -3670,11 +3676,9 @@
</object> </object>
</objectgroup> </objectgroup>
<animation> <animation>
<frame tileid="7939" duration="100"/> <frame tileid="7939" duration="140"/>
<frame tileid="7940" duration="180"/> <frame tileid="7940" duration="140"/>
<frame tileid="7941" duration="260"/> <frame tileid="7684" duration="140"/>
<frame tileid="7940" duration="100"/>
<frame tileid="7939" duration="100"/>
</animation> </animation>
</tile> </tile>
<tile id="7940"> <tile id="7940">
@@ -3684,13 +3688,11 @@
</tile> </tile>
<tile id="7941"> <tile id="7941">
<properties> <properties>
<property name="item" value=""/>
<property name="player" type="int" value="1"/> <property name="player" type="int" value="1"/>
</properties> </properties>
</tile> </tile>
<tile id="7942" type="javlin"> <tile id="7942">
<properties> <properties>
<property name="item" value=""/>
<property name="player" type="int" value="1"/> <property name="player" type="int" value="1"/>
</properties> </properties>
<objectgroup draworder="index" id="2"> <objectgroup draworder="index" id="2">
@@ -3699,9 +3701,8 @@
</object> </object>
</objectgroup> </objectgroup>
</tile> </tile>
<tile id="7943" type="arrow"> <tile id="7943">
<properties> <properties>
<property name="item" value=""/>
<property name="player" type="int" value="1"/> <property name="player" type="int" value="1"/>
</properties> </properties>
<objectgroup draworder="index" id="2"> <objectgroup draworder="index" id="2">
@@ -3875,9 +3876,8 @@
</object> </object>
</objectgroup> </objectgroup>
</tile> </tile>
<tile id="8197" type="sythe"> <tile id="8197">
<properties> <properties>
<property name="item" value=""/>
<property name="player" type="int" value="1"/> <property name="player" type="int" value="1"/>
</properties> </properties>
<objectgroup draworder="index" id="2"> <objectgroup draworder="index" id="2">
@@ -3886,9 +3886,8 @@
</object> </object>
</objectgroup> </objectgroup>
</tile> </tile>
<tile id="8198" type="mace"> <tile id="8198">
<properties> <properties>
<property name="item" value=""/>
<property name="player" type="int" value="1"/> <property name="player" type="int" value="1"/>
</properties> </properties>
<objectgroup draworder="index" id="2"> <objectgroup draworder="index" id="2">
@@ -3897,9 +3896,8 @@
</object> </object>
</objectgroup> </objectgroup>
</tile> </tile>
<tile id="8199" type="battlehammer"> <tile id="8199">
<properties> <properties>
<property name="item" value=""/>
<property name="player" type="int" value="1"/> <property name="player" type="int" value="1"/>
</properties> </properties>
<objectgroup draworder="index" id="2"> <objectgroup draworder="index" id="2">
@@ -3908,9 +3906,8 @@
</object> </object>
</objectgroup> </objectgroup>
</tile> </tile>
<tile id="8200" type="spear"> <tile id="8200">
<properties> <properties>
<property name="item" value=""/>
<property name="player" type="int" value="1"/> <property name="player" type="int" value="1"/>
</properties> </properties>
<objectgroup draworder="index" id="2"> <objectgroup draworder="index" id="2">
@@ -3919,10 +3916,7 @@
</object> </object>
</objectgroup> </objectgroup>
</tile> </tile>
<tile id="8201" type="trident"> <tile id="8201">
<properties>
<property name="item" value=""/>
</properties>
<objectgroup draworder="index" id="2"> <objectgroup draworder="index" id="2">
<object id="1" name="handle" x="4" y="12"> <object id="1" name="handle" x="4" y="12">
<point/> <point/>
@@ -3989,6 +3983,51 @@
<property name="player" type="int" value="1"/> <property name="player" type="int" value="1"/>
</properties> </properties>
</tile> </tile>
<tile id="8448" type="sythe">
<properties>
<property name="item" value=""/>
</properties>
<objectgroup draworder="index" id="2">
<object id="1" name="handle" x="6" y="9">
<point/>
</object>
</objectgroup>
</tile>
<tile id="8449">
<properties>
<property name="item" value=""/>
</properties>
</tile>
<tile id="8450" type="hammer">
<properties>
<property name="item" value=""/>
</properties>
<objectgroup draworder="index" id="2">
<object id="1" name="handle" x="5" y="11">
<point/>
</object>
</objectgroup>
</tile>
<tile id="8451" type="spear">
<properties>
<property name="item" value=""/>
</properties>
<objectgroup draworder="index" id="2">
<object id="1" name="handle" x="4" y="12">
<point/>
</object>
</objectgroup>
</tile>
<tile id="8452" type="fork">
<properties>
<property name="item" value=""/>
</properties>
<objectgroup draworder="index" id="2">
<object id="1" name="handle" x="4" y="12">
<point/>
</object>
</objectgroup>
</tile>
<tile id="8453"> <tile id="8453">
<properties> <properties>
<property name="player" type="int" value="1"/> <property name="player" type="int" value="1"/>