-2
+3
canSprint
0
canJump
0
+Slow
+1
std::string id;
bool triggered;
public:
+ bool notext;
+
Trigger(void);
void act(void);
* Weather is set by the world somewhere.
*/
enum class WorldWeather : unsigned char {
- Sunny = 0, /**< Sunny/daytime */
- Dark, /**< Nighttime */
+ None = 0, /**< None (sunny) */
Rain, /**< Rain */
Snowy /**< Snow */
};
* @see addStructure()
* @see getStructurePos()
*/
+ std::vector<Structures *> build;
/**
* A vector of all villages in the world.
public:
- std::vector<Structures *> build;
/**
* A vector of pointers to all entities from the other vectors.
* This is used to mass-manage entities, or operate on entities
/**
* Updates entity positions, time of day, and music.
*/
- void update(Player *p, unsigned int delta, unsigned int ticks);
+ void update(Player *p, unsigned int delta);
/**
* Gets the width of the world, presumably in pixels.
std::string getWeatherStr(void) const;
const WorldWeather& getWeatherId(void) const;
+ // sets the weatherrrr
+ void setWeather(const std::string& w);
+
// sets / gets pathnames of XML files for worlds to the left and right
std::string setToLeft(std::string file);
std::string setToRight(std::string file);
#include <ui.hpp>
#include <gametime.hpp>
+#include <fstream>
+
/* ----------------------------------------------------------------------------
** Variables section
** --------------------------------------------------------------------------*/
int main(int argc, char *argv[])
{
static SDL_GLContext mainGLContext = NULL;
- static bool worldReset = false;
+ static bool worldReset = false, worldDontReallyRun = false;
// handle command line arguments
if (argc > 1) {
for (const auto &s : args) {
if (s == "--reset" || s == "-r")
worldReset = true;
+ else if (s == "--dontrun" || s == "-d")
+ worldDontReallyRun = true;
}
}
}
game::briceClear();
+
+ std::ofstream pdat ("xml/.main.dat", std::ios::out);
+ pdat.close();
}
+ if (worldDontReallyRun)
+ return 0;
+
if (currentWorld == nullptr) {
// load the first valid XML file for the world
if (game::time::tickHasPassed())
logic();
- currentWorld->update(player, game::time::getDeltaTime(), game::time::getTickCount());
+ currentWorld->update(player, game::time::getDeltaTime());
currentWorld->detect(player);
}
}
for (int i = 0; i < lightSize; i++) {
vec2 loc = light[i].xy;
float dist = length(loc - fragCoord.xy);
- float attenuation = clamp(1.0f - dist*dist/(light[i].w*light[i].w), 0.0f, 1.0f);
- attenuation *= attenuation;
+ if (dist < light[i].w) {
+ float attenuation = clamp(1.0f - dist*dist/(light[i].w*light[i].w), 0.0f, 1.0f);
+ attenuation *= attenuation;
- shadeColor += (vec4(attenuation, attenuation, attenuation, 0.0f) * vec4(lightColor[i])) * lightImpact;
+ shadeColor += (vec4(attenuation, attenuation, attenuation, 0.0f) * vec4(lightColor[i])) * lightImpact;
+ }
}
}
shadeColor += ambientLight;
void briceClear(void) {
std::ofstream out ("brice.dat", std::ios::out);
+ const std::string defaultt = "1\nSlow\n1\n";
+ out.write(defaultt.data(), defaultt.size());
out.close();
- brice.clear();
+ briceLoad();
}
void briceSave(void) {
// custom health value
E_LOAD_HEALTH;
+ // movemenet
+ if (e->QueryBoolAttribute("canMove", &dialog) == XML_NO_ERROR)
+ canMove = dialog;
+
// dialog index
if (e->QueryUnsignedAttribute("dindex", &flooor) == XML_NO_ERROR)
dialogIndex = flooor;
vel.x = HLINES(-0.018);
else if (loc.x < targetx - HLINES(5))
vel.x = HLINES(0.018);
- else
+ else {
targetx = 0.9112001f;
+ vel.x = 0;
+ }
} else if (ticksToUse == 0) {
ticksToUse = timeRun;
XMLElement *exml,*oxml;
static unsigned int oldidx = 9999;
+ const char *ptr;
std::string nname;
unsigned int idx;
bool stop;
moveTo(std::stoi(oxml->GetText()));
// asdlfkj
- auto ptr = exml->GetText() - 1;
- while (isspace(*++ptr));
+ if (exml->GetText() == nullptr)
+ goto OTHERSTUFF;
+
+ ptr = exml->GetText() - 1;
+ while (*++ptr && isspace(*ptr));
// handle dialog options
if ((oxml = exml->FirstChildElement("option"))) {
ui::waitForDialog();
}
+OTHERSTUFF:
+
// trigger other npcs if desired
if (!(nname = exml->StrAttribute("call")).empty()) {
NPC *n = *std::find_if(std::begin(currentWorld->npc), std::end(currentWorld->npc), [nname](NPC *npc) {
void Player::save(void) {
std::string data;
- std::ofstream out ("xml/main.dat",std::ios::out | std::ios::binary);
+ std::ofstream out (xmlFolder + ".main.dat", std::ios::out | std::ios::binary);
std::cout<<"Saving player data..."<<std::endl;
data.append(std::to_string((int)loc.x) + "\n");
data.append(std::to_string((int)loc.y) + "\n");
void Player::sspawn(float x,float y) {
unsigned int i;
int count;
- std::ifstream in (std::string(xmlFolder + "main.dat"),std::ios::in | std::ios::binary);
+ std::ifstream in (xmlFolder + ".main.dat", std::ios::in | std::ios::binary);
spawn(x,y);
if (in.good()) {
height = 2000;
//tex = TextureIterator();
triggered = false;
+ notext = false;
}
void Trigger::act(void)
player->vel.x = 0;
- if (exml == nullptr) {
+ if (notext) {
+ for (auto &n : currentWorld->npc) {
+ if (n->name == exml->GetText()) {
+ n->interact();
+ break;
+ }
+ }
+ } else {
+
+ /*if (exml == nullptr) {
auto id = xmle->StrAttribute("cid");
if (!id.empty()) {
game::setValue(id, xmle->StrAttribute("cvalue"));
game::briceUpdate();
}
return;
- }
+ }*/
- ui::toggleBlackFast();
- ui::waitForCover();
+ ui::toggleBlackFast();
+ ui::waitForCover();
- std::string text = exml->GetText();
- char *pch = strtok(&text[0], "\n");
+ std::string text = exml->GetText();
+ char *pch = strtok(&text[0], "\n");
- while (pch) {
- ui::importantText(pch);
- ui::waitForDialog();
- pch = strtok(NULL, "\n");
- }
+ while (pch) {
+ ui::importantText(pch);
+ ui::waitForDialog();
+ pch = strtok(NULL, "\n");
+ }
- ui::toggleBlackFast();
+ ui::toggleBlackFast();
+ }
triggered = true;
running = false;
void Trigger::createFromXML(XMLElement *e, World *w=nullptr)
{
(void)w;
- float Xlocx;
- if (e->QueryFloatAttribute("x", &Xlocx) == XML_NO_ERROR)
- loc.x = Xlocx;
- id = e->StrAttribute("id");
+ float Xlocx;
+
+ if (e->QueryFloatAttribute("spawnx", &Xlocx) == XML_NO_ERROR)
+ loc.x = Xlocx;
+
+ if (e->QueryBoolAttribute("notext", ¬ext) != XML_NO_ERROR)
+ notext = false;
+
+ id = e->StrAttribute("id");
+
+ xmle = e;
}
void Trigger::saveToXML(void)
if (fadeEnable)
break;
player->vel.x = -PLAYER_SPEED_CONSTANT;
+ if (std::stoi(game::getValue("Slow")) == 1)
+ player->vel.x /= 2.0f;
player->left = left = true;
player->right = right = false;
if (currentWorldToLeft) {
if (fadeEnable)
break;
player->vel.x = PLAYER_SPEED_CONSTANT;
+ if (std::stoi(game::getValue("Slow")) == 1)
+ player->vel.x /= 2.0f;
player->right = right = true;
player->left = left = false;
if (currentWorldToRight) {
extern bool inBattle; // ui.cpp?
extern std::string xmlFolder;
+static const std::array<std::string, 3> WorldWeatherString {
+ "None",
+ "Rainy",
+ "Snowy"
+};
+
// particle mutex
std::mutex partMutex;
s.y = (randGet() % game::SCREEN_HEIGHT) + 100;
}
- weather = WorldWeather::Sunny;
+ weather = WorldWeather::None;
}
/**
* Also handles music fading, although that could probably be placed elsewhere.
*/
void World::
-update(Player *p, unsigned int delta, unsigned int ticks)
+update(Player *p, unsigned int delta)
{
- // update day/night time
- if (!(ticks % DAY_CYCLE) || ticks == 0) {
- if (weather == WorldWeather::Sunny)
- weather = WorldWeather::Dark;
- else if (weather == WorldWeather::Dark)
- weather = WorldWeather::Sunny;
- }
-
// update player coords
p->loc.y += p->vel.y * delta;
p->loc.x +=(p->vel.x * p->speed) * delta;
*/
std::string World::getWeatherStr(void) const
{
- switch (weather) {
- case WorldWeather::Sunny:
- return "Sunny";
- break;
- case WorldWeather::Dark:
- return "Dark";
- break;
- case WorldWeather::Rain:
- return "Rainy";
- break;
- case WorldWeather::Snowy:
- return "Snowy";
- break;
- }
- return "???";
+ return WorldWeatherString[static_cast<int>(weather)];
}
const WorldWeather& World::getWeatherId(void) const
return weather;
}
+void World::setWeather(const std::string &s)
+{
+ for (unsigned int i = WorldWeatherString.size(); i--;) {
+ if (WorldWeatherString[i] == s) {
+ weather = static_cast<WorldWeather>(i);
+ return;
+ }
+ }
+ weather = WorldWeather::None;
+}
+
/**
* Pretty self-explanatory.
*/
}
}
+ // weather tags
+ else if (name == "weather") {
+ tmp->setWeather(wxml->GetText());
+ }
+
+ // set spawn x for player
+ else if (name == "spawnx") {
+ player->loc.x = std::stoi(wxml->GetText());
+ }
+
// mob creation
else if (name == "rabbit") {
newEntity = new Rabbit();
if (newEntity != nullptr) {
bool alive = true;
if (wxml->QueryBoolAttribute("alive", &alive) != XML_NO_ERROR || alive) {
- newEntity->createFromXML(wxml, tmp);
-
switch (newEntity->type) {
case NPCT:
tmp->addNPC(dynamic_cast<NPC *>(newEntity));
default:
break;
}
+
+ newEntity->createFromXML(wxml, tmp);
}
}
--- /dev/null
+<?xml version="1.0"?>
+<World>
+ <style background="0" bgm="assets/music/embark.wav" folder="assets/style/classic/"/>
+ <generation type="Random" width="500"/>
+ <link right="playerSpawnHill2.xml"/>
+ <hill peakx="0" peaky="1000" width="50"/>
+ <weather>Rainy</weather>
+ <time>3400</time>
+ <spawnx>-880</spawnx>
+ <trigger spawnx="-850" id="first" notext="1"/>
+ <npc name="Guy" hasDialog="true" spawnx="0" canMove="false" health="1" x="-582.05096" y="65.998985" dindex="9999"/>
+</World>
+
+<Trigger id="first">Guy</Trigger>
+
+<Dialog name="Guy">
+ <text id="0">
+ <gotox>-600</gotox>
+ </text>
+</Dialog>
<link right="playerSpawnHill2.xml"/>
<time>12000</time>
<hill peakx="0" peaky="1000" width="50"/>
- <rabbit spawnx="300" aggressive="false" maxHealth="100" health="50"/>
- <bird spawny="500" x="-534.19525" y="712.36743" health="1"/>
- <cat x="-48.600014" y="64.996986" alive="1"/>
+ <rabbit spawnx="300" aggressive="false" maxHealth="100"/>
+ <bird spawny="500" maxHealth="1"/>
+ <cat/>
<!--<trigger x="-300" id="Test"/>-->
- <npc name="Ralph" hasDialog="true" spawnx="300" health="1" x="-22.480118" y="64.996986" dindex="0"/>
- <npc name="Johnny" hasDialog="false" spawnx="300" health="1" x="639.87152" y="68.796982" dindex="9999"/>
- <npc name="Big Dave" hasDialog="true" spawnx="300" health="1" x="794.33545" y="69.796974" dindex="0"/>
+ <npc name="Ralph" hasDialog="true" spawnx="300"/>
+ <npc name="Johnny" hasDialog="false" spawnx="300"/>
+ <npc name="Big Dave" hasDialog="true" spawnx="300"/>
<page spawnx="-200" id="assets/pages/gootaGoFast.png" cid="canSprint" cvalue="1"/>
<page spawnx="-500" id="assets/pages/gootaJump.png" cid="canJump" cvalue="1"/>
<village name="Big Dave's bagel emporium! The greatest place on earth!">
<Dialog name="Ralph">
<text id="0" nextid="1">
- Hello there! My name is Ralph. <gotox>300</gotox>
+ Hello there! My name is Ralph.
+ <gotox>300</gotox>
</text>
<text id="1" nextid="2" call="Johnny" callid="0" pause="true">
You should go talk to my friend Johnny. He's a pretty chill dude.
</text>
<text id="2">
Niice.
- <quest check="Your First Quest" fail="3"/></text>
+ <quest check="Your First Quest" fail="3"/></text>
<text id="3">
Go check out Johnny. He's cool.
</text>
<Dialog name="Johnny">
<text id="0" nextid="1" pause="true">
Sup bro! Have a quest. To complete it, just go talk to Ralph again.
- <quest assign="Your First Quest">
- Dank MayMay,2
- Wood Sword,1
+ <quest assign="Your First Quest">
+ Dank MayMay,2
+ Wood Sword,1
</quest>
</text>
<text id="1" nextid="1" pause="true">
</Dialog>
<Dialog name="Big Dave">
- <text id="0" pause="true">
+ <text id="0" stop="true">
Hey friend! It's dangerous out there, here take these!
Wait, promise you'll stop by my stand in the local market!
- <give id="Wood Sword" count="1"/> <give id="Hunters Bow" count="1"/> <give id="Crude Arrow" count="110"/> <give id="Fried Chicken" count="1"/> <give id="Mossy Torch" count="1"/></text>
+ <give id="Wood Sword" count="1"/> <give id="Hunters Bow" count="1"/> <give id="Crude Arrow" count="110"/> <give id="Fried Chicken" count="1"/> <give id="Mossy Torch" count="1"/></text>
</Dialog>
<Dialog name="Bob">
<text id="0" nextid="1" pause="true">
Hey. Have a Dank MayMay :)
- <give id="Dank MayMay" count="1"/></text>
+ <give id="Dank MayMay" count="1"/></text>
<text id="1" nextid="2">
What? You want another Dank MayMay?
</text>
<text id="2" nextid="3" pause="true">
K.
- <give id="Dank MayMay" count="1"/></text>
+ <give id="Dank MayMay" count="1"/></text>
<text id="3" nextid="4">
Well... I'm out of Dank MayMays.
</text>
<text id="4">
Have a sword though.
- <give id="Wood Sword" count="1"/></text>
+ <give id="Wood Sword" count="1"/></text>
</Dialog>