Ran clang-format

This commit is contained in:
mibi88 2024-08-02 18:29:56 +02:00
parent fe824d7340
commit a27ad9a14f
2 changed files with 68 additions and 73 deletions

View file

@ -169,39 +169,39 @@ void game_get_inputs(Game *game) {
} else if(game->inventory.open) { } else if(game->inventory.open) {
if(keydown(KEY_LEFT)) if(keydown(KEY_LEFT))
inventory_move_selection(&game->inventory, D_LEFT); inventory_move_selection(&game->inventory, D_LEFT);
/* TODO: Make something cleaner */ /* TODO: Make something cleaner */
while(keydown(KEY_LEFT)) { while(keydown(KEY_LEFT)) {
clearevents(); clearevents();
sleep(); sleep();
} }
if(keydown(KEY_RIGHT)) if(keydown(KEY_RIGHT))
inventory_move_selection(&game->inventory, D_RIGHT); inventory_move_selection(&game->inventory, D_RIGHT);
/* TODO: Make something cleaner */ /* TODO: Make something cleaner */
while(keydown(KEY_RIGHT)) { while(keydown(KEY_RIGHT)) {
clearevents(); clearevents();
sleep(); sleep();
} }
if(keydown(KEY_UP)) if(keydown(KEY_UP))
inventory_move_selection(&game->inventory, D_UP); inventory_move_selection(&game->inventory, D_UP);
/* TODO: Make something cleaner */ /* TODO: Make something cleaner */
while(keydown(KEY_UP)) { while(keydown(KEY_UP)) {
clearevents(); clearevents();
sleep(); sleep();
} }
if(keydown(KEY_DOWN)) if(keydown(KEY_DOWN))
inventory_move_selection(&game->inventory, D_DOWN); inventory_move_selection(&game->inventory, D_DOWN);
/* TODO: Make something cleaner */ /* TODO: Make something cleaner */
while(keydown(KEY_DOWN)) { while(keydown(KEY_DOWN)) {
clearevents(); clearevents();
sleep(); sleep();
} }
if(keydown(KEY_OPTN)) if(keydown(KEY_OPTN))
inventory_move_from_selected(&game->inventory); inventory_move_from_selected(&game->inventory);
/* TODO: Make something cleaner */ /* TODO: Make something cleaner */
while(keydown(KEY_OPTN)) { while(keydown(KEY_OPTN)) {
clearevents(); clearevents();
sleep(); sleep();
} }
if(keydown(KEY_SQUARE)) { if(keydown(KEY_SQUARE)) {
inventory_use(&game->inventory, &game->player); inventory_use(&game->inventory, &game->player);
} }

View file

@ -10,20 +10,13 @@ extern bopti_image_t selected_img;
extern bopti_image_t player_male_inv_img; extern bopti_image_t player_male_inv_img;
extern bopti_image_t player_female_inv_img; extern bopti_image_t player_female_inv_img;
char item_types[I_AMOUNT] = { char item_types[I_AMOUNT] = {IT_NONE, IT_ARMOR, IT_WEAPON, IT_WEAPON,
IT_NONE, IT_FOOD, IT_FOOD, IT_TALISMAN};
IT_ARMOR,
IT_WEAPON,
IT_WEAPON,
IT_FOOD,
IT_FOOD,
IT_TALISMAN
};
void inventory_init(Inventory *inventory) { void inventory_init(Inventory *inventory) {
inventory->open = 0; inventory->open = 0;
memset(inventory->slots, 0, sizeof(Slot)*SLOT_NUM); memset(inventory->slots, 0, sizeof(Slot) * SLOT_NUM);
memset(inventory->equipped, 0, sizeof(Slot)*3); memset(inventory->equipped, 0, sizeof(Slot) * 3);
inventory->selected = -1; inventory->selected = -1;
inventory->selection = 0; inventory->selection = 0;
} }
@ -37,12 +30,12 @@ void inventory_draw(Inventory *inventory, Player *player) {
SLOT_Y + (i / SLOT_COLUMNS) * SLOT_SPACING, &items_img, SLOT_Y + (i / SLOT_COLUMNS) * SLOT_SPACING, &items_img,
inventory->slots[i].i * SLOT_W, 0, SLOT_W, SLOT_H, inventory->slots[i].i * SLOT_W, 0, SLOT_W, SLOT_H,
DIMAGE_NONE); DIMAGE_NONE);
if(i == inventory->selection){ if(i == inventory->selection) {
dimage(SLOT_X + (i % SLOT_COLUMNS) * SLOT_SPACING, dimage(SLOT_X + (i % SLOT_COLUMNS) * SLOT_SPACING,
SLOT_Y + (i / SLOT_COLUMNS) * SLOT_SPACING, SLOT_Y + (i / SLOT_COLUMNS) * SLOT_SPACING,
&selection_img); &selection_img);
} }
if(i == inventory->selected){ if(i == inventory->selected) {
dimage(SLOT_X + (i % SLOT_COLUMNS) * SLOT_SPACING, dimage(SLOT_X + (i % SLOT_COLUMNS) * SLOT_SPACING,
SLOT_Y + (i / SLOT_COLUMNS) * SLOT_SPACING, SLOT_Y + (i / SLOT_COLUMNS) * SLOT_SPACING,
&selected_img); &selected_img);
@ -75,7 +68,8 @@ char inventory_add(Inventory *inventory, Item item) {
} }
void inventory_move_from_selected(Inventory *inventory) { void inventory_move_from_selected(Inventory *inventory) {
if(inventory->selected < 0) return; if(inventory->selected < 0)
return;
Slot current = inventory->slots[inventory->selection]; Slot current = inventory->slots[inventory->selection];
Slot new = inventory->slots[inventory->selected]; Slot new = inventory->slots[inventory->selected];
inventory->slots[inventory->selection] = new; inventory->slots[inventory->selection] = new;
@ -84,46 +78,47 @@ void inventory_move_from_selected(Inventory *inventory) {
void inventory_use(Inventory *inventory, Player *player) { void inventory_use(Inventory *inventory, Player *player) {
Item item = inventory->slots[inventory->selection].i; Item item = inventory->slots[inventory->selection].i;
switch(item_types[item]){ switch(item_types[item]) {
case IT_TALISMAN: case IT_TALISMAN:
inventory->equipped[0] = inventory->slots[inventory->selection]; inventory->equipped[0] = inventory->slots[inventory->selection];
break; break;
case IT_ARMOR: case IT_ARMOR:
inventory->equipped[1] = inventory->slots[inventory->selection]; inventory->equipped[1] = inventory->slots[inventory->selection];
break; break;
case IT_WEAPON: case IT_WEAPON:
inventory->equipped[2] = inventory->slots[inventory->selection]; inventory->equipped[2] = inventory->slots[inventory->selection];
break; break;
case IT_FOOD: case IT_FOOD:
/* TODO */ /* TODO */
break; break;
default: default:
break; break;
} }
inventory->slots[inventory->selection].i = I_NONE; inventory->slots[inventory->selection].i = I_NONE;
inventory->slots[inventory->selection].durability = 255; inventory->slots[inventory->selection].durability = 255;
} }
void inventory_unequip(Inventory *inventory, ItemType type) { void inventory_unequip(Inventory *inventory, ItemType type) {
if(inventory->slots[inventory->selection].i) return; if(inventory->slots[inventory->selection].i)
switch(type){ return;
case IT_TALISMAN: switch(type) {
inventory->slots[inventory->selection] = inventory->equipped[0]; case IT_TALISMAN:
inventory->equipped[0].i = I_NONE; inventory->slots[inventory->selection] = inventory->equipped[0];
inventory->equipped[0].durability = 255; inventory->equipped[0].i = I_NONE;
break; inventory->equipped[0].durability = 255;
case IT_ARMOR: break;
inventory->slots[inventory->selection] = inventory->equipped[1]; case IT_ARMOR:
inventory->equipped[1].i = I_NONE; inventory->slots[inventory->selection] = inventory->equipped[1];
inventory->equipped[1].durability = 255; inventory->equipped[1].i = I_NONE;
break; inventory->equipped[1].durability = 255;
case IT_WEAPON: break;
inventory->slots[inventory->selection] = inventory->equipped[2]; case IT_WEAPON:
inventory->equipped[2].i = I_NONE; inventory->slots[inventory->selection] = inventory->equipped[2];
inventory->equipped[2].durability = 255; inventory->equipped[2].i = I_NONE;
break; inventory->equipped[2].durability = 255;
default: break;
break; default:
break;
} }
} }