-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cleaned everything up a bit. NOT WORKING YET!
- Loading branch information
Showing
9 changed files
with
240 additions
and
187 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#include "Entity.h" | ||
|
||
Entity::Entity(string name, char symbol) | ||
{ | ||
public: | ||
this.name = name; | ||
this.mychar = symbol; | ||
//ctor | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
#ifndef ENTITY_H | ||
#define ENTITY_H | ||
|
||
|
||
class Entity | ||
{ | ||
string name,message; | ||
int xpos; | ||
int ypos; | ||
char mychar; | ||
|
||
public: | ||
Entity(); | ||
|
||
//function for drawing the name on the map... I don't know why I wrote this. | ||
void drawNameOnMap(void){ | ||
for(int thisChar = 0; thisChar < name.size(); thisChar++){ | ||
y[ypos - 1][x - static_cast<int>(name.size() / 2) + thisChar] = static_cast<char>(name[thisChar]); | ||
} | ||
} | ||
void say(string message){ | ||
cout << name << " says: " << message << endl; | ||
} | ||
|
||
//checks collision, returns true if you can move there, false if not. | ||
bool checkCollide(int tx, int ty){ | ||
if (y[ty][tx] == '-' || y[ty][tx] == '|' || tx == y[0].capacity() || abs(ty - y.capacity()) == 1 || tx < 1 || ty < 1){ | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
//Function for handling movement in a specific direction | ||
void mv(string direction){ | ||
switch(direction){ | ||
case "down": | ||
if(checkCollide(x, ypos + 1){ | ||
ypos = ypos + 1; | ||
} | ||
break; | ||
case "up": | ||
if(checkCollide(x, ypos - 1)){ | ||
ypos = ypos - 1; | ||
} | ||
break; | ||
case "left": | ||
if(checkCollide(x - 1, ypos)){ | ||
x -= 1; | ||
} | ||
break; | ||
case "right": | ||
if(checkCollide(x + 1, ypos)){ | ||
x += 1; | ||
} | ||
break; | ||
case "upright": | ||
if(checkCollide(x + 1, ypos - 1)){ | ||
x += 1; | ||
ypos -= 1; | ||
} | ||
break; | ||
case "upleft": | ||
if(checkCollide(x - 1, ypos - 1) == 0){ | ||
x -= 1; | ||
ypos -= 1; | ||
} | ||
break; | ||
case "downright": | ||
if(checkCollide(x + 1, ypos + 1) == 0){ | ||
x += 1; | ||
ypos += 1; | ||
} | ||
break; | ||
case "downleft": | ||
if(checkCollide(x - 1, ypos + 1) == 0){ | ||
x -= 1; | ||
ypos += 1; | ||
} | ||
break; | ||
} | ||
} | ||
|
||
//rudimentary pathfinding, one movement at a time | ||
void findPath(int tx, int ty){ | ||
int distanceX = tx - xpos; | ||
int distanceY = ty - ypos; | ||
if(abs(distanceX) <= 2 && abs(distanceY) <= 2){ | ||
} else if(distanceX > 0 && distanceY > 0){ | ||
mv("downright"); | ||
} else if(distanceX < 0 && distanceY > 0){ | ||
mv("downleft"); | ||
} else if(distanceX > 0 && distanceY < 0){ | ||
mv("upright"); | ||
} else if(distanceX < 0 && distanceY < 0){ | ||
mv("upleft"); | ||
} else if(distanceX < 1 && distanceY == 0){ | ||
mv("left"); | ||
} else if(distanceX > 1 && distanceY == 0){ | ||
mv("right"); | ||
} else if(distanceX == 0 && distanceY > 1){ | ||
mv("down"); | ||
} else if(distanceX == 0 && distanceY < 1){ | ||
mv("up"); | ||
} | ||
} | ||
protected: | ||
|
||
private: | ||
}; | ||
|
||
#endif // ENTITY_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#include "MapUtils.h" | ||
|
||
MapUtils::MapUtils() | ||
{ | ||
//ctor | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#ifndef MAPUTILS_H | ||
#define MAPUTILS_H | ||
|
||
|
||
class MapUtils | ||
{ | ||
public: | ||
vector<vector<char> >gameMap; | ||
MapUtils(); | ||
|
||
void makeMap(int size){ | ||
gameMap.reserve(size); | ||
int height = size; | ||
int width = height; | ||
for(int i=0; i < height; i++){ | ||
vector<char>x; | ||
width = height * 2; | ||
x.reserve(width); | ||
for(int k = 0; k < x.capacity(); k++){ | ||
x.push_back(' '); | ||
} | ||
gameMap.push_back(x); | ||
} | ||
} | ||
|
||
void makeWall(int xpos, int ypos, int width, int height){ | ||
for(int i = 0; i < height; i++){ | ||
for(int k = 0; k < width; k++){ | ||
char wallsym; | ||
if(height > width){ | ||
wallsym = '|'; | ||
} else { | ||
wallsym = '-'; | ||
} | ||
gameMap[ypos + i][xpos + k] = wallsym; | ||
} | ||
} | ||
} | ||
|
||
void drawMap(){ | ||
for(int i=0; i < gameMap.size(); i++){ | ||
for(int k=0; k < y[i].size(); k++){ | ||
cout << gameMap[i][k]; | ||
} | ||
cout << endl; | ||
} | ||
} | ||
|
||
|
||
protected: | ||
|
||
private: | ||
}; | ||
|
||
#endif // MAPUTILS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#include "NPC.h" | ||
|
||
NPC::NPC() | ||
{ | ||
//ctor | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#ifndef NPC_H | ||
#define NPC_H | ||
|
||
#include <Entity.h> | ||
|
||
|
||
class NPC : public Entity | ||
{ | ||
public: | ||
NPC(); | ||
bool canWander,friendly; | ||
int aggroRadius; | ||
float health,damage; | ||
|
||
protected: | ||
|
||
private: | ||
}; | ||
|
||
#endif // NPC_H |
Oops, something went wrong.