Skip to content

Commit

Permalink
Cleaned everything up a bit. NOT WORKING YET!
Browse files Browse the repository at this point in the history
  • Loading branch information
Ceikry committed May 4, 2020
1 parent bc7a67d commit 77280b1
Show file tree
Hide file tree
Showing 9 changed files with 240 additions and 187 deletions.
9 changes: 9 additions & 0 deletions Entity.cpp
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
}
111 changes: 111 additions & 0 deletions Entity.h
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
6 changes: 6 additions & 0 deletions MapUtils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "MapUtils.h"

MapUtils::MapUtils()
{
//ctor
}
55 changes: 55 additions & 0 deletions MapUtils.h
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
6 changes: 6 additions & 0 deletions NPC.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "NPC.h"

NPC::NPC()
{
//ctor
}
20 changes: 20 additions & 0 deletions NPC.h
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
Loading

0 comments on commit 77280b1

Please sign in to comment.