summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/creature.cpp49
-rw-r--r--src/entity.cpp2
-rw-r--r--src/resource.cpp16
3 files changed, 35 insertions, 32 deletions
diff --git a/src/creature.cpp b/src/creature.cpp
index 83b9f4d..01882a3 100644
--- a/src/creature.cpp
+++ b/src/creature.cpp
@@ -8,9 +8,10 @@ Creature::Creature(Window m, std::string s)
maxHealth = 1000;
hunger = 0;
- yPosition=yTarget=rand()%800;
- xPosition=xTarget=rand()%1200;
- hasTarget = false;
+ L.y=yTarget=rand()%800;
+ L.x=xTarget=rand()%1200;
+
+ hasTarget = false;
wandering = false;
able = true;
n=0;
@@ -108,49 +109,49 @@ bool Creature::Action()
}
//Makes moves towards target coordinates
- if(xPosition==xTarget)
+ if(L.x==xTarget)
{
- if(yPosition<yTarget)
- yPosition+=speed;
+ if(L.y<yTarget)
+ L.y+=speed;
else
- yPosition-=speed;
+ L.y-=speed;
}
- else if(yPosition==yTarget)
+ else if(L.y==yTarget)
{
- if(xPosition<xTarget)
- xPosition+=speed;
+ if(L.x<xTarget)
+ L.x+=speed;
else
- xPosition-=speed;
+ L.x-=speed;
}
- else if(xPosition<xTarget)
+ else if(L.x<xTarget)
{
- if(yPosition<yTarget)
+ if(L.y<yTarget)
{
- xPosition+=speed;
- yPosition+=speed;
+ L.x+=speed;
+ L.y+=speed;
}
else
{
- xPosition+=speed;
- yPosition-=speed;
+ L.x+=speed;
+ L.y-=speed;
}
}
- else if (xPosition>xTarget)
+ else if (L.x>xTarget)
{
- if(yPosition<yTarget)
+ if(L.y<yTarget)
{
- xPosition-=speed;
- yPosition+=speed;
+ L.x-=speed;
+ L.y+=speed;
}
else
{
- xPosition-=speed;
- yPosition-=speed;
+ L.x-=speed;
+ L.y-=speed;
}
}
@@ -160,7 +161,7 @@ bool Creature::Action()
Location Creature::getLocation()
{
//returns location object of the specific creature
- Location L(xPosition, yPosition, 1);
+ //Location L(xPosition, yPosition, 1);
return L;
}
diff --git a/src/entity.cpp b/src/entity.cpp
index 10a3ccc..909dd15 100644
--- a/src/entity.cpp
+++ b/src/entity.cpp
@@ -2,7 +2,7 @@
void Entity::Place()
{
- SDL_Rect rect = {xPosition, yPosition, width/8, height/8};
+ SDL_Rect rect = {L.x, L.y, width/8, height/8};
SDL_RenderCopyEx(renderer,texture,NULL,&rect,degrees,NULL,SDL_FLIP_NONE);
}
diff --git a/src/resource.cpp b/src/resource.cpp
index 8f1a4cf..9583f14 100644
--- a/src/resource.cpp
+++ b/src/resource.cpp
@@ -5,8 +5,9 @@ Resource::Resource(Window m, std::string s)
texture = loadTexture(s, m);
renderer = m.getRenderer();
- yPosition = rand()%800;
- xPosition = rand()%1200;
+ L.y = rand()%800;
+ L.x = rand()%1200;
+ L.type = 2;
amount = 100;
}
@@ -16,15 +17,16 @@ Resource::Resource(Window m, std::string s, Location z)
texture = loadTexture(s, m);
renderer = m.getRenderer();
- yPosition = z.y;
- xPosition = z.x;
-
- amount = 100;
+ L.y = z.y;
+ L.x = z.x;
+ L.type = 2;
+
+ amount = 100;
}
Location Resource::getLocation()
{
- Location L(xPosition,yPosition,2);
+ //Location L(xPosition,yPosition,2);
return L;
}