Exemplo n.º 1
0
static void
GrDestroyTimerWrapper(void *r)
{
    nxDestroyTimerReq *req = r;
    
    GrDestroyTimer(req->timerid);
}
Exemplo n.º 2
0
/* exit, release all created stuff */
void lights_exit( void ) 
{
	GrDestroyTimer( lights_timer );
	GrDestroyGC( lights_gc );
	pz_close_window( lights_wid );
	GrDestroyWindow( lights_bufwid );
}
Exemplo n.º 3
0
static void credits_exit(void)
{
	credits_free_var();
	GrDestroyGC(credits_gc);
	GrDestroyTimer(credits_timer);
	pz_close_window(credits_wid);
}
Exemplo n.º 4
0
static void msg_destroy_msg()
{
	int i;

	pz_close_window(msg_wid);
	GrDestroyGC(msg_gc);
	GrDestroyTimer(msg_timer);
	for(i = linenum; i; i--)
		free(msglines[i-1]);
	free(msglines);
}
Exemplo n.º 5
0
// Handles timer/key events.
static int handle_event(GR_EVENT *event)
{
    switch (event->type)
    {
		case GR_EVENT_TYPE_TIMER:
			if (running && !hold) 
				advance_and_check();
			break;
		case GR_EVENT_TYPE_KEY_DOWN:
			switch (event->keystroke.ch)
			{
				case 'm': // Menu button.
					GrDestroyTimer( timer_id );
					writeHighScore();
					pz_close_window (tunnel_wid);
					break;
				case 'w': // rewind button
				case 'l': // scroll wheel left
					if (running && ball.radius < ball.x)
						ball.x -= 2;
					break;	
				case 'f': // fast forward button
				case 'r': // scroll wheel right
					if (running && wi.width - 2 - ball.radius  > ball.x)
						ball.x += 2;
					break;						
				case 'd': // play button. Who decided to make it d!
					if (running == 0)
						running = 1;
					else
						reset();
					break;
				case 'h': // Hold button
					hold = 1;
					break;					
				default:
					break;
			}
			break; 
		case GR_EVENT_TYPE_KEY_UP:
			switch( event->keystroke.ch )
			{
				case 'h': // Hold button
					hold = 0;
					break;
			}
			break;
		default:
			break;
    }
	return 0;
}
Exemplo n.º 6
0
// Resets the game.
static void reset()
{
	if (running == 1)
		GrDestroyTimer( timer_id );
	reset_chasm_queue(&head, &middle, &tail);
	if(new_chasm_queue((wi.width - chasmWidth) / 2, wi.height / 2, &head, &middle, &tail) == -1)
	{
		pz_error("Error making queue.");
		pz_close_window (tunnel_wid);
		return;
	}
	score = 0;
	running = 0;
	ball.radius = ballRadius;
	ball.x = wi.width / 2;
	timer_id = GrCreateTimer(tunnel_wid, timerSpeed); 
	advance_and_check();
}
Exemplo n.º 7
0
void timer_event(GR_EVENT_TIMER *ev, nxeyes_state *state)
{
	if(ev->tid != state->tid) return;

	/* Must free timer - even though it's fired, the handle and data structure live on. */
	GrDestroyTimer(state->tid);
	state->tid = 0;
	
	if(state->eyes_closed) {
		state->eyes_closed = 0;
		start_blink_timer(state);
	} else {
		state->eyes_closed = 1;
		start_blink_timer(state);
	}

	draw_eyes(state, 1);
}
Exemplo n.º 8
0
void
mvpw_set_timer(mvp_widget_t *widget, void (*callback)(mvp_widget_t*),
	       uint32_t timeout)
{
	if (widget->callback_timer) {
		widget->event_mask &= ~GR_EVENT_MASK_TIMER;
		GrSelectEvents(widget->wid, widget->event_mask);
		GrDestroyTimer(widget->tid);
	}

	widget->callback_timer = callback;

	if (callback) {
		widget->event_mask |= GR_EVENT_MASK_TIMER;
		GrSelectEvents(widget->wid, widget->event_mask);
		widget->tid = GrCreateTimer(widget->wid, timeout);
	}

}
Exemplo n.º 9
0
/* checks the selected item for timer worthy features */
void menu_handle_timer(menu_st *menulist, int force)
{
	item_st *item;
	item = &menulist->items[menulist->sel];
	/* is a submenu item or is wider than the screen */
	if((SUB_MENU_HEADER & item->op || item->text_width > menulist->w -
			(8 * 2) || ARROW_MENU & item->op || EXECUTE_MENU &
			item->op || CFLASH & item->op) && !force) {
		if(!menulist->timer)
			menulist->timer =
				GrCreateTimer(menulist->menu_wid, 150);
		menulist->timer_step = 0;
	}
	/* the timer needs destroying */
	else if(menulist->timer) {
		GrDestroyTimer(menulist->timer);
		menulist->timer = 0;
		menulist->timer_step = 0;
	}
}
Exemplo n.º 10
0
static int chopHandleEvent (GR_EVENT *event)
{
    switch (event->type)
    {
    case GR_EVENT_TYPE_TIMER:
        chopGameLoop();
        break;
	
	case GR_EVENT_TYPE_KEY_UP:
	if(event->keystroke.ch == '\r')
		bPlayerPressingUp = 0;
		break;

    case GR_EVENT_TYPE_KEY_DOWN:
    	if(bWaitingToStart == 1)
	{
	
	iPlayerSpeedY = 5;
    	bWaitingToStart = 0;
	
	}
        switch (event->keystroke.ch)
        {
        case '\r': /* Wheel button */
            bPlayerPressingUp = 1;
	    break;
         case 'm': /* Menu button */
            pz_close_window (chopWindow);
            GrDestroyTimer (chopTimer);
            GrDestroyGC(chopGC);
            break;
        default:
            break;
        }
        break;   /* key down */
    }
    return 1;
}
Exemplo n.º 11
0
/* if you are apt enough to use this to clean-up, everyone profits */
menu_st *menu_destroy(menu_st *menulist)
{
	int i;
	menu_st *parent = menulist->parent;

	if(parent != NULL)
		menu_left_transition(menulist);

	/* make sure its not a static menu we are trying to free */
	if(menulist->alloc_items != 0)
		free(menulist->items);
	if(menulist->timer)
		GrDestroyTimer(menulist->timer);
	GrDestroyGC(menulist->menu_gc);
	for(i=0; i<menulist->screen_items; i++)
		GrDestroyWindow(menulist->pixmaps[i]);
	GrDestroyWindow(menulist->transition);
	free(menulist->pixmaps);
	free(menulist->pixmap_pos);
	free(menulist);

	return parent;
}
Exemplo n.º 12
0
void handle_screensaver_event(lstate *state)
{
	GR_EVENT_SCREENSAVER *event = &state->event.screensaver;

	if(event->activate != GR_TRUE) {
		if(state->ssrotatetimer > 0)
			GrDestroyTimer(state->ssrotatetimer);
		return;
	}

	if(!state->ssitems) {
		GrError("Got screensaver activate event with no "
				"screensavers defined\n");
		return;
	}

	activate_screensaver(state);

	if(state->rotatess) {
		state->ssrotatetimer = GrCreateTimer(state->main_window,
				state->rotatess * 1000 /*, GR_TRUE*/);
	} else state->ssrotatetimer = -1;
}
Exemplo n.º 13
0
static int poddraw_handle_event(GR_EVENT * event)
{
	int ret = 0;
	switch( event->type )
	{
	case( GR_EVENT_TYPE_TIMER ):
		poddraw_cycle_point();
		break;
	    
	case( GR_EVENT_TYPE_KEY_DOWN ):
		switch( event->keystroke.ch )
		{
		    case IPOD_BUTTON_ACTION: /* action */
			    // toggle lr-ud
			    updown = (updown + 1) & 0x01;
			    break;

		    case IPOD_BUTTON_PLAY: /* play/pause */
			    // clear screen
			    poddraw_cls();
			    break;

		    case IPOD_BUTTON_FORWARD: /* >>| */
			    poddraw_color = (poddraw_color +1 ) & 
				(( screen_info.bpp == 16 )?0x0f:0x03);
			    poddraw_draw_box( colors[poddraw_color], 0, 0 );
			    break;

		    case IPOD_BUTTON_REWIND: /* |<< */
			    poddraw_color = (poddraw_color -1 ) & 
				(( screen_info.bpp == 16 )?0x0f:0x03);
			    poddraw_draw_box( colors[poddraw_color], 0, 0 );
			    break;

		    case IPOD_WHEEL_ANTICLOCKWISE: /* CCW spin */
			    poddraw_place_point( poddraw_color );
			    if( updown ) poddraw_x = PDMAX( poddraw_x-2, 0 );
			    else         poddraw_y = PDMAX( poddraw_y-2, 0 );
			    break;

		    case IPOD_WHEEL_CLOCKWISE: /* CW spin */
			    poddraw_place_point( poddraw_color );
			    if( updown )
				poddraw_x = PDMIN( poddraw_x+2, 
						    screen_info.cols-2 );
			    else
				poddraw_y = PDMIN( poddraw_y+2, 
					  (screen_info.rows - 
						(HEADER_TOPLINE + 1))-2);
			break;

		    case IPOD_BUTTON_MENU:
		    case ('q'):
			    poddraw_save();
			    GrDestroyTimer( poddraw_timer );
			    pz_close_window( poddraw_wid );
			    poddraw_free_buffer();
			    ret = 1;
			    break;

		    default:
			    ret |= EVENT_UNUSED;
			    break;
		}
		break;
	}
	return ret;
}
Exemplo n.º 14
0
static int browser_do_keystroke(GR_EVENT * event)
{
	int ret = 0;

	switch(event->type) {
	case GR_EVENT_TYPE_TIMER:
		if(((GR_EVENT_TIMER *)event)->tid == browser_key_timer) {
			GrDestroyTimer(browser_key_timer);
			browser_key_timer = 0;
			menu_handle_timer(browser_menu, 1);
			browser_action(browser_menu->items[browser_menu->sel].orig_pos);
			browser_do_draw();
		}
		else
			menu_draw_timer(browser_menu);
		break;

	case GR_EVENT_TYPE_KEY_DOWN:
		switch (event->keystroke.ch) {
		case '\r':
		case '\n':
			if(browser_menu->parent == NULL)
				browser_key_timer = GrCreateTimer(browser_wid,
						500);
			else {
				menu_handle_timer(browser_menu, 1);
				browser_menu = menu_handle_item(browser_menu, 
						browser_menu->sel);
				if(browser_menu_overlay) {
					browser_menu = browser_menu_overlay;
					browser_menu_overlay = 0;
				}
				browser_do_draw();
			}	
			break;

		case 'm':
		case 'q':
			browser_menu = menu_destroy(browser_menu);
			ret |= KEY_CLICK;
			if(browser_menu != NULL) {
				browser_do_draw();
				break;
			}
			browser_exit();
			GrDestroyGC(browser_gc);
			pz_close_window(browser_wid);
			break;

		case 'r':
			if (menu_shift_selected(browser_menu, 1)) {
				menu_draw(browser_menu);
				ret |= KEY_CLICK;
			}
			break;

		case 'l':
			if (menu_shift_selected(browser_menu, -1)) {
				menu_draw(browser_menu);
				ret |= KEY_CLICK;
			}
			break;
		default:
			ret |= KEY_UNUSED;
		}
		break;
	case GR_EVENT_TYPE_KEY_UP:
		switch (event->keystroke.ch) {
		case '\r':
		case '\n':
			if(browser_key_timer) {
				GrDestroyTimer(browser_key_timer);
				browser_key_timer = 0;
				menu_handle_timer(browser_menu, 1);
				browser_selection_activated(browser_menu->items[browser_menu->sel].orig_pos);
				browser_do_draw();
			}
			break;
		}
		break;
	default:
		ret |= EVENT_UNUSED;
		break;
	}
	return ret;
}
Exemplo n.º 15
0
static int cube_handle_event(GR_EVENT * event)
{
	int ret = 0;
	switch( event->type )
	{
		case( GR_EVENT_TYPE_TIMER ):
			if (!paused) cube_loop();
			break;
		case( GR_EVENT_TYPE_KEY_DOWN ):
			switch( event->keystroke.ch )
			{
				case '\r':
				case '\n': /* action */
					switch( xy_or_z ) {
						case 'x':
							xy_or_z ='y';
							strncpy(t_ax[0], "x", 4);
							strncpy(t_ax[1], "[y]", 4);
							break;
						case 'y':
							xy_or_z ='z';
							strncpy(t_ax[1], "y", 4);
							strncpy(t_ax[2], "[z]", 4);
							break;
						case 'z':
							xy_or_z ='x';
							strncpy(t_ax[2], "z", 4);
							strncpy(t_ax[0], "[x]", 4);
							break;
					}
					ret |= KEY_CLICK;
					break;
				case 'p': /* play/pause */
				case 'd': /*or this */
					if (t_disp) { t_disp=0; } else { t_disp=1; }
					if (solid) { solid=0; } else { solid=1; }
					break;
				case 'f': /* >>| */
					zoom_in = 1;
					break;
				case 'w': /* |<< */
					zoom_out = 1;
					break;
				case 'l': /* CCW spin */
					switch( xy_or_z )
					{
						case 'x':
							xs-=1;
							if (xs<-10) { xs=-10;}
							break;
						case 'y':
							ys-=1;
							if (ys<-10) { ys=-10;}
							break;
						case 'z':
							zs-=1;
							if (zs<-10) { zs=-10;}
							break;
					}
					break;
				case 'r': /* CW spin */
					switch( xy_or_z )
					{
						case 'x':
							xs+=1;
							if (xs>10) { xs=10;}
							break;
						case 'y':
							ys+=1;
							if (ys>10) { ys=10;}
							break;
						case 'z':
							zs+=1;
							if (zs>10) { zs=10;}
							break;
					}
					break;
				case 'h': /* hold */
					paused=1;
					break;
				case 'm':
					GrDestroyTimer( cube_timer );
					GrDestroyGC( cube_gc );
					pz_close_window( cube_wid );
					ret |= KEY_CLICK;
					break;
			}
			break;
		case( GR_EVENT_TYPE_KEY_UP ):
			switch( event->keystroke.ch )
			{
				case 'f': /* >>| */
					zoom_in = 0;
					break;
				case 'w': /* |<< */
					zoom_out = 0;
					break;
				case 'h': /* hold */
					paused = 0;
					break;
			}
			break;
	}
	return ret;
}
Exemplo n.º 16
0
static int keyman_handle_event(GR_EVENT * event)
{
	int ret = 0;
    switch( event->type )
    {
    case( GR_EVENT_TYPE_TIMER ):
	
	switch(GAMEN){
		
		
		case MENU:
			makemenu();
			
			MINIPHOTO(0,0,160,128);
			wlastkey.AR=0;wlastkey.AL=0;wlastkey.AU=0;wlastkey.AD=0;wlastkey.REE=0;wlastkey.PAU=0;
			break;
		case INGAME:
			
		
		
		
			if (wlastkey.AL==1){wnow.LR=-1;wnow.MUKI=-1;}
			else if(wlastkey.AR==1){wnow.LR=1;wnow.MUKI=1;}
			else {wnow.LR=0;}
			
			
			if(wlastkey.REE==1){
					if(wnow.JIMEN==ZIM){
					wnow.YKANSEI=-9;
					wnow.JIMEN=SORA;
					}
					else if (wnow.HASIGO==1){
					wnow.YKANSEI=-9;
					wnow.JIMEN=SORA;
					wnow.HASIGO=0;
					
					}
			}
			
			if (INIT(wnow.XLOC+8,wnow.YLOC+8,'G')==FALSE){wnow.HASIGO=0;}
			
			
			
			if (INIT(wnow.XLOC+8,wnow.YLOC+8,'G')== TRUE && wlastkey.AU !=0){
				wnow.HASIGO=1;
				wnow.shupict=2;
				//GrCopyArea(shu_pixmap,keyman_gc,0,0,16,16,yomipict_pixmap,32,112,0);
				wnow.XKANSEI=0;
				//wnow.YLOC=wnow.YLOC-3;
				}
			else if (INIT(wnow.XLOC+8,wnow.YLOC+8,'G')== TRUE && wlastkey.AD !=0){
				wnow.HASIGO=0;
				//GrCopyArea(shu_pixmap,keyman_gc,0,0,16,16,yomipict_pixmap,32,112,0);
				wnow.XKANSEI=0;
				//wnow.YLOC=wnow.YLOC+3;	
				}
				
			
			if (wnow.JIMEN==ZIM){wnow.XKANSEI=(0.9*wnow.XKANSEI)+(1*wnow.LR);}
			else {
				if (wnow.LR != 0){
				wnow.XKANSEI=(0.99*wnow.XKANSEI)+(0.3*wnow.LR);
				}
			}
			if (wnow.HASIGO==0 ){
				if (wnow.YKANSEI <= 6){
					wnow.YKANSEI++;
				}
			}
			else {wnow.YKANSEI=0;}
			
			
			

			
			wnow.XLOC=wnow.XLOC+wnow.XKANSEI;
			wnow.YLOC=wnow.YLOC+wnow.YKANSEI;
			
			
			if (wnow.NUPDW==-1 && ((wnow.MAPSCROLL) % 16)==0){wnow.YLOC=wnow.YLOC+16;}
			else if (wnow.NUPDW==1 && (wnow.MAPSCROLL % 16)==15){wnow.YLOC=wnow.YLOC-16;}
			
			
			
			if (wnow.MAPSCROLL>0 && wnow.MAPSCROLL<TATEHABA*16){
				wnow.MAPSCROLL=wnow.MAPSCROLL+wnow.NUPDW;
			}
			scr= (wnow.MAPSCROLL/16);
			ATARI2();
						
			
			if (wlastkey.AU != 1 && wlastkey.AD != 1){
			 if (wnow.MUKI==1){
			 wnow.shupict=0;
			 //GrCopyArea(shu_pixmap,keyman_gc,0,0,16,16,yomipict_pixmap,0,112,0);
			 }
			 else {
			 wnow.shupict=1;
			 //GrCopyArea(shu_pixmap,keyman_gc,0,0,16,16,yomipict_pixmap,16,112,0);
			 }
			}			
			
						
			if (wnow.NUPDW==-1 && wnow.YLOC>136){
				wdeady.sp=-20;
				wdeady.g=1.6;
				wdeady.nowt=128;
				GAMEN=END;
				wdeady.kaiten=0;
				ketumatu=0;
				wdeady.deadcount=1;}
				
			else if(wnow.NUPDW==1 && wnow.YLOC<0){
				wdeady.sp=12;
				wdeady.g=0;
				wdeady.nowt=-16;
				GAMEN=END;
				wdeady.kaiten=0;
				ketumatu=0;
				wdeady.deadcount=1;}
			else if (wnow.NUPDW==0 && (wnow.YLOC>136)) {
			
				wdeady.sp=-10;
				wdeady.g=1.6;
				wdeady.nowt=128;
				GAMEN=END;
				wdeady.kaiten=0;
				ketumatu=0;
				wdeady.deadcount=1;}
					
				
			
			GrCopyArea(mainmenu_pixmap,keyman_gc,0,0,160,128,allmap_pixmap,0,wnow.MAPSCROLL,0);
			kmbitmap();
			//GrCopyArea(mainmenu_pixmap,keyman_gc,wnow.XLOC,(wnow.YLOC-(wnow.MAPSCROLL % 16)),160,128,shu_pixmap,0,0,0);
			hensu();		
			
			MINIPHOTO(0,0,160,128);
			if (wlastkey.PAU==1){GAMEN=PAUSE;}
			
			wlastkey.AR=0;wlastkey.AL=0;wlastkey.AU=0;wlastkey.AD=0;wlastkey.REE=0;wlastkey.PAU=0;
			break;
		case PAUSE:
			GrCopyArea(dialogall_pixmap,keyman_gc,0,0,96,80,dialog_pixmap,0,0,0);
			GrCopyArea(dialogall_pixmap,keyman_gc,3,24+(dialogkey*24),13,16,yomipict_pixmap,115,48,0);
			GrCopyArea(keyman_wid,keyman_gc,32+((screen_info.cols-160)/2),24+((screen_info.rows-128)/2),96,80,dialogall_pixmap,0,0,0);
			
			break;
		case END:
				if (ketumatu==0){
					wdeady.sp=wdeady.sp+wdeady.g;
					wdeady.nowt=wdeady.nowt+wdeady.sp;
					//sprintf(hensuu,"%d",wnow.MAPSCROLL+(wdeady.deadcount*wnow.NUPDW));
					
					if (wnow.MAPSCROLL+(wdeady.deadcount*wnow.NUPDW)>0 && wnow.MAPSCROLL+(wdeady.deadcount*wnow.NUPDW)<TATEHABA*16){
						GrCopyArea(mainmenu_pixmap,keyman_gc,0,0,160,128,allmap_pixmap,0,wnow.MAPSCROLL+(wdeady.deadcount*wnow.NUPDW),0);
					}
					
					GrCopyArea(shu_pixmap,keyman_gc,0,0,16,16,yomipict_pixmap,wdeady.kaiten*16,16,0);
					GrCopyArea(mainmenu_pixmap,keyman_gc,wnow.XLOC,wdeady.nowt,160,128,shu_pixmap,0,0,0);
					hensu();
					
					MINIPHOTO(0,0,160,128);
					if (wdeady.kaiten<7){wdeady.kaiten++;}else{wdeady.kaiten=0;}
					if (training==0){
						if (wdeady.deadcount>31){GAMEN=MENU;
					
						}   
					}
					else if (training==1){
						if (wdeady.deadcount>15){opencard();GAMEN=INGAME;
						}
						
					}
					wdeady.deadcount++;
				}
				else if (ketumatu==1){
					if (training==0){
					GAMEN=MENU;
					}
					if (training==1){
						if (tranum>=MAXTRA){
							GAMEN=MENU;
						}
						else{
							startgame();
							GAMEN=INGAME;
						}
					
					}
				}
			break;
		case NODATA:
			GrSetGCForeground(keyman_gc, WHITE);
			GrFillRect(keyman_wid,keyman_gc,0,0,160,128);
			
			GrSetGCForeground(keyman_gc, GRAY);
			GrLine(keyman_wid,keyman_gc,80,20,34,100);
			GrLine(keyman_wid,keyman_gc,80,20,126,100);
			GrLine(keyman_wid,keyman_gc,34,100,126,100);
			GrEllipse(keyman_wid,keyman_gc,80,55,5,20);
			GrEllipse(keyman_wid,keyman_gc,80,85,5,5);
			
			GrSetGCForeground(keyman_gc, BLACK);
			GrText(keyman_wid,keyman_gc,50,48,"Please Copy",-1,GR_TFASCII|GR_TFTOP);
			GrText(keyman_wid,keyman_gc,30,68,"KMData folder to /etc",-1,GR_TFASCII|GR_TFTOP);
			GrText(keyman_wid,keyman_gc,50,100,"Click to Quit",-1,GR_TFASCII|GR_TFTOP);
			break;
		}
		
			
	break;
	

    case( GR_EVENT_TYPE_KEY_DOWN ):
	
	switch(GAMEN){
		case INGAME:
			if (event->keystroke.ch==wsetkey.KLEFT){wlastkey.AL=1;}else{wlastkey.AL=0;}
			if (event->keystroke.ch==wsetkey.KRIGHT){wlastkey.AR=1;}else{wlastkey.AR=0;}
			if (event->keystroke.ch==wsetkey.KUP){wlastkey.AU=1;}else{wlastkey.AU=0;}
			if (event->keystroke.ch==wsetkey.KDOWN){wlastkey.AD=1;}else{wlastkey.AD=0;}
			if (event->keystroke.ch==wsetkey.KJUMP){wlastkey.REE=1;}else{wlastkey.REE=0;}
			if (event->keystroke.ch==wsetkey.KPAUSE){wlastkey.PAU=1;}else{wlastkey.PAU=0;}
			break;
		case MENU:
			switch( event->keystroke.ch )
			{
	    
			case '\r': /* action */
				switch (wmenukey.BA){
				case 0:if (wmenukey.KEY<2){wmenukey.KEY++;}else{wmenukey.KEY=1;}break;	
				case 1:if (wmenukey.STAGE<MAXSTAGE){wmenukey.STAGE++;}
						else {wmenukey.STAGE=1;}
						break;
				
				case 2: GAMEN=INGAME; 
					training=0;
					startgame();
					break;
				case 3:GAMEN=INGAME;
					tranum=0;
					training=1;
					startgame();
					break;
				case 4: pz_close_window(keyman_wid);
					GrDestroyTimer(keyman_timer);
					GrUnmapWindow(keyman_wid);
					GrDestroyWindow(keyman_wid);
					GrFreeImage(kmimage_id);
					GrDestroyGC(keyman_gc);
					ret = 1;
					break;
				}
			break;
			case 'r': /* CCW spin */
			if (wmenukey.BA<4){ipod_beep();wmenukey.BA++;}		
			break;

			case 'l': /* CW spin */
			if (wmenukey.BA>0){ipod_beep();wmenukey.BA--;}
			break;
			
			case 'm': /* menu */
					pz_close_window(keyman_wid);
					GrDestroyTimer(keyman_timer);
					GrUnmapWindow(keyman_wid);
					GrDestroyWindow(keyman_wid);
					GrFreeImage(kmimage_id);
					GrDestroyGC(keyman_gc);
					ret = 1;		
			break;
			}
			break;
			
					
		case PAUSE:
			if (event->keystroke.ch==wsetkey.KLEFT && dialogkey == 1){ipod_beep();dialogkey=0;}
			if (event->keystroke.ch==wsetkey.KRIGHT && dialogkey == 0){ipod_beep();dialogkey=1;}
			if (event->keystroke.ch==wsetkey.KJUMP && dialogkey == 0){GAMEN=INGAME;}
			else if (event->keystroke.ch==wsetkey.KJUMP && dialogkey == 1){GAMEN=MENU;}
			
			break;
		case END:break;
		case NODATA:
			if (event->keystroke.ch=='\r'){
			GrDestroyTimer(keyman_timer);
			GrUnmapWindow(keyman_wid);
			GrDestroyWindow(keyman_wid);
			GrFreeImage(kmimage_id);
			GrDestroyGC(keyman_gc);
			ret = 1;
			}
			break;
		}
	
	
	
	break;
    }

    return ret;
}
Exemplo n.º 17
0
// Advances the game, draws the frame, then checks to see if the ball hit a chasm wall.
static void advance_and_check()
{
	
	// Increment game
	time_t t1;
	int i;
	int y;
	QUEUENODE *node;
	GR_COLOR gr = GRAY;
	GR_COLOR wh = WHITE;
	
	GrSetGCForeground(tunnel_gc, WHITE);
	GrFillRect(temp_pixmap, tunnel_gc,
			   0, 0, screen_info.cols, (screen_info.rows - (HEADER_TOPLINE + 1)));
	
	(void) time(&t1);
	srandom((long)t1);
	i = random() % 3;
	if (i == 0 && tail->offset > 0)
		cycle_chasm_queue(tail->offset - 1, &head, &middle, &tail);
	else if (i == 1 && tail->offset + chasmWidth < wi.width)
		cycle_chasm_queue(tail->offset + 1, &head, &middle, &tail);
	else
		cycle_chasm_queue(tail->offset, &head, &middle, &tail);
	
	// Draw chasm
	if( screen_info.bpp >= 16 ) {
		gr = GR_RGB( 255, 128, 0 );
		wh = GR_RGB( 128,  50, 0 );
	}

	node = head;
	y = 0;
	while (node != NULL)
	{
		GrSetGCForeground(tunnel_gc, wh);
		GrFillRect(temp_pixmap, tunnel_gc, 0, y, screen_info.cols, 2);

		GrSetGCForeground(tunnel_gc, WHITE);
		GrFillRect(temp_pixmap, tunnel_gc, 
				node->offset, y, chasmWidth, 2);

		GrSetGCForeground(tunnel_gc, BLACK);
		GrFillRect(temp_pixmap, tunnel_gc, 
				node->offset-5, y, 5, 2);
		GrFillRect(temp_pixmap, tunnel_gc,
				node->offset + chasmWidth, y,
				5, 2);

		GrSetGCForeground(tunnel_gc, gr);
		GrFillRect(temp_pixmap, tunnel_gc, 
				node->offset-8, y, 3, 2);
		GrFillRect(temp_pixmap, tunnel_gc,
				node->offset + chasmWidth+5, y,
				3, 2);

		node = node->next;
		y+=2;
	}
	
	// Draw ball
    GrSetGCForeground(tunnel_gc, BLACK);
	GrFillEllipse(temp_pixmap ,tunnel_gc, ball.x, wi.height / 2, ball.radius, ball.radius);
	
	// Map window 
	GrCopyArea(tunnel_wid, tunnel_gc, 0, 0,
			   screen_info.cols, (screen_info.rows - (HEADER_TOPLINE + 1)),
			   temp_pixmap, 0, 0, MWROP_SRCCOPY);
	
	// Check for collisions. Stop game if one is found.
	if (middle->offset >= ball.x - ball.radius || middle->offset + chasmWidth < ball.x + ball.radius)
	{
		running = 0;
		GrDestroyTimer( timer_id );
		running = 1;
		draw_result();
	}
	
	// increment score
	score++;
}
Exemplo n.º 18
0
static int ipobble_handle_event(GR_EVENT *event)
{
	int ret = 0;
	static int paused = 0;
	
	if(game_status) {
		switch(event->type) {
		case ( GR_EVENT_TYPE_TIMER ):
			if (!paused)
				ipobble_Game_Loop();
			break;
		/* if in game there is 1 status: waiting for direction */
		case( GR_EVENT_TYPE_KEY_DOWN ):
			switch(event->keystroke.ch) {
			case '\r': /* push button : do fire! */
				if(ball_firing)
					break;
				do_fire();
				ret |= KEY_CLICK;
				break;

			case 'l':
				GrSetGCForeground(ipobble_gc, WHITE);
				me_draw(current_angle);
				draw_podzilla(podzilla_bmp_var);
				if(accel_status>0)
					accel_status++;
				else
					accel_status=1;
				current_angle = (current_angle >= 80) ? 80 :
					current_angle + delta_angle *
					(accel_status / 5 + 1);
				GrSetGCForeground(ipobble_gc, BLACK);
				podzilla_bmp_var = !podzilla_bmp_var;
				draw_podzilla(podzilla_bmp_var);
				me_draw(current_angle);
				ret |= KEY_CLICK;
				break;

			case 'r':
				GrSetGCForeground(ipobble_gc, WHITE);
				me_draw(current_angle);
				draw_podzilla(podzilla_bmp_var);
				if (accel_status < 0)
					accel_status--;
				else
					accel_status=-1;
				current_angle = (current_angle <= -80) ? -80 :
					current_angle + delta_angle *
					(accel_status / 5 - 1);
				GrSetGCForeground(ipobble_gc, BLACK);
				podzilla_bmp_var = !podzilla_bmp_var;
				draw_podzilla(podzilla_bmp_var);
				me_draw(current_angle);
				ret |= KEY_CLICK;
				break;	

			case 'm':
				/* if Menu Button then destroy all dynamically
				 * created */
				pz_close_window(ipobble_wid);
				GrDestroyTimer (ipobble_timer_id);
				GrDestroyGC(ipobble_gc);
				break;

			case 'h':
				paused = 1;
				break;
				
			default:
				ret |= KEY_UNUSED;
				break;
				
			}
			
			break;

		case( GR_EVENT_TYPE_KEY_UP ):
			if (event->keystroke.ch == 'h')
				paused = 0;	
			break;

		default:
			ret |= EVENT_UNUSED;
			break;
		}
		return ret;
	} /* if game status play */
	
	/* END OF GAME */
	
	if(onetime == 0){

		GrSetGCForeground(ipobble_gc, BLACK);
		GrText(ipobble_wid, ipobble_gc, screen_info.cols / 2 - 36,
				screen_info.rows / 2 - 24, "GAME OVER", -1,
				GR_TFASCII);
		gameover_waitcounter = 30;
	}
	onetime = 1;
	gameover_waitcounter--;
	switch(event->type) {
	case( GR_EVENT_TYPE_KEY_DOWN ):
		switch(event->keystroke.ch) {
		case '\r': /* push button */
			if(gameover_waitcounter <= 0){
				score = 0;
				GrSetGCForeground(ipobble_gc, WHITE);
				GrFillRect(ipobble_wid, ipobble_gc, 0, 0,
						screen_info.cols,
						screen_info.rows);
				GrSetGCForeground(ipobble_gc, BLACK);
				level = 0;
				score = 0;
				ipobble_create_board(level);
				game_status = GAME_STATUS_PLAY;
				draw_first();
				ret |= KEY_CLICK;
			}
			break;
				
		case 'm':
			/* if Menu Button then destroy all dynamically
			 * created */
			pz_close_window(ipobble_wid);
			GrDestroyTimer(ipobble_timer_id);
			GrDestroyGC(ipobble_gc);
			break;

		default:
			ret |= KEY_UNUSED;
			break;	
		}
		break;
	default:
		ret |= EVENT_UNUSED;
		break;
	}	
	return ret;
}
Exemplo n.º 19
0
static int nxsnake_handle_event(GR_EVENT *event)
{
  switch(event->type)
    {
    case GR_EVENT_TYPE_KEY_DOWN:

      /* Allow m to quit no matter where we are*/
      
      if (event->keystroke.ch == 'm')
	    {
	      //GrClose();
          fin = 1;
          pz_close_window(offscreen);
          pz_close_window(swindow);
          GrDestroyTimer(nxsnake_timer);
	      //exit(0);
	    }
      
      switch(game_state)
	{
	case SNAKE_START:
        if (event->keystroke.ch == 'd') 
            {
			game_state = SNAKE_START;
            draw_string((char *) instructions, 1);
            show_buffer();
            break;
            }
	case SNAKE_INSTRUCTIONS:
	case SNAKE_DONE:
	  
	  switch(event->keystroke.ch)
	    {

	    default:
	      start_game();
	      break;
	    }

	  break;

	case SNAKE_PAUSED:
	  if ((event->keystroke.ch == '\r') ||
          (event->keystroke.ch == 'd'))
	    {
	      draw_score();
	      do_frame(1);
	      game_state = SNAKE_PLAYING;
	    }
	  
	  break;

	case SNAKE_NEXTLEVEL:

	  if (current_level >= LEVELCOUNT)
	    current_level = 0;
	  
	  start_level(current_level);
	  draw_score();
	  do_frame(1);   /* and show the first frame */

	  break;

	case SNAKE_PLAYING:
      if (event->keystroke.ch == 'd') 
            {
			game_state = SNAKE_PAUSED;
            draw_string((char *) instructions, 1);
            show_buffer();
            break;
            }
    
	  if (event->keystroke.ch == '\r')
	    	{
			game_state = SNAKE_PAUSED;
          	draw_string((char *) gamepaused, 2);
	  	  	show_buffer();
	      	break;
	    	}
	  
      if ((event->keystroke.ch == 'w') || (event->keystroke.ch == 'f'))
      		{
      		if (redirect_snake(event->keystroke)) 
	    		do_snake_advance();
        	}
        
      if ((event->keystroke.ch == 'l') || (event->keystroke.ch == 'r'))
      	{
        if(last_keystroke == event->keystroke.ch)
      		{
        	if (count_wheel > 7)
            	{
                if (redirect_snake(event->keystroke)) 
	    			do_snake_advance();
                count_wheel = 0;
                }
        	else
 				count_wheel ++;
        	}
      	else
      		count_wheel = 0;
        }
      
        
	  last_keystroke = event->keystroke.ch;
      
	  break;
	}

      break;

    case GR_EVENT_TYPE_EXPOSURE:
      show_buffer();
      break;
    }
 return(1);
}
Exemplo n.º 20
0
/*
 * Destroy windows and eventclient structures used by client.
 * Called by GsDropClient after a client has exited to clean
 * up resources.
 */
void
GsDestroyClientResources(GR_CLIENT * client)
{
	GR_WINDOW     * wp, *nwp;
	GR_PIXMAP     * pp, *npp;
	GR_GC 	      * gp, *ngp;
	GR_REGION     * rp, *nrp;
	GR_FONT       * fp, *nfp;
	GR_CURSOR     *	cp, *ncp;
	GR_EVENT_CLIENT *ecp, *necp;
	GR_EVENT_CLIENT *pecp = NULL;
	GR_EVENT_LIST	*evp;
	GR_GRABBED_KEY	*kp, *nkp;
#if MW_FEATURE_IMAGES
	GR_IMAGE      * ip, *nip;
#endif
#if MW_FEATURE_TIMERS
	GR_TIMER      * tp, *ntp;
#endif

DPRINTF("Destroy client %d resources\n", client->id);
	/* search window list, destroy windows owned by client*/
	for(wp=listwp; wp; wp=nwp) {
		nwp = wp->next;
		/*
		 * Remove eventclient structures for this client
		 */
		ecp = wp->eventclients;
		while (ecp) {
			necp = ecp->next;
			if (ecp->client == client) {
DPRINTF( "  Destroy window %d eventclient mask %08lx\n", wp->id, ecp->eventmask);
				if (ecp == wp->eventclients)
					wp->eventclients = ecp->next;
				else
					pecp->next = ecp->next;
				free(ecp);
			} else
				pecp = ecp;
			ecp = necp;
		}
		if (wp->owner == client) {
DPRINTF("  Destroy window %d\n", wp->id);
			GrDestroyWindow(wp->id);
		}
	}

	/* search pixmap list, destroy pixmaps owned by client*/
	for(pp=listpp; pp; pp=npp) {
		npp = pp->next;
		if (pp->owner == client) {
DPRINTF("  Destroy pixmap %d\n", pp->id);
			GrDestroyWindow(pp->id);
		}
	}

	/* free gc's owned by client*/
	for(gp=listgcp; gp; gp=ngp) {
		ngp = gp->next;
		if (gp->owner == client) {
DPRINTF("  Destroy gc %d\n", gp->id);
			GrDestroyGC(gp->id);
		}
	}

	/* free fonts owned by client*/
	for(fp=listfontp; fp; fp=nfp) {
		nfp = fp->next;
		if (fp->owner == client) {
DPRINTF("  Destroy font %d\n", fp->id);
			GrDestroyFont(fp->id);
		}
	}

	/* free regions owned by client*/
	for(rp=listregionp; rp; rp=nrp) {
		nrp = rp->next;
		if (rp->owner == client) {
DPRINTF("  Destroy region %d\n", rp->id);
			GrDestroyRegion(rp->id);
		}
	}

#if MW_FEATURE_IMAGES
	/* free images owned by client*/
	for(ip=listimagep; ip; ip=nip) {
		nip = ip->next;
		if (ip->owner == client) {
DPRINTF("  Destroy image %d\n", ip->id);
			GrFreeImage(ip->id);
		}
	}
#endif

#if MW_FEATURE_TIMERS
	/* free timers owned by client*/
	for(tp=list_timer; tp; tp=ntp) {
		ntp = tp->next;
		if (tp->owner == client) {
DPRINTF("  Destroy timer %d\n", tp->id);
			GrDestroyTimer(tp->id);
		}
	}
#endif

	/* free cursors owned by client*/
	for(cp=listcursorp; cp; cp=ncp) {
		ncp = cp->next;
		if (cp->owner == client) {
DPRINTF("  Destroy cursor %d\n", cp->id);
			GrDestroyCursor(cp->id);
		}
	}

	/* Free key grabs associated with client*/
	for (kp=list_grabbed_keys; kp; kp = nkp) {
		nkp = kp->next;
		if (kp->owner == curclient) {
DPRINTF("  Destroy grabkey %d,%d\n", kp->wid, kp->key);
			GrUngrabKey(kp->wid, kp->key);
		}
	}

	/* Free events associated with client*/
	evp = client->eventhead;
	while (evp) {
DPRINTF("  Destroy event %d\n", evp->event.type);
		client->eventhead = evp->next;
		evp->next = eventfree;
		eventfree = evp;
		evp = client->eventhead;
	}
}
Exemplo n.º 21
0
static int invaders_handle_event(GR_EVENT *event)
{
	int ret = 0;
	static int paused;
	if(game_status) {
		switch(event->type) {
		case ( GR_EVENT_TYPE_TIMER ):
			if (!paused)
				invaders_Game_Loop();
			break;
		case( GR_EVENT_TYPE_KEY_DOWN ):
			switch(event->keystroke.ch) {
			case '\r': /* push button */
				if(me_firing < ME_MAX_FIRES) {
					me_firing++;
					myfire[me_firing - 1].posx = me_posx;
					myfire[me_firing - 1].posy = me_posy -4;
					myfire[me_firing - 1].dir = -2;
				}
				ret |= KEY_CLICK;
				break;

			case 'l':
				GrSetGCForeground(invaders_gc, GR_RGB(255,255,255));
				me_draw();
				GrSetGCForeground(invaders_gc, GR_RGB(0,0,0));

				if(me_still == 'l'){
					me_accel_counter++;
					me_accel = (me_accel_counter < 20) ?
						me_accel_counter / 5 : me_accel;
				} else {
					me_still = 'l';
					me_accel_counter = 0;
					me_accel = 2;
				}
				me_posx = (me_posx <= me_left) ? me_left :
					(me_posx - me_accel);
				me_draw();
				ret |= KEY_CLICK;
				break;
			case 'r':
				GrSetGCForeground(invaders_gc, GR_RGB(255,255,255));
				me_draw();
				GrSetGCForeground(invaders_gc, GR_RGB(0,0,0));

				if(me_still == 'r'){
					me_accel_counter++;
					me_accel = (me_accel_counter < 20) ?
						me_accel_counter / 5 : me_accel;
				} else {
					me_still = 'r';
					me_accel_counter = 0;
					me_accel = 2;
				}
				me_posx = (me_posx >= me_right) ? me_right :
					me_posx + me_accel;
				me_draw();
				ret |= KEY_CLICK;
				break;	
			case 'm':
				/* if Menu Button destroy all dynamically
				 * created */
				pz_close_window(invaders_wid);
				GrDestroyWindow(invaders_score_pix);
				GrDestroyTimer (invaders_timer_id);
				GrDestroyGC(invaders_gc);
				break;
			case 'h':
				paused = 1;
				break;
			default:
				me_still = 0; /* for what key? */
				ret |= KEY_UNUSED; /* right? */
				break;
			}
			break;
		case( GR_EVENT_TYPE_KEY_UP ):
			switch(event->keystroke.ch) {
			case 'h': /* push button */
				paused = 0;
				break;
			default:
				ret |= KEY_UNUSED;
			}
			break;
		default:
			ret |= KEY_UNUSED;
		}
		return ret;
	}/* if game status play */
	
	/* END OF GAME */
	if(onetime == 0){
		char game_over[] = "GAME OVER";
		int x = screen_info.cols / 2;
		int y = ((screen_info.rows - 21) / 4) * 3;
		int xp = x - (vector_string_pixel_width(game_over, 1, 2) / 2);
		int yp = y - 8;
		GrSetGCForeground(invaders_gc, GR_RGB(255,255,255));
		GrFillRect(invaders_wid, invaders_gc, xp - 2, yp - 2,
				(x - xp + 2) * 2, (y - yp + 2) * 2);
		GrSetGCForeground(invaders_gc, GR_RGB(0,0,0));
		vector_render_string(invaders_wid, invaders_gc,
				game_over, 1, 2,
				xp, yp);
		gameover_waitcounter = 30;
	}
	onetime = 1;
	gameover_waitcounter--;
	switch(event->type) {
	case( GR_EVENT_TYPE_KEY_DOWN ):
		switch(event->keystroke.ch) {
		case '\r': /* push button */
			if(gameover_waitcounter <= 0) {
				score = 0;
				GrSetGCForeground(invaders_gc, GR_RGB(255,255,255));
				GrFillRect(invaders_wid,invaders_gc,
					0, 0, screen_info.cols,
					screen_info.rows);
				GrSetGCForeground(invaders_gc, GR_RGB(0,0,0));
				level = 0;
				score = 0;
				invaders_create_board(level);
				game_status=GAME_STATUS_PLAY;
				draw_first();
			}
			ret |= KEY_CLICK;
			break;
				
		case 'm':
			/* if Menu Button then destroy all
			 * dynamically created */
			pz_close_window(invaders_wid);
			GrDestroyWindow(invaders_score_pix);
			GrDestroyTimer(invaders_timer_id);
			GrDestroyGC(invaders_gc);
			break;
		default:
			ret |= KEY_UNUSED;
			break;	
		}
		break;
	default:
		ret |= EVENT_UNUSED;
		break;
	}
	return ret;
}