Added custom crosshair.

This commit is contained in:
Felix Ableitner 2013-08-18 17:19:34 +02:00
parent 2709f0a505
commit 0fccc7e3af
4 changed files with 20 additions and 8 deletions

View file

@ -22,3 +22,4 @@ Space: pause
Player/Enemy (modified): http://opengameart.org/content/top-down-runner Player/Enemy (modified): http://opengameart.org/content/top-down-runner
Tiles (modified): http://opengameart.org/content/metalstone-textures Tiles (modified): http://opengameart.org/content/metalstone-textures
Item: http://opengameart.org/content/random-adventure-kit Item: http://opengameart.org/content/random-adventure-kit
Crosshair: http://opengameart.org/content/20-crosshairs-for-re

Binary file not shown.

After

Width:  |  Height:  |  Size: 912 B

View file

@ -14,18 +14,12 @@
#include "items/Shield.h" #include "items/Shield.h"
#include "sprites/Enemy.h" #include "sprites/Enemy.h"
#include "sprites/Player.h" #include "sprites/Player.h"
#include "util/Loader.h"
#include "util/ResourceManager.h"
#include "util/Yaml.h" #include "util/Yaml.h"
const int Game::FPS_GOAL = 60; const int Game::FPS_GOAL = 60;
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);
}
/** /**
* Initializes game, including window and objects (sprites). * Initializes game, including window and objects (sprites).
*/ */
@ -41,6 +35,11 @@ Game::Game(tgui::Window& window) :
mGenerator.generateCurrentAreaIfNeeded(Vector2f()); mGenerator.generateCurrentAreaIfNeeded(Vector2f());
initPlayer(); initPlayer();
mCrosshairTexture = ResourceManager::i().acquire(Loader::i()
.fromFile<sf::Texture>("crosshair.png"));
mCrosshair.setTexture(*mCrosshairTexture, true);
mWindow.setMouseCursorVisible(false);
mHealth = window.add<tgui::Label>(); mHealth = window.add<tgui::Label>();
mHealth->setTextSize(20); mHealth->setTextSize(20);
mAmmo = window.add<tgui::Label>(); mAmmo = window.add<tgui::Label>();
@ -55,6 +54,14 @@ Game::Game(tgui::Window& window) :
mPickupInstruction->setTextSize(14); 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. * Closes window.
*/ */
@ -161,6 +168,7 @@ Game::input() {
case sf::Event::MouseMoved: case sf::Event::MouseMoved:
mPlayer->setCrosshairPosition(convertCoordinates(event.mouseMove.x, mPlayer->setCrosshairPosition(convertCoordinates(event.mouseMove.x,
event.mouseMove.y)); event.mouseMove.y));
mCrosshair.setPosition(Vector2f(sf::Mouse::getPosition(mWindow) - Vector2i(mCrosshair.getTextureRect().width, mCrosshair.getTextureRect().height) / 2));
break; break;
case sf::Event::MouseWheelMoved: case sf::Event::MouseWheelMoved:
mPlayer->toggleWeapon(); mPlayer->toggleWeapon();
@ -294,6 +302,7 @@ Game::render() {
// Render GUI and static stuff. // Render GUI and static stuff.
mWindow.setView(mWindow.getDefaultView()); mWindow.setView(mWindow.getDefaultView());
mWindow.drawGUI(); mWindow.drawGUI();
mWindow.draw(mCrosshair);
mWindow.display(); mWindow.display();
} }

View file

@ -52,6 +52,8 @@ private:
tgui::Label* mLeftGadget; tgui::Label* mLeftGadget;
tgui::Label* mRightGadget; tgui::Label* mRightGadget;
tgui::Label* mPickupInstruction; tgui::Label* mPickupInstruction;
std::shared_ptr<sf::Texture> mCrosshairTexture;
sf::Sprite mCrosshair;
World mWorld; World mWorld;
Pathfinder mPathfinder; Pathfinder mPathfinder;