pouët.net

WORLDS FIRST SNOWMO by WASNIACH

#include "StdAfx.h"

#define SNE 400

static byte * pal;
static byte * tex;
static byte * font;
static CObject obj;
static vertex *t;
static float snow[SNE*2];

char msg[]="           welcome to the worlds first snowmo brought to you exclusively by wasniahc      it is febuary     it is snowing    we are drinking   yes it is snowmo time     we kintobor and mallorcat would like to take this moment to greet                           and that was the greets       yes we hate you all     stop making crap start making demos       and once again we need to remind you that this year our world domination will be complete with the release of the long awaited demo from us             intershoelace         credits for this snowmo      code kintobor     grafx mallorcat     music doctor vector of megahawks incorporated      you can find us on the world wide web at   www wasniahc tk        and now for the tech info      the snow routine uses a special fuzzy logic artifactal intelligence routine to maximize the realism and overall feel of the effect      the texturemapper easily handles well over one million polys per second and is perspective correct and garrantied to look nice on all computers in the world";

void effect01_load()
{
	pal = LoadPalette("gfx\\taex.gif");
	tex = LoadImage("gfx\\taex.gif");
	font = LoadImage("gfx\\font.gif");
	obj.Load3DS("3ds\\peter_er_vammel.3DS");
	t = new vertex[obj.m_NumVertices];
	memcpy(t,obj.m_Vertices,sizeof(vertex)*obj.m_NumVertices);
}

void effect01_unload()
{
	delete[]t;
	delete[]pal;
	delete[]tex;
}

void effect01_prerun()
{
	Graphics_SetPal(pal);
	Graphics_ClearScreen(vscr2,0);
	for(int i=0; i<SNE; i++)
	{
		snow[i*2+0] = rand()%320;
		snow[i*2+1] = rand()%40-35;
	}
}

void PutChar(int xp, int yp, int ch, byte *dest)
{
	if(ch == ' ') return;
	ch = tolower(ch);
	if(ch<'a' || ch>'z') return;
	int x, y;

	byte* fnt = font+(ch-'a')*16;
	dest+=xp+yp*320;

	for(y=0; y<16; y++)
	{
		if(y+yp>=0 && y+yp<240){
			for(x=0; x<16; x++)
			{
				if(x+xp>=0 && x+xp<320){
					if(fnt[x] != 210)
						dest[x]=fnt[x];
				}
			}
		}
		dest+=320;
		fnt+=416;
	}
}

void effect01_run(float tid)
{
	camera cam(vertex(cos(tid*1.7),sin(tid*1.7),0.7)*75,vertex(0,0,0),90.0f);

	byte *v=vscr;
	for(int y=0; y<240; y++)
	{
		int u=0;
		byte * temp = &tex[((y<<8)/240)<<8];
		for(int x=0; x<320; x++)
		{
			*v++ = temp[u>>16];
			u += 256*65536/320;
		}
	}

	
	for(dword i=0; i<obj.m_NumVertices; i++)
	{
		float z = 0.7+(0.7*pow(sin(tid*1.6 + t[i].x*0.092),7)+0.4*cos(tid*0.6+t[i].z*0.075)+0.5*pow(sin(t[i].y*0.06+tid*1.55), 3));
		obj.m_Vertices[i] = t[i] * z;
	}

	obj.CalcVertexNormals();
	obj.Transform(cam.tmat,true);
	obj.ZSort(true);
	Clipper<2> clipper; 
	for(dword cnt=0; cnt<obj.m_NumSortedFaces; cnt++)
	{
		face_t * f = obj.m_SortedFaces[cnt];
		Clipper<2>::clippedface in, out;
		
		in.nv		= 3;
		in.v[0]		= *f->v_a;
		in.maps[0]	= 128+127*obj.m_TransformedVertexNormals[f->a].x;
		in.maps[1]	= 128+127*obj.m_TransformedVertexNormals[f->a].y;
		in.v[1]		= *f->v_b;
		in.maps[2]	= 128+127*obj.m_TransformedVertexNormals[f->b].x;
		in.maps[3]	= 128+127*obj.m_TransformedVertexNormals[f->b].y;
		in.v[2]		= *f->v_c;
		in.maps[4]	= 128+127*obj.m_TransformedVertexNormals[f->c].x;
		in.maps[5]	= 128+127*obj.m_TransformedVertexNormals[f->c].y;
		
		if(clipper.clip(&cam, &in, &out))
		{
			int p[20*2];
			int u[20];
			int v[20];
			
			for(int i=0; i<out.nv; i++)
			{
				cam.project(out.v[i],p[i*2],p[i*2+1]);
				u[i] = out.maps[i*2];
				v[i] = out.maps[i*2+1];
			}
			
			DrawTexturePoly(p,u,v,out.nv,tex,vscr);
		}
	}

	static float lt = tid;
	float dt = fmod((tid-lt),0.1)*180;
	lt=tid;

	for(i=0; i<SNE; i++)
	{
		float nx = snow[i*2+0]+cos(tid*0.5+i*10/(float)SNE);
		float ny = snow[i*2+1]+(dt+(rand()%80)/40.0f);

		if((vscr2[int(nx)+int(ny)*320] || int(ny)>=240) && (int(snow[i*2+1]) != int(ny)) && int(ny)>int(240-tid*2)){
			snow[i*2+0] = rand()%320;
			snow[i*2+1] = rand()%40-35;
		}
		else
		{
			if(int(snow[i*2+1])>0 && int(snow[i*2+1])<240 && int(snow[i*2+0])>0 && int(snow[i*2+0])<320)
				vscr2[int(snow[i*2+0])+int(snow[i*2+1])*320] = 0;
			snow[i*2+0]=nx;
			snow[i*2+1]=ny;
			if(int(ny)>0 && int(ny)<240 && int(nx)>0 && int(nx)<320)
				vscr2[int(nx)+int(ny)*320]=1;
		}


	}
	for(i=0; i<320*240; i++)
	{
		if(vscr2[i])
			vscr[i]=255;
	}
	for(i=0; i<22; i++)
	{
		float pgs = tid*150;
		float x = (i-1)*16-(fmod(pgs,16));
		PutChar(x,112+10*(cos(tid*1.9+x*0.034)+sin(tid*-1.2+x*0.002)),msg[(i+(int(pgs)/16))%strlen(msg)],vscr);
	}

	Graphics_Flip(vscr);

	static float sidste_clear=tid;

	

	if(tid-sidste_clear >= 5)
	{
		int x, y;

		Graphics_ClearScreen(vscr,0);
		for(y=1; y<239; y++)
		{
			for(x=1; x<319; x++)
			{
				int o=x+y*320;

				vscr[o]= (vscr2[o]+vscr2[o+1]+vscr2[o+1]+vscr2[o+320])/4 ? 1 : 0;
			}
		}
		Graphics_CopyScreen(vscr2,vscr);
		sidste_clear=tid;
	}
}