aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authordrumsetmonkey <abelleisle@roadrunner.com>2016-04-28 11:49:19 -0400
committerdrumsetmonkey <abelleisle@roadrunner.com>2016-04-28 11:49:19 -0400
commit992969772def3578acbd1cef0155333636f75862 (patch)
tree2794c7591bb463d5fe28a669eb97d211d72f4501 /src
parent4f0dff18e4680d9bb4e7efc9cffdb0b63937533c (diff)
parent62df9319f06bb52da8878522117ebe85fc5226b5 (diff)
Merge branch 'master' of https://github.com/tcsullivan/gamedev
Diffstat (limited to 'src')
-rw-r--r--src/entities.cpp6
-rw-r--r--src/mob.cpp106
-rw-r--r--src/ui.cpp65
-rw-r--r--src/world.cpp42
4 files changed, 155 insertions, 64 deletions
diff --git a/src/entities.cpp b/src/entities.cpp
index 869f0d4..b9c1d0d 100644
--- a/src/entities.cpp
+++ b/src/entities.cpp
@@ -332,6 +332,12 @@ void Entity::draw(void)
glColor3ub(255, 255, 255);
else if (gender == FEMALE)
glColor3ub(255, 105, 180);
+ } else if (type == MOBT) {
+ if (Mobp(this)->rider != nullptr) {
+ Mobp(this)->rider->loc.x = loc.x + width / 2;
+ Mobp(this)->rider->loc.y = loc.y + height - game::HLINE;
+ Mobp(this)->rider->vel.y = .12;
+ }
}
if (left) {
glScalef(-1.0f,1.0f,1.0f);
diff --git a/src/mob.cpp b/src/mob.cpp
index c783209..1608234 100644
--- a/src/mob.cpp
+++ b/src/mob.cpp
@@ -1,12 +1,19 @@
#include <mob.hpp>
#include <ui.hpp>
-Page::Page(void)
+Mob::Mob(void)
{
type = MOBT;
+ rider = nullptr;
+ canMove = true;
+}
+
+Page::Page(void) : Mob()
+{
+
+ ridable = false;
aggressive = false;
maxHealth = health = 50;
- canMove = true;
width = HLINES(6);
height = HLINES(4);
tex = new Texturec({"assets/items/ITEM_PAGE.png"});
@@ -39,12 +46,11 @@ void Page::createFromXML(const XMLElement *e)
pageTexPath = e->StrAttribute("id");
}
-Door::Door(void)
+Door::Door(void) : Mob()
{
- type = MOBT;
+ ridable = false;
aggressive = false;
maxHealth = health = 50;
- canMove = true;
width = HLINES(12);
height = HLINES(20);
tex = new Texturec({"assets/door.png"});
@@ -68,10 +74,61 @@ void Door::createFromXML(const XMLElement *e)
loc.x = Xlocx;
}
-Rabbit::Rabbit(void)
+Cat::Cat(void) : Mob()
{
- type = MOBT;
- canMove = true;
+ ridable = true;
+ aggressive = false;
+ maxHealth = health = 1000;
+ width = HLINES(19);
+ height = HLINES(15);
+ tex = new Texturec({"assets/cat.png"});
+ actCounterInitial = 0;
+ actCounter = 1;
+}
+
+void Cat::act(void)
+{
+ static float vely = 0;
+ if (rider != nullptr) {
+ if (!rider->ground) {
+ loc.y += HLINES(2);
+ vel.y = .4;
+ }
+ if (rider->speed > 1) {
+ vely = .5;
+ } else if (rider->speed == .5) {
+ vely = -.5;
+ } else {
+ vely = 0;
+ }
+ vel.y = vely;
+ if (!rider->ground) {
+ if ((vel.y -= .015) < -.2)
+ rider->ground = true;
+ }
+ vel.x = .1 * (rider->left ? -1 : 1);
+ } else {
+ vel = 0;
+ }
+}
+
+bool Cat::bindTex(void)
+{
+ glActiveTexture(GL_TEXTURE0);
+ tex->bind(0);
+ return true;
+}
+
+void Cat::createFromXML(const XMLElement *e)
+{
+ float Xlocx;
+ if (e->QueryFloatAttribute("x", &Xlocx) == XML_NO_ERROR)
+ loc.x = Xlocx;
+}
+
+Rabbit::Rabbit(void) : Mob()
+{
+ ridable = true;
aggressive = false;
maxHealth = health = 50;
width = HLINES(10);
@@ -118,12 +175,11 @@ void Rabbit::createFromXML(const XMLElement *e)
aggressive = false;
}
-Bird::Bird(void)
+Bird::Bird(void) : Mob()
{
- type = MOBT;
+ ridable = true;
aggressive = false;
maxHealth = health = 50;
- canMove = true;
width = HLINES(8);
height = HLINES(8);
tex = new Texturec({"assets/robin.png"});
@@ -164,12 +220,11 @@ void Bird::createFromXML(const XMLElement *e)
aggressive = false;
}
-Trigger::Trigger(void)
+Trigger::Trigger(void) : Mob()
{
- type = MOBT;
+ ridable = false;
aggressive = false;
maxHealth = health = 50;
- canMove = true;
width = HLINES(20);
height = 2000;
tex = new Texturec(0);
@@ -231,17 +286,21 @@ void Trigger::createFromXML(const XMLElement *e)
id = e->StrAttribute("id");
}
-Mob::~Mob() {
+Mob::~Mob()
+{
delete inv;
delete tex;
delete[] name;
}
-void Mob::wander(void) {
+void Mob::wander(void)
+{
//static bool YAYA = false;
- if (forcedMove)
+
+ if (forcedMove)
return;
- /*if (aggressive && !YAYA && isInside(vec2 {player->loc.x + width / 2, player->loc.y + height / 4})) {
+
+ /*if (aggressive && !YAYA && isInside(vec2 {player->loc.x + width / 2, player->loc.y + height / 4})) {
if (!ui::dialogBoxExists) {
Arena *a = new Arena(currentWorld, player, this);
a->setStyle("");
@@ -258,3 +317,14 @@ void Mob::wander(void) {
}*/
act();
}
+
+void Mob::ride(Entity *e)
+{
+ if (!ridable)
+ return;
+
+ if (rider == e)
+ rider = nullptr;
+ else
+ rider = e;
+}
diff --git a/src/ui.cpp b/src/ui.cpp
index 0f81f34..4e3bf23 100644
--- a/src/ui.cpp
+++ b/src/ui.cpp
@@ -565,7 +565,7 @@ namespace ui {
fadeIntensity = 255;
}
- void waitForNothing (unsigned int ms) {
+ void waitForNothing(unsigned int ms) {
unsigned int target = millis() + ms;
while (millis() < target);
}
@@ -917,7 +917,7 @@ EXIT:
auto SCREEN_HEIGHT = game::SCREEN_HEIGHT;
World *tmp;
- vec2 oldpos,tmppos;
+ Mob *m; // ;lkjfdsa
SDL_Event e;
// update mouse coords
@@ -1019,43 +1019,45 @@ EXIT:
game::time::tick(50);
break;
case SDLK_a:
- if (fadeEnable)break;
+ if (fadeEnable)
+ break;
player->vel.x = -PLAYER_SPEED_CONSTANT;
player->left = left = true;
player->right = right = false;
if (currentWorldToLeft) {
- oldpos = player->loc;
- if ((tmp = currentWorld->goWorldLeft(player)) != currentWorld) {
- tmppos = player->loc;
- player->loc = oldpos;
-
- toggleBlackFast();
- waitForCover();
- player->loc = tmppos;
-
- currentWorld = tmp;
- toggleBlackFast();
- }
+ std::thread([&](void){
+ auto thing = currentWorld->goWorldLeft(player);
+ if (thing.first != currentWorld) {
+ player->canMove = false;
+ toggleBlackFast();
+ waitForCover();
+ currentWorld = thing.first;
+ player->loc = thing.second;
+ toggleBlackFast();
+ player->canMove = true;
+ }
+ }).detach();
}
break;
case SDLK_d:
- if (fadeEnable)break;
+ if (fadeEnable)
+ break;
player->vel.x = PLAYER_SPEED_CONSTANT;
player->right = right = true;
player->left = left = false;
if (currentWorldToRight) {
- oldpos = player->loc;
- if ((tmp = currentWorld->goWorldRight(player)) != currentWorld) {
- tmppos = player->loc;
- player->loc = oldpos;
-
- toggleBlackFast();
- waitForCover();
- player->loc = tmppos;
-
- currentWorld = tmp;
- toggleBlackFast();
- }
+ std::thread([&](void){
+ auto thing = currentWorld->goWorldRight(player);
+ if (thing.first != currentWorld) {
+ player->canMove = false;
+ toggleBlackFast();
+ waitForCover();
+ currentWorld = thing.first;
+ player->loc = thing.second;
+ toggleBlackFast();
+ player->canMove = true;
+ }
+ }).detach();
}
break;
case SDLK_w:
@@ -1136,7 +1138,12 @@ EXIT:
debug ^= true;
break;
case SDLK_z:
- weather = WorldWeather::Rain;
+ weather = WorldWeather::Snowy;
+ break;
+ case SDLK_x:
+ m = currentWorld->getNearMob(*player);
+ if (m != nullptr)
+ m->ride(player);
break;
case SDLK_i:
if (isCurrentWorldIndoors() && Indoorp(currentWorld)->isFloorAbove(player)) {
diff --git a/src/world.cpp b/src/world.cpp
index ab2c908..cd57087 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -744,7 +744,7 @@ update(Player *p, unsigned int delta)
}
}
// iterate through particles
- particles.erase(std::remove_if(particles.begin(), particles.end(), [&delta](Particles &part){
+ particles.erase(std::remove_if(particles.begin(), particles.end(), [&delta](Particles &part) {
return part.kill(delta);
}),
particles.end());
@@ -814,6 +814,17 @@ getNearInteractable(Entity &e)
return n == std::end(entity) ? nullptr : *n;
}
+Mob *World::
+getNearMob(Entity &e)
+{
+ auto n = std::find_if(std::begin(mob), std::end(mob), [&](Mob *&a) {
+ return e.isNear(*a) && (e.left ? (a->loc.x < e.loc.x + e.width / 2) : (a->loc.x > e.loc.x + e.width / 2));
+ });
+
+ return n == std::end(mob) ? nullptr : *n;
+}
+
+
/**
* Get the file path for the `index`th building.
*/
@@ -1042,7 +1053,7 @@ getToRight(void) const
/**
* Attempts to go to the left world, returning either that world or itself.
*/
-World *World::
+std::pair<World *, vec2> World::
goWorldLeft(Player *p)
{
World *tmp;
@@ -1052,34 +1063,28 @@ goWorldLeft(Player *p)
// load world (`toLeft` conditional confirms existance)
tmp = loadWorldFromPtr(currentWorldToLeft);
- // adjust player location
- p->loc.x = tmp->worldStart + HLINES(20);
- p->loc.y = tmp->worldData[tmp->lineCount - 1].groundHeight;
-
- return tmp;
+ // return pointer and new player coords
+ return std::make_pair(tmp, vec2 {tmp->worldStart + tmp->getTheWidth() - (float)HLINES(15),
+ tmp->worldData[tmp->lineCount - 1].groundHeight});
}
- return this;
+ return std::make_pair(this, vec2 {0, 0});
}
/**
* Attempts to go to the right world, returning either that world or itself.
*/
-World *World::
+std::pair<World *, vec2> World::
goWorldRight(Player *p)
{
World *tmp;
if (!toRight.empty() && p->loc.x + p->width > -worldStart - HLINES(15)) {
- tmp = loadWorldFromPtr(currentWorldToRight);
-
- p->loc.x = tmp->worldStart - HLINES(-15.0);
- p->loc.y = GROUND_HEIGHT_MINIMUM;
-
- return tmp;
+ tmp = loadWorldFromPtr(currentWorldToRight);
+ return std::make_pair(tmp, vec2 {tmp->worldStart + (float)HLINES(15.0), GROUND_HEIGHT_MINIMUM} );
}
- return this;
+ return std::make_pair(this, vec2 {0, 0});
}
/**
@@ -1093,7 +1098,7 @@ goWorldLeft(NPC *e)
currentWorldToLeft->addNPC(e->loc.x,e->loc.y);
e->die();
- currentWorldToLeft->npc.back()->loc.x = 0;
+ currentWorldToLeft->npc.back()->loc.x = currentWorldToLeft->worldStart + currentWorldToLeft->getTheWidth() - HLINES(15);
currentWorldToLeft->npc.back()->loc.y = GROUND_HEIGHT_MAXIMUM;
return true;
@@ -1716,6 +1721,9 @@ loadWorldFromXMLNoSave(std::string path) {
} else if (name == "page") {
tmp->addMob(new Page(), vec2 {0, 0});
tmp->getLastMob()->createFromXML(wxml);
+ } else if (name == "cat") {
+ tmp->addMob(new Cat(), vec2 {0, 0});
+ tmp->getLastMob()->createFromXML(wxml);
}
// npc creation