generated from sigonasr2/CPlusPlusProjectTemplate
Neggs now spawn smartly.
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
cc9bb002c1
commit
27a88c38bb
BIN
MeercaChase
BIN
MeercaChase
Binary file not shown.
@ -2,6 +2,10 @@
|
||||
#include "pixelGameEngine.h"
|
||||
#include <math.h>
|
||||
|
||||
#define boolean char
|
||||
#define true 1
|
||||
#define false 0
|
||||
|
||||
using namespace std;
|
||||
|
||||
class MeercaChase : public olc::PixelGameEngine
|
||||
@ -9,7 +13,7 @@ class MeercaChase : public olc::PixelGameEngine
|
||||
public:
|
||||
olc::Decal*meerca,*negg,*badnegg;
|
||||
const float UPDATE_RATE = 0.016666667f;
|
||||
const int NEGG_BOUNDARY=16;
|
||||
const int NEGG_BOUNDARY=6;
|
||||
float accumulatedTime = 0.0f;
|
||||
int frameCount=0;
|
||||
int moveSpd=4;
|
||||
@ -20,13 +24,34 @@ public:
|
||||
int badNeggCount=0;
|
||||
|
||||
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;
|
||||
} 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;
|
||||
} while(!positionFree(badNeggs+(badNeggCount*2-2),true));
|
||||
}
|
||||
boolean positionFree(float*pos) {
|
||||
return positionFree(pos,false);
|
||||
}
|
||||
boolean positionFree(float*pos,boolean badNegg) {
|
||||
if (badNegg&&abs(pos[0]-neggPos[0])<4&&abs(pos[1]-neggPos[1])<4) {
|
||||
return false;
|
||||
}
|
||||
if (abs(pos[0]-meercaPos[0])<64&&abs(pos[1]-meercaPos[1])<64) {
|
||||
return false;
|
||||
}
|
||||
for (int i=0;i<((badNegg)?badNeggCount-1:badNeggCount);i++) {
|
||||
if (abs(pos[0]-badNeggs[i*2])<4&&abs(pos[1]-badNeggs[i*2+1])<4) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
MeercaChase()
|
||||
{
|
||||
@ -43,6 +68,8 @@ public:
|
||||
badNeggCount=0;
|
||||
meercaPos[0]=240;
|
||||
meercaPos[1]=240;
|
||||
meercaSpd[0]=0;
|
||||
meercaSpd[1]=0;
|
||||
}
|
||||
bool OnUserCreate() override
|
||||
{
|
||||
@ -53,6 +80,10 @@ public:
|
||||
ConsoleCaptureStdOut(true);
|
||||
Clear(olc::DARK_CYAN);
|
||||
|
||||
for (int i=0;i<5000;i++) {
|
||||
spawnBadNegg();
|
||||
}
|
||||
|
||||
// Called once at the start, so create things here
|
||||
return true;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user