aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--brice.dat4
-rw-r--r--include/mob.hpp2
-rw-r--r--include/world.hpp10
-rw-r--r--main.cpp14
-rw-r--r--shaders/world.frag8
-rw-r--r--src/brice.cpp4
-rw-r--r--src/entities.cpp22
-rw-r--r--src/mob.cpp50
-rw-r--r--src/ui.cpp4
-rw-r--r--src/world.cpp59
-rw-r--r--xml/000.xml20
-rw-r--r--xml/playerSpawnHill1.xml27
-rw-r--r--xml/playerSpawnHill1_Building1.xml6
13 files changed, 155 insertions, 75 deletions
diff --git a/brice.dat b/brice.dat
index ea71945..3b090ad 100644
--- a/brice.dat
+++ b/brice.dat
@@ -1,5 +1,7 @@
-2
+3
canSprint
0
canJump
0
+Slow
+1
diff --git a/include/mob.hpp b/include/mob.hpp
index 0dd50ac..7ef4ff9 100644
--- a/include/mob.hpp
+++ b/include/mob.hpp
@@ -115,6 +115,8 @@ private:
std::string id;
bool triggered;
public:
+ bool notext;
+
Trigger(void);
void act(void);
diff --git a/include/world.hpp b/include/world.hpp
index fa8e4d8..e240973 100644
--- a/include/world.hpp
+++ b/include/world.hpp
@@ -27,8 +27,7 @@ enum class WorldBGType : unsigned int {
* 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 */
};
@@ -265,6 +264,7 @@ protected:
* @see addStructure()
* @see getStructurePos()
*/
+ std::vector<Structures *> build;
/**
* A vector of all villages in the world.
@@ -291,7 +291,6 @@ protected:
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
@@ -349,7 +348,7 @@ public:
/**
* 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.
@@ -417,6 +416,9 @@ public:
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);
diff --git a/main.cpp b/main.cpp
index 4dac3b8..9c0ba2f 100644
--- a/main.cpp
+++ b/main.cpp
@@ -20,6 +20,8 @@ using namespace tinyxml2;
#include <ui.hpp>
#include <gametime.hpp>
+#include <fstream>
+
/* ----------------------------------------------------------------------------
** Variables section
** --------------------------------------------------------------------------*/
@@ -118,7 +120,7 @@ void mainLoop(void);
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) {
@@ -129,6 +131,8 @@ int main(int argc, char *argv[])
for (const auto &s : args) {
if (s == "--reset" || s == "-r")
worldReset = true;
+ else if (s == "--dontrun" || s == "-d")
+ worldDontReallyRun = true;
}
}
@@ -286,8 +290,14 @@ int main(int argc, char *argv[])
}
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
@@ -372,7 +382,7 @@ void mainLoop(void){
if (game::time::tickHasPassed())
logic();
- currentWorld->update(player, game::time::getDeltaTime(), game::time::getTickCount());
+ currentWorld->update(player, game::time::getDeltaTime());
currentWorld->detect(player);
}
}
diff --git a/shaders/world.frag b/shaders/world.frag
index bde5fa5..617cbb1 100644
--- a/shaders/world.frag
+++ b/shaders/world.frag
@@ -23,10 +23,12 @@ void main()
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;
diff --git a/src/brice.cpp b/src/brice.cpp
index d5ac46d..de95f51 100644
--- a/src/brice.cpp
+++ b/src/brice.cpp
@@ -35,8 +35,10 @@ namespace game {
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) {
diff --git a/src/entities.cpp b/src/entities.cpp
index 01255d5..9f9a47c 100644
--- a/src/entities.cpp
+++ b/src/entities.cpp
@@ -257,6 +257,10 @@ void NPC::createFromXML(XMLElement *e, World *w=nullptr)
// 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;
@@ -591,8 +595,10 @@ wander(int timeRun)
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;
@@ -628,6 +634,7 @@ void NPC::interact() { //have the npc's interact back to the player
XMLElement *exml,*oxml;
static unsigned int oldidx = 9999;
+ const char *ptr;
std::string nname;
unsigned int idx;
bool stop;
@@ -704,8 +711,11 @@ COMMONAIFUNC:
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"))) {
@@ -736,6 +746,8 @@ COMMONAIFUNC:
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) {
@@ -1062,7 +1074,7 @@ bool Particles::timeUp(void)
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");
@@ -1088,7 +1100,7 @@ void Player::save(void) {
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()) {
diff --git a/src/mob.cpp b/src/mob.cpp
index 7701086..798f09a 100644
--- a/src/mob.cpp
+++ b/src/mob.cpp
@@ -331,6 +331,7 @@ Trigger::Trigger(void) : Mob()
height = 2000;
//tex = TextureIterator();
triggered = false;
+ notext = false;
}
void Trigger::act(void)
@@ -355,28 +356,38 @@ 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;
@@ -397,10 +408,17 @@ bool Trigger::bindTex(void)
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", &notext) != XML_NO_ERROR)
+ notext = false;
+
+ id = e->StrAttribute("id");
+
+ xmle = e;
}
void Trigger::saveToXML(void)
diff --git a/src/ui.cpp b/src/ui.cpp
index f32bc79..c5d134e 100644
--- a/src/ui.cpp
+++ b/src/ui.cpp
@@ -1256,6 +1256,8 @@ EXIT:
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) {
@@ -1270,6 +1272,8 @@ EXIT:
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) {
diff --git a/src/world.cpp b/src/world.cpp
index a36a9b8..2eebc4a 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -31,6 +31,12 @@ extern World *currentWorldToRight; // main.cpp
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;
@@ -220,7 +226,7 @@ generate(int width)
s.y = (randGet() % game::SCREEN_HEIGHT) + 100;
}
- weather = WorldWeather::Sunny;
+ weather = WorldWeather::None;
}
/**
@@ -1010,16 +1016,8 @@ detect(Player *p)
* 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;
@@ -1230,21 +1228,7 @@ void World::setStyle(std::string pre)
*/
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
@@ -1252,6 +1236,17 @@ 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.
*/
@@ -2008,6 +2003,16 @@ loadWorldFromXMLNoSave(std::string path) {
}
}
+ // 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();
@@ -2054,8 +2059,6 @@ loadWorldFromXMLNoSave(std::string path) {
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));
@@ -2069,6 +2072,8 @@ loadWorldFromXMLNoSave(std::string path) {
default:
break;
}
+
+ newEntity->createFromXML(wxml, tmp);
}
}
diff --git a/xml/000.xml b/xml/000.xml
new file mode 100644
index 0000000..9996cec
--- /dev/null
+++ b/xml/000.xml
@@ -0,0 +1,20 @@
+<?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>
diff --git a/xml/playerSpawnHill1.xml b/xml/playerSpawnHill1.xml
index f16b511..94ef9b8 100644
--- a/xml/playerSpawnHill1.xml
+++ b/xml/playerSpawnHill1.xml
@@ -5,13 +5,13 @@
<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&apos;s bagel emporium! The greatest place on earth!">
@@ -37,14 +37,15 @@ And it wasn't stormy.
<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>
@@ -53,9 +54,9 @@ And it wasn't stormy.
<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">
@@ -64,8 +65,8 @@ And it wasn't stormy.
</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>
diff --git a/xml/playerSpawnHill1_Building1.xml b/xml/playerSpawnHill1_Building1.xml
index eb63d7b..0b51b55 100644
--- a/xml/playerSpawnHill1_Building1.xml
+++ b/xml/playerSpawnHill1_Building1.xml
@@ -10,17 +10,17 @@
<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>