//DISPLAY
void background(void){
//BACKGROUND sky
glColor3f(1.0,1.0,1.0);
        glBegin(GL_POLYGON);
	glVertex2f(0,0);
    glColor3f(1.0,1.0,1.0);
glColor3f(0.0,0.5,1.0);
	glVertex2f(0,250);
        glColor3f(0.0,0.5,1.0);
        glVertex2f(250,250);
        glColor3f(1.0,1.0,1.0);
	glVertex2f(250,0);
	glEnd();

//sea
glColor3f(0.0,0.4,1.0);
        glBegin(GL_POLYGON);
	glVertex2f(0,0);
	glVertex2f(0,100);
        glVertex2f(250,100);
        glColor3f(1.0,1.0,1.0);
	glVertex2f(250,0);
	glEnd();

sand();
waves();
//light();
//shade();
//cloud 2
glColor3f(1.0,1.0,1.0);
drawCircle(100,160,12);   
drawCircle(110,160,16);
drawCircle(120,160,12);

//cloud 3
drawCircle(10,170,19);   
drawCircle(20,170,23);
drawCircle(30,170,19);
}
예제 #2
0
void sandbox(SDL_Surface *s, int width, int height){
	form sand(0,0,1000,600);
	cout<<sand.children.size()<<"\n";
	XAutomataEngine game(&sand,200,100,750,400,width,height);
	//configure key events to pass preview to sand.
	sand.tag = &game;
	sand.addHandler(event_keydown,sandKey);

	//pan controls
	Button panUp(&sand,70,190,45,45); panUp.text = "Up";
	Button panDown(&sand,70,290,45,45); panDown.text = "Down";
	Button panLeft(&sand,20,240,45,45); panLeft.text = "Left";
	Button panRight(&sand,120,240,45,45); panRight.text = "Right";
	Button home(&sand,70,240,45,45); home.text = (width==-1&&height==-1?"Home":"Fit");

	panUp.tag = panDown.tag = panLeft.tag = panRight.tag = home.tag = (void*)(&game);
	panUp.addHandler(event_Lclick,sandUpHandler);
	panDown.addHandler(event_Lclick,sandDownHandler);
	panLeft.addHandler(event_Lclick,sandLeftHandler);
	panRight.addHandler(event_Lclick,sandRightHandler);
	home.addHandler(event_Lclick,sandHomeHandler);

	//zoom controls
	Button zoomIn(&sand,55,375,75,45); zoomIn.text = "Zoom in";
	Button zoomOut(&sand,55,445,75,45); zoomOut.text = "Zoom out";
	zoomIn.tag = zoomOut.tag =  (void*)(&game);
	zoomIn.addHandler(event_Lclick,sandZoomInHandler);
	zoomOut.addHandler(event_Lclick,sandZoomOutHandler);

	//speed controls
	label speedLabel(&sand,200,530,130,30); speedLabel.text = "Speed: Paused";
	HScroll speedScroll(&sand,350,530,200,30,1,10,5);
	Button pause(&sand,600,530,70,30); pause.text = "Pause";
	Button step(&sand,700,530,70,30); step.text = "Step";
	speedLabel.tag = speedScroll.tag = pause.tag = step.tag = (void*)(&game);
	speedScroll.addHandler(event_scroll,sandScrollHandler);
	pause.addHandler(event_Lclick,sandPause);
	step.addHandler(event_Lclick,sandStep);
	
	//colour controls
	radioButton white(&sand,300,35,80,20,NULL);	white.setTextColour(255,255,255);	white.setText("Master");
	radioButton red(&sand,400,35,80,20,&white);	red.setTextColour(255,100,100);		red.setText("Red");
	radioButton green(&sand,500,35,80,20,&red);	green.setTextColour(0,255,100);	green.setText("Green");
	radioButton blue(&sand,600,35,80,20,&green);	blue.setTextColour(100,100,255);	blue.setText("Blue");
	radioButton yellow(&sand,700,35,80,20,&green);	yellow.setTextColour(255,255,0);	yellow.setText("Yellow");

	checkBox bind(&sand,300,70,150,30); bind.setText("Enforce rules");
	bind.tag = (void*)&game;
	bind.addHandler(event_checkchanged,changeRestrict);

	teamRadioStruct params[5];
	radioButton *colours[5] = {&white,&red,&green,&blue,&yellow};
	for(int i = 0; i < 5; i++){
		params[i] = teamRadioStruct(i,&game);
		colours[i]->tag = &params[i];
		colours[i]->addHandler(event_checkchanged,changeTeam);
	}
	
	white.select();
	game.fit();

	//adding a save feature. No open yet...
	Button save(&sand,900,10,80,40); save.text = "Save";

	//exit controls
	Button back(&sand,50,50,100,50); back.text = "Back";
	back.addHandler(event_Lclick,sandBack);

	sand.addHandler(event_quit,sandBack);

	//keep that label and pause button updated
	pause.addHandler(event_frameTick,sandPauseButtonText);
	speedLabel.addHandler(event_frameTick,sandLabelText);

	sand.startFramerate(20,s);
	
	running = true;
	while(running){
		sand.wait();
		SDL_Flip(s);
	}
	cout<<"Ended";
}
예제 #3
0
파일: world.cpp 프로젝트: DZvO/awesome
void motor::World::generate()
{
	//DEBUG
	for (int z = 0; z < int(worldDimZ * chunkSizeZ); ++z)
		for (int x = 0; x < int(worldDimX * chunkSizeX); ++x)
		{
			for (int y = 0; y < int(worldDimY * chunkSizeY); ++y)
			{
				setBlock(x, y, z, BLOCK_AIR);
			}
		}
	//DEBUG
	memoryAllocationRam = memoryAllocationGfx = 0;

	float random = 0;
	int mX, mY;
	SDL_GetMouseState(&mX, &mY);
	random = (mX * mY);
	cout << "random seed: " << random << "\n";
//#define DEBUG
#ifndef DEBUG
	PerlinNoise base(0, 0, 0, 0, random);
	base.setPersistence(0.4);
	base.setFrequency(0.4);
	base.setAmplitude(1.5);
	base.setOctaves(6);

	PerlinNoise mountains(0, 0, 0, 0, random);
	mountains.setPersistence(1.0);
	mountains.setFrequency(0.1);
	mountains.setAmplitude(14.5);
	mountains.setOctaves(1);

	PerlinNoise sand(0.6, 0.15, 0.8, 3, random);

	for (int z = 0; z < int(worldDimZ * chunkSizeZ); ++z)
		for (int x = 0; x < int(worldDimX * chunkSizeX); ++x)
		{
			float fBase = base.getHeight(x, z);
			float fMountains = mountains.getHeight(x, z);
			float fSand = sand.getHeight(x, z);

			float Height = fBase * worldDimY / 4 + worldDimY / 3;
			Height += fMountains > 0 ? fMountains : 0;

			if(Height < 0)
				Height = 1;

			for (int y = 0; y < Height; ++y)
			{
				if(fMountains > 1.4)
					setBlock(x, y, z, BLOCK_DIRT);
				else if(Height == 1)
					setBlock(x, y, z, BLOCK_DIRT);
				else
					setBlock(x, y, z, BLOCK_STONE);
			}

			if(fSand > 0.5)
				setBlock(x, int(Height), z, BLOCK_SAND);
		}
#else
	//for (int z = 0; z < int(worldDimZ * chunkSizeZ); ++z)
		//for (int x = 0; x < int(worldDimX * chunkSizeX); ++x)
		//{
//
			//float Height = 1;
			//for (int y = 0; y < Height; ++y)
			//{
				//setBlock(x, y, z, BLOCK_STONE);
			//}
		//}
	for (int z = 0; z < int(worldDimZ * chunkSizeZ); ++z)
		for (int x = 0; x < int(worldDimX * chunkSizeX); ++x)
		{
			for (int y = 0; y < int(worldDimY * chunkSizeY); ++y)
			{
				setBlock(x, y, z, BLOCK_STONE);
			}
		}
#endif

	unsigned int vertices = 0;
	for(unsigned int i = 0; i < worldDimX; i++)
		for(unsigned int j = 0; j < worldDimY; j++)
			for(unsigned int k = 0; k < worldDimZ; k++)
			{
				vertices += chunks[i][j][k].calculateVisibleSides(i * chunkSizeX, j * chunkSizeY, k * chunkSizeZ, false);
				chunks[i][j][k].uploadToVbo();

				memoryAllocationRam += chunks[i][j][k].memoryAllocationRam;
				memoryAllocationGfx += chunks[i][j][k].memoryAllocationGfx;
			}
	cout << worldDimX * worldDimY * worldDimZ << " chunks, " << vertices << " vertices, with a ";
	cout << "total of " << float(memoryAllocationRam) / 1000.f << " kB RAM, " << float(memoryAllocationGfx) / 1000.f << " kB Gfx memory used (probably more :>)" << endl;
}