Page MenuHomePhabricator (Chris)

No OneTemporary

Size
19 KB
Referenced Files
None
Subscribers
None
diff --git a/assets/fnt/8bitOperatorPlus-Bold.ttf b/assets/fnt/8bitOperatorPlus-Bold.ttf
new file mode 100644
index 0000000..63c7b5f
Binary files /dev/null and b/assets/fnt/8bitOperatorPlus-Bold.ttf differ
diff --git a/assets/fnt/8bitOperatorPlus-Regular.ttf b/assets/fnt/8bitOperatorPlus-Regular.ttf
new file mode 100644
index 0000000..80c12b9
Binary files /dev/null and b/assets/fnt/8bitOperatorPlus-Regular.ttf differ
diff --git a/assets/fnt/8bitOperatorPlus8-Bold.ttf b/assets/fnt/8bitOperatorPlus8-Bold.ttf
new file mode 100644
index 0000000..10ce55d
Binary files /dev/null and b/assets/fnt/8bitOperatorPlus8-Bold.ttf differ
diff --git a/assets/fnt/8bitOperatorPlus8-Regular.ttf b/assets/fnt/8bitOperatorPlus8-Regular.ttf
new file mode 100644
index 0000000..bb5dc61
Binary files /dev/null and b/assets/fnt/8bitOperatorPlus8-Regular.ttf differ
diff --git a/assets/fnt/8bitOperatorPlusSC-Bold.ttf b/assets/fnt/8bitOperatorPlusSC-Bold.ttf
new file mode 100644
index 0000000..c656c31
Binary files /dev/null and b/assets/fnt/8bitOperatorPlusSC-Bold.ttf differ
diff --git a/assets/fnt/8bitOperatorPlusSC-Regular.ttf b/assets/fnt/8bitOperatorPlusSC-Regular.ttf
new file mode 100644
index 0000000..306a9ff
Binary files /dev/null and b/assets/fnt/8bitOperatorPlusSC-Regular.ttf differ
diff --git a/assets/fnt/SIL Open Font License.txt b/assets/fnt/SIL Open Font License.txt
new file mode 100644
index 0000000..4c1508d
--- /dev/null
+++ b/assets/fnt/SIL Open Font License.txt
@@ -0,0 +1,43 @@
+Copyright (c) 2009 - 2014 Grandoplex Productions (http://grandchaos9000.deviantart.com), with Reserved Font Name 8-bit Operator+.
+
+This Font Software is licensed under the SIL Open Font License, Version 1.1.
+This license is copied below, and is also available with a FAQ at: http://scripts.sil.org/OFL
+
+-----------------------------------------------------------
+SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
+-----------------------------------------------------------
+
+PREAMBLE
+The goals of the Open Font License (OFL) are to stimulate worldwide development of collaborative font projects, to support the font creation efforts of academic and linguistic communities, and to provide a free and open framework in which fonts may be shared and improved in partnership with others.
+
+The OFL allows the licensed fonts to be used, studied, modified and redistributed freely as long as they are not sold by themselves. The fonts, including any derivative works, can be bundled, embedded, redistributed and/or sold with any software provided that any reserved names are not used by derivative works. The fonts and derivatives, however, cannot be released under any other type of license. The requirement for fonts to remain under this license does not apply to any document created using the fonts or their derivatives.
+
+DEFINITIONS
+"Font Software" refers to the set of files released by the Copyright Holder(s) under this license and clearly marked as such. This may include source files, build scripts and documentation.
+
+"Reserved Font Name" refers to any names specified as such after the copyright statement(s).
+
+"Original Version" refers to the collection of Font Software components as distributed by the Copyright Holder(s).
+
+"Modified Version" refers to any derivative made by adding to, deleting, or substituting -- in part or in whole -- any of the components of the Original Version, by changing formats or by porting the Font Software to a new environment.
+
+"Author" refers to any designer, engineer, programmer, technical writer or other person who contributed to the Font Software.
+
+PERMISSION & CONDITIONS
+Permission is hereby granted, free of charge, to any person obtaining a copy of the Font Software, to use, study, copy, merge, embed, modify, redistribute, and sell modified and unmodified copies of the Font Software, subject to the following conditions:
+
+1) Neither the Font Software nor any of its individual components, in Original or Modified Versions, may be sold by itself.
+
+2) Original or Modified Versions of the Font Software may be bundled, redistributed and/or sold with any software, provided that each copy contains the above copyright notice and this license. These can be included either as stand-alone text files, human-readable headers or in the appropriate machine-readable metadata fields within text or binary files as long as those fields can be easily viewed by the user.
+
+3) No Modified Version of the Font Software may use the Reserved Font Name(s) unless explicit written permission is granted by the corresponding Copyright Holder. This restriction only applies to the primary font name as presented to the users.
+
+4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font Software shall not be used to promote, endorse or advertise any Modified Version, except to acknowledge the contribution(s) of the Copyright Holder(s) and the Author(s) or with their explicit written permission.
+
+5) The Font Software, modified or unmodified, in part or in whole, must be distributed entirely under this license, and must not be distributed under any other license. The requirement for fonts to remain under this license does not apply to any document created using the Font Software.
+
+TERMINATION
+This license becomes null and void if any of the above conditions are not met.
+
+DISCLAIMER
+THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE FONT SOFTWARE.
diff --git a/enfucraft.pro b/enfucraft.pro
index 32f880f..13029e2 100644
--- a/enfucraft.pro
+++ b/enfucraft.pro
@@ -1,30 +1,27 @@
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
CONFIG += c++11
SOURCES += main.cpp \
game.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 \
selector.h \
playerhud.h
-OTHER_FILES += \
- assets/img/zw-tilesets/_MAP.png
-
RESOURCES += \
images.qrc
diff --git a/game.cpp b/game.cpp
index 60ecfc7..2de92a6 100644
--- a/game.cpp
+++ b/game.cpp
@@ -1,121 +1,199 @@
#include <stdlib.h>
#include <iostream>
#include "game.h"
+#include <time.h> /* time */
#include "playerhud.h"
namespace efc {
Game::Game()
{
int tileSize = 25;
int mapSize = 16;
+ std::srand (time(NULL));
+
+ int turn = 0;
+
+
sf::Texture textureFaces;
if (!textureFaces.loadFromFile("assets/img/faces.jpg"))
- std::exit(1);
+ std::exit(1);
+
+ sf::Font gameFont;
+ if (!gameFont.loadFromFile("assets/fnt/8bitOperatorPlus-Regular.ttf"))
+ {
+ std::exit(1);
+ }
+
- sf::RenderWindow window(sf::VideoMode(512, 400), "Tilemap");
+ sf::RenderWindow window(sf::VideoMode(512, 400), "EnFuCraft");
// Grass tile starts at 342 and has 11 tiles
int level[256];
+ int levelElems[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;
+ int grass = (rand() % 10) + 1;
level[i] = 342 + grass;
+ levelElems[i] = level[i];
}
+
+
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);
-
- 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);
+ Selector selector(tileSize);
+ TileMap mapElem;
+
+ selector.changeColor(turn);
+ PlayerHud playerHud1(std::rand() % 80, &textureFaces, &gameFont, 32,0);
+ PlayerHud playerHud2(std::rand() % 30, &textureFaces, &gameFont, 32,1);
+ PlayerHud playerHud3(std::rand() % 60, &textureFaces, &gameFont, 32,2);
+ PlayerHud playerHud4(std::rand() % 50, &textureFaces, &gameFont, 32,3);
+ PlayerHud players[4] = {playerHud1, playerHud2, playerHud3, playerHud4};
+
+
if (!map.load("assets/img/zw-tilesets/_MAP.png", sf::Vector2u(tileSize, tileSize), level, mapSize, mapSize))
std::exit(1);
+ levelElems[0] = 0;
+ levelElems[15] = 0;
+ levelElems[8] = 813;
+ levelElems[24] = 803;
+ levelElems[40] = 803;
+ levelElems[56] = 803;
+ levelElems[72] = 803;
+
+ levelElems[88] = 801;
+// levelElems[104] = 80;
+// levelElems[120] = 803;
+// levelElems[135] = 803;
+// levelElems[151] = 803;
+// levelElems[161] = 803;
+ levelElems[167] = 809;
+ levelElems[183] = 803;
+ levelElems[199] = 803;
+ levelElems[215] = 803;
+ levelElems[231] = 803;
+ levelElems[247] = 812;
+
+ levelElems[112] = 811;
+ for (int i=113;i<117;i++)
+ levelElems[i] = 816;
+ levelElems[117] = 815;
+
+ levelElems[138] = 800;
+ for (int i=139;i<143;i++)
+ levelElems[i] = 816;
+ levelElems[143] = 814;
+
+ levelElems[240] = 0;
+ levelElems[255] = 0;
+
+
+
+ if (!mapElem.load("assets/img/zw-tilesets/_MAP.png", sf::Vector2u(tileSize, tileSize), levelElems, 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();
+
+
+ if (event.type == sf::Event::MouseButtonPressed)
+ {
+ if (event.mouseButton.button == sf::Mouse::Left)
+ {
+ std::cout << "the right button was pressed" << std::endl;
+ std::cout << "mouse x: " << event.mouseButton.x << std::endl;
+ std::cout << "mouse y: " << event.mouseButton.y << std::endl;
+ turn++;
+ if (turn==4)
+ turn = 0;
+ selector.changeColor(turn);
+ }
+ }
+
+
}
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);
+ 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(mapElem);
+
window.draw(selector);
window.setView(viewGui);
window.draw(playerHud1);
window.draw(playerHud2);
window.draw(playerHud3);
window.draw(playerHud4);
window.display();
}
}
}
diff --git a/playerhud.cpp b/playerhud.cpp
index d453281..7a6faca 100644
--- a/playerhud.cpp
+++ b/playerhud.cpp
@@ -1,47 +1,106 @@
#include "playerhud.h"
-PlayerHud::PlayerHud(int faceNumber, sf::Texture *faces, int tileSize, int pos)
+PlayerHud::PlayerHud(int faceNumber, sf::Texture *faces, sf::Font *gameFont, int tileSize, int pos)
{
this->tileSize = tileSize;
spriteFace.setTexture(*faces);
this->pos = pos;
-
+ food = 0;
+ cash = 0;
+ energy = 0;
int y = (int) faceNumber /10;
int x = faceNumber % 10;
+// if (!gameFontloadFromFile("assets/fnt/8bitOperatorPlus-Regular.ttf"))
+// {
+// std::exit(1);
+// }
+
+
+ txtCash.setFont(*gameFont);
+ txtFood.setFont(*gameFont);
+ txtEnergy.setFont(*gameFont);
+
+
+ txtCash.setPosition(1,(pos*100)+40);
+ txtCash.setString("Cash: " + std::to_string(cash));
+ txtCash.setCharacterSize(10);
+ txtCash.setScale(sf::Vector2f(0.25f, 1.f));
+
+
+ txtFood.setPosition(1,(pos*100)+55);
+ txtFood.setString("Food: " + std::to_string(food));
+ txtFood.setCharacterSize(10);
+ txtFood.setScale(sf::Vector2f(0.25f, 1.f));
+
+
+ txtEnergy.setPosition(1,(pos*100)+70);
+ txtEnergy.setString("Enrg: " + std::to_string(energy));
+ txtEnergy.setCharacterSize(10);
+ txtEnergy.setScale(sf::Vector2f(0.25f, 1.f));
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,pos*100);
}
void PlayerHud::draw(sf::RenderTarget& target, sf::RenderStates states) const
{
// // apply the transform
states.transform *= getTransform();
sf::RectangleShape rectangle(sf::Vector2f(tileSize, tileSize));
+ sf::RectangleShape rectangle2(sf::Vector2f(tileSize, (tileSize*2)+3));
+
if (pos==0)
+ {
rectangle.setFillColor(sf::Color(50, 50, 150,168));
+ rectangle2.setFillColor(sf::Color(100, 100, 150,168));
+ rectangle.setOutlineColor(sf::Color(0,0,128));
+ }
else if (pos==1)
+ {
rectangle.setFillColor(sf::Color(50, 150, 50,168));
+ rectangle2.setFillColor(sf::Color(100, 150,100,168));
+
+ rectangle.setOutlineColor(sf::Color(0,128,0));
+ }
+
else if (pos==2)
+ {
rectangle.setFillColor(sf::Color(150, 50, 50,168));
+ rectangle2.setFillColor(sf::Color(150, 100,100,168));
+
+ rectangle.setOutlineColor(sf::Color(128,0,0));
+
+ }
else if (pos==3)
+ {
rectangle.setFillColor(sf::Color(150, 150, 150,168));
+ rectangle2.setFillColor(sf::Color(200, 200,200,168));
+
+ rectangle.setOutlineColor(sf::Color(128,128,128));
+
+ }
rectangle.setOutlineThickness(1);
- rectangle.setOutlineColor(sf::Color(0,0,128));
rectangle.setPosition(0, pos*100);
+ rectangle2.setPosition(0, (pos*100)+tileSize+1);
target.draw(rectangle, states);
+ target.draw(rectangle2, states);
+ target.draw(txtCash);
+ target.draw(txtFood);
+ target.draw(txtEnergy);
+
+
target.draw(spriteFace);
}
diff --git a/playerhud.h b/playerhud.h
index 9430b63..eaa1e6d 100644
--- a/playerhud.h
+++ b/playerhud.h
@@ -1,21 +1,31 @@
#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, int tileSize, int pos);
+ PlayerHud(int faceNumber, sf::Texture *faces, sf::Font *gameFont, int tileSize, int pos);
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
int pos;
+ int cash;
+ int energy;
+ int food;
+
+ std::vector<int> properties;
+
private:
+// sf::Font gameFont;
sf::Sprite spriteFace;
+ sf::Text txtCash;
+ sf::Text txtEnergy;
+ sf::Text txtFood;
int tileSize;
};
#endif // PLAYERHUD_H
diff --git a/selector.cpp b/selector.cpp
index 3bcbc19..09e02b8 100644
--- a/selector.cpp
+++ b/selector.cpp
@@ -1,30 +1,61 @@
#include "selector.h"
Selector::Selector(int squareSize)
+ :rectangle(sf::Vector2f(squareSize, squareSize))
{
this->squareSize = squareSize;
+ rectangle.setFillColor(sf::Color(150, 250, 150,168));
+
+ rectangle.setOutlineThickness(1);
+ rectangle.setOutlineColor(sf::Color(0,255,0));
+ changeColor(3);
}
+void Selector::changeColor(int colorNumber)
+{
+
+ if (colorNumber==0)
+ {
+ rectangle.setFillColor(sf::Color(150, 150, 250,168));
+ rectangle.setOutlineColor(sf::Color(0,0,255));
+ }
+ else if (colorNumber==1)
+ {
+ rectangle.setFillColor(sf::Color(150, 250, 150,168));
+ rectangle.setOutlineColor(sf::Color(0,255,0));
+ }
+ else if (colorNumber==2)
+ {
+ rectangle.setFillColor(sf::Color(250, 150, 150,168));
+ rectangle.setOutlineColor(sf::Color(255,0,0));
+ }
+ else if (colorNumber==3)
+ {
+ rectangle.setFillColor(sf::Color(200, 200, 200,168));
+ rectangle.setOutlineColor(sf::Color(200,200,200));
+ }
+
+
+
+}
void Selector::draw(sf::RenderTarget& target, sf::RenderStates states) const
{
-// // apply the transform
- states.transform *= getTransform();
+ // // apply the transform
+ states.transform *= getTransform();
-// // apply the tileset texture
-// states.texture = &m_tileset;
+ // // apply the tileset texture
+ // states.texture = &m_tileset;
-// // draw the vertex array
-// target.draw(m_vertices, states);
+ // // 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));
+// sf::RectangleShape rectangle(sf::Vector2f(squareSize, squareSize));
+
target.draw(rectangle, states);
}
diff --git a/selector.h b/selector.h
index 42128d9..e925b0d 100644
--- a/selector.h
+++ b/selector.h
@@ -1,15 +1,19 @@
#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;
+ void changeColor(int colorNumber);
+
int squareSize;
+private:
+ sf::RectangleShape rectangle;
};
#endif // SELECTOR_H

File Metadata

Mime Type
text/x-diff
Expires
Mon, Feb 2, 9:12 PM (2 d, 4 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
55588
Default Alt Text
(19 KB)

Event Timeline