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 "pixelGameEngine.h"
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
|
#define boolean char
|
||||||
|
#define true 1
|
||||||
|
#define false 0
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
class MeercaChase : public olc::PixelGameEngine
|
class MeercaChase : public olc::PixelGameEngine
|
||||||
@ -9,7 +13,7 @@ class MeercaChase : public olc::PixelGameEngine
|
|||||||
public:
|
public:
|
||||||
olc::Decal*meerca,*negg,*badnegg;
|
olc::Decal*meerca,*negg,*badnegg;
|
||||||
const float UPDATE_RATE = 0.016666667f;
|
const float UPDATE_RATE = 0.016666667f;
|
||||||
const int NEGG_BOUNDARY=16;
|
const int NEGG_BOUNDARY=6;
|
||||||
float accumulatedTime = 0.0f;
|
float accumulatedTime = 0.0f;
|
||||||
int frameCount=0;
|
int frameCount=0;
|
||||||
int moveSpd=4;
|
int moveSpd=4;
|
||||||
@ -20,13 +24,34 @@ public:
|
|||||||
int badNeggCount=0;
|
int badNeggCount=0;
|
||||||
|
|
||||||
void assignNeggRandomPos() {
|
void assignNeggRandomPos() {
|
||||||
neggPos[0]=(float)rand()/(float)RAND_MAX*(480-NEGG_BOUNDARY*2)+NEGG_BOUNDARY;
|
do {
|
||||||
neggPos[1]=(float)rand()/(float)RAND_MAX*(480-NEGG_BOUNDARY*2)+NEGG_BOUNDARY;
|
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() {
|
void spawnBadNegg() {
|
||||||
badNeggs=(float*)realloc(badNeggs,sizeof(float)*(++badNeggCount*2));
|
badNeggs=(float*)realloc(badNeggs,sizeof(float)*(++badNeggCount*2));
|
||||||
badNeggs[badNeggCount*2-2]=(float)rand()/(float)RAND_MAX*(480-NEGG_BOUNDARY*2)+NEGG_BOUNDARY;
|
do {
|
||||||
badNeggs[badNeggCount*2-1]=(float)rand()/(float)RAND_MAX*(480-NEGG_BOUNDARY*2)+NEGG_BOUNDARY;
|
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()
|
MeercaChase()
|
||||||
{
|
{
|
||||||
@ -43,6 +68,8 @@ public:
|
|||||||
badNeggCount=0;
|
badNeggCount=0;
|
||||||
meercaPos[0]=240;
|
meercaPos[0]=240;
|
||||||
meercaPos[1]=240;
|
meercaPos[1]=240;
|
||||||
|
meercaSpd[0]=0;
|
||||||
|
meercaSpd[1]=0;
|
||||||
}
|
}
|
||||||
bool OnUserCreate() override
|
bool OnUserCreate() override
|
||||||
{
|
{
|
||||||
@ -52,6 +79,10 @@ public:
|
|||||||
SetPixelMode(olc::Pixel::ALPHA);
|
SetPixelMode(olc::Pixel::ALPHA);
|
||||||
ConsoleCaptureStdOut(true);
|
ConsoleCaptureStdOut(true);
|
||||||
Clear(olc::DARK_CYAN);
|
Clear(olc::DARK_CYAN);
|
||||||
|
|
||||||
|
for (int i=0;i<5000;i++) {
|
||||||
|
spawnBadNegg();
|
||||||
|
}
|
||||||
|
|
||||||
// Called once at the start, so create things here
|
// Called once at the start, so create things here
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user