// // Here some random eplosion/fireworks effects. // I actually discovered here that the GetRandomValue does not return floats! // // // #include "raylib.h" #include #define MAX_EFFECT 1000 int myMap[10][11] = { {1,1,1,1,1,1,1,1,1,1,1}, {1,1,1,1,1,1,1,1,1,1,1}, {1,1,1,1,1,1,1,1,1,1,1}, {1,1,1,1,1,1,1,1,1,1,1}, {1,1,1,1,1,1,1,1,1,1,1}, {1,1,1,1,1,1,1,1,1,1,1}, {1,1,1,1,1,1,1,1,1,1,1}, {1,1,1,1,1,1,1,1,1,1,1}, {1,1,1,1,1,1,1,1,1,1,1}, {1,1,1,1,1,1,1,1,1,1,1} }; int mapWidth = 11; int mapHeight = 10; float tileWidth; float tileHeight; static struct effect{ bool active; Vector2 position; Vector2 inc; Vector2 incmod; int w; int h; int countdown; }effect; static struct effect arr_effect[MAX_EFFECT]; int screenWidth; int screenHeight; void createeffect(); //Unit collide with solid blocks true/false bool recttilecollide(int x, int y, int w, int h, int offsetx,int offsety); // Our rectsoverlap function. Returns true/false. static bool rectsoverlap(int x1,int y1,int w1,int h1,int x2,int y2,int w2,int h2); int main(void) { // Initialization //-------------------------------------------------------------------------------------- screenWidth = 800; screenHeight = 450; InitWindow(screenWidth, screenHeight, "raylib example."); tileWidth = ceil((float)(float)screenWidth/(float)mapWidth); tileHeight = ceil((float)screenHeight/(float)mapHeight); SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- createeffect(); int effectdelay=0; // Main game loop while (!WindowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- effectdelay--; if(effectdelay<0){ effectdelay=GetRandomValue(0,100); createeffect(); } // update the effect for(int i=0;iMAX_EFFECT){ continue; cnt=51; } if(arr_effect[i].active==true){ continue; } arr_effect[i].active = true; arr_effect[i].position.x = posx; arr_effect[i].position.y = posy; arr_effect[i].w = 16; arr_effect[i].h = 16; arr_effect[i].inc.x = GetRandomValue(-1,1); arr_effect[i].inc.y = GetRandomValue(-10,-5); arr_effect[i].incmod.x = (float)(GetRandomValue(0,100)/2500.0f); arr_effect[i].incmod.y = (float)(GetRandomValue(0,100)/1000.0f)+0.2f; if(GetRandomValue(0,8)==1){ arr_effect[i].incmod.x*=5; arr_effect[i].inc.y*=1.5; } arr_effect[i].countdown = GetRandomValue(50,120); cnt++; } } //Unit collide with solid blocks true/false bool recttilecollide(int x, int y,int w, int h, int offsetx,int offsety){ int cx = (x+offsetx)/tileWidth; int cy = (y+offsety)/tileHeight; for(int y2=cy-1; y2=0 && x2=0 && y2= (x2 + w2) || (x1 + w1) <= x2) return false; if(y1 >= (y2 + h2) || (y1 + h1) <= y2) return false; return true; }