CXXFLAGS = -g -m$(TARGET_BITS) -std=c++14 -fext-numeric-literals
CXXINC = -Iinclude -Iinclude/freetype
-CXXWARN = -Wall -Wextra -Werror #-pedantic-errors
+CXXWARN = -Wall -Wextra -Werror
CXXSRCDIR = src
CXXOUTDIR = out
3
-Slow
-0
-canJump
-0
canSprint
1
+canJump
+0
+Slow
+0
// a prototype of the world class, necessary for some function prototypes
class World;
+class IndoorWorld;
/**
* The light structure, used to store light coordinates and color.
class Structures : public Entity {
public:
BUILD_SUB bsubtype;
- World *inWorld, *insideWorld;
+ World *inWorld;
+ IndoorWorld *insideWorld;
std::string inside;
std::string textureLoc;
void saveToXML(void) final;
};
+class Chest : public Mob {
+public:
+ Chest(void);
+
+ void act(void);
+ void onHit(unsigned int);
+ bool bindTex(void);
+ void createFromXML(XMLElement *e, World *w) final;
+ void saveToXML(void) final;
+};
+
#endif // MOB_H_
** The UI namespace
** --------------------------------------------------------------------------*/
+void setControl(unsigned int index, SDL_Keycode key);
+
namespace ui {
// the pixel-coordinates of the mouse
typedef void (*menuFunc)(void);
+class Menu;
+
class menuItem {
public:
int member;
+ Menu *child;
union {
struct {
vec2 loc;
class Menu {
public:
std::vector<menuItem> items;
- Menu *parent, *child;
+ Menu *parent;
~Menu()
{
items.clear();
- //delete child;
- //delete parent;
- child = NULL;
parent = NULL;
}
- void gotoChild(void);
void gotoParent(void);
};
namespace ui {
namespace menu {
menuItem createButton(vec2 l, dim2 d, Color c, const char* t, menuFunc f);
- menuItem createChildButton(vec2 l, dim2 d, Color c, const char* t);
+ menuItem createChildButton(vec2 l, dim2 d, Color c, const char* ti, Menu *_child);
menuItem createParentButton(vec2 l, dim2 d, Color c, const char* t);
menuItem createSlider(vec2 l, dim2 d, Color c, float min, float max, const char* t, float* v);
public:
+ World *outside;
+
// creates an IndoorWorld object
IndoorWorld(void);
// edge
if (!inside.empty()) {
- insideWorld = loadWorldFromXMLNoTakeover(inside);
+ insideWorld = dynamic_cast<IndoorWorld *>(loadWorldFromXMLNoTakeover(inside));
+ insideWorld->outside = inWorld;
}
textureLoc = e->StrAttribute("texture");
void Trigger::saveToXML(void)
{}
+Chest::Chest(void) : Mob()
+{
+ ridable = false;
+ aggressive = false;
+ maxHealth = health = 100;
+ width = HLINES(10);
+ height = HLINES(5);
+ tex = TextureIterator({"assets/chest.png"});
+}
+
+void Chest::act(void)
+{
+ //die();
+}
+
+void Chest::onHit(unsigned int _health)
+{
+ (void)_health;
+ die();
+}
+
+bool Chest::bindTex(void)
+{
+ glActiveTexture(GL_TEXTURE0);
+ tex(0);
+ return true;
+}
+
+void Chest::createFromXML(XMLElement *e, World *w)
+{
+ (void)w;
+ loc = vec2 { 0, 100 };
+ xmle = e;
+}
+
+void Chest::saveToXML(void)
+{
+ xmle->SetAttribute("alive", alive);
+}
+
+
+
Mob::~Mob()
{
delete inv;
*/
extern bool gameRunning;
+
+static SDL_Keycode controlMap[] = {
+ SDLK_w, SDLK_s, SDLK_a, SDLK_d
+};
+
+void setControl(unsigned int index, SDL_Keycode key)
+{
+ controlMap[index] = key;
+}
+
/**
* Freetype variables
*/
// only let other keys be handled if dialog allows it
} else if (!dialogBoxExists || dialogPassive) {
- switch(SDL_KEY) {
- case SDLK_DELETE:
- gameRunning = false;
- break;
- case SDLK_t:
- game::time::tick(50);
- break;
- case SDLK_a:
- 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) {
- std::thread([&](void){
- auto thing = currentWorld->goWorldLeft(player);
- if (thing.first != currentWorld)
- worldSwitch(thing);
- }).detach();
- }
- break;
- case SDLK_d:
- 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) {
- std::thread([&](void){
- auto thing = currentWorld->goWorldRight(player);
- if (thing.first != currentWorld)
- worldSwitch(thing);
- }).detach();
- }
- break;
- case SDLK_w:
+ if (SDL_KEY == controlMap[0]) {
if (inBattle) {
std::thread([&](void){
auto thing = dynamic_cast<Arena *>(currentWorld)->exitArena(player);
worldSwitch(thing);
}).detach();
}
+ } else if (SDL_KEY == controlMap[1]) {
+ } else if (SDL_KEY == controlMap[2]) {
+ if (!fadeEnable) {
+ 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) {
+ std::thread([&](void){
+ auto thing = currentWorld->goWorldLeft(player);
+ if (thing.first != currentWorld)
+ worldSwitch(thing);
+ }).detach();
+ }
+ }
+ } else if (SDL_KEY == controlMap[3]) {
+ if (!fadeEnable) {
+ 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) {
+ std::thread([&](void){
+ auto thing = currentWorld->goWorldRight(player);
+ if (thing.first != currentWorld)
+ worldSwitch(thing);
+ }).detach();
+ }
+ }
+ } else switch(SDL_KEY) {
+ case SDLK_DELETE:
+ gameRunning = false;
+ break;
+ case SDLK_t:
+ game::time::tick(50);
break;
case SDLK_LSHIFT:
if (game::canSprint) {
ui::menu::toggle();
player->save();
return;
- }
- switch (SDL_KEY) {
+ } else if (SDL_KEY == controlMap[2]) {
+ left = false;
+ } else if (SDL_KEY == controlMap[3]) {
+ right = false;
+ } else switch (SDL_KEY) {
case SDLK_F3:
debug ^= true;
break;
player->ground = false;
}
break;
- case SDLK_a:
- left = false;
- break;
- case SDLK_d:
- right = false;
- break;
case SDLK_LSHIFT:
if (player->speed == 4)
Mix_FadeOutChannel(1,2000);
static Menu pauseMenu;
static Menu optionsMenu;
+static Menu controlsMenu;
void Menu::gotoParent(void)
{
}
}
-void Menu::gotoChild(void)
+inline void segFault() {
+ (*((int *)NULL))++;
+}
+
+void setControlF(unsigned int index)
{
- currentMenu = child;
+ SDL_Event e;
+ do SDL_WaitEvent(&e);
+ while (e.type != SDL_KEYDOWN);
+ setControl(index, e.key.keysym.sym);
}
-inline void segFault() {
- (*((int *)NULL))++;
+void setLeftKey(void) {
+ SDL_Event e;
+
+ std::cout << "Waiting...\n";
+ do SDL_WaitEvent(&e);
+ while (e.type != SDL_KEYDOWN);
+ std::cout << "Good.\n";
+
+ setControl(2, e.key.keysym.sym);
}
namespace ui {
temp.button.color = c;
temp.button.text = t;
temp.button.func = f;
+ temp.child = nullptr;
return temp;
}
- menuItem createChildButton(vec2 l, dim2 d, Color c, const char* t) {
+ menuItem createChildButton(vec2 l, dim2 d, Color c, const char* t, Menu *_child) {
menuItem temp;
temp.member = -1;
temp.button.color = c;
temp.button.text = t;
temp.button.func = NULL;
+ temp.child = _child;
return temp;
}
temp.button.color = c;
temp.button.text = t;
temp.button.func = NULL;
+ temp.child = nullptr;
return temp;
}
temp.slider.text = t;
temp.slider.var = v;
temp.slider.sliderLoc = *v;
+ temp.child = nullptr;
return temp;
}
void init(void) {
- pauseMenu.items.push_back(ui::menu::createParentButton({-256/2,0},{256,75},{0.0f,0.0f,0.0f}, "Resume"));
- pauseMenu.items.push_back(ui::menu::createChildButton({-256/2,-100},{256,75},{0.0f,0.0f,0.0f}, "Options"));
- pauseMenu.items.push_back(ui::menu::createButton({-256/2,-200},{256,75},{0.0f,0.0f,0.0f}, "Save and Quit", ui::quitGame));
- pauseMenu.items.push_back(ui::menu::createButton({-256/2,-300},{256,75},{0.0f,0.0f,0.0f}, "Segfault", segFault));
- pauseMenu.child = &optionsMenu;
-
+ // Create the main pause menu
+ pauseMenu.items.push_back(ui::menu::createParentButton({-128,0},{256,75},{0.0f,0.0f,0.0f}, "Resume"));
+ pauseMenu.items.push_back(ui::menu::createChildButton({-128,-100},{256,75},{0.0f,0.0f,0.0f}, "Options", &optionsMenu));
+ pauseMenu.items.push_back(ui::menu::createChildButton({-128,-200},{256,75},{0.0f,0.0f,0.0f}, "Controls", &controlsMenu));
+ pauseMenu.items.push_back(ui::menu::createButton({-128,-300},{256,75},{0.0f,0.0f,0.0f}, "Save and Quit", ui::quitGame));
+ pauseMenu.items.push_back(ui::menu::createButton({-128,-400},{256,75},{0.0f,0.0f,0.0f}, "Segfault", segFault));
+
+ // Create the options (sound) menu
optionsMenu.items.push_back(ui::menu::createSlider({0-static_cast<float>(game::SCREEN_WIDTH)/4,0-(512/2)}, {50,512}, {0.0f, 0.0f, 0.0f}, 0, 100, "Master", &game::config::VOLUME_MASTER));
optionsMenu.items.push_back(ui::menu::createSlider({-200,100}, {512,50}, {0.0f, 0.0f, 0.0f}, 0, 100, "Music", &game::config::VOLUME_MUSIC));
optionsMenu.items.push_back(ui::menu::createSlider({-200,000}, {512,50}, {0.0f, 0.0f, 0.0f}, 0, 100, "SFX", &game::config::VOLUME_SFX));
optionsMenu.parent = &pauseMenu;
+
+ // Create the controls menu
+ controlsMenu.items.push_back(ui::menu::createButton({-300,200}, {-200, 100}, {0.0f, 0.0f, 0.0f}, "Left", [](){ setControlF(2);}));
+ controlsMenu.items.push_back(ui::menu::createButton({-300,50}, {-200, 100}, {0.0f, 0.0f, 0.0f}, "Right", [](){ setControlF(3);}));
+ controlsMenu.parent = &pauseMenu;
}
void toggle(void) {
m.button.func();
break;
case -1:
- currentMenu->gotoChild();
+ currentMenu = m.child;
break;
case -2:
currentMenu->gotoParent();
// +size cuts folder prefix
inside.push_back(¤tXML[xmlFolder.size()]);
- tmp = loadWorldFromXML((*d)->inside);
+ tmp = (*d)->insideWorld;
return std::make_pair(tmp, vec2 {0, 100});
}
// exit the building
else {
std::string current = ¤tXML[xmlFolder.size()];
- tmp = loadWorldFromXML(inside.back());
+ tmp = dynamic_cast<IndoorWorld *>(currentWorld)->outside; //loadWorldFromXML(inside.back());
inside.clear();
Structures *b = nullptr;
// TODO make floor texture
static GLuint floorTex = Texture::genColor(Color(150, 100, 50));
-
- glUseProgram(worldShader);
glBindTexture(GL_TEXTURE_2D, floorTex);
- std::vector<GLfloat>f;
+ std::vector<GLfloat> fc;
+ std::vector<GLfloat> ft;
for (fl = 0; fl < floor.size(); fl++) {
i = 0;
for (const auto &h : floor[fl]) {
- x = worldStart + fstart[fl] * HLINE + HLINES(i);
-
- f.emplace_back(x);
- f.emplace_back(h);
- f.emplace_back(-3);
- f.emplace_back(0);
- f.emplace_back(0);
-
- f.emplace_back(x + HLINE);
- f.emplace_back(h);
- f.emplace_back(-3);
- f.emplace_back(1);
- f.emplace_back(0);
-
- f.emplace_back(x + HLINE);
- f.emplace_back(h - INDOOR_FLOOR_THICKNESS);
- f.emplace_back(-3);
- f.emplace_back(1);
- f.emplace_back(1);
-
- f.emplace_back(x + HLINE);
- f.emplace_back(h - INDOOR_FLOOR_THICKNESS);
- f.emplace_back(-3);
- f.emplace_back(1);
- f.emplace_back(1);
-
- f.emplace_back(-3);
- f.emplace_back(0);
- f.emplace_back(1);
-
- f.emplace_back(x);
- f.emplace_back(h);
- f.emplace_back(-3);
- f.emplace_back(0);
- f.emplace_back(0);
+ x = worldStart + HLINES(fstart[fl] + i);
+
+ fc.emplace_back(x);
+ fc.emplace_back(h);
+ fc.emplace_back(-3);
+ ft.emplace_back(0);
+ ft.emplace_back(0);
+
+ fc.emplace_back(x + HLINE);
+ fc.emplace_back(h);
+ fc.emplace_back(-3);
+ ft.emplace_back(1);
+ ft.emplace_back(0);
+
+ fc.emplace_back(x + HLINE);
+ fc.emplace_back(h - INDOOR_FLOOR_THICKNESS);
+ fc.emplace_back(-3);
+ ft.emplace_back(1);
+ ft.emplace_back(1);
+
+ fc.emplace_back(x + HLINE);
+ fc.emplace_back(h - INDOOR_FLOOR_THICKNESS);
+ fc.emplace_back(-3);
+ ft.emplace_back(1);
+ ft.emplace_back(1);
+
+ fc.emplace_back(x);
+ fc.emplace_back(h - INDOOR_FLOOR_THICKNESS);
+ fc.emplace_back(-3);
+ ft.emplace_back(0);
+ ft.emplace_back(1);
+
+ fc.emplace_back(x);
+ fc.emplace_back(h);
+ fc.emplace_back(-3);
+ ft.emplace_back(0);
+ ft.emplace_back(0);
i++;
}
}
- makeWorldDrawingSimplerEvenThoughAndyDoesntThinkWeCanMakeItIntoFunctions_JustDrawThis(5 * sizeof(GLfloat), &f[0], &f[3], floor.size() * 6);
+ glUseProgram(worldShader);
+
+ makeWorldDrawingSimplerEvenThoughAndyDoesntThinkWeCanMakeItIntoFunctions_JustDrawThis(0, &fc[0], &ft[0], floor.size() * 6);
glUseProgram(0);
}
// tells what world is outside, if in a structure
- else if (Indoor && (ptr = wxml->Attribute("outside")))
- inside.push_back(ptr);
+ else if (Indoor && (ptr = wxml->Attribute("outside"))) {
+// if (!loadedLeft && !loadedRight)
+// inside.push_back(ptr);
+ }
// error, invalid link tag
- else
+ else {
UserError("XML Error: Invalid <link> tag in " + _currentXML + "!");
+ }
}
newEntity = new Page();
} else if (name == "cat") {
newEntity = new Cat();
- }
+ } else if (name == "chest") {
+ newEntity = new Chest();
+ }
// npc creation
else if (name == "npc") {
newEntity->createFromXML(wxml, tmp);
std::swap(currentXML, _currentXML);
std::swap(currentXMLRaw, _currentXMLRaw);
- std::cout << currentXML << '\n';
//}
}
<Dialog name="Guy">
<text id="0" nextid="1">
Hello there! My name is Ralph.
- <gotox>300</gotox>
+ <gotox>300</gotox>
</text>
<text id="1">
...
- <gotox>1000</gotox>
+ <gotox>1000</gotox>
<set id="Slow" value="0"/>
<set id="canSprint" value="1"/>
</text>
<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>
<generation type="Random" width="1600"/>
<time>6000</time>
<spawnx>-300</spawnx>
- <npc name="Sanc" hasDialog="true" health="1" x="21.680096" y="63.399021" dindex="0"/>
- <npc name="Bob" hasDialog="true" spawnx="30" health="1" x="30" y="62.99902" dindex="0"/>
+ <npc name="Sanc" hasDialog="true" health="1" x="122.07431" y="66.698975" dindex="0"/>
+ <npc name="Bob" hasDialog="true" spawnx="30" health="1" x="637.40271" y="63.396015" dindex="0"/>
<structure type="1" spawnx="300" alive="1"/>
<structure inside="bobshouse.xml" type="1" spawnx="10" alive="1"/>
+ <chest alive="1"/>
</World>
<Dialog name="Bob">
</content>
</text>
<text id="1" pause="true" alive="1">
- <quest assign="Check out m'swag, man!" health="1" x="-0.20029223" y="62.099083" dindex="0">
+ <quest assign="Check out m'swag, man!" health="1" x="-197.83293" y="71.963989" dindex="0">
No description
</quest>
- <content health="1" x="176.35571" y="61.999001" dindex="0">
+ <content health="1" x="-206.1515" y="70.798996" dindex="0">
Looks like you've got yourself pretty empty handed... you know, I have a simple solution for that. Come on inside, I have somethin' to show you.
</content>
</text>