Page Menu
Home
Phabricator (Chris)
Search
Configure Global Search
Log In
Files
F102520
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
7 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/assets/img/faces.jpg b/assets/img/faces.jpg
new file mode 100644
index 0000000..f1e1870
Binary files /dev/null and b/assets/img/faces.jpg differ
diff --git a/enfucraft.pro b/enfucraft.pro
index 354d98b..32f880f 100644
--- a/enfucraft.pro
+++ b/enfucraft.pro
@@ -1,17 +1,30 @@
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
CONFIG += c++11
SOURCES += main.cpp \
game.cpp \
- tilemap.cpp
+ tilemap.cpp \
+ selector.cpp \
+ playerhud.cpp
LIBS += -lsfml-window -lsfml-system -lsfml-graphics
+DESTDIR = ../build_release_enfucraft
+
+assets.path = $${DESTDIR}/assets
+assets.files = assets/*
+
+INSTALLS += assets
HEADERS += \
game.h \
- tilemap.h
+ tilemap.h \
+ selector.h \
+ playerhud.h
OTHER_FILES += \
assets/img/zw-tilesets/_MAP.png
+
+RESOURCES += \
+ images.qrc
diff --git a/game.cpp b/game.cpp
index 24337d6..1afd404 100644
--- a/game.cpp
+++ b/game.cpp
@@ -1,60 +1,110 @@
#include <stdlib.h>
+#include <iostream>
#include "game.h"
+
+#include "playerhud.h"
+
+
namespace efc {
Game::Game()
{
- sf::RenderWindow window(sf::VideoMode(512, 512), "Tilemap");
+ int tileSize = 25;
+ int mapSize = 16;
+
+ sf::Texture textureFaces;
+
+
+ if (!textureFaces.loadFromFile("assets/img/faces.jpg"))
+ std::exit(1);
+
+ sf::RenderWindow window(sf::VideoMode(512, 400), "Tilemap");
// Grass tile starts at 342 and has 11 tiles
int level[256];
/* =
{
342, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
80, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 2, 0, 0, 0, 0,
1, 1, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3, 3, 3, 3, 3,
0, 1, 0, 0, 2, 0, 3, 3, 3, 0, 1, 1, 1, 0, 0, 0,
0, 1, 1, 0, 3, 3, 3, 0, 0, 0, 1, 1, 1, 2, 0, 0,
0, 0, 1, 0, 3, 0, 2, 2, 0, 0, 1, 1, 1, 1, 2, 0,
2, 0, 1, 0, 3, 0, 2, 2, 2, 0, 1, 1, 1, 1, 1, 1,
0, 0, 1, 0, 3, 2, 2, 2, 0, 0, 0, 0, 1, 1, 1, 1,
342, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
80, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 2, 0, 0, 0, 0,
1, 1, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3, 3, 3, 3, 3,
0, 1, 0, 0, 2, 0, 3, 3, 3, 0, 1, 1, 1, 0, 0, 0,
0, 1, 1, 0, 3, 3, 3, 0, 0, 0, 1, 1, 1, 2, 0, 0,
0, 0, 1, 0, 3, 0, 2, 2, 0, 0, 1, 1, 1, 1, 2, 0,
2, 0, 1, 0, 3, 0, 2, 2, 2, 0, 1, 1, 1, 1, 1, 1,
0, 0, 1, 0, 3, 2, 2, 2, 0, 0, 0, 0, 1, 1, 1, 1,
};*/
+
// Fill the array
for (int i=0;i<256;i++)
{
int grass = rand() % 11;
level[i] = 342 + grass;
}
+ sf::View viewGui(sf::FloatRect(00, 00, 112, 400));
+ viewGui.setViewport(sf::FloatRect(0.8f,0, 1.0f, 1.0f));
+
+
+ sf::View viewTiles(sf::FloatRect(00, 00, 400, 400));
+ viewTiles.setViewport(sf::FloatRect(0,0, 0.8f, 1.0f));
+
// create the tilemap from the level definition
TileMap map;
- if (!map.load("/home/bluszcz/repo/enfucraft/assets/img/zw-tilesets/_MAP.png", sf::Vector2u(25, 25), level, 16, 16))
+ Selector selector(tileSize);
+ PlayerHud playerHud(1, &textureFaces);
+ if (!map.load("assets/img/zw-tilesets/_MAP.png", sf::Vector2u(tileSize, tileSize), level, mapSize, mapSize))
std::exit(1);
+
// run the main loop
while (window.isOpen())
{
// handle events
sf::Event event;
while (window.pollEvent(event))
{
if(event.type == sf::Event::Closed)
window.close();
}
+ sf::Vector2i localPositionTmp = sf::Mouse::getPosition(window);
+ sf::Vector2f localPosition = window.mapPixelToCoords(localPositionTmp,viewTiles);
+
+
+
+ if ((localPosition.x>=0) && (localPosition.y>=0) && (localPosition.x<=mapSize*tileSize) && (localPosition.y<=mapSize*tileSize))
+ {
+ std::cout << localPosition.x << " " << localPosition.y << " " << localPosition.x / tileSize << " " << localPosition.y / tileSize << std::endl;
+ selector.setPosition((int) (localPosition.x / tileSize)*tileSize, ((int) localPosition.y / tileSize)*tileSize);
+ }
+
+
// draw the map
window.clear();
+
+
+ window.setView(viewTiles);
+
window.draw(map);
+ window.draw(selector);
+
+ window.setView(viewGui);
+ window.draw(playerHud);
window.display();
+
+
+
+
+
}
}
}
diff --git a/game.h b/game.h
index fb3e6a5..c3985f9 100644
--- a/game.h
+++ b/game.h
@@ -1,15 +1,16 @@
#ifndef GAME_H
#define GAME_H
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include "tilemap.h"
+#include "selector.h"
namespace efc {
class Game
{
public:
Game();
sf::RenderWindow window;
};
}
#endif // GAME_H
diff --git a/images.qrc b/images.qrc
new file mode 100644
index 0000000..67e7dbc
--- /dev/null
+++ b/images.qrc
@@ -0,0 +1,5 @@
+<RCC>
+ <qresource prefix="/textures">
+ <file>assets/img/zw-tilesets/_MAP.png</file>
+ </qresource>
+</RCC>
diff --git a/playerhud.cpp b/playerhud.cpp
new file mode 100644
index 0000000..c0810ba
--- /dev/null
+++ b/playerhud.cpp
@@ -0,0 +1,22 @@
+#include "playerhud.h"
+
+PlayerHud::PlayerHud(int faceNumber, sf::Texture *faces)
+{
+
+}
+
+void PlayerHud::draw(sf::RenderTarget& target, sf::RenderStates states) const
+{
+// // apply the transform
+ states.transform *= getTransform();
+
+
+ sf::RectangleShape rectangle(sf::Vector2f(25, 25));
+ rectangle.setFillColor(sf::Color(50, 50, 150,168));
+ rectangle.setOutlineThickness(1);
+ rectangle.setOutlineColor(sf::Color(0,0,128));
+
+ target.draw(rectangle, states);
+
+
+}
diff --git a/playerhud.h b/playerhud.h
new file mode 100644
index 0000000..527083b
--- /dev/null
+++ b/playerhud.h
@@ -0,0 +1,16 @@
+#ifndef PLAYERHUD_H
+#define PLAYERHUD_H
+#include <SFML/Window.hpp>
+#include <SFML/Graphics.hpp>
+#include <SFML/System.hpp>
+class PlayerHud : public sf::Drawable, public sf::Transformable
+{
+public:
+ PlayerHud(int faceNumber, sf::Texture *faces);
+ virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
+
+};
+
+
+
+#endif // PLAYERHUD_H
diff --git a/selector.cpp b/selector.cpp
new file mode 100644
index 0000000..3bcbc19
--- /dev/null
+++ b/selector.cpp
@@ -0,0 +1,30 @@
+#include "selector.h"
+
+Selector::Selector(int squareSize)
+{
+ this->squareSize = squareSize;
+
+}
+
+
+void Selector::draw(sf::RenderTarget& target, sf::RenderStates states) const
+{
+// // apply the transform
+ states.transform *= getTransform();
+
+// // apply the tileset texture
+// states.texture = &m_tileset;
+
+// // draw the vertex array
+// target.draw(m_vertices, states);
+
+
+ sf::RectangleShape rectangle(sf::Vector2f(squareSize, squareSize));
+ rectangle.setFillColor(sf::Color(150, 250, 150,168));
+ rectangle.setOutlineThickness(1);
+ rectangle.setOutlineColor(sf::Color(0,255,0));
+
+ target.draw(rectangle, states);
+
+
+}
diff --git a/selector.h b/selector.h
new file mode 100644
index 0000000..42128d9
--- /dev/null
+++ b/selector.h
@@ -0,0 +1,15 @@
+#ifndef SELECTOR_H
+#define SELECTOR_H
+#include <SFML/Window.hpp>
+#include <SFML/Graphics.hpp>
+#include <SFML/System.hpp>
+
+class Selector : public sf::Drawable, public sf::Transformable
+{
+public:
+ Selector(int squareSize);
+ virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
+ int squareSize;
+};
+
+#endif // SELECTOR_H
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Mon, Feb 2, 9:13 PM (1 d, 19 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
55591
Default Alt Text
(7 KB)
Attached To
Mode
R82 deerportal
Attached
Detach File
Event Timeline
Log In to Comment