Start atlas
This commit is contained in:
@@ -26,7 +26,7 @@ SDL_Rect targetItemRect;
|
||||
SDL_Color healthBarColor = {0, 240, 0, 255};
|
||||
SDL_Color breakingBarColor = {128, 128, 0, 255};
|
||||
|
||||
void setActivePlayerSlot(Player *plr, uint16_t activeSlotIndex) {
|
||||
void setActivePlayerSlot(Player *plr, ItemType activeSlotIndex) {
|
||||
activeSlotIndex = activeSlotIndex % itemRegistryIndex;
|
||||
if (activeSlotIndex <= 0) {
|
||||
activeSlotIndex = 1;
|
||||
@@ -35,35 +35,30 @@ void setActivePlayerSlot(Player *plr, uint16_t activeSlotIndex) {
|
||||
}
|
||||
|
||||
void moveActivePlayerSlot(Player *plr, bool up, bool seek) {
|
||||
if (seek) {
|
||||
uint16_t prevSlot = plr->inventory.activeSlotIndex;
|
||||
uint16_t newSlot = prevSlot;
|
||||
ItemType prevSlot = plr->inventory.activeSlotIndex;
|
||||
ItemType newSlot = prevSlot;
|
||||
|
||||
do {
|
||||
newSlot = (newSlot + (up ? 1 : ITEMREGISTRY_SIZE - 1)) % ITEMREGISTRY_SIZE;
|
||||
do {
|
||||
newSlot = (newSlot + (up ? 1 : ITEMREGISTRY_SIZE - 1)) % ITEMREGISTRY_SIZE;
|
||||
|
||||
// Stop if we've looped all the way around
|
||||
if (newSlot == prevSlot) break;
|
||||
// Stop if we've looped all the way around
|
||||
if (newSlot == prevSlot) break;
|
||||
|
||||
// Stop if we found a slot with count > 0
|
||||
if (plr->inventory.slotCounts[newSlot] > 0 && newSlot != 0) break;
|
||||
} while (true);
|
||||
plr->inventory.activeSlotIndex = newSlot;
|
||||
} else {
|
||||
if (plr->inventory.activeSlotIndex == 1 && !up) {
|
||||
plr->inventory.activeSlotIndex = itemRegistryIndex - 1;
|
||||
} else if (plr->inventory.activeSlotIndex == itemRegistryIndex - 1 && up) {
|
||||
plr->inventory.activeSlotIndex = 1;
|
||||
// Stop if we found a slot with count > 0
|
||||
if (!strlen(ItemRegistry[newSlot].name)) continue;
|
||||
if (newSlot == 0) continue;
|
||||
if (seek) {
|
||||
if (plr->inventory.slotCounts[newSlot] > 0) break;
|
||||
} else {
|
||||
plr->inventory.activeSlotIndex =
|
||||
(plr->inventory.activeSlotIndex + (up ? 1 : ITEMREGISTRY_SIZE - 1)) % ITEMREGISTRY_SIZE;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
} while (true);
|
||||
plr->inventory.activeSlotIndex = newSlot;
|
||||
|
||||
}
|
||||
|
||||
void adjustRect(SDL_Rect *rect, SDL_Rect playerRect) {
|
||||
inline void adjustRect(SDL_Rect *rect, SDL_Rect playerRect) {
|
||||
rect->x -= playerRect.x;
|
||||
rect->y -= playerRect.y;
|
||||
rect->x += DISPLAY_WIDTH / 2;
|
||||
@@ -117,7 +112,11 @@ void initPlayer(Player *plr) {
|
||||
plr->rect.w = TILE_SIZE;
|
||||
plr->rect.h = TILE_SIZE;
|
||||
|
||||
for (uint16_t ui = 0; ui < itemRegistryIndex; ui++) {
|
||||
for (ItemType ui = 0; ui < tileTypeIndex; ui++) {
|
||||
plr->inventory.slotCounts[ui] = 64;
|
||||
}
|
||||
|
||||
for (ItemType ui = ITEMREGISTRY_SIZE / 2; ui < itemRegistryIndex; ui++) {
|
||||
plr->inventory.slotCounts[ui] = 64;
|
||||
}
|
||||
|
||||
@@ -172,7 +171,7 @@ void renderPlayer(Player *plr) {
|
||||
SDL_SetRenderDrawColor(mainRenderer, plr->cursor.canReach ? 0 : 255, plr->cursor.canReach ? 255 : 0, 0, 128);
|
||||
DrawThickRect(mainRenderer, plr->cursor.targetTileRect, 4);
|
||||
|
||||
uint16_t itemIndex = plr->inventory.activeSlotIndex;
|
||||
ItemType itemIndex = plr->inventory.activeSlotIndex;
|
||||
SDL_Texture *itemTex;
|
||||
char itemStringCount[6];
|
||||
if (itemIndex < itemRegistryIndex) {
|
||||
@@ -205,8 +204,12 @@ void renderPlayer(Player *plr) {
|
||||
renderBar(mainRenderer, (DISPLAY_WIDTH / 2) - 128, DISPLAY_HEIGHT - 50, 200, 8, playerMaxHealth, plr->health,
|
||||
healthBarColor, 4);
|
||||
|
||||
renderBar(mainRenderer, (DISPLAY_WIDTH / 2) - 128, DISPLAY_HEIGHT - 70, 200, 8,
|
||||
getBreakTime(plr->cursor.targetTile->type), plr->cursor.breakingProgress, breakingBarColor, 4);
|
||||
if (plr->cursor.targetTile) {
|
||||
uint16_t tempko = getBreakTime(plr->cursor.targetTile->type);
|
||||
uint16_t tempko2 = plr->cursor.breakingProgress;
|
||||
renderBar(mainRenderer, (DISPLAY_WIDTH / 2) - 128, DISPLAY_HEIGHT - 70, 200, 8,
|
||||
tempko, tempko2, breakingBarColor, 4);
|
||||
}
|
||||
|
||||
|
||||
SDL_SetRenderDrawColor(mainRenderer, 0, 0, 0, 255);
|
||||
@@ -215,7 +218,7 @@ void renderPlayer(Player *plr) {
|
||||
targetItemRect.y = DISPLAY_HEIGHT - 30 + TILE_SIZE / 4 + 3;
|
||||
targetItemRect.x = TILE_SIZE / 4;
|
||||
|
||||
for (uint16_t i = 1; i < itemRegistryIndex; i++) {
|
||||
for (ItemType i = 1; i < ITEMREGISTRY_SIZE; i++) {
|
||||
itemTex = ItemRegistry[i].textureOnBelt[plr->cursor.direction];
|
||||
if (itemTex == NULL) {
|
||||
itemTex = ItemRegistry[i].textureOnBelt[ORIENT_LEFT];
|
||||
@@ -228,17 +231,17 @@ void renderPlayer(Player *plr) {
|
||||
SDL_RenderCopy(mainRenderer, itemTex, NULL, &targetItemRect);
|
||||
SDL_SetTextureColorMod(itemTex, 255, 255, 255);
|
||||
|
||||
if (plr->inventory.activeSlotIndex == i) {
|
||||
SDL_SetRenderDrawColor(mainRenderer, 16, plr->inventory.slotCounts[i] > 0 ? 128 : 16,
|
||||
plr->inventory.slotCounts[i] > 0 ? 32 : 128, 255);
|
||||
DrawThickRect(mainRenderer, targetItemRect, 4);
|
||||
}
|
||||
sprintf(itemStringCount, "%d", plr->inventory.slotCounts[i]);
|
||||
renderText(mainRenderer, fonts[2], itemStringCount, targetItemRect.x - 3,
|
||||
targetItemRect.y - (fonts[2].size * 3 / 2));
|
||||
//targetItemRect.x += (TILE_SIZE / 2) + (TILE_SIZE / 4);
|
||||
targetItemRect.x += TILE_SIZE;
|
||||
}
|
||||
if (plr->inventory.activeSlotIndex == i) {
|
||||
SDL_SetRenderDrawColor(mainRenderer, 16, plr->inventory.slotCounts[i] > 0 ? 128 : 16,
|
||||
plr->inventory.slotCounts[i] > 0 ? 32 : 128, 255);
|
||||
DrawThickRect(mainRenderer, targetItemRect, 4);
|
||||
}
|
||||
sprintf(itemStringCount, "%d", plr->inventory.slotCounts[i]);
|
||||
renderText(mainRenderer, fonts[2], itemStringCount, targetItemRect.x - 3,
|
||||
targetItemRect.y - (fonts[2].size * 3 / 2));
|
||||
//targetItemRect.x += (TILE_SIZE / 2) + (TILE_SIZE / 4);
|
||||
targetItemRect.x += TILE_SIZE;
|
||||
}
|
||||
|
||||
SDL_SetRenderTarget(mainRenderer, originalTarget);
|
||||
|
Reference in New Issue
Block a user