#pragma once
#include <enginend/engine.h>
#include "shared.h"


class mainmenu:public enginend::scene {
public:
	Texture2D bg;
	Texture2D title;
	Music bgm;
	Shader bzzzz;
	int wins:3=0b111;
	mainmenu() {
		
	}
	void boot() override {
		std::string modifier=".png";
		bg=LoadTexture(AT("res/menu/"+
			std::to_string(wins>>2&1)+std::to_string(wins>>1&1)+std::to_string(wins&1)
			+modifier));
		bgm=LoadMusicStream(AT("res/snd/song.mp3"));
		title=LoadTexture(AT("res/menu/title.png"));
		bgm.looping=true;
		PlayMusicStream(bgm);
		bzzzz=LoadShaderFromMemory(
		"attribute vec2 vertexPosition;attribute vec2 vertexTexCoord;attribute vec4 vertexColor;"
		"varying vec2 fragTexCoord;varying vec4 fragColor;varying float randf;"
		"uniform mat4 mvp;uniform float t;"
		"float rand(vec2 co){return fract(sin(dot(co,vec2(12.9898,78.233)))*43758.5453);}"
		"void main(){fragTexCoord=vertexTexCoord;fragColor=vertexColor;"
		"gl_Position=mvp*vec4(vertexPosition,0.,1.);"
		"randf=rand(vec2(gl_Position.x+t,gl_Position.y+t));}",
		"varying vec2 fragTexCoord;varying vec4 fragColor;varying float randf;"
		"uniform sampler2D texture0;"
		"void main(){"
		"vec4 texel=texture2D(texture0,fragTexCoord)*fragColor;"
		"float idx=(texel.r+texel.g+texel.b);"
		"if(idx<0.7||idx>0.9){idx*=randf;}"
		"gl_FragColor=vec4(texel.rgb,texel.a*idx);}"
		);
	}
	void tick() override {
		
	}
	void draw() override {
		float screenw=(float)GetScreenWidth();float screenh=(float)GetScreenHeight();
		UpdateMusicStream(bgm);
		BeginDrawing();
		ClearBackground(rl::BLACK);
		DrawTexturePro(bg,{0,0,320,240},{0,0,screenw,screenh},{0,0},0,rl::WHITE);
		float t=GetTime()/200000;
		SetShaderValue(bzzzz,GetShaderLocation(bzzzz,"t"),&t,SHADER_UNIFORM_FLOAT);
		BeginShaderMode(bzzzz);
		DrawTexturePro(title,{0,0,1065,194},{0,0,screenw,(screenh/4)},{0,0},0,rl::WHITE);
		EndShaderMode();
		EndDrawing();
		
	}
	void exit() override {
		
	}
};