Example #1
0
void DragSprite::Update(float deltaTime)
{
	if(mVisible)
	{
		float x = Input_GetMouseScreenX();
		float y = Input_GetMouseScreenY();

		if(Input_IsMouseDown(Mouse::LBUTTON) && x - mPosition.x > 176 && y  - mPosition.y < 16)
		{
			mVisible = false;
		}

		// Draggable Inventory
		else if(Input_IsMouseDown(Mouse::LBUTTON) && 
			(x > mPosition.x && x < mPosition.x + mSprite.GetWidth() - 20)
			&& (y > mPosition.y && y < mPosition.y + 30))
		{
			mDragDown = true;
		}

		if(!Input_IsMouseDown(Mouse::LBUTTON) && mDragDown)
		{	
			mDragDown = false;
		}

		if(mDragDown)
		{
			mPosition = SVector2(x - 75, y - 20);
			mSprite.Update(deltaTime);
		}
	}
}
Example #2
0
void Equip::Update(float deltaTime) {
	mDragSprite.Update(deltaTime);
	mStats.Update(deltaTime);

	mStats.SetPosition(mDragSprite.GetPosition() + SVector2(13.5f, 228.0f));

	SVector2 position = mDragSprite.GetPosition();
	float x = Input_GetMouseScreenX() - position.x;
	float y = Input_GetMouseScreenY() - position.y - 32;

	bool mouseDown = Input_IsMousePressed(Mouse::LBUTTON);

	// Exit Button
	if (mouseDown && x > 260 && x < 290 && y < 2) {
		mDragSprite.ToggleVisible();
	}

	// Stat Button
	if ((mouseDown && x > 77 && x < 220 && y > 168 && y < 187)) {
		mStats.ToggleVisible();
	}
}
Example #3
0
void InputBox::Update(float deltaTime)
{
	mSprite.Update(deltaTime);

	// Update caret info
	mCaret += deltaTime;
	if (mCaret > CARET_BLINK_RATE_SECONDS) {
		mCaret -= CARET_BLINK_RATE_SECONDS;
	}

	SVector2 mouse((float) Input_GetMouseScreenX(), (float) Input_GetMouseScreenY());
	// If a mouse click is detected this box is no longer selected. Below it checks if it is the one being clicked on
	if(Input_IsMousePressed(Mouse::LBUTTON))
	{
		mActive = mouse.x > (mPosition.x - 25) && mouse.x < mPosition.x + mWidth && mouse.y > (mPosition.y - 25) && mouse.y < mPosition.y + mHeight;
	}

	// If Active Capture Text
	if(mActive)
	{
		// Dont go over max length
		if(mTextPosition < mMaxLength)
		{		if (Input_IsKeyDown(Keys::LSHIFT) || Input_IsKeyDown(Keys::RSHIFT) )
				{
					if(Input_IsKeyPressed(Keys::A)) { mText[mTextPosition++] = 'A'; }
					if(Input_IsKeyPressed(Keys::B)) { mText[mTextPosition++] = 'B'; }
					if(Input_IsKeyPressed(Keys::C)) { mText[mTextPosition++] = 'C'; }
					if(Input_IsKeyPressed(Keys::D)) { mText[mTextPosition++] = 'D'; }
					if(Input_IsKeyPressed(Keys::E)) { mText[mTextPosition++] = 'E'; }
					if(Input_IsKeyPressed(Keys::F)) { mText[mTextPosition++] = 'F'; }
					if(Input_IsKeyPressed(Keys::G)) { mText[mTextPosition++] = 'G'; }
					if(Input_IsKeyPressed(Keys::H)) { mText[mTextPosition++] = 'H'; }
					if(Input_IsKeyPressed(Keys::I)) { mText[mTextPosition++] = 'I'; }
					if(Input_IsKeyPressed(Keys::J)) { mText[mTextPosition++] = 'J'; }
					if(Input_IsKeyPressed(Keys::K)) { mText[mTextPosition++] = 'K'; }
					if(Input_IsKeyPressed(Keys::L)) { mText[mTextPosition++] = 'L'; }
					if(Input_IsKeyPressed(Keys::M)) { mText[mTextPosition++] = 'M'; }
					if(Input_IsKeyPressed(Keys::N)) { mText[mTextPosition++] = 'N'; }
					if(Input_IsKeyPressed(Keys::O)) { mText[mTextPosition++] = 'O'; }
					if(Input_IsKeyPressed(Keys::P)) { mText[mTextPosition++] = 'P'; }
					if(Input_IsKeyPressed(Keys::Q)) { mText[mTextPosition++] = 'Q'; }
					if(Input_IsKeyPressed(Keys::R)) { mText[mTextPosition++] = 'R'; }
					if(Input_IsKeyPressed(Keys::S)) { mText[mTextPosition++] = 'S'; }
					if(Input_IsKeyPressed(Keys::T)) { mText[mTextPosition++] = 'T'; }
					if(Input_IsKeyPressed(Keys::U)) { mText[mTextPosition++] = 'U'; }
					if(Input_IsKeyPressed(Keys::V)) { mText[mTextPosition++] = 'V'; }
					if(Input_IsKeyPressed(Keys::W)) { mText[mTextPosition++] = 'W'; }
					if(Input_IsKeyPressed(Keys::X)) { mText[mTextPosition++] = 'X'; }
					if(Input_IsKeyPressed(Keys::Y)) { mText[mTextPosition++] = 'Y'; }
					if(Input_IsKeyPressed(Keys::Z)) { mText[mTextPosition++] = 'Z'; }

					if(Input_IsKeyPressed(Keys::SEMICOLON)) { mText[mTextPosition++] = ':'; }
					if(Input_IsKeyPressed(Keys::ONE)) { mText[mTextPosition++] = '!'; }
					if(Input_IsKeyPressed(Keys::TWO)) { mText[mTextPosition++] = '@'; }
					if(Input_IsKeyPressed(Keys::THREE)) { mText[mTextPosition++] = '#'; }
					if(Input_IsKeyPressed(Keys::FOUR)) { mText[mTextPosition++] = '$'; }
					if(Input_IsKeyPressed(Keys::FIVE)) { mText[mTextPosition++] = '%'; }
					if(Input_IsKeyPressed(Keys::SIX)) { mText[mTextPosition++] = '^'; }
					if(Input_IsKeyPressed(Keys::SEVEN)) { mText[mTextPosition++] = '&'; }
					if(Input_IsKeyPressed(Keys::EIGHT)) { mText[mTextPosition++] = '*'; }
					if(Input_IsKeyPressed(Keys::NINE)) { mText[mTextPosition++] = '('; }
					if(Input_IsKeyPressed(Keys::ZERO)) { mText[mTextPosition++] = ')'; }
					if(Input_IsKeyPressed(Keys::SLASH)) { mText[mTextPosition++] = '?'; }
					if(Input_IsKeyPressed(Keys::PERIOD)) { mText[mTextPosition++] = '>'; }
					if(Input_IsKeyPressed(Keys::COMMA)) { mText[mTextPosition++] = '<'; }
					if(Input_IsKeyPressed(Keys::APOSTROPHE)) { mText[mTextPosition++] = '"'; }
					if(Input_IsKeyPressed(Keys::GRAVE)) { mText[mTextPosition++] = '~'; }
					if(Input_IsKeyPressed(Keys::LBRACKET)) { mText[mTextPosition++] = '{'; }
					if(Input_IsKeyPressed(Keys::RBRACKET)) { mText[mTextPosition++] = '}'; }
				}
				else
				{
					if(Input_IsKeyPressed(Keys::A)) { mText[mTextPosition++] = 'a'; }
					if(Input_IsKeyPressed(Keys::B)) { mText[mTextPosition++] = 'b'; }
					if(Input_IsKeyPressed(Keys::C)) { mText[mTextPosition++] = 'c'; }
					if(Input_IsKeyPressed(Keys::D)) { mText[mTextPosition++] = 'd'; }
					if(Input_IsKeyPressed(Keys::E)) { mText[mTextPosition++] = 'e'; }
					if(Input_IsKeyPressed(Keys::F)) { mText[mTextPosition++] = 'f'; }
					if(Input_IsKeyPressed(Keys::G)) { mText[mTextPosition++] = 'g'; }
					if(Input_IsKeyPressed(Keys::H)) { mText[mTextPosition++] = 'h'; }
					if(Input_IsKeyPressed(Keys::I)) { mText[mTextPosition++] = 'i'; }
					if(Input_IsKeyPressed(Keys::J)) { mText[mTextPosition++] = 'j'; }
					if(Input_IsKeyPressed(Keys::K)) { mText[mTextPosition++] = 'k'; }
					if(Input_IsKeyPressed(Keys::L)) { mText[mTextPosition++] = 'l'; }
					if(Input_IsKeyPressed(Keys::M)) { mText[mTextPosition++] = 'm'; }
					if(Input_IsKeyPressed(Keys::N)) { mText[mTextPosition++] = 'n'; }
					if(Input_IsKeyPressed(Keys::O)) { mText[mTextPosition++] = 'o'; }
					if(Input_IsKeyPressed(Keys::P)) { mText[mTextPosition++] = 'p'; }
					if(Input_IsKeyPressed(Keys::Q)) { mText[mTextPosition++] = 'q'; }
					if(Input_IsKeyPressed(Keys::R)) { mText[mTextPosition++] = 'r'; }
					if(Input_IsKeyPressed(Keys::S)) { mText[mTextPosition++] = 's'; }
					if(Input_IsKeyPressed(Keys::T)) { mText[mTextPosition++] = 't'; }
					if(Input_IsKeyPressed(Keys::U)) { mText[mTextPosition++] = 'u'; }
					if(Input_IsKeyPressed(Keys::V)) { mText[mTextPosition++] = 'v'; }
					if(Input_IsKeyPressed(Keys::W)) { mText[mTextPosition++] = 'w'; }
					if(Input_IsKeyPressed(Keys::X)) { mText[mTextPosition++] = 'x'; }
					if(Input_IsKeyPressed(Keys::Y)) { mText[mTextPosition++] = 'y'; }
					if(Input_IsKeyPressed(Keys::Z)) { mText[mTextPosition++] = 'z'; }

					if(Input_IsKeyPressed(Keys::ZERO)) { mText[mTextPosition++] = '0'; }
					if(Input_IsKeyPressed(Keys::ONE)) { mText[mTextPosition++] = '1'; }
					if(Input_IsKeyPressed(Keys::TWO)) { mText[mTextPosition++] = '2'; }
					if(Input_IsKeyPressed(Keys::THREE)) { mText[mTextPosition++] = '3'; }
					if(Input_IsKeyPressed(Keys::FOUR)) { mText[mTextPosition++] = '4'; }
					if(Input_IsKeyPressed(Keys::FIVE)) { mText[mTextPosition++] = '5'; }
					if(Input_IsKeyPressed(Keys::SIX)) { mText[mTextPosition++] = '6'; }
					if(Input_IsKeyPressed(Keys::SEVEN)) { mText[mTextPosition++] = '7'; }
					if(Input_IsKeyPressed(Keys::EIGHT)) { mText[mTextPosition++] = '8'; }
					if(Input_IsKeyPressed(Keys::NINE)) { mText[mTextPosition++] = '9'; }
					if(Input_IsKeyPressed(Keys::SLASH)) { mText[mTextPosition++] = '/'; }
					if(Input_IsKeyPressed(Keys::PERIOD)) { mText[mTextPosition++] = '.'; }
					if(Input_IsKeyPressed(Keys::APOSTROPHE)) { mText[mTextPosition++] = '\''; }
					if(Input_IsKeyPressed(Keys::COMMA)) { mText[mTextPosition++] = ','; }
					if(Input_IsKeyPressed(Keys::MINUS)) { mText[mTextPosition++] = '-'; }
					if(Input_IsKeyPressed(Keys::EQUALS)) { mText[mTextPosition++] = '='; }
					if(Input_IsKeyPressed(Keys::SEMICOLON)) { mText[mTextPosition++] = ';'; }
					if(Input_IsKeyPressed(Keys::GRAVE)) { mText[mTextPosition++] = '`'; }
					if(Input_IsKeyPressed(Keys::LBRACKET)) { mText[mTextPosition++] = '['; }
					if(Input_IsKeyPressed(Keys::RBRACKET)) { mText[mTextPosition++] = ']'; }
				}

				if(Input_IsKeyPressed(Keys::SPACE)) { mText[mTextPosition++] = ' '; }
		}

		// Backspace
		if(mTextPosition > 0 && Input_IsKeyPressed(Keys::BACKSPACE))
		{
			mText[--mTextPosition] = '\0';
		}
	}
}
Example #4
0
void Inventory::Update(float deltaTime) {
	mDragSprite.Update(deltaTime);

	int x = Input_GetMouseScreenX();
	int y = Input_GetMouseScreenY();
	int dragSpriteX = mDragSprite.GetPosition().x;
	int dragSpriteY = mDragSprite.GetPosition().y;
	int width = mDragSprite.GetSpriteWidth();
	int height = mDragSprite.GetSpriteHeight();

	// Check for item use
	if (((x > dragSpriteX) && x < dragSpriteX + width)
			&& (y > dragSpriteY && y < dragSpriteY + height)
			&& mDragSprite.GetVisible()) {
		bool mouseDown = Input_IsMousePressed(Mouse::LBUTTON);
		SVector2 position = mDragSprite.GetPosition();
		float x = Input_GetMouseScreenX() - position.x;
		float y = Input_GetMouseScreenY() - position.y - 32;

		// Exit Button
		if (mouseDown && x > 264 && x < 286 && y < 0) {
			mDragSprite.ToggleVisible();
		}

		int itemSlot = -1;

		// Figure out what item we are selecting
		int xSlot = -1;

		if (x > 27 && x < 70)
			xSlot = 0;
		if (x > 78 && x < 120)
			xSlot = 1;
		if (x > 127 && x < 170)
			xSlot = 2;
		if (x > 178 && x < 218)
			xSlot = 3;
		if (x > 226 && x < 270)
			xSlot = 4;

		int ySlot = -1;

		if (y > -4 && y < 34)
			ySlot = 0;
		if (y > 46 && y < 85)
			ySlot = 1;
		if (y > 93 && y < 135)
			ySlot = 2;
		if (y > 143 && y < 183)
			ySlot = 3;
		if (y > 192 && y < 234)
			ySlot = 4;
		if (y > 242 && y < 282)
			ySlot = 5;

		if (xSlot >= 0 && ySlot >= 0) {
			itemSlot = xSlot + ySlot * 5;
		}

		if (mouseDown) {
			if (itemSlot >= 0 && itemSlot < mItems.size()) {
				mItems[itemSlot]->UseItem(mPlayerInfo, mRaknet);
				mItems.erase(mItems.begin() + itemSlot);
			}
		}

		if (Input_IsMousePressed(Mouse::RBUTTON)) {
			// Delete Item in slot
			if (itemSlot >= 0 && itemSlot < mItems.size()) {
				ItemBase* item = mItems[itemSlot];
				int imageNumber = item->GetImageNumber();
				mItems.erase(mItems.begin() + itemSlot);

				// Let the server know we droped a item
				RakNet::BitStream bsOut;
				bsOut.Write((RakNet::MessageID) ID_DROP_ITEM);

				bsOut.Write(mPlayerInfo.GetMap());
				bsOut.Write(imageNumber);
				bsOut.Write(item->GetItemNumber());
				bsOut.Write(mCharacter.GetTileIndex());

				mRaknet.mPeer->Send(&bsOut, HIGH_PRIORITY, RELIABLE_ORDERED, 0,
						mRaknet.mServerAddress, false);
			}
		}
	}
}
Example #5
0
void Equip::Render() {
	if (mDragSprite.GetVisible()) {
		SVector2 position = mDragSprite.GetPosition();
		float x = Input_GetMouseScreenX() - position.x;
		float y = Input_GetMouseScreenY() - position.y - 32;

		int slot = -1;
		if (Input_IsMousePressed(Mouse::LBUTTON)) {
			// Ring Left
			if (x > 226 && x < 269 && y > 93 && y < 138) {
				slot = ring2;
			}

			// Ring Right
			if (x > 226 && x < 269 && y > 144 && y < 187) {
				slot = ring;
			}

			// Right arm
			if (x > 177 && x < 219 && y > 119 && y < 162) {
				slot = shield;
			}

			// Left arm
			if (x > 78 && x < 118 && y > 120 && y < 163) {
				slot = weapon;
			}

			// Helmet
			if (x > 28 && x < 70 && y > -4 && y < 40) {
				slot = helmet;
			}

			// Armor
			if (x > 28 && x < 70 && y > 94 && y < 137) {
				slot = armor;
			}

			// Boots
			if (x > 28 && x < 70 && y > 143 && y < 189) {
				slot = boots;
			}

			// Necklace
			if (x > 28 && x < 70 && y > 45 && y < 88) {
				slot = necklace;
			}

			if (slot >= 0 && mInventory.GetSpaceLeft() > 0
					&& mPlayerInfo.GetEqiupItemImage(slot) > 0) {
				mSprite[slot].Unload();
				mPlayerInfo.SetEqiupItem(slot, 0, 0);

				RakNet::BitStream bsOut;
				bsOut.Write((RakNet::MessageID) ID_UNEQIUP_ITEM);
				bsOut.Write(slot);
				mRaknet.mPeer->Send(&bsOut, HIGH_PRIORITY, RELIABLE_ORDERED, 0,
						mRaknet.mServerAddress, false);
			}
		}

		mDragSprite.Render();
		mStats.Render();

		mSprite[weapon].SetPosition(position.x + 83, position.y + 155);
		mSprite[shield].SetPosition(position.x + 182, position.y + 155);
		mSprite[helmet].SetPosition(position.x + 32, position.y + 32);
		mSprite[armor].SetPosition(position.x + 32, position.y + 130);
		mSprite[boots].SetPosition(position.x + 32, position.y + 182);
		mSprite[necklace].SetPosition(position.x + 32, position.y + 81);
		mSprite[ring].SetPosition(position.x + 230, position.y + 132);
		mSprite[ring2].SetPosition(position.x + 230, position.y + 182);

		for (int a = 0; a < 8; ++a) {
			if (mPlayerInfo.GetEqiupItemImage(a) > 0) {
				mSprite[a].Render();
			}
		}

		char temp[CHAR_MAX];
		sprintf(temp, "MouseX: %f", x);
		Graphics_DebugText(temp, 5, 225, 0XFF0000);

		sprintf(temp, "MouseY: %f", y);
		Graphics_DebugText(temp, 5, 250, 0XFF0000);

		sprintf(temp, "%s", mPlayerInfo.GetUsername());
		mFont.Print(temp, (int) (position.x + 112.0f),
				(int) (position.y + 23.0f));

		if (mStats.GetVisible()) {
			sprintf(temp, "%d", mPlayerInfo.GetStr());
			mFont.Print(temp, (int) (position.x + 210.0f),
					(int) (position.y + 288.0f));

			sprintf(temp, "%d", mPlayerInfo.GetDex());
			mFont.Print(temp, (int) (position.x + 210.0f),
					(int) (position.y + 305.0f));

			sprintf(temp, "%d", mPlayerInfo.GetInt());
			mFont.Print(temp, (int) (position.x + 210.0f),
					(int) (position.y + 322.0f));

			sprintf(temp, "%d", mPlayerInfo.GetAttack());
			mFont.Print(temp, (int) (position.x + 210.0f),
					(int) (position.y + 339.0f));

			sprintf(temp, "%d", mPlayerInfo.GetDefence());
			mFont.Print(temp, (int) (position.x + 210.0f),
					(int) (position.y + 356.0f));

			sprintf(temp, "%d", mPlayerInfo.GetCrit());
			mFont.Print(temp, (int) (position.x + 210.0f),
					(int) (position.y + 373.0f));
		}
	}
}