void Shop::renderShop() { if (shopOpen) { //Render the background lib->loop_portion(start, end, [&](Point p) { lib->rendertile(0x125, p); }); //Render the close button if (lib->mouseLoc() == start) //Highlight if mouse is over close button tl_color(0x000000FF); lib->rendertile(static_cast<int>('x'), start); tl_color(0xFFFFFFFF); //If close button is hit, close the shop if (tl_buttonwentdown(1) && lib->mouseLoc() == start) shopOpen = false; tl_scale(2); lib->renderText(Point(start.x() + 6, start.y() + 3), "Well Hello There, Stranger!"); //Compensate start point with scale lib->renderText(Point(start.x() + 10, end.y() + 12), "Gold Amount: " + to_string(shopGold)); tl_scale(1); //Render icon slots unsigned int idx = 0; Point iconStart = start + Point(5, 5); Point iconEnd = end + Point(-5, -5); lib->loop_portion(iconStart, end + Point(-5, -5), [&](Point p) { lib->rendertile(0x13D, p); if (lib->mouseLoc() == p && storeItems[idx].getLoc() != Point(-1, -1)) { tl_color(0xFF000040); lib->rendertile(0x13D, p); } tl_color(0xFFFFFFFF); if (storeItems[idx].getLoc() != Point(-1, -1)) lib->rendertile(storeItems[idx].getPickupDef().getTile(), p); idx++; }); if (lib->mouseLoc() >= iconStart && lib->mouseLoc() <= iconEnd - Point(1, 1)) { //Render item mouse over Pickup p = storeItems[idxFromPoint(lib->mouseLoc() - iconStart)]; Point loc = lib->mouseLoc() - iconStart; if (p.getLoc() != Point(-1, -1)) { if (p.getPickupDef().getType() != 0) log->renderMouseOver(p.getPickupDef().getName(), p.getPickupDef().getDESC(), "Uses left: " + to_string(p.getUsesLeft()), "Cost: " + to_string(p.getPickupDef().getPrice())); else log->renderMouseOver(p.getPickupDef().getName(), p.getPickupDef().getDESC(), "Cost: " + to_string(p.getPickupDef().getPrice()), ""); } //Buy item if (tl_buttonwentdown(1)) buy(loc); } else if (lib->mouseLoc() >= Point(lib->res().x() - 3, 3) && lib->mouseLoc() <= Point(lib->res().x() - 2, 9)) { if (tl_buttonwentdown(1)) { Pickup p = invLog->sellItem(lib->mouseLoc()); sell(p); } } } }
void Shop::sell(Pickup p) { if (p.getLoc() != Point(-1, -1)) { //Make sure we're actually selling an item //Add it to the store if there's room for (unsigned int i = 0; i < storeItems.size(); i++) { if (storeItems[i].getLoc() == Point(-1, -1)) { storeItems[i] = p; break; } } //Decrement gold, add it to the player int price = p.getPickupDef().getPrice(); invLog->changeGold(price); shopGold -= price; lib->play("Sell"); log->registerEvent("Sold a " + p.getPickupDef().getName() + " for " + to_string(price) + " gold"); } }
void GameEngine::onMouseOver() { //Render inventory item information if (lib.mouseLoc().x() > lib.res().x() - 4) { Pickup item = invLog.getItemAtLoc(lib.mouseLoc()); if (item.getLoc() != Point(-1, -1)) { if (item.getPickupDef().getType() != 0) log.renderMouseOver(item.getPickupDef().getName(), item.getPickupDef().getDESC(), "Uses left: " + to_string(item.getUsesLeft()), ""); else log.renderMouseOver(item.getPickupDef().getName(), item.getPickupDef().getDESC(), "", ""); } } //Render world information else { Point relMouseLoc = screenOrientation - lib.res() / 2 + lib.mouseLoc(); if (relMouseLoc.x() > 0 && relMouseLoc.y() > 0 && relMouseLoc.x() <= worldSize - 1 && relMouseLoc.y() <= worldSize - 1 && !shop.isShopping()) { if (!map[relMouseLoc.x()][relMouseLoc.y()].isVisible()) { Pickup* p = map[relMouseLoc.x()][relMouseLoc.y()].getPickup(); Actor* a = map[relMouseLoc.x()][relMouseLoc.y()].getActor(); if (a != NULL) log.renderMouseOver(a->getActorDef().getDESC(), "HP: " + to_string(a->getHP()), "ATK: " + a->getActorDef().actorATK().to_str(), "DEF: " + to_string(a->getActorDef().getDEF())); else if (p != NULL) { if (p->getPickupDef().getType() != 0) log.renderMouseOver(p->getPickupDef().getName(), p->getPickupDef().getDESC(), "Uses left: " + to_string(p->getUsesLeft()), ""); else log.renderMouseOver(p->getPickupDef().getName(), p->getPickupDef().getDESC(), "", ""); } } } } tl_scale(1); }
//main void GameEngine::run() { lib.framestart(); if (!gameStart) renderGameMenu(); else { //Move the char left, right, up, and down if (!deadHero && !shop.isShopping()) { onPlayerTurn((lib.keywentdown("left") || lib.keywentdown("a")), Point(-1, 0)); onPlayerTurn((lib.keywentdown("up") || lib.keywentdown("w")), Point(0, -1)); onPlayerTurn((lib.keywentdown("right") || lib.keywentdown("d")), Point(1, 0)); onPlayerTurn((lib.keywentdown("down") || lib.keywentdown("s")), Point(0, 1)); //Enter stairs if (lib.keywentdown("return") || lib.keywentdown("enter")) { if (hero->getLoc() == stairLoc) { currLevel++; generateLevel(); } if (hero->getLoc() == shop.getLoc()) shop.activateShop(); if (hero->getLoc() == bossLoc) enterBossRoom(); if (hero->getLoc() == stairAscend) leaveBossRoom(); } if (tl_buttonwentdown(1)) { Pickup p = registerInventoryClick(); if (p.getLoc() != Point(-1, -1)) { if (p.getPickupDef().getType() == 0) log.registerEvent(("Used a " + p.getPickupDef().getName() + "!").c_str()); else log.registerEvent(("Equipped a " + p.getPickupDef().getName() + "!").c_str()); } if (lib.mouseLoc() >= Point(lib.res().x() / 2 - 3, lib.res().y() - 4) && lib.mouseLoc() <= Point(lib.res().x() / 2 + 3, lib.res().y() - 4)) useSpell(lib.mouseLoc()); } if (tl_buttonwentdown(3)) { Pickup p; if (invLog.overInvOrGear(lib.mouseLoc()) == 0) { p = invLog.dropItem(lib.mouseLoc()); if (p.getLoc() != Point(-1, -1)) log.registerEvent(("Dropped the " + p.getPickupDef().getName() + "!").c_str()); } else if (invLog.overInvOrGear(lib.mouseLoc()) == 1) { OutputDebugString("herpderp"); p = invLog.unequipGear(lib.mouseLoc()); if (p.getLoc() != Point(-1, -1)) log.registerEvent(("Unequipped the " + p.getPickupDef().getName() + "!").c_str()); } } } drawMap(); onMouseOver(); if(deadHero) { if (lib.keywentdown("escape")) gameStart = false; } } }