summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortom <tom@ground-control>2015-11-21 12:30:13 -0600
committertom <tom@ground-control>2015-11-21 12:30:13 -0600
commit7f79b2e216617ff74ebd41ac02663b20ef3d0904 (patch)
treee0eb8f820c61c45afcb1506f5b025eeb7e534691 /src
parent032d4f98c809bde6231ff78ba50e8c244334739f (diff)
began adding collision *added a location class for ease *much refractoring needed to fully implement it*
Diffstat (limited to 'src')
-rw-r--r--src/Character.cpp70
-rw-r--r--src/Frame.cpp12
-rw-r--r--src/List.cpp35
-rw-r--r--src/main.cpp15
4 files changed, 88 insertions, 44 deletions
diff --git a/src/Character.cpp b/src/Character.cpp
index 7f12035..fd482a9 100644
--- a/src/Character.cpp
+++ b/src/Character.cpp
@@ -6,18 +6,20 @@ Character::Character(char nSymbol, int nColor, int nRow, int nCol)
row = nRow;
col = nCol;
color = nColor;
+ l.x = row;
+ l.y = col;
}
-void Character::move(int nRow, int nCol)
+void Character::move(Location L)
{
- row = nRow;
- col = nCol;
+ l.x = L.x;
+ l.y = L.y;
}
void Character::draw(WINDOW * w)
{
wattron(w,COLOR_PAIR(color));
- mvwaddch(w,row,col,symbol);
+ mvwaddch(w,l.x,l.y,symbol);
}
int Character::getRow()
@@ -34,3 +36,63 @@ char Character::getSymbol()
{
return symbol;
}
+
+bool Character::action(vector <Location> occupied)
+{
+ if(order == "wander")
+ {
+ Location L;
+ int r = rand()%15+1;
+ if(r==1)
+ {
+ L.x = l.x+1;
+ L.y = l.y;
+ }
+ else if(r==2)
+ {
+ L.x = l.x-1;
+ L.y = l.y;
+ }
+ else if(r==3)
+ {
+ L.x = l.x; L.y = l.y+1;
+ }
+ else if(r==4)
+ {
+ L.x = l.x; L.y = l.y-1;
+ }
+ else if(r==5)
+ {
+ L.x = l.x+1; L.y = l.y+1;
+ }
+ else if(r==6)
+ {
+ L.x = l.x-1; L.y = l.y-1;
+ }
+ else if(r==7)
+ {
+ L.x = l.x+1; L.y = l.y-1;
+ }
+ else if(r==8)
+ { L.x = l.x-1; L.y = l.y+1;
+
+ }
+ else
+ return false;
+
+ if(check(L,occupied))
+ move(L);
+ else
+ return false;
+
+ return true;
+ }
+}
+
+bool Character::check(Location L, vector <Location> occupied)
+{
+ for(int i = 0; i < 10; i++)
+ if(l.x == occupied[i].x && l.y == occupied[i].y)
+ return true;
+ return true;
+}
diff --git a/src/Frame.cpp b/src/Frame.cpp
index 4a0df5d..77c7063 100644
--- a/src/Frame.cpp
+++ b/src/Frame.cpp
@@ -44,17 +44,17 @@ Frame::~Frame()
{
delwin(w);
}
-
+/*
void Frame::add(Character &c)
{
mvwaddch(w,c.getRow(),c.getCol(),c.getSymbol());
}
-
+*/
void Frame::erase(Character &c)
{
mvwaddch(w,c.getRow(),c.getCol(),' ');
}
-
+/*
void Frame::add(Character &c, int nRow, int nCol)
{
if((nRow >= 0 && nRow < height) && (nCol >= 0 && nCol < width))
@@ -64,7 +64,7 @@ void Frame::add(Character &c, int nRow, int nCol)
c.move(nRow,nCol);
}
}
-
+*/
void Frame::center(Character &ch)
{
if(hasSuper)
@@ -72,8 +72,8 @@ void Frame::center(Character &ch)
int rr = row;
int cc = col;
int hh, ww;
- int r = ch.getRow() - height/2;
- int c = ch.getCol() - width/2;
+ int r = ch.getLocation().x - height/2;
+ int c = ch.getLocation().y - width/2;
getmaxyx(super, hh, ww);
diff --git a/src/List.cpp b/src/List.cpp
index c0d956f..94506f4 100644
--- a/src/List.cpp
+++ b/src/List.cpp
@@ -6,8 +6,8 @@ List::List()
{
Character x ('@',4,150,150+i);
men.push_back(x);
- }
- srand(time(NULL));
+ occupied.push_back(x.getLocation());
+ }
}
void List::draw(WINDOW * w)
@@ -16,31 +16,12 @@ void List::draw(WINDOW * w)
men[i].draw(w);
}
-void List::actions()
+void List::action()
{
for(int i = 0; i < 10; i++)
- {
- int x = men[i].getRow();
- int y = men[i].getCol();
- int r = rand()%15+1;
- if(r==1)
- men[i].move(x+1,y);
- else if(r==2)
- men[i].move(x-1,y);
- else if(r==3)
- men[i].move(x,y+1);
- else if(r==4)
- men[i].move(x,y-1);
- else if(r==5)
- men[i].move(x+1,y+1);
- else if(r==6)
- men[i].move(x-1,y-1);
- else if(r==7)
- men[i].move(x+1,y-1);
- else if(r==8)
- men[i].move(x-1,y+1);
- else
- continue;
- }
-
+ if(men[i].action(occupied))
+ {
+ //rows[i] = 0;
+ //cols[i] = 0;
+ }
}
diff --git a/src/main.cpp b/src/main.cpp
index 93693ee..2a33d65 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -17,19 +17,20 @@ int main()
while(true)
{
char c = getch();
-
+ Location l = cursor.getLocation();
if (c == 'h')
- cursor.move(cursor.getRow(),cursor.getCol()-1);
+ l.y = l.y-1;
else if (c == 'l')
- cursor.move(cursor.getRow(),cursor.getCol()+1);
+ l.y = l.y+1;
else if (c == 'k')
- cursor.move(cursor.getRow()-1,cursor.getCol());
+ l.x = l.x+1;
else if (c == 'j')
- cursor.move(cursor.getRow()+1,cursor.getCol());
+ l.x = l.x-1;
else if (c == 'q')
- break;
+ break;
- L.actions();
+ cursor.move(l);
+ L.action();
map.fillWindow();
L.draw(map.getWin());
cursor.draw(map.getWin());