take care of other player
This commit is contained in:
parent
633592a4ea
commit
53a2a09399
@ -1,14 +0,0 @@
|
|||||||
QT += network gui widgets
|
|
||||||
CONFIG += c++14 console
|
|
||||||
CONFIG -= app_bundle
|
|
||||||
HEADERS += \
|
|
||||||
app.h \
|
|
||||||
interface/iStompObserver.h \
|
|
||||||
interface/iStompSubject.h \
|
|
||||||
stomp.h \
|
|
||||||
stompframe.h
|
|
||||||
SOURCES += \
|
|
||||||
app.cpp \
|
|
||||||
main.cpp \
|
|
||||||
stomp.cpp \
|
|
||||||
stompframe.cpp
|
|
27
app.cpp
27
app.cpp
@ -17,7 +17,6 @@ void App::sendConfirmation(bool success) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void App::subscribeConfirmation(bool success) {
|
void App::subscribeConfirmation(bool success) {
|
||||||
st_->sendRequest("/topic/sdi10.gem.command", "up");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void App::receiveIndication(int id, QString destination, QString body) {
|
void App::receiveIndication(int id, QString destination, QString body) {
|
||||||
@ -52,6 +51,9 @@ void App::fillField(QString body) {
|
|||||||
if(c == 'Y') {
|
if(c == 'Y') {
|
||||||
myVehicle_ = Vector2D(Vector2D::CreatePoint(x, GRID_SIZE-y));
|
myVehicle_ = Vector2D(Vector2D::CreatePoint(x, GRID_SIZE-y));
|
||||||
}
|
}
|
||||||
|
if(c == 'h') {
|
||||||
|
otherVehicles_.append(Vector2D(Vector2D::CreatePoint(x, GRID_SIZE-y)));
|
||||||
|
}
|
||||||
if(c == 'g') addGem(x, y, 100);
|
if(c == 'g') addGem(x, y, 100);
|
||||||
if(c == 'G') addGem(x, y, 250);
|
if(c == 'G') addGem(x, y, 250);
|
||||||
if(c == 'D') addGem(x, y, 500);
|
if(c == 'D') addGem(x, y, 500);
|
||||||
@ -69,14 +71,33 @@ Vector2D App::computeRelativePts(Gem g) {
|
|||||||
v.reverse();
|
v.reverse();
|
||||||
v.normalize(MAX_LENGHT);
|
v.normalize(MAX_LENGHT);
|
||||||
|
|
||||||
return Vector2D(v.lenght()*g.pts*v.lenght(), v.angle());
|
return Vector2D(v.lenght()*g.pts, v.angle());
|
||||||
|
}
|
||||||
|
|
||||||
|
void App::computeRelativeDistance(Gem* g) {
|
||||||
|
int deltaX = abs(g->coordinate.x() - myVehicle_.x());
|
||||||
|
int deltaY = abs(g->coordinate.y() - myVehicle_.y());
|
||||||
|
g->relativeDistanceToMe = deltaX+deltaY;
|
||||||
|
g->relativeDistanceToOtherPlayer = MAX_LENGHT*2;
|
||||||
|
for(Vector2D v : otherVehicles_) {
|
||||||
|
deltaX = abs(g->coordinate.x() - v.x());
|
||||||
|
deltaY = abs(g->coordinate.y() - v.y());
|
||||||
|
if(deltaX+deltaY < g->relativeDistanceToOtherPlayer) {
|
||||||
|
g->relativeDistanceToOtherPlayer = deltaX+deltaY;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void App::computeMove() {
|
void App::computeMove() {
|
||||||
static const double PI = 3.14159265358979323846;
|
static const double PI = 3.14159265358979323846;
|
||||||
Vector2D myRelativePts;
|
Vector2D myRelativePts;
|
||||||
for(Gem g : gems_) {
|
for(Gem g : gems_) {
|
||||||
myRelativePts = myRelativePts+computeRelativePts(g);
|
computeRelativeDistance(&g);
|
||||||
|
Vector2D v = computeRelativePts(g);
|
||||||
|
myRelativePts = myRelativePts+v;
|
||||||
|
if(g.relativeDistanceToMe <= g.relativeDistanceToOtherPlayer) {
|
||||||
|
myRelativePts = myRelativePts+v;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
double angle = myRelativePts.angle();
|
double angle = myRelativePts.angle();
|
||||||
|
|
||||||
|
4
app.h
4
app.h
@ -32,6 +32,8 @@ protected:
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
Vector2D coordinate;
|
Vector2D coordinate;
|
||||||
|
int relativeDistanceToMe;
|
||||||
|
int relativeDistanceToOtherPlayer;
|
||||||
int pts;
|
int pts;
|
||||||
} Gem;
|
} Gem;
|
||||||
|
|
||||||
@ -43,9 +45,11 @@ protected:
|
|||||||
|
|
||||||
QVector<Gem> gems_;
|
QVector<Gem> gems_;
|
||||||
Vector2D myVehicle_;
|
Vector2D myVehicle_;
|
||||||
|
QVector<Vector2D> otherVehicles_;
|
||||||
void addGem(int x, int y, int pts);
|
void addGem(int x, int y, int pts);
|
||||||
void fillField(QString body);
|
void fillField(QString body);
|
||||||
Vector2D computeRelativePts(Gem g);
|
Vector2D computeRelativePts(Gem g);
|
||||||
|
void computeRelativeDistance(Gem* g);
|
||||||
void computeMove();
|
void computeMove();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user