summaryrefslogtreecommitdiff
path: root/background.h
blob: 0739e5fb6be029a1282a5d61f82b14e194e2036a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
//Chrisoft Bullet Lab Remix HGE
//Background drawing Implementations
//"Copyleft" Chrisoft 2013
const char* BACKGROUND_H_FN="background.h";

double deltaBG;
//********************************************
//Full-screen Leaves Background
//********************************************
class BG_Leaves
{
private:
	DWORD alpha,alim;
	bool onfadein,onfadeout;
	int fadebreak;
	hgeSprite* BGSpr[6][6];
	HTEXTURE LeafTex;
	void DoFadeIn()
	{
		if (LOWFPS)fadebreak+=17;else ++fadebreak;
		if (fadebreak>17)fadebreak=0;else return;
		if (LOWFPS)if(alpha+0x20<=alim)alpha+=0x20;else{}
		else if (alpha+0x2<=alim)alpha+=2;
		if (alpha>=alim)onfadein=false;
	}
	void DoFadeOut()
	{
		if (LOWFPS)fadebreak+=17;else ++fadebreak;
		if (fadebreak>30)fadebreak=0;else return;
		if (LOWFPS)
			if (alpha<0x20)alpha=0;else alpha-=0x20;
		else
			if (alpha<0x2)alpha=0;else alpha-=0x2;
		if (!alpha)onfadeout=0;
	}
public:
	bool IsActive()
	{
		return alpha?true:false;
	}
	void Init(DWORD limalpha)
	{
		LeafTex=hge->Texture_Load("./Resources/b_leaves.png");
		for (int i=0;i<6;++i)
		for (int j=0;j<6;++j)
		{
			BGSpr[i][j]=new hgeSprite(LeafTex,0,0,200,150);
			BGSpr[i][j]->SetColor(0x00CCCCCC);
		}
		onfadein=onfadeout=false;alpha=0x00;alim=limalpha;fadebreak=0;

	}
	void SetFadeIn()
	{
		alpha=0x01;
		onfadein=true;
	}
	void SetFadeOut()
	{
		alpha=alim;
		onfadeout=true;
	}
	void Update()
	{
		double tx,ty,dt;
		DWORD tcol;
		if (onfadein)DoFadeIn();
		if (onfadeout)DoFadeOut();
		dt=hge->Timer_GetDelta();
		deltaBG+=dt;
		tx=200*cosf(deltaBG/10);
		ty=150*sinf(deltaBG/10);
		for (int i=-1;i<5;++i)
		for (int j=-1;j<5;++j)
			BGSpr[i+1][j+1]->SetColor(ARGB(alpha,0xCC,0xCC,0xCC)),
			BGSpr[i+1][j+1]->Render(i*199.0f+tx,j*149.0f+ty);
	}
};
BG_Leaves Leaves;
//********************************************
//Animated Leaves Background
//********************************************
HTEXTURE TLeaf;
HTEXTURE TSflake;
class Leaf_Anim;
Leaf_Anim *Head,*Tail;
bool LE_Active;
double lescale;
HTEXTURE letex;TextureRect letr;
DWORD lecolor;
class Leaf_Anim
{
private:
	hgeSprite* Leaf;
	double Rotation,DRotate;
	double x,y,dx,dy;
	int lim;
	~Leaf_Anim(){}
public:
	Leaf_Anim *Last,*Next;
	void init(int _lim)
	{
		//Leaf=new hgeSprite(letex,0,0,108,108);
		Leaf=new hgeSprite(letex,letr.x,letr.y,letr.w,letr.h);
		Leaf->SetColor(lecolor);
		x=rand()%908-108;
		y=-108;
		lim=_lim;
		dx=rand()%200/100.0f-1.0f;
		dx*=0.075;
		dy=rand()%200/100.0f+0.5f;
		dy*=0.075;
		Rotation=0;
		DRotate=rand()%100/10000.0f;
		DRotate*=0.1;
		Next=NULL;
	}
	void Delete()
	{
		if (this==Head)Head=this->Next;
		if (this==Tail)Tail=this->Last;
		if (this->Next)
		this->Next->Last=this->Last;
		if (this->Last)
		this->Last->Next=this->Next;
		delete this->Leaf;
		delete this;//Not sure this will work?..--Answer: This worked...
	}
	void Update()
	{
		if (!this||!Leaf)return;
		int times=1;if (LOWFPS)times=17;
		for (int i=1;i<=times;++i)
		{
			Rotation+=DRotate;
			x+=dx;y+=dy;
		}
		if (x>908||x<-108||y>708)return Delete();
		if (!Leaf)return;
		Leaf->RenderEx(x,y,Rotation,lescale);
	}
	void Process()
	{
		int times=1;
		if(LOWFPS) times=17;
		for (int i=1;i<=times;++i)
		if (rand()%1000>lim&&LE_Active)
		{
			Tail->Next=new Leaf_Anim();
			Tail->Next->init(990);
			Tail->Next->Last=Tail;
			Tail=Tail->Next;
		}
		Leaf_Anim *cur=Head;
		while (cur)cur->Update(),cur=cur->Next;
	}
};
//********************************************
//3D-Clouds Background
//********************************************
class TDClouds
{
private:
	hgeQuad CQuad;
	double DTime;
	int alpha,lima;
	bool onFadein,onFadeout;
	void DoFadein()
	{
		int times=1;
		if (LOWFPS)times=17;
		for (int i=1;i<=times;++i)if (alpha<lima)++alpha;
	}
	void DoFadeout()
	{
		int times=1;
		if (LOWFPS)times=17;
		for (int i=1;i<=times;++i)if (alpha>0)--alpha;
	}
public:
	void Init(int _lima)
	{
		DTime=0.0f;
		CQuad.tex=hge->Texture_Load("sky.png");
		CQuad.blend=BLEND_ALPHABLEND;
		alpha=0;lima=_lima;
		onFadein=onFadeout=false;
		for (int i=0;i<4;++i)
		CQuad.v[i].col=0x00FFFFFF;
		CQuad.v[0].x=0,CQuad.v[0].y=300;
		CQuad.v[1].x=800,CQuad.v[1].y=300;
		CQuad.v[2].x=1000,CQuad.v[2].y=600;
		CQuad.v[3].x=-200,CQuad.v[3].y=600;
		CQuad.v[0].tx=0,CQuad.v[0].ty=0;
		CQuad.v[0].tx=0.5,CQuad.v[0].ty=0;
		CQuad.v[0].tx=0.5,CQuad.v[0].ty=0.5;
		CQuad.v[0].tx=0,CQuad.v[0].ty=0.5;
	}
	void SetFadein()
	{
		onFadein=true;
		onFadeout=false;
		alpha=0;
	}
	void SetFadeout()
	{
		onFadeout=true;
		onFadein=false;
		alpha=lima;
	}
	void Update()
	{
		if (onFadein)DoFadein();
		if (onFadeout)DoFadeout();
		for (int i=0;i<4;++i)
		CQuad.v[i].col=ARGB(alpha,0xFF,0xFF,0xFF);
		DTime+=0.1*hge->Timer_GetDelta();
		CQuad.v[0].tx=cos(DTime),CQuad.v[0].ty=sin(DTime);
		CQuad.v[1].tx=CQuad.v[0].tx+0.5f;CQuad.v[1].ty=CQuad.v[0].ty;
		CQuad.v[2].tx=CQuad.v[0].tx+0.5f;CQuad.v[2].ty=CQuad.v[0].ty+0.5f;
		CQuad.v[3].tx=CQuad.v[0].tx;CQuad.v[3].ty=CQuad.v[0].ty+0.5f;
		hge->Gfx_RenderQuad(&CQuad);
	}
};
TDClouds Sky;

DWORD ColorTransfer(DWORD a,DWORD t)
{
	int r=GETR(a),g=GETG(a),b=GETB(a);
	int tr=GETR(t),tg=GETG(t),tb=GETB(t);
	if (r<tr)++r;if (r>tr)--r;
	if (g<tg)++g;if (g>tg)--g;
	if (b<tb)++b;if (b>tb)--b;
	a=SETR(a,r);a=SETG(a,g);a=SETB(a,b);
}