void DrawBuySellScreen(vector<CItem> *pItemList) { // This function takes in a inventory list. This could either // be the shop keeper's inventory (for buying) or the player's // inventory (for selling). This way we cut down on code, since // we will use most of the same code for buying or selling. char szItem[25] = {0}; // Reset the menu's data to start a new menu g_Shop.ResetButtons(); g_Shop.ResetEscapeFlag(); g_Shop.ResetMenuChoice(); // Draw the map screen again and then draw the inventory menu's dialog boxes g_Map.Draw(); g_Shop.DrawBox(kEqMenuWidth, kEqMenuHeight, kEqMenuX, kEqMenuY); g_Shop.DrawBox(kInvMenuWidth, kInvMenuHeight, kInvMenuX, kInvMenuY); g_Shop.DrawBox(kStatsMenuWidth, kStatsMenuHeight, kStatsMenuX, kStatsMenuY); // Draw the item stats in the bottom dialog box (initially nothing) DrawItemStats(); // Now we want to go through all the items in the inventory list passed in // and draw them to the screen in a formatted way, just like in a normal // inventory screen. for(int i = 0; i < (int)pItemList->size(); i++) { // Get the current item in the list (make sure to dereference the list to access it) CItem *pInvItem = &((*pItemList)[i]); // Initially we have these offsets for the item, but will change for different columns int xOffset = kTileWidth, yOffset = kTileHeight + i * kFontHeight; // Here we check if we need to move to another column for displaying the items if(i >= kMaxItemHeight) { // Set a new offset to create a new column for the next items xOffset += (kMaxItemWidth * (i / kMaxItemHeight)) * kTileWidth; yOffset = (i - ((i/kMaxItemHeight) * kMaxItemHeight)) * kFontHeight + kTileHeight; } // Here we store the retail price for the items in the list int salePrice = CalculateItemPrice(pInvItem, true); // If we are buying, we want to display the cost of the item next to it if(g_Shop.IsBuying()) sprintf(szItem, "%s - $%d", pInvItem->GetItemName(), salePrice); else sprintf(szItem, "%s", pInvItem->GetItemName()); // Draw the item to the screen as a button so the user can click on it to choose it g_Shop.DrawString(szItem, (int)strlen(szItem), kInvMenuX + xOffset, kInvMenuY + yOffset, pInvItem); } g_Buffer.SwapBackBuffer(FALSE); }
void DrawBuySellScreen(vector<CItem> *pItemList) { char szItem[25] = {0}; // Reset the menu's data to start a new menu g_Shop.ResetButtons(); g_Shop.ResetEscapeFlag(); g_Shop.ResetMenuChoice(); g_Shop.ResetItemChoice(); // Draw the map screen again and then draw the inventory menu's dialog boxes g_Map.Draw(); g_Shop.DrawBox(kEqMenuWidth, kEqMenuHeight, kEqMenuX, kEqMenuY); g_Shop.DrawBox(kInvMenuWidth, kInvMenuHeight, kInvMenuX, kInvMenuY); g_Shop.DrawBox(kStatsMenuWidth, kStatsMenuHeight, kStatsMenuX, kStatsMenuY); // Draw the item stats in the bottom dialog box (initially nothing) DrawItemStats(); // Go through all of the items and display them for(int i = 0; i < (int)pItemList->size(); i++) { // Get the current item in the list (make sure to dereference the list to access it) CItem *pInvItem = &((*pItemList)[i]); // Initially we have these offsets for the item, but will change for different columns int xOffset = 3, yOffset = i + 2; // Here we check if we need to move to another column for displaying the items if(i >= kMaxItemHeight) { // Set a new offset to create a new column for the next items xOffset += kMaxItemWidth * (i / kMaxItemHeight); yOffset = i - ((i/kMaxItemHeight) * kMaxItemHeight) + 2; } // Here we store the retail price for the items in the list int salePrice = CalculateItemPrice(pInvItem, true); // If we are buying, we want to display the cost of the item next to it if(g_Shop.IsBuying()) sprintf(szItem, "%s - $%d", pInvItem->GetItemName(), salePrice); else sprintf(szItem, "%s", pInvItem->GetItemName()); // Draw the item to the screen as a button so the user can click on it to choose it g_Shop.DrawString(szItem, (int)strlen(szItem), kInvMenuX + xOffset, kInvMenuY + yOffset, pInvItem); } }
void ItemPromptBuy() { // Get the selected item to buy and make sure it's valid CItem *pItem = g_Shop.GetSelectedItem(); if(!pItem) return; // Copy the item's data directly over to a new item and calculate it's retail price (true) CItem newItem = *pItem; int salePrice = CalculateItemPrice(&newItem, true); // If the user can't afford the item, make them feel stupid for trying to cheat :) if(g_Player.GetGold() < salePrice) { g_Shop.DrawMessageBox("You don't have enough money for that! This isn't a charity! "); Sleep(1500); return; } // Subtract the gold and add the item to the player's inventory g_Player.SetGold(g_Player.GetGold() - salePrice); g_Player.AddItem(newItem); // Display a message saying the player bought the item for such and such $$$ char szMessage[80] = {0}; sprintf(szMessage, "You bought the %s for %d gold.", newItem.GetItemName(), salePrice); g_Shop.DrawMessageBox(szMessage); Sleep(1500); }
void ItemPromptBuy() { // When the user finally decides they want to buy an item, this function // is called. We just need to get a pointer to the item, calculate it's // price, then see if the player has enough gold to even buy it. If so, // we subtract the gold from the player to buy the item, then add it to // the inventory. // Get the selected item to buy and make sure it's valid CItem *pItem = g_Shop.GetSelectedItem(); if(!pItem) return; // Copy the item's data directly over to a new item and calculate it's retail price (true) CItem newItem = *pItem; int salePrice = CalculateItemPrice(&newItem, true); // If the user can't afford the item, make them feel stupid for trying to cheat :) if(g_Player.GetGold() < salePrice) { g_Shop.DrawMessageBox("You don't have enough money for that! This isn't a charity! "); Sleep(1500); return; } // Subtract the gold and add the item to the player's inventory g_Player.SetGold(g_Player.GetGold() - salePrice); g_Player.AddItem(newItem); // Display a message saying the player bought the item for such and such $$$ char szMessage[80] = {0}; sprintf(szMessage, "You bought the %s for %d gold.", newItem.GetItemName(), salePrice); g_Shop.DrawMessageBox(szMessage); Sleep(1500); }
CItem *CPlayer::GetItem(char *szName) { // Go through all of the items for(int i = 0; i < (int)m_vItems.size(); i++) { CItem *pCurrentItem = &m_vItems[i]; // If the current item has the name of the desired item if(!strcmp(szName,pCurrentItem->GetItemName())) return pCurrentItem; } // Return an invalid item return NULL; }
void ItemPromptSell() { // If the player finally decides to sell their item, this function is called. // First we get the item and then calculate it's USED price (false). CItem *pItem = g_Shop.GetSelectedItem(); int salePrice = CalculateItemPrice(pItem, false); // Drop the item and delete it from the map to get rid of it from the player g_Player.DropItem(pItem); g_Map.DeleteTile(kItemType, pItem->GetIndex().X, pItem->GetIndex().Y); // Add the money made to our current gold g_Player.SetGold(g_Player.GetGold() + salePrice); // Display the transaction made char szMessage[80] = {0}; sprintf(szMessage, "You recieved %d gold for the %s.", salePrice, pItem->GetItemName()); g_Shop.DrawMessageBox(szMessage); Sleep(1000); }
void ItemPromptSell() { // If the player finally decides to sell their item, this function is called. // First we get the item and then calculate it's USED price (false). CItem *pItem = g_Shop.GetSelectedItem(); int salePrice = CalculateItemPrice(pItem, false); // We don't add the item to the shop keeper's list, but instead just make // the player drop it and then it is deleted from the map. You can change // this if you want to have the option to buy the item back. g_Player.DropItem(pItem); g_Map.DeleteTile(kItemType, g_Player.GetPosition().x, g_Player.GetPosition().y); // Add the money made to our current gold g_Player.SetGold(g_Player.GetGold() + salePrice); // Display the transaction made char szMessage[80] = {0}; sprintf(szMessage, "You recieved %d gold for the %s.", salePrice, pItem->GetItemName()); g_Shop.DrawMessageBox(szMessage); Sleep(1000); }
void DrawInventoryScreen() { char szItem[25] = {0}; char szHead[80] = {0}; char szChest[80] = {0}; char szWeapon[80] = {0}; char szFeet[80] = {0}; // Reset all the menu flags to start over on a new menu g_Menu.ResetButtons(); g_Menu.ResetEscapeFlag(); g_Menu.ResetMenuChoice(); // Let's redraw the map so it destroys the previous menu artifacts. We then // want to draw new dialog boxes to house the inventory and stats information. g_Map.SetDrawFlag(true); g_Map.Draw(); // Draw the 3 boxes that will make up the inventory screen: TopLeft, TopRight, Bottom g_Menu.DrawBox(kEqMenuWidth, kEqMenuHeight, kEqMenuX, kEqMenuY); g_Menu.DrawBox(kInvMenuWidth, kInvMenuHeight, kInvMenuX, kInvMenuY); g_Menu.DrawBox(kStatsMenuWidth, kStatsMenuHeight, kStatsMenuX, kStatsMenuY); // If the user has anything equipped, let's get pointers to those items CItem *pHead = g_Player.GetEquipment(kHead); CItem *pChest = g_Player.GetEquipment(kChest); CItem *pWeapon = g_Player.GetEquipment(kWeapon); CItem *pFeet = g_Player.GetEquipment(kFeet); // We there is an item equipped then we want to insert it's name in the EQ menu if(pHead) sprintf(szHead, "Head: %s", pHead->GetItemName()); else sprintf(szHead, "Head: "); if(pChest) sprintf(szChest, "Chest: %s", pChest->GetItemName()); else sprintf(szChest, "Chest: "); if(pWeapon) sprintf(szWeapon, "Weapon: %s", pWeapon->GetItemName()); else sprintf(szWeapon, "Weapon: "); if(pFeet) sprintf(szFeet, "Feet: %s", pFeet->GetItemName()); else sprintf(szFeet, "Feet: "); // Now we draw the current player's equipment and pass in the item pointers for clicking on g_Menu.DrawString(szHead, (int)strlen(szHead), kEqMenuX + kTileWidth, kEqMenuY + 115, pHead); g_Menu.DrawString(szChest, (int)strlen(szChest), kEqMenuX + kTileWidth, kEqMenuY + 147, pChest); g_Menu.DrawString(szWeapon, (int)strlen(szWeapon), kEqMenuX + kTileWidth, kEqMenuY + 179, pWeapon); g_Menu.DrawString(szFeet, (int)strlen(szFeet), kEqMenuX + kTileWidth, kEqMenuY + 211, pFeet); // Let's draw the stats screen that goes at the bottom of the inventory menu DrawStatsString(); // Go through all of the items in our inventory and draw them for(int i = 0; i < g_Player.GetInventorySize(); i++) { // Get the current item and set it's default position CItem *pInvItem = g_Player.GetItem(i); int xOffset = kTileWidth, yOffset = kTileHeight + i * kFontHeight; // If the current column has more items than it should hold we need to // go to the next column on the right and start drawing the next items. if(i >= kMaxItemHeight) { // Increase the x and y position accordingly for each item xOffset += (kMaxItemWidth * (i / kMaxItemHeight)) * kTileWidth; yOffset = (i - ((i/kMaxItemHeight) * kMaxItemHeight)) * kFontHeight + kTileHeight; } // Get the item's name and create a button for it, then display it to the screen sprintf(szItem, "%s", pInvItem->GetItemName()); g_Menu.DrawString(szItem, (int)strlen(szItem), kInvMenuX + xOffset, kInvMenuY + yOffset, pInvItem); } // After the items are drawn, let's load and draw a small picture of the player HBITMAP hPlayerBust = g_Buffer.LoadABitmap((LPSTR)kPlayerBust); g_Buffer.DisplayBitmap(hPlayerBust, kPlayerBustX, kPlayerBustY); // Swap the backbuffers to display the bitmaps to the screen g_Buffer.SwapBackBuffer(FALSE); Sleep(100); // Since the picture is drawn, we don't need it anymore, let's delete it DeleteObject(hPlayerBust); }
void DrawInventoryScreen() { char szItem[25] = {0}; char szHead[80] = {0}; char szChest[80] = {0}; char szWeapon[80] = {0}; char szFeet[80] = {0}; // Reset all the menu flags to start over on a new menu g_Menu.ResetButtons(); g_Menu.ResetEscapeFlag(); g_Menu.ResetMenuChoice(); g_Menu.ResetItemChoice(); // Let's redraw the map so it destroys the previous menu artifacts. We then // want to draw new dialog boxes to house the inventory and stats information. g_Map.Draw(); g_Menu.DrawBox(kEqMenuWidth, kEqMenuHeight, kEqMenuX, kEqMenuY); g_Menu.DrawBox(kInvMenuWidth, kInvMenuHeight, kInvMenuX, kInvMenuY); g_Menu.DrawBox(kStatsMenuWidth, kStatsMenuHeight, kStatsMenuX, kStatsMenuY); // If the user has anything equipped, let's get pointers to those items CItem *pHead = g_Player.GetEquipment(kHead); CItem *pChest = g_Player.GetEquipment(kChest); CItem *pWeapon = g_Player.GetEquipment(kWeapon); CItem *pFeet = g_Player.GetEquipment(kFeet); // We there is an item equipped then we want to insert it's name in the EQ menu if(pHead) sprintf(szHead, "Head: %s", pHead->GetItemName()); else sprintf(szHead, "Head: "); if(pChest) sprintf(szChest, "Chest: %s", pChest->GetItemName()); else sprintf(szChest, "Chest: "); if(pWeapon) sprintf(szWeapon, "Weapon: %s", pWeapon->GetItemName()); else sprintf(szWeapon, "Weapon: "); if(pFeet) sprintf(szFeet, "Feet: %s", pFeet->GetItemName()); else sprintf(szFeet, "Feet: "); // Now we draw the current player's equipment and pass in the item pointers for clicking on g_Menu.DrawString(szHead, (int)strlen(szHead), kEqMenuX + 3, kEqMenuY + 5, pHead); g_Menu.DrawString(szChest, (int)strlen(szChest), kEqMenuX + 3, kEqMenuY + 9, pChest); g_Menu.DrawString(szWeapon, (int)strlen(szWeapon), kEqMenuX + 3, kEqMenuY + 13, pWeapon); g_Menu.DrawString(szFeet, (int)strlen(szFeet), kEqMenuX + 3, kEqMenuY + 17, pFeet); // Let's draw the stats screen that goes at the bottom of the inventory menu DrawStatsString(); // Go through all of the items in our inventory and draw them for(int i = 0; i < g_Player.GetInventorySize(); i++) { // Get the current item and set it's default position CItem *pInvItem = g_Player.GetItem(i); int xOffset = 3, yOffset = i + 2; // If the current column has more items than it should hold we need to // go to the next column on the right and start drawing the next items. if(i >= kMaxItemHeight) { // Increase the x offset to a new column and reset the y // offset to start at the top of the next column. xOffset += kMaxItemWidth * (i / kMaxItemHeight); yOffset = i - ((i/kMaxItemHeight) * kMaxItemHeight) + 2; } // Get the item's name and create a button for it, then display it to the screen sprintf(szItem, "%s", pInvItem->GetItemName()); g_Menu.DrawString(szItem, (int)strlen(szItem), kInvMenuX + xOffset, kInvMenuY + yOffset, pInvItem); } }