Example #1
0
void LoseLife(char *reason) {
	//Draw cracked screen - but draw all the rest of the world & hud first
	CloseGraphics();
	OpenGraphics();
	DrawWorld(&world, cameraPos, cameraAngle);
	DrawHUD();
	DrawArrow(cameraAngle.y);
	DrawRadarDots(true);
	DrawRadarArm(sweepAngle * sweepStepCount++);
	DrawRadarDots(false);
	//finally!
	DrawCrackedScreen();
	SetTextColor(RED);
	DrawText(25,40,reason);
	if (--lives<=0) {
		SetTextColor(GREEN);
		DrawText(30,55,"GAME OVER!");
	}
	Show();
	PlaySound(SOUND_EXPLOSION);
	//dead?
	if (lives<=0) {
		Sleep(2000);
		//Reset back to splash screen
		ResetTimer();
		mode=0;

		Splash();
	} else {
		// Hit but still going
		InitialiseWorld();
	}
}
Example #2
0
void End()
{
  	CloseGraphics();
  	CloseMotors();
	CloseIR();
	CloseFileSystem();
}
Example #3
0
File: qplot.c Project: WndSks/msys
static int
nice_end(int junk)
{
    CloseGraphics();
    putchar('\n');
    exit(EXIT_SUCCESS);
    return 0;
}
Example #4
0
void PlaySound(char *filename) {
	CloseGraphics();// free up our processor to do audio digitizing
	StartAudioPlayback(filename); // begin playing file
	// wait for audio to finish
	while( IsAudioPlaying() )
	{
		Sleep( 50 );
	}
	OpenGraphics();// open the display again
}
Example #5
0
File: grxlib.c Project: WndSks/msys
int
InitializeGraphics(int scroll_text_up)
{
    int             fno, i;
    char           *screen_tty;
    struct winsize  winsize;

    fno = fileno(stdout);
    if (!isatty(fno)) {
	fprintf(stderr, "stdout must be a tty\n");
	return 0;
    }
    screen_tty = ttyname(fno);

#ifdef HAVE_TERMIOS_H
    GET_TERMIOS(fno, &ttmode);
    ttmode.c_lflag &= ~ECHO;
    SET_TERMIOS(fno, &ttmode);
#endif

    infd = fopen(screen_tty, "rw");

#ifdef HAVE_TERMIOS_H
    fno2 = fileno(infd);
    GET_TERMIOS(fno2, &ttmode);
    ttmode.c_lflag &= ~ECHO;
    SET_TERMIOS(fno2, &ttmode);
#endif

    /* query rxvt to find if graphics are available */
    fflush(stdout);
    printf("\033GQ");
    fflush(stdout);
    while (1) {
	if ((fgets(line, LINESZ, infd) != NULL) &&
	    (sscanf(line, "\033G%d", &i) == 1)) {
	    if (!i) {
		fprintf(stderr, "rxvt graphics not available\n");
		CloseGraphics();
		return 0;
	    }
	    break;
	}
    }
    if (scroll_text_up) {
	ioctl(fno, TIOCGWINSZ, &winsize);
	fflush(stdout);
	for (i = 0; i < winsize.ws_row; i++)
	    putchar('\n');
	fflush(stdout);
    }
    return i;
}
Example #6
0
//Splash screen
void Splash() {
	ResetTimer(); //we're going to use it for random seed
	//Setup a world with a tank and a pyramid in specific places
	CloseGraphics();
	OpenGraphics();

	Point3d centre;
	world=CreateNewWorld();

	//A tank pointing straight at us
	centre=CreatePoint(0.0,0.0,45.0);
	obj=CreateTank(GREEN, centre, 4.5);
	RotateObjectYAxis(&obj, 2.0 * PI / 360.0 * 195);
	AddObjectToWorld(&world, obj);

	//A yellow pyramid behind the tank and to the right
	centre=CreatePoint(10.0, 0.0, 70.0);
	obj=CreatePyramid(YELLOW, centre, 5.0);
	RotateObjectYAxis(&obj, 3.0*PI/5.0);
	AddObjectToWorld(&world, obj);

	//A blue cube behind the tank and to the left
	centre=CreatePoint(-10.0, 0.0, 60.0);
	obj=CreateCube(BLUE, centre, 5.0);
	RotateObjectYAxis(&obj, 195.0*PI/180.0);
	AddObjectToWorld(&world,obj);

	//Draw world, add splash graphics, prompt to start
	cameraPos=CreatePoint(0.0,5.0,0.0);
	cameraAngle=CreatePoint(0.0,0.0,0.0);
	DrawWorld(&world, cameraPos, cameraAngle);
	SetTextColor(GREEN);
	DrawText(5,25, "by RorschachUK");

	SetTextColor(CYAN);
	DrawText(5,100, "Help");
	DrawText(110,100,"Start");
	DrawImage(logoImage, 5,5,RGBColor(253,255,252,0));
	DrawImage(signatureImage, 135,24,BLACK);

	Show();
	Sleep(100);
	mode=0;
}
Example #7
0
//Help screen
void ShowHelp() {
	CloseGraphics();
	OpenGraphics();

	//DrawImage(logoImage, 5,5,RGBColor(253,255,252,0));
	SetTextColor(WHITE);
	DrawText(6, 7, "Find the enemy &");
	DrawText(6, 22, "shoot him before");
	DrawText(6, 37, "he shoots you!");
	SetTextColor(GREEN);
	DrawText(6, 52, "Press GO to fire,");
	SetTextColor(RED);
	DrawText(6, 67, "beware of the red");
	DrawText(6, 82, "exploding barrels!");
	SetTextColor(CYAN);
	DrawText(120,100, "OK");
	Show();
	mode=2;
}
Example #8
0
static int CloseGraphics (lua_State * L)
{
	CloseGraphics();

	return 0;
}
Example #9
0
void main()
{
	Action action = Draw;
	SetGraphicsColor(color, 1);


	InitGraf();

	int menu_it = 0;
	polygon.n = 0;

	InitGraphics();

	menu_item = 0;
	CheckMenuItem(menu_action, 1, MF_CHECKED);
	CheckMenuItem(menu_draw, 20, MF_CHECKED);

	while (key_input != ESC)						// ESC exits the program
	{
		CheckGraphicsMsg();

		if (menu_it != menu_item)
		{
			switch (menu_item){
			case 20:
				CheckMenuItem(menu_draw, 20, MF_CHECKED);
				CheckMenuItem(menu_draw, 21, MF_UNCHECKED);
				CheckMenuItem(menu_draw, 22, MF_UNCHECKED);
				menu_it = menu_item;
				shape = Line;
				break;
			case 21:
				CheckMenuItem(menu_draw, 20, MF_UNCHECKED);
				CheckMenuItem(menu_draw, 21, MF_CHECKED);
				CheckMenuItem(menu_draw, 22, MF_UNCHECKED);

				menu_it = menu_item;
				shape = Poly;
				break;
			case 22:
				CheckMenuItem(menu_draw, 20, MF_UNCHECKED);
				CheckMenuItem(menu_draw, 21, MF_UNCHECKED);
				CheckMenuItem(menu_draw, 22, MF_CHECKED);
				menu_it = menu_item;
				shape = Circle;
				break;
			default:
				int i;
				for (i = 1; i <= 16; i++)
					CheckMenuItem(menu_action, i, MF_UNCHECKED);
				CheckMenuItem(menu_action, menu_item, MF_CHECKED);
				if (menu_item >= 1 && menu_item <= 16){
					switch (menu_item) {
					case 1:
						action = Draw;
						break;
					case 2:
						action = Pick;
						break;
					case 3:
						action = Zoom;
						break;
					}
					mouse_action = NO_ACTION;
				}
				menu_it = menu_item;

			}

		}

		if (mouse_action == L_MOUSE_DOWN)
		{
			switch (action) {
			case Draw:
				MouseDownDraw();
				break;
			case Pick:
				MouseDownPick();
				break;
			case Zoom:
				MouseDownZoom();
				break;
			}
		}
		if (mouse_action == L_MOUSE_MOVE_DOWN)
		{
			switch (action) {
			case Draw:
				MouseMoveDraw();
				break;
			case Pick:
				MouseMovePick();
				break;
			case Zoom:
				MouseMoveZoom();
				break;
			}
		}
		else  if (mouse_action == L_MOUSE_UP)
		{
			switch (action) {
			case Draw:
				MouseUpDraw();
				break;
			case Pick:
				MouseUpPick();
				break;
			case Zoom:
				MouseUpZoom();
				break;
			}
		}
		else  if (mouse_action == R_MOUSE_DOWN)
		{
			switch (action) {
			case Draw:
				RMouseDownDraw();
				break;
			case Pick:
				RMouseDownPick();
				break;
			case Zoom:
				RMouseDownZoom();
				break;
			}
		}
	}

	CloseGraphics();
}
Example #10
0
int main() {

    int r;

#if GRAPHICS
    struct Button *but,*button;
    boolean quit=FALSE;
    context = (struct Context *)malloc(sizeof(struct Context));

    but= context->Buttons= CreateButton(RUN_BUTTON,"RUN/STOP",WINDOW_W-50,WINDOW_H-90);
    but= but->Next=CreateButton(DISPLAY_RATE_UP_BUTTON,"+",WINDOW_W-40,WINDOW_H-60);
    but= but->Next=CreateButton(DISPLAY_RATE_DOWN_BUTTON,"-",WINDOW_W-60,WINDOW_H-60);
    but= but->Next=CreateButton(QUIT_BUTTON,"QUIT",WINDOW_W-50,WINDOW_H-30);

    display_rate=1L;

    OpenGraphics();
#endif

    robots = (struct Robot **)malloc(NR*sizeof(struct Robot*));

    for (r=0;r<NR;r++) {
        robots[r] = (struct Robot *)malloc(sizeof(struct Robot));
    }

    InitFiles();
    InitGlobal();

    for (r=0;r<NR;r++) {
        InitRobot(r,robots[r]);
    }

#if GRAPHICS
    while(quit == FALSE) {
        button=PressButton(context);
        switch(button->Value) {
        case QUIT_BUTTON:  
            quit = TRUE;
            break;
        case DISPLAY_RATE_UP_BUTTON:
            display_rate*=10L;
            if (display_rate>100000L) display_rate=100000L;
            display_rate-=display_rate%10L;
            if (display_rate<1L) display_rate=1L;
            DrawWindow(context);
            break;
        case DISPLAY_RATE_DOWN_BUTTON:
            if (display_rate>9L) display_rate/=10L;
            display_rate-=display_rate%10L;
            if (display_rate<1L) display_rate=1L;
            DrawWindow(context);
            break;

        case RUN_BUTTON:
#endif
            do { 

                for (r=0;r<NR;r++) {
                    RunRobot(r,robots[r]);
                    EvalRobot(t,r,robots[r]);
                }
                t++;
                if (t>TM) {
#if GRAPHICS
                    CloseGraphics();
#endif
                    return(1);
                    exit(1);
                }

#if GRAPHICS
                if (t%display_rate==0L) {
                    DrawWindow(context);
#if DISTY*(DISTY-2)
                    if (t%(250L*display_rate)==0L) {
                        DrawPlate(0,0,WINDOW_W-1,WINDOW_H-1,BLACK,PLATE_UP);
                    }
#endif
                }
#endif
            }
#if GRAPHICS
            while (UnpressButton(context,button)==FALSE); 
            break;
#else
            while (TRUE); 
#endif
#if GRAPHICS
        }
        button->State = PLATE_UP;
    }

    CloseGraphics();
#endif
    return(1);
}
Example #11
0
//Cleanup
void End() {
	CloseGraphics();
	CloseFileSystem();
}
Example #12
0
//Main program loop - Run gets called until it returns false
bool Run() {
  	//Main loop - get keypresses and interpret them
  	keystate=GetRemoteKeys();
	if(keystate & KEY_HOME) {
		return false;
	}
	switch(mode) {
		case 0: {	//Splash screen
			if (keystate & KEY_INPUT2) { //Button B
				//Start game
				InitialiseGame();
				PlaySound(SOUND_BEEP);
			}

			if (keystate & KEY_INPUT1) { //Button A
				//show help
				ShowHelp();
				PlaySound(SOUND_BEEP);
			}
		}
		break;
		case 2: {	//Help - wait for 'OK' press
			if (keystate & KEY_INPUT2) { //Button B
				//Reset back to splash screen
				ResetTimer();
				mode=0;

				Splash();
				PlaySound(SOUND_BEEP);
			}
		}
		break;
		case 1: {	//Game
			if (keystate & KEY_INPUT1) { //Button A
				//Reset back to splash screen
				ResetTimer();
				mode=0;

				Splash();
			}
			if (keystate & KEY_RUN) { //Go button
				//Fire!
				PlaySound(SOUND_SHOOT);
				refreshCount = 0;
				int hit;
				hit = LineHitsObject(cameraPos, cameraAngle);
				if (hit == tankObjectIndex) {
					//we hit the tank!
					score += 100;
					CloseGraphics();
					OpenGraphics();
					DrawWorld(&world, cameraPos, cameraAngle);
					DrawHUD();
					DrawExplosion();
					DrawArrow(cameraAngle.y);
					DrawRadarDots(true);
					DrawRadarArm(sweepAngle * sweepStepCount++);
					DrawRadarDots(false);

					SetTextColor(CYAN);
					DrawText(6,100,"Quit");
					Show();
					PlaySound(SOUND_EXPLOSION);
					PlaceTank(cameraPos, cameraAngle);
				}
			}

			//Have the movement sticks changed? This bit doesn't care about buttons
			if((keystate & (KEY_RIGHT_BACK+KEY_RIGHT_FORWARD+KEY_LEFT_BACK+KEY_LEFT_FORWARD)) != (oldKeystate & (KEY_RIGHT_BACK+KEY_RIGHT_FORWARD+KEY_LEFT_BACK+KEY_LEFT_FORWARD))) {

				MoveCamera(&cameraPos, &cameraAngle, baselinePos, arrowRefAngle, ReadTimer(), oldKeystate);
				arrowRefAngle=cameraAngle.y;
				baselinePos=cameraPos;

				ResetTimer();
				oldKeystate = keystate;
				if (keystate==0) //we've just stopped moving
					refreshCount=0;
			}

			if (mode==1) {
				if (sweepStepCount == SWEEPSTEPS)
					sweepStepCount=0;

				if (--behaviourCount<0)
					ChooseBehaviour();

				MoveTank();

				MoveCamera(&cameraPos, &cameraAngle, baselinePos, arrowRefAngle, ReadTimer(), oldKeystate);
				//is it time to reset the tank model?  Otherwise it gradually gets distorted
				if (--resetCount<0) {
					//Refresh the tank model which is prone to getting distorted
					//due to cumulative inaccuracies of sin/cos approximations
					Point3d angle=world.objects[tankObjectIndex].heading;
					Point3d tankPos=world.objects[tankObjectIndex].centre;
					world.objects[tankObjectIndex]=tank;
					MoveObject(&(world.objects[tankObjectIndex]), tankPos);
					RotateObjectYAxis(&(world.objects[tankObjectIndex]), angle.y);
					resetCount=50;
				}

				//Is it time to redraw the world?
				if (--refreshCount<0) {
					//Seems a bit brutal to have to close graphics but it's
					//the only way to clear the screen that'll let us draw
					//on it properly again - ClearScreen or ClearRectangle mess up
					CloseGraphics();
					OpenGraphics();

					DrawWorld(&world, cameraPos, cameraAngle);

					DrawHUD();
					refreshCount=2;
				}
				DrawArrow(cameraAngle.y);
				DrawRadarDots(true);
				DrawRadarArm(sweepAngle * sweepStepCount++);
				DrawRadarDots(false);

				SetTextColor(CYAN);
				DrawText(6,100,"Quit");
				Show();

				//just in case we changed mode...
				if (mode==0)
					Splash();
			}
		}
	}
	Sleep(50);
	return true;
}