Dynamic adjustable window sizes

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
master
sigonasr2 2 years ago
parent a59acd4634
commit 63440c5996
  1. BIN
      MeercaChase
  2. 39
      MeercaChase.cpp
  3. 2
      MeercaChase.js
  4. BIN
      MeercaChase.wasm

Binary file not shown.

@ -13,6 +13,9 @@ using namespace std;
#define DOWN 2
#define LEFT 3
#define WINDOW_WIDTH 480
#define WINDOW_HEIGHT 240
#define TAIL_DISTANCE 4
struct TailData{
@ -40,12 +43,13 @@ public:
olc::Decal*meerca,*negg,*badnegg,*goldennegg,*rainbownegg;
const float UPDATE_RATE = 0.016666667f;
const int NEGG_BOUNDARY=6;
const int WALL_BOUNDARY=-8;
float accumulatedTime = 0.0f;
int frameCount=0;
int moveSpd=4;
int neggType=1;
float meercaSpd[2] = {0,0};
float meercaPos[2] = {240,240};
float meercaPos[2] = {WINDOW_WIDTH/2,WINDOW_HEIGHT/2};
float scorePos[2] = {-50,-50};
int scoreTransparency=255;
int scoreValue=1;
@ -58,15 +62,15 @@ public:
void assignNeggRandomPos() {
do {
neggPos[0]=(float)rand()/(float)RAND_MAX*(480-NEGG_BOUNDARY*2)+NEGG_BOUNDARY;
neggPos[1]=(float)rand()/(float)RAND_MAX*(480-NEGG_BOUNDARY*2)+NEGG_BOUNDARY;
neggPos[0]=(float)rand()/(float)RAND_MAX*(WINDOW_WIDTH-NEGG_BOUNDARY*2)+NEGG_BOUNDARY;
neggPos[1]=(float)rand()/(float)RAND_MAX*(WINDOW_HEIGHT-NEGG_BOUNDARY*2)+NEGG_BOUNDARY;
} while(!positionFree(neggPos));
}
void spawnBadNegg() {
badNeggs=(float*)realloc(badNeggs,sizeof(float)*(++badNeggCount*2));
do {
badNeggs[badNeggCount*2-2] = (float)rand()/(float)RAND_MAX*(480-NEGG_BOUNDARY*2)+NEGG_BOUNDARY;
badNeggs[badNeggCount*2-1] = (float)rand()/(float)RAND_MAX*(480-NEGG_BOUNDARY*2)+NEGG_BOUNDARY;
badNeggs[badNeggCount*2-2] = (float)rand()/(float)RAND_MAX*(WINDOW_WIDTH-NEGG_BOUNDARY*2)+NEGG_BOUNDARY;
badNeggs[badNeggCount*2-1] = (float)rand()/(float)RAND_MAX*(WINDOW_HEIGHT-NEGG_BOUNDARY*2)+NEGG_BOUNDARY;
} while(!positionFree(badNeggs+(badNeggCount*2-2),true));
}
boolean positionFree(float*pos) {
@ -103,8 +107,8 @@ public:
badNeggCount=0;
tailSize=0;
score=0;
meercaPos[0]=240;
meercaPos[1]=240;
meercaPos[0]=WINDOW_WIDTH/2;
meercaPos[1]=WINDOW_HEIGHT/2;
meercaSpd[0]=0;
meercaSpd[1]=0;
}
@ -134,19 +138,19 @@ public:
if (GetKey(olc::F1).bPressed) {
ConsoleShow(olc::F1,false);
}
if (GetKey(olc::W).bPressed&&(meercaSpd[0]+meercaSpd[1]==0||meercaSpd[0]!=0)) {
if ((GetKey(olc::W).bPressed||(GetMouse(0).bPressed&&(GetMouseY()-meercaPos[1]<0&&(meercaSpd[0]!=0||abs(GetMouseX()-meercaPos[0])<abs(GetMouseY()-meercaPos[1])))))&&(meercaSpd[0]+meercaSpd[1]==0||meercaSpd[0]!=0)) {
meercaSpd[0]=0;
meercaSpd[1]=-moveSpd;
}
if (GetKey(olc::A).bPressed&&(meercaSpd[0]+meercaSpd[1]==0||meercaSpd[1]!=0)) {
} else
if ((GetKey(olc::A).bPressed||(GetMouse(0).bPressed&&(GetMouseX()-meercaPos[0]<0&&(meercaSpd[1]!=0||abs(GetMouseY()-meercaPos[1])<abs(GetMouseX()-meercaPos[0])))))&&(meercaSpd[0]+meercaSpd[1]==0||meercaSpd[1]!=0)) {
meercaSpd[0]=-moveSpd;
meercaSpd[1]=0;
}
if (GetKey(olc::D).bPressed&&(meercaSpd[0]+meercaSpd[1]==0||meercaSpd[1]!=0)) {
} else
if ((GetKey(olc::D).bPressed||(GetMouse(0).bPressed&&(GetMouseX()-meercaPos[0]>0&&(meercaSpd[1]!=0||abs(GetMouseY()-meercaPos[1])<abs(GetMouseX()-meercaPos[0])))))&&(meercaSpd[0]+meercaSpd[1]==0||meercaSpd[1]!=0)) {
meercaSpd[0]=moveSpd;
meercaSpd[1]=0;
}
if (GetKey(olc::S).bPressed&&(meercaSpd[0]+meercaSpd[1]==0||meercaSpd[0]!=0)) {
} else
if ((GetKey(olc::S).bPressed||(GetMouse(0).bPressed&&(GetMouseY()-meercaPos[1]>0&&(meercaSpd[0]!=0||abs(GetMouseX()-meercaPos[0])<abs(GetMouseY()-meercaPos[1])))))&&(meercaSpd[0]+meercaSpd[1]==0||meercaSpd[0]!=0)) {
meercaSpd[0]=0;
meercaSpd[1]=moveSpd;
}
@ -198,9 +202,6 @@ public:
DrawRotatedDecal({badNeggs[i*2],badNeggs[i*2+1]},badnegg,0,{16,16},{1,1});
}
DrawString({16,16},"Score: "+to_string(score),olc::VERY_DARK_BLUE);
if (IsMobile()) {
DrawString({16,32},"<Using Mobile Controls>",olc::WHITE,2);
}
for (int i=0;i<tailSize;i++) {
if (i!=tailSize-1&&abs(meercaPos[0]-meercaPreviousPos[(i*8+6)])<8&&abs(meercaPos[1]-meercaPreviousPos[(i*8+7)])<8) {
init();
@ -247,7 +248,7 @@ public:
spawnBadNegg();
}
}
if (meercaPos[0]<-8||meercaPos[0]>488||meercaPos[1]<-8||meercaPos[1]>488) {
if (meercaPos[0]<WALL_BOUNDARY||meercaPos[0]>WINDOW_WIDTH-WALL_BOUNDARY||meercaPos[1]<WALL_BOUNDARY||meercaPos[1]>WINDOW_HEIGHT-WALL_BOUNDARY) {
init();
}
for (int i=0;i<badNeggCount;i++) {
@ -264,7 +265,7 @@ public:
int main()
{
MeercaChase game;
if (game.Construct(480, 480, 4, 4))
if (game.Construct(WINDOW_WIDTH, WINDOW_HEIGHT, 4, 4))
game.Start();
return 0;

File diff suppressed because one or more lines are too long

Binary file not shown.
Loading…
Cancel
Save