コード例 #1
0
ファイル: Shop.cpp プロジェクト: ntaylorbishop/HGAMRoguelike
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);
			}
		}
	}
}
コード例 #2
0
void Shop::render(cint mousePos, vector<Pickup*>* inventory)
{
	Shop::inStore = true;
	cint currentLocation;
	Console::print("Shop:", (tl_xres() - 6) * 2, (tl_yres() - 6) * 2 + 1);
	int length = inventory->size();
	for (int i = 0; i < length; i++)
	{
		inventory->at(i)->inventoryPosition = i;
		tl_scale(1);
		currentLocation = cint(tl_xres() - 6 + (i % 6), tl_yres() - 5 + (i / 6));
		if (mousePos == currentLocation)
		{
			tl_color(0xFF0000FF);
			tl_rendertile(0x125, currentLocation.X(), currentLocation.Y());
			tl_color(0xFFFFFFFF);
			inventory->at(i)->describe(BUY);
		}
		else
		{
			tl_rendertile(0x116, currentLocation.X(), currentLocation.Y());
		}
		tl_rendertile(inventory->at(i)->Tile(), currentLocation.X(), currentLocation.Y());
	}
}
コード例 #3
0
void GameEngine::renderGameMenu() {
	justDied = false;

	lib.loop_portion(Point(0, 0), lib.res(), [&](Point p) {
		lib.rendertile(0x125, p);
	});

	tl_scale(2);
	string title = "Welcome to the Kingdoms of Amalor!";
	Point center = Point(lib.res().x() / 2 - title.length() / 2, lib.res().y() / 2 - 15);
	lib.renderText(center, title);

	tl_scale(3);
	string title2 = "Press enter to start the game";
	Point t2Loc = Point(lib.res().x() / 2 - title2.length() / 2, lib.res().y() / 2);
	lib.renderText(t2Loc, title2);
	string title3 = "Press escape to exit the game";
	Point t3Loc = Point(lib.res().x() / 2 - title3.length() / 2, lib.res().y() / 2 + 2);
	lib.renderText(t3Loc, title3);

	tl_scale(1);

	//Take input
	if (lib.keywentdown("return") || lib.keywentdown("enter")) {
		gameStart = true;
		justDied = true;
		if (deadHero) {
			restart();
		}
	}

	//Player animation
	if (heroAnimMenu > lib.res().x() + 1)
		heroAnimMenu = 0;

	Point p(heroAnimMenu, lib.res().y() - 5);
	lib.rendertile(0x0AC, p);

	animSpeed++;
	if (animSpeed % 20 == 0)
		heroAnimMenu++;
}
コード例 #4
0
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);
}