diff --git a/MeercaChase b/MeercaChase index 48d631a..a365260 100755 Binary files a/MeercaChase and b/MeercaChase differ diff --git a/MeercaChase.cpp b/MeercaChase.cpp index abae68d..b9340a3 100644 --- a/MeercaChase.cpp +++ b/MeercaChase.cpp @@ -8,6 +8,22 @@ using namespace std; +#define UP 0 +#define RIGHT 1 +#define DOWN 2 +#define LEFT 3 + +#define TAIL_DISTANCE 4 + +struct TailData{ + char direction = 0; + char*future_direction; + int*pos; + int*frameCount; + int waitTime = 0; + char futureIndex=0; +}; + class MeercaChase : public olc::PixelGameEngine { public: @@ -22,6 +38,8 @@ public: float neggPos[2] = {}; float*badNeggs=NULL; int badNeggCount=0; + TailData*tail=NULL; + int tailSize=0; void assignNeggRandomPos() { do { @@ -61,11 +79,18 @@ public: void init() { srand(432189); assignNeggRandomPos(); - if (badNeggs!=NULL) { - free(badNeggs); - } + if (badNeggs!=NULL) {free(badNeggs);} + if (tail!=NULL) { + for (int i=0;i=UPDATE_RATE) { accumulatedTime-=UPDATE_RATE; @@ -98,21 +120,41 @@ public: if (GetKey(olc::F1).bPressed) { ConsoleShow(olc::F1,false); } - if (GetKey(olc::W).bPressed) { + if (GetKey(olc::W).bPressed&&(meercaSpd[0]+meercaSpd[1]==0||meercaSpd[0]!=0)) { meercaSpd[0]=0; meercaSpd[1]=-moveSpd; + if (tailSize>0) { + tail[0].future_direction[tail[0].futureIndex]=UP; + tail[0].frameCount[tail[0].futureIndex]=TAIL_DISTANCE; + tail[0].futureIndex=(tail[0].futureIndex+1)%TAIL_DISTANCE; + } } - if (GetKey(olc::A).bPressed) { + if (GetKey(olc::A).bPressed&&(meercaSpd[0]+meercaSpd[1]==0||meercaSpd[1]!=0)) { meercaSpd[0]=-moveSpd; meercaSpd[1]=0; + if (tailSize>0) { + tail[0].future_direction[tail[0].futureIndex]=LEFT; + tail[0].frameCount[tail[0].futureIndex]=TAIL_DISTANCE; + tail[0].futureIndex=(tail[0].futureIndex+1)%TAIL_DISTANCE; + } } - if (GetKey(olc::D).bPressed) { + if (GetKey(olc::D).bPressed&&(meercaSpd[0]+meercaSpd[1]==0||meercaSpd[1]!=0)) { meercaSpd[0]=moveSpd; meercaSpd[1]=0; + if (tailSize>0) { + tail[0].future_direction[tail[0].futureIndex]=RIGHT; + tail[0].frameCount[tail[0].futureIndex]=TAIL_DISTANCE; + tail[0].futureIndex=(tail[0].futureIndex+1)%TAIL_DISTANCE; + } } - if (GetKey(olc::S).bPressed) { + if (GetKey(olc::S).bPressed&&(meercaSpd[0]+meercaSpd[1]==0||meercaSpd[0]!=0)) { meercaSpd[0]=0; meercaSpd[1]=moveSpd; + if (tailSize>0) { + tail[0].future_direction[tail[0].futureIndex]=DOWN; + tail[0].frameCount[tail[0].futureIndex]=TAIL_DISTANCE; + tail[0].futureIndex=(tail[0].futureIndex+1)%TAIL_DISTANCE; + } } // called once per frame if (meercaSpd[0]==moveSpd) { @@ -130,6 +172,10 @@ public: for (int i=0;i0) { + tail[i].waitTime--; + } else { + for (int j=0;j=0) { + tail[i].frameCount[j]--; + if (tail[i].frameCount[j]==-1) { + tail[i].direction=tail[i].future_direction[j]; + if (i+1