From 41c2d41746582db5439dc51a3c35b60384ea1e4a Mon Sep 17 00:00:00 2001 From: miguel Date: Sat, 23 Sep 2017 23:13:25 +0200 Subject: integrated perlin noise map into game as minimap --- main.cpp | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) (limited to 'main.cpp') diff --git a/main.cpp b/main.cpp index f11d658..a218da5 100644 --- a/main.cpp +++ b/main.cpp @@ -9,7 +9,9 @@ #include #include "World.h" +#include "PerlinNoise.h" +#include using SDLInitType=std::pair>; struct Context @@ -444,6 +446,10 @@ void main_loop(void *arg) SDL_RenderCopy(ctx->ren,ctx->textures[7],NULL,&rect); break; } + //show map !? + rect={100,20,150,150}; + SDL_RenderCopy(ctx->ren,ctx->textures[8],NULL,&rect); + if(ctx->world.player.dead) { sdl_put_str(ctx->ren, ctx->textures[3],300, -1, 10,"LUNATIC LEMMY DIED!",250,100,100,19,ctx->win_width,ctx->win_height,1,2); @@ -499,6 +505,83 @@ int main(int, char**){ ctx->textures.push_back(sdl_load_texture("gridder01.bmp",255,255,255,ctx->ren)); ctx->textures.push_back(sdl_load_texture("gridder02.bmp",255,255,255,ctx->ren)); ctx->textures.push_back(sdl_load_texture("gridder03.bmp",255,255,255,ctx->ren)); +// PERLIN GENEARTED MAP + ctx->textures.push_back(SDL_CreateTexture(ctx->ren, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, 1024, 768)); + + double seed=22; + PerlinNoise perlin(seed); + + SDL_SetRenderTarget(ctx->ren, ctx->textures[8]); + SDL_SetRenderDrawColor(ctx->ren, 0x00, 0x00, 0x00, 0x00); + SDL_RenderClear(ctx->ren); + + +// std::random_device rd(seed); //Will be used to obtain a seed for the random number engine + std::mt19937 gen(seed); //Standard mersenne_twister_engine seeded with rd() + std::uniform_int_distribution<> dis(0,50); + + for(int x=0;x<1024;x++) + for(int y=0;y<768;y++) + { + //SDL_SetRenderDrawColor(ren, (0.7*perlin.noise(x/1024.0*20,y/768.0*20,0)+0.2*perlin.noise(x/1024.0*200,y/768.0*200,0))*0xFF, 0x00, 0x00, 0x00); + double per1=perlin.noise(x/1024.0*3,y/768.0*3,0); + double per2=perlin.noise(x/1024.0*50,y/768.0*50,0); + if(per1<0.4)per1+=per2*0.1; + + if(per1<0.25)SDL_SetRenderDrawColor(ctx->ren, 0x00, 0x00, 0x99, 0x00); + else if(per1<0.4)SDL_SetRenderDrawColor(ctx->ren, 0x00, 0x33, 0xff, 0x00); + else if(per1<0.51)SDL_SetRenderDrawColor(ctx->ren, 0x55, 0xff, 0x55,0x00); + else if(per1<0.8) + { + SDL_SetRenderDrawColor(ctx->ren, 0x33, 0x99, 0x33,0x00); + } + else if(per1<0.85)SDL_SetRenderDrawColor(ctx->ren, 0x99, 0x99, 0x99,0x00); + else SDL_SetRenderDrawColor(ctx->ren, 0xff, 0xff, 0xff, 0x00); + //else SDL_SetRenderDrawColor(ren, perlin.noise(x/1024.0*20,y/768.0*20,0)*100, 0x00, 0x00, 0x00); + + SDL_RenderDrawPoint(ctx->ren,x,y); + } + + for(int i=0;i<30;i++) + { + int x=dis(gen); + int y=dis(gen); + int t=dis(gen); + SDL_Rect r; + r.x=1024*x/50+25; + r.y=768*y/50+25; + double per1=perlin.noise(r.x/1024.0*3,r.y/768.0*3,0); + double per2=perlin.noise(r.x/1024.0*50,r.y/768.0*50,0); + if(per1<0.4)per1+=per2*0.1; + r.w=1024/100; + r.h=768/100; + + if(per1<0.4) + { + SDL_SetRenderDrawColor(ctx->ren, 0x00, 0x00, 0x00,0x00); + SDL_RenderFillRect(ctx->ren,&r); + sdl_put_str(ctx->ren,ctx->textures[3], r.x+5, r.y,15,"boat",255,0,0,12,0,0,0,0); + } + + if(per1>0.51&&per1<0.8) + { + SDL_SetRenderDrawColor(ctx->ren, 0x00, 0x00, 0x00,0x00); + SDL_RenderFillRect(ctx->ren,&r); +// sdl_put_str(ren, textures[0],10, 10, 10,strbuffer.str(),222,255,222,60,win_width,win_height,1,1); + if(t<10)sdl_put_str(ctx->ren,ctx->textures[3], r.x+5, r.y,15,"blacksmith",0,0,0,12,0,0,0,0); + else if(t<20)sdl_put_str(ctx->ren,ctx->textures[3], r.x+5, r.y,15,"inn",255,0,255,12,0,0,0,0); + else if(t<30)sdl_put_str(ctx->ren,ctx->textures[3], r.x+5, r.y,15,"armory",255,255,0,12,0,0,0,0); + else if(t<40)sdl_put_str(ctx->ren,ctx->textures[3], r.x+5, r.y,15,"quest",0,255,255,12,0,0,0,0); + else sdl_put_str(ctx->ren,ctx->textures[3], r.x+5, r.y,15,"safehouse",255,255,255,12,0,0,0,0); + } + } + SDL_SetRenderTarget(ctx->ren, NULL); + +// PERLIN GENEARTED MAP OVER + + + + ctx->show_tiles_size=ctx->win_height/15; ctx->show_tiles_back=ctx->win_width/ctx->show_tiles_size*0.25; -- cgit v1.2.3