예제 #1
0
int main(){
	/*Game Settings*/

	State state = STARTED;
	int render = 0;
	ALLEGRO_DISPLAY *display;
	ALLEGRO_EVENT_QUEUE *queue;
	ALLEGRO_TIMER *timer;
	ALLEGRO_FONT *pixelate;
	ALLEGRO_BITMAP *back1;
	ALLEGRO_BITMAP *back2;
	ALLEGRO_BITMAP *space;
	ALLEGRO_BITMAP *logo;
	struct Background bg1;
	struct Background bg2;
	struct Background bgspace;

	al_init();

	display = al_create_display(800, 600);
	al_set_window_position(display, 100, 100);
	al_set_window_title(display, "GaliType - Grupo 6");

	al_init_font_addon();
	al_init_ttf_addon();
	al_init_image_addon();
	al_install_keyboard();

	back1 = al_load_bitmap("back1.png");
	back2 = al_load_bitmap("back2.png");
	space = al_load_bitmap("space.jpg");
	logo = al_load_bitmap("logo.png");

	initBack(&bg1, 0, 0, 1.5, -1, 800, 600, back1);
	initBack(&bg2, 0, 0, 1, -1, 800, 600, back2);
	initBack(&bgspace, 0, 0, 0.5, -1, 1000, 600, space);

	queue = al_create_event_queue();
	timer = al_create_timer(1.0 / 60);

	al_register_event_source(queue, al_get_timer_event_source(timer));
	al_register_event_source(queue, al_get_keyboard_event_source());
	al_register_event_source(queue, al_get_display_event_source(display));



	pixelate = al_load_ttf_font("Pixelate.ttf", 30, 0);

	al_start_timer(timer);
	while (state != FINISHED){
		ALLEGRO_EVENT ev;
		al_wait_for_event(queue, &ev);
		if (ev.type == ALLEGRO_EVENT_KEY_DOWN){
			if (state == STARTED){
				switch (ev.keyboard.keycode)
				{
				case ALLEGRO_KEY_ESCAPE:
					state = FINISHED;
					break;
				case ALLEGRO_KEY_ENTER:
					state = SELECT_DIFFICULTY;
					break;
				}
			}
			if (state == SELECT_DIFFICULTY){
				switch (ev.keyboard.keycode){
					case ALLEGRO_KEY_1:
					case ALLEGRO_KEY_PAD_1:
						startGame(EASY);
						break;
					case ALLEGRO_KEY_2:
					case ALLEGRO_KEY_PAD_2:
						startGame(MEDIUM);
						break;
					case ALLEGRO_KEY_3:
					case ALLEGRO_KEY_PAD_3:
						startGame(HARD);
						break;
					case ALLEGRO_KEY_4:
					case ALLEGRO_KEY_PAD_4:
						startGame(TYPING_MASTER);
						break;
					case ALLEGRO_KEY_ESCAPE:
						state = STARTED;
						break;
				}
			}
		}

		else if (ev.type == ALLEGRO_EVENT_TIMER)
		{
			updateBack(&bg1);
			updateBack(&bg2);
			updateBack(&bgspace);
			render = 1;
		}
		else if (ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE){
			state = FINISHED;
		}
		if (render == 1 && al_is_event_queue_empty(queue))
		{
			render = 0;
			drawBack(&bgspace);
			drawBack(&bg1);
			drawBack(&bg2);

			al_draw_bitmap(logo, 50, 25, 0);
			if (state == STARTED){
				al_draw_text(pixelate, al_map_rgb(255, 255, 255), 50, 250, 0, "Get ready to type...");
				al_draw_text(pixelate, al_map_rgb(255, 255, 255), 50, 350, 0, "Press Enter to start a new game");
				al_draw_text(pixelate, al_map_rgb(255, 255, 255), 50, 450, 0, "Press Esc to exit.");
			}
			if (state == SELECT_DIFFICULTY){
				al_draw_text(pixelate, al_map_rgb(255, 255, 255), 50, 250, 0, "Select difficulty:");
				al_draw_text(pixelate, al_map_rgb(255, 255, 255), 50, 300, 0, "1. Easy");
				al_draw_text(pixelate, al_map_rgb(255, 255, 255), 50, 350, 0, "2. Medium");
				al_draw_text(pixelate, al_map_rgb(255, 255, 255), 50, 400, 0, "3. Hard");
				al_draw_text(pixelate, al_map_rgb(255, 255, 255), 50, 450, 0, "4. Typing Boss");
				al_draw_text(pixelate, al_map_rgb(255, 255, 255), 50, 500, 0, "Press Esc to return...");
			}
			al_flip_display();
			al_clear_to_color(al_map_rgb(0, 0, 0));

		}

	}

	al_destroy_bitmap(back1);
	al_destroy_bitmap(back2);
	al_destroy_bitmap(space);
	al_destroy_bitmap(logo);
	al_destroy_font(pixelate);
	al_destroy_display(display);
	return 0;
}
예제 #2
0
void testApp::update() {	
	kinect.update();
	if(!panel.getValueB("pause") && kinect.isFrameNew())	{
		zCutoff = panel.getValueF("zCutoff");
		
		float fovWidth = panel.getValueF("fovWidth");
		float fovHeight = panel.getValueF("fovHeight");
		int left = Xres * (1 - fovWidth) / 2;
		int top = Yres * (1 - fovHeight) / 2;
		int right = left + Xres * fovWidth;
		int bottom = top + Yres * fovHeight;
		roiStart = Point2d(left, top);
		roiEnd = Point2d(right, bottom);
		
		ofVec3f nw = ConvertProjectiveToRealWorld(roiStart.x, roiStart.y, zCutoff);
		ofVec3f se = ConvertProjectiveToRealWorld(roiEnd.x - 1, roiEnd.y - 1, zCutoff);
		float width = (se - nw).x;
		float height = (se - nw).y;
		globalScale = panel.getValueF("stlSize") / MAX(width, height);
		
		backOffset = panel.getValueF("backOffset") / globalScale;
		
		cutoffKinect();
		
		if(panel.getValueB("useSmoothing")) {
			smoothKinect();
		}
		
		if(panel.getValueB("useWatermark")) {
			startTimer();
			injectWatermark();
			injectWatermarkTime = stopTimer();
		}
		
		startTimer();
		updateSurface();
		updateSurfaceTime = stopTimer();
		
		bool exportStl = panel.getValueB("exportStl");
		bool useRandomExport = panel.getValueB("useRandomExport");
		
		startTimer();
		if((exportStl && useRandomExport) || panel.getValueB("useRandom")) {
			updateTrianglesRandom();
		} else if(panel.getValueB("useSimplify")) {
			updateTrianglesSimplify();
		} else {
			updateTriangles();
		}
		calculateNormals(triangles, normals);
		updateTrianglesTime = stopTimer();
		
		startTimer();
		updateBack();
		updateBackTime = stopTimer();
		
		startTimer();
		postProcess();
		postProcessTime = stopTimer();
		
		if(exportStl) {
			string pocoTime = Poco::DateTimeFormatter::format(Poco::LocalDateTime(), "%Y-%m-%d at %H.%M.%S");
			
			ofxSTLExporter exporter;
			exporter.beginModel("Kinect Export");
			addTriangles(exporter, triangles, normals);
			addTriangles(exporter, backTriangles, backNormals);
			exporter.saveModel("Kinect Export " + pocoTime + ".stl");
			
#ifdef USE_REPLICATORG
			if(printer.isConnected()) {
				printer.printToFile("/home/matt/MakerBot/repg_workspace/ReplicatorG/examples/Snake.stl", "/home/matt/Desktop/snake.s3g");
			}
#endif
			
			panel.setValueB("exportStl", false);
		}
	}
	
	float diffuse = panel.getValueF("diffuseAmount");
	redLight.setDiffuseColor(ofColor(diffuse / 2, diffuse / 2, 0));
	greenLight.setDiffuseColor(ofColor(0, diffuse / 2, diffuse / 2));
	blueLight.setDiffuseColor(ofColor(diffuse / 2, 0, diffuse / 2));
	
	float ambient = 255 - diffuse;
	redLight.setAmbientColor(ofColor(ambient / 2, ambient / 2, 0));
	greenLight.setAmbientColor(ofColor(0, ambient / 2, ambient / 2));
	blueLight.setAmbientColor(ofColor(ambient / 2, 0, ambient / 2));
	
	float lightY = ofGetHeight() / 2 + panel.getValueF("lightY");
	float lightZ = panel.getValueF("lightZ");
	float lightDistance = panel.getValueF("lightDistance");
	float lightRotation = panel.getValueF("lightRotation");
	redLight.setPosition(ofGetWidth() / 2 + cos(lightRotation + 0 * TWO_PI / 3) * lightDistance,
											 lightY + sin(lightRotation + 0 * TWO_PI / 3) * lightDistance,
											 lightZ);
	greenLight.setPosition(ofGetWidth() / 2 + cos(lightRotation + 1 * TWO_PI / 3) * lightDistance,
												 lightY + sin(lightRotation + 1 * TWO_PI / 3) * lightDistance,
												 lightZ);
	blueLight.setPosition(ofGetWidth() / 2 + cos(lightRotation + 2 * TWO_PI / 3) * lightDistance,
												lightY + sin(lightRotation + 2 * TWO_PI / 3) * lightDistance,
												lightZ);
}