From 0fccc7e3afc218dd0af03e4055ee3abb278f9152 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Sun, 18 Aug 2013 17:19:34 +0200 Subject: [PATCH] Added custom crosshair. --- README.txt | 1 + resources/textures/crosshair.png | Bin 0 -> 912 bytes source/Game.cpp | 25 +++++++++++++++++-------- source/Game.h | 2 ++ 4 files changed, 20 insertions(+), 8 deletions(-) create mode 100644 resources/textures/crosshair.png diff --git a/README.txt b/README.txt index ccdf9cf..ef13217 100644 --- a/README.txt +++ b/README.txt @@ -22,3 +22,4 @@ Space: pause Player/Enemy (modified): http://opengameart.org/content/top-down-runner Tiles (modified): http://opengameart.org/content/metalstone-textures Item: http://opengameart.org/content/random-adventure-kit +Crosshair: http://opengameart.org/content/20-crosshairs-for-re diff --git a/resources/textures/crosshair.png b/resources/textures/crosshair.png new file mode 100644 index 0000000000000000000000000000000000000000..a5a317304bfd1e49569dbb3d39539a8fc3e508c1 GIT binary patch literal 912 zcmV;B18@9^P)iSR}i8O(RZ2oet0u)cIE-@x+Zk1XA02ERWlWfDl3^) z#rpsshA@b6%&5XL=99@dey#UgxMaTx%d_ye>d)mZ0l0kRSz(w}@*Fv_Sv4fr$s?kq z=E%q7kjV>@uce-K_*rt%;Sb4XI<)|}{bZ%+a7c32VfhwCluVthk%PKc6P^3Wm-zGL zW@bP8B5hv+6?z0`16wfZD56Afh-!_e=GhC>^ZYdK zV9D&iXKEFuBhDZEi$L#_ZNE(d-UFbuYulekw%uw1o_pZ3(e+mvjPr$hy{iQefxr%M zcG1D02O*vSae}^bZBpK004N}b4$(1 ztN;K7g#r2JaaSh*00E#$L_t(o!((6=1w$3|_xCS8ckbN(zP`Ril$gUpu0|~_Ee1nF zLxxwcUQy%`CUQ0Y{P`1wrn>{E1x6h(>HxAGz{tqRj!e_N95{RS>=AZ$c4iPgS}czO zx`FWUaFhD_`dVyqMMXu)@$vC?G_yP}FVFwZojafZ13^tqO#zx*$oKEx|KGoV|9ft3 zt{>Gc@9pg^d-?Ju$nO6aE?js7w8RlvJ|!i^4A?ff50ZcS^y&ZR=H_&2+0D9S$&&g1 z{`~`6zI*rXqnw;I`!r?ygLGq8k{*tv7(A&`L}2P|8* z4Ak-=RO)fBU%!6ye<%Ps9w^34vgQ8%{-$TnoOu8;{6y<+YHCUZCZ=y7&9`sg{#;yK9869KPM9#E?&HUgU`HH2eE57)Qj#W7 z8YfMf)C24&8j0H$%Aq0000 (new Player(mWorld, mPathfinder, mGenerator.getPlayerSpawn())); - mPlayer->setLeftGadget(std::shared_ptr < Gadget > (new Heal())); - mPlayer->setRightGadget(std::shared_ptr < Gadget > (new Shield())); - mWorld.insertCharacter(mPlayer); -} - /** * Initializes game, including window and objects (sprites). */ @@ -41,6 +35,11 @@ Game::Game(tgui::Window& window) : mGenerator.generateCurrentAreaIfNeeded(Vector2f()); initPlayer(); + mCrosshairTexture = ResourceManager::i().acquire(Loader::i() + .fromFile("crosshair.png")); + mCrosshair.setTexture(*mCrosshairTexture, true); + mWindow.setMouseCursorVisible(false); + mHealth = window.add(); mHealth->setTextSize(20); mAmmo = window.add(); @@ -55,6 +54,14 @@ Game::Game(tgui::Window& window) : mPickupInstruction->setTextSize(14); } +void Game::initPlayer() { + mPlayer = std::shared_ptr < Player + > (new Player(mWorld, mPathfinder, mGenerator.getPlayerSpawn())); + mPlayer->setLeftGadget(std::shared_ptr < Gadget > (new Heal())); + mPlayer->setRightGadget(std::shared_ptr < Gadget > (new Shield())); + mWorld.insertCharacter(mPlayer); +} + /** * Closes window. */ @@ -161,6 +168,7 @@ Game::input() { case sf::Event::MouseMoved: mPlayer->setCrosshairPosition(convertCoordinates(event.mouseMove.x, event.mouseMove.y)); + mCrosshair.setPosition(Vector2f(sf::Mouse::getPosition(mWindow) - Vector2i(mCrosshair.getTextureRect().width, mCrosshair.getTextureRect().height) / 2)); break; case sf::Event::MouseWheelMoved: mPlayer->toggleWeapon(); @@ -294,6 +302,7 @@ Game::render() { // Render GUI and static stuff. mWindow.setView(mWindow.getDefaultView()); mWindow.drawGUI(); + mWindow.draw(mCrosshair); mWindow.display(); } diff --git a/source/Game.h b/source/Game.h index 6924ff7..7d79914 100644 --- a/source/Game.h +++ b/source/Game.h @@ -52,6 +52,8 @@ private: tgui::Label* mLeftGadget; tgui::Label* mRightGadget; tgui::Label* mPickupInstruction; + std::shared_ptr mCrosshairTexture; + sf::Sprite mCrosshair; World mWorld; Pathfinder mPathfinder;