예제 #1
0
void Sound_initTracks(void) {
  const char *music_path;
  List *soundList;
  List *p;
  int i;

  music_path = getDirectory( PATH_MUSIC );
	soundList = readDirectoryContents(music_path, NULL);
  if(soundList->next == NULL) {
    fprintf(stderr, "[sound] no music files found...exiting\n");
    exit(1); // FIXME: handle missing songs somewhere else
  }
  
  //soundList->data="revenge_of_cats.it";
  
  i = 1;
  for(p = soundList; p->next != NULL; p = p->next) {
    
    // bugfix: filter track list to readable files (and without directories)
    char *path = getPossiblePath( PATH_MUSIC, (char*)p->data );
  	if( path != NULL && fileExists( path ) ) {
    	scripting_RunFormat("tracks[%d] = \"%s\"", i, (char*) p->data);
        i++;
    	free( path );
    }
  }
  scripting_Run("setupSoundTrack()");
}
예제 #2
0
void Sound_initTracks(void) {
  const char *music_path;
  nebu_List *soundList;
  nebu_List *p;
  int i;

  music_path = getDirectory( PATH_MUSIC );
	soundList = readDirectoryContents(music_path, NULL);
  if(soundList->next == NULL) {
    fprintf(stderr, "[sound] no music files found...exiting\n");
    nebu_assert(0); exit(1); // TODO: handle missing songs somewhere else
  }
    
  i = 1;
  for(p = soundList; p->next != NULL; p = p->next) {
    
    // bugfix: filter track list to readable files (and without directories)
    char *path = getPossiblePath( PATH_MUSIC, (char*)p->data );
  	if( path != NULL && nebu_FS_Test( path ) ) {
    	scripting_RunFormat("tracks[%d] = \"%s\"", i, (char*) p->data);
        i++;
    	free( path );
		
    }
	free(p->data);
  }
  nebu_List_Free(soundList);
  scripting_Run("setupSoundTrack()");
}
예제 #3
0
void keyboardConfigure(int state, int key, int x, int y) {
	if(state == SYSTEM_KEYSTATE_DOWN) {
		scripting_RunFormat("settings.keys[ configure_player ][ configure_event ]"
												"= %d", key);
		SystemExitLoop(RETURN_PROMPT_ESCAPE);
	}
}
예제 #4
0
void saveSettings(void) {
	char *script;
	script = getPath(PATH_SCRIPTS, "save.lua");
	scripting_RunFile(script);
	free(script);

#ifdef WIN32
	scripting_Run("file = io.open(\"gltron.ini\", \"w\")");
	scripting_Run("io.output(file)");
#else
	{
		char *path = getPossiblePath(PATH_PREFERENCES, RC_NAME);
		if(path == NULL)
			return;
		scripting_RunFormat("file = io.open(\"%s\", \"w\")", path);
		scripting_Run("io.output(file)");
		free(path);
	}
#endif

	scripting_Run("save()");
	scripting_Run("io.write \"save_completed = 1\\n\"");
	scripting_Run("io.output(io.stdout)"); // select stdout again
}
예제 #5
0
void drawMenu(Visual *d) {
  /* draw Menu pCurrent */

  int i;
  int x, y, size, lineheight;
  int hsize, vsize;
  int max_label = 0;
  int max_data = 0;
  int nEntries;
  char pMenuName[200];
  int iActiveItem;

  rasonly(d);

#define MENU_TEXT_START_X 0.08
#define MENU_TEXT_START_Y 0.40

#define MENU_WIDTH 0.80
#define MENU_HEIGHT 0.40

#define MENU_TEXT_LINEHEIGHT 1.5

  x = (int) (d->vp_w * MENU_TEXT_START_X);
  y = (int) (d->vp_h * MENU_TEXT_START_Y);

  /* obtain menu name */
  scripting_Run("return Menu.current");
  scripting_CopyStringResult(pMenuName, 200);
  /* obtain some information about the active menu */
  scripting_RunFormat("return table.getn( Menu.%s.items )", pMenuName);
  scripting_GetIntegerResult(&nEntries);

  /* new stuff: calculate menu dimensions */
  for(i = 0; i < nEntries; i++) {
    int len_label = 0;
    int len_data = 0;

    scripting_RunFormat("return string.len( Menu[Menu.%s.items[%d]].caption )", 
			pMenuName, i + 1);
    scripting_GetIntegerResult(&len_label);
    len_label += 2; /* add ': ' */
    scripting_RunFormat("return GetMenuValueWidth( Menu.%s.items[%d] )",
			pMenuName, i + 1);
    scripting_GetIntegerResult(&len_data);

    if(len_label > max_label) max_label = len_label;
    if(len_data > max_data) max_data = len_data;
  }

  /* adjust size so menu fits into MENU_WIDTH/HEIGHT */

  hsize = (int) ((float)d->vp_w * MENU_WIDTH / (float) (max_label + max_data));
  vsize = (int) ((float)d->vp_h * MENU_HEIGHT / 
		 ( (float)nEntries * MENU_TEXT_LINEHEIGHT));

  size = (hsize < vsize) ? hsize : vsize;

  lineheight = (int)( (float) size * MENU_TEXT_LINEHEIGHT);  

  /* printf("%d %d %d %d %d\n", x, y, size, maxw, pCurrent->nEntries); */
  /* draw the entries */

  scripting_Run("return Menu.active");
  scripting_GetIntegerResult(&iActiveItem);

  glEnable(GL_BLEND);
  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  for(i = 0; i < nEntries; i++) {
    if(i == iActiveItem - 1) {
      float color[4];
      float active1[4];
      float active2[4];
      int j;
      float t;
      int time = nebu_Time_GetElapsed() & 4095; 
      t = sinf( time * PI / 2048.0 ) / 2.0f + 0.5f;

			scripting_GetGlobal("menu_item_active1", NULL);
      scripting_GetFloatArrayResult(active1, 4);
			scripting_GetGlobal("menu_item_active2", NULL);
      scripting_GetFloatArrayResult(active2, 4);

      for(j = 0; j < 4; j++) {
	color[j] = t * active1[j] + (1 - t) * active2[j];
      }
      glColor4fv(color);
      /* fprintf(stderr, "%.2f: %.2f %.2f %.2f\n", 
	 t, color[0], color[1], color[2]); */
    } else {
      float color[4];
			scripting_GetGlobal("menu_item", NULL);
      scripting_GetFloatArrayResult(color, 4);
      glColor4fv(color);
    }

      {
	char line_label[100];
	char line_data[100];
	scripting_RunFormat("return "			    
			    "GetMenuValueString( Menu.%s.items[%d] )",
			    pMenuName, i + 1);
	scripting_CopyStringResult(line_data, sizeof(line_data));

	if(line_data[0] != 0)
	  scripting_RunFormat("return "
			      "Menu[Menu.%s.items[%d]].caption .. ': '",
			      pMenuName, i + 1);
	else
	  scripting_RunFormat("return "
			      "Menu[Menu.%s.items[%d]].caption",
			      pMenuName, i + 1);

	scripting_CopyStringResult(line_label, sizeof(line_label));

	drawText(guiFtx, (float)x, (float)y, (float)size, line_label);
	drawText(guiFtx, (float)x + max_label * size, (float)y, (float)size, line_data);
      }

    /*
    if(i == pCurrent->iHighlight) 
      drawSoftwareHighlight(x, y, size, ((Menu*)*(pCurrent->pEntries + i))->display.szCaption);
    */
    y -= lineheight;
  }
  
  glDisable(GL_BLEND);
}
예제 #6
0
void keyGame(int state, int k, int x, int y)
{
  int i;

	if(state == SYSTEM_KEYSTATE_DOWN) {
		switch (k) {
			/* case 'q': SystemExit(); return; */
		case 27:
			game->pauseflag = PAUSE_GAME_SUSPENDED;
			nebu_System_ExitLoop(RETURN_GAME_ESCAPE);
			return;
		case ' ':
			game->pauseflag = PAUSE_GAME_SUSPENDED;
			nebu_System_ExitLoop(RETURN_GAME_PAUSE);
			return;
		case SYSTEM_KEY_F1: changeDisplay(0); return;
		case SYSTEM_KEY_F2: changeDisplay(1); return;
		case SYSTEM_KEY_F3: changeDisplay(2); return;
		case SYSTEM_KEY_F4: changeDisplay(3); return;

		// somehow, this breaks the 'keys' array, and saving
		// at the end of the game fails
		// case SYSTEM_KEY_F5: saveSettings(); return;

		case SYSTEM_KEY_F10: nextCameraType(); return;
		case SYSTEM_KEY_F11: doBmpScreenShot(gScreen); return;
		case SYSTEM_KEY_F12: doPngScreenShot(gScreen); return;

		case SYSTEM_KEY_F6: console_Seek(-1); return;
		case SYSTEM_KEY_F7: console_Seek(1); return;
    /* toggle lighting
  case SYSTEM_KEY_F6: 
      setSettingi("light_cycles", !game->settings->light_cycles);
      return;
    */
		}
	}
	for( i = 0; i < game->players; i++) {
		if(PLAYER_IS_ACTIVE(&game->player[i]) &&
			 !game->player[i].ai->active) {
			int key;
			if(state == SYSTEM_KEYSTATE_DOWN) { 
				scripting_RunFormat("return settings.keys[%d].left", i + 1);
				scripting_GetIntegerResult( &key );
				if(key == k) {
					createEvent(i, EVENT_TURN_LEFT);
					return;
				}
				scripting_RunFormat("return settings.keys[%d].right", i + 1);
				scripting_GetIntegerResult( &key );
				if(key == k) {
					createEvent(i, EVENT_TURN_RIGHT);
					return;
				}
			}
			// deal with glance keys
			scripting_RunFormat("return settings.keys[%d].glance_left", i + 1);
			scripting_GetIntegerResult( &key );
			if(key == k) {
				if(state == SYSTEM_KEYSTATE_DOWN) {
					// printf("glance left down\n");
					game->player[i].camera->movement[CAM_PHI_OFFSET] = PI / 2.0f;
				}	else {
					// printf("glance left up\n");
					game->player[i].camera->movement[CAM_PHI_OFFSET] = 0;
				}
				return;
			}
			// deal with glance keys
			scripting_RunFormat("return settings.keys[%d].glance_right", i + 1);
			scripting_GetIntegerResult( &key );
			if(key == k) {
				if(state == SYSTEM_KEYSTATE_DOWN) {
					// printf("glance right down\n");
					game->player[i].camera->movement[CAM_PHI_OFFSET] = - PI / 2.0f;
				} else {
					// printf("glance right up\n");
					game->player[i].camera->movement[CAM_PHI_OFFSET] = 0;
				}
				return;
			}
			// boost
			scripting_RunFormat("return settings.keys[%d].boost", i + 1);
			scripting_GetIntegerResult( &key );
			if(key == k) {
				if(state == SYSTEM_KEYSTATE_DOWN) {
					// printf("boost down\n");
					if(game->player[i].data->booster > getSettingf("booster_min"))
						game->player[i].data->boost_enabled = 1;
				} else {
					// printf("boost up\n");
					game->player[i].data->boost_enabled = 0;
				}
				return;
			}
			// wallbuster
			scripting_RunFormat("return settings.keys[%d].bust", i + 1);
			scripting_GetIntegerResult( &key );
			if(key == k) {
				if(state == SYSTEM_KEYSTATE_DOWN) {
					// printf("wall_buster down\n");
					if(game->player[i].data->wall_buster > getSettingf("wall_buster_min"))
						game->player[i].data->wall_buster_enabled = 1;
				} else {
					// printf("wall_buster up\n");
					game->player[i].data->wall_buster_enabled = 0;
				}
				return;
			}
		}
	}
	if(state == SYSTEM_KEYSTATE_DOWN) {
		displayMessage(TO_STDERR, "key '%s' (%d) is not bound", 
									 SystemGetKeyName(k), k);
	}
}