Page MenuHomePhabricator (Chris)

No OneTemporary

Size
6 KB
Referenced Files
None
Subscribers
None
diff --git a/game.cpp b/game.cpp
index 1afd404..60ecfc7 100644
--- a/game.cpp
+++ b/game.cpp
@@ -1,110 +1,121 @@
#include <stdlib.h>
#include <iostream>
#include "game.h"
#include "playerhud.h"
namespace efc {
Game::Game()
{
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;
- Selector selector(tileSize);
- PlayerHud playerHud(1, &textureFaces);
+ Selector selector(tileSize);
+
+ int faceNumber = std::rand() % 80;
+// faceNumber = 1;
+ PlayerHud playerHud1(std::rand() % 80, &textureFaces, 32,0);
+ PlayerHud playerHud2(std::rand() % 80, &textureFaces, 32,1);
+ PlayerHud playerHud3(std::rand() % 80, &textureFaces, 32,2);
+ PlayerHud playerHud4(std::rand() % 80, &textureFaces, 32,3);
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.draw(playerHud1);
+ window.draw(playerHud2);
+ window.draw(playerHud3);
+ window.draw(playerHud4);
window.display();
+
+
}
}
}
diff --git a/playerhud.cpp b/playerhud.cpp
index d9e76d0..d453281 100644
--- a/playerhud.cpp
+++ b/playerhud.cpp
@@ -1,26 +1,47 @@
#include "playerhud.h"
-PlayerHud::PlayerHud(int faceNumber, sf::Texture *faces)
+PlayerHud::PlayerHud(int faceNumber, sf::Texture *faces, int tileSize, int pos)
{
+ this->tileSize = tileSize;
spriteFace.setTexture(*faces);
- spriteFace.setTextureRect(sf::IntRect(0, 0, 31, 31));
+ this->pos = pos;
+
+
+
+ int y = (int) faceNumber /10;
+ int x = faceNumber % 10;
+
+
+ std::cout << "playerHud" << faceNumber << " " << x << " " << y << std::endl;
+
+ spriteFace.setTextureRect(sf::IntRect(x*tileSize, y*tileSize, tileSize, tileSize));
spriteFace.setScale(sf::Vector2f(0.25f, 1.f));
- spriteFace.setPosition(0,200);
+ spriteFace.setPosition(0,pos*100);
}
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));
+ sf::RectangleShape rectangle(sf::Vector2f(tileSize, tileSize));
+
+ if (pos==0)
+ rectangle.setFillColor(sf::Color(50, 50, 150,168));
+ else if (pos==1)
+ rectangle.setFillColor(sf::Color(50, 150, 50,168));
+ else if (pos==2)
+ rectangle.setFillColor(sf::Color(150, 50, 50,168));
+ else if (pos==3)
+ rectangle.setFillColor(sf::Color(150, 150, 150,168));
+
+
rectangle.setOutlineThickness(1);
rectangle.setOutlineColor(sf::Color(0,0,128));
-
+ rectangle.setPosition(0, pos*100);
target.draw(rectangle, states);
target.draw(spriteFace);
}
diff --git a/playerhud.h b/playerhud.h
index 45a5530..9430b63 100644
--- a/playerhud.h
+++ b/playerhud.h
@@ -1,19 +1,21 @@
#ifndef PLAYERHUD_H
#define PLAYERHUD_H
+#include <iostream>
#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);
+ PlayerHud(int faceNumber, sf::Texture *faces, int tileSize, int pos);
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
-
+ int pos;
private:
sf::Sprite spriteFace;
+ int tileSize;
};
#endif // PLAYERHUD_H

File Metadata

Mime Type
text/x-diff
Expires
Mon, Feb 2, 9:12 PM (2 d, 7 m ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
55589
Default Alt Text
(6 KB)

Event Timeline