示例#1
0
文件: main.c 项目: luksamuk/opengames
// Funções globais principais
void init()
{
	running = true;
	// O canto superior da tela agora ficará
	// em (0, 0).
	glMatrixMode(GL_PROJECTION);
		glOrtho(0, WIN_WIDTH, WIN_HEIGHT, 0, -1, 1);
	glMatrixMode(GL_MODELVIEW);

	// Defina a cor de tela vazia
	glClearColor(0, 0, 0, 1);

	// Carregue a fase
	loadlevel("leveldef.lvl", &lvl);

	// Carregue o personagem
	loadcharacter("brbr.chr", &chr);
	initcharacter(&chr, &lvl);

	// Caso haja um joystick, carregue-o.
	if(SDL_NumJoysticks() >= 1)
		joystick = SDL_JoystickOpen(0);

	// Inicie os direcionais
	directionals[0] = false;
	directionals[1] = false;
}
示例#2
0
void loadcollectionlevel(int levelnum)
  {
  char loadfilename[32]="co00.lvl";

  loadfilename[2]=48+levelnum/10;
  loadfilename[3]=48+levelnum%10;

  loadlevel(loadfilename);
  }
示例#3
0
文件: custom.c 项目: miquella/gish
void loadlevelmenu(void)
  {
  int count,count2;
  int changeddir;
  int numoffiles;
  int pagenum;

  changeddir=chdir("level");

  listfiles("*.lvl",levellist,0);

  if (changeddir==0)
    chdir("..");

  numoffiles=0;
  while (levellist[numoffiles][0]!=0)
    numoffiles++;

  pagenum=0;

  resetmenuitems();

  joymenunum=1;

  while (!menuitem[0].active && !windowinfo.shutdown)
    {
    glClearColor(0.0f,0.0f,0.0f,0.0f);
    glClear(GL_COLOR_BUFFER_BIT);

    numofmenuitems=0;
    createmenuitem(TXT_BACK,0,0,16,1.0f,1.0f,1.0f,1.0f);
    setmenuitem(MO_HOTKEY,SCAN_ESC);

    count=0;
    for (count2=0;count2<8;count2++)
    if (pagenum+count<numoffiles)
      {
      createmenuitem(levellist[pagenum+count],64,320+count2*12,12,1.0f,1.0f,1.0f,1.0f);
      count++;
      }
    for (count2=0;count2<8;count2++)
    if (pagenum+count<numoffiles)
      {
      createmenuitem(levellist[pagenum+count],256,320+count2*12,12,1.0f,1.0f,1.0f,1.0f);
      count++;
      }
    for (count2=0;count2<8;count2++)
    if (pagenum+count<numoffiles)
      {
      createmenuitem(levellist[pagenum+count],448,320+count2*12,12,1.0f,1.0f,1.0f,1.0f);
      count++;
      }

    createmenuitem(TXT_PAGE_UP,(304|TEXT_END),416,16,1.0f,1.0f,1.0f,1.0f);
    setmenuitem(MO_HOTKEY,SCAN_PAGEUP);
    setmenuitem(MO_SET,&pagenum,pagenum-24);
    if (pagenum<24)
      setmenuitem(MO_HIGHLIGHT,0);

    createmenuitem(TXT_PAGE_DOWN,320,416,16,1.0f,1.0f,1.0f,1.0f);
    setmenuitem(MO_HOTKEY,SCAN_PAGEDOWN);
    setmenuitem(MO_SET,&pagenum,pagenum+24);
    if (pagenum+24>=numoffiles)
      setmenuitem(MO_HIGHLIGHT,0);

    checksystemmessages();
    checkkeyboard();
    checkmouse();
    checkjoystick();
    checkmenuitems();

    setuptextdisplay();

    glColor4f(1.0f,1.0f,1.0f,1.0f);
    displaybackground(620);

    drawtext(TXT_LOAD_LEVEL,(320|TEXT_CENTER),304,16,1.0f,1.0f,1.0f,1.0f);

    drawmenuitems();

    drawmousecursor(768+font.cursornum,mouse.x,mouse.y,16,1.0f,1.0f,1.0f,1.0f);

    SDL_GL_SwapBuffers();

    for (count=1;count<=24;count++)
    if (pagenum+count-1<numoffiles)
    if (menuitem[count].active)
      {
      game.editing=0;
      game.levelnum=0;
      loadlevel(levellist[pagenum+count-1]);
      gameloop();

      joymenunum=count;
      }
    }

  resetmenuitems();
  }
示例#4
0
int main(int argc, char* argv[])
{
	SetDirectory();

	behaviac::IMemAllocator& allocator = behaviac::GetDefaultMemoryAllocator();
	uint32_t allocatedSize = allocator.GetAllocatedSize();

	MyCommandLine cl(argc, argv);
	cl.PrintHelp();
	cl.ReadOptions();

	g_level = cl.Level();
	if (g_level == -1)
	{
		g_level = cl.SelectLevel();
	}

	behaviac::Workspace::GetInstance()->SetFilePath("../example/spaceship/data/bt/exported");
	behaviac::Workspace::GetInstance()->SetFileFormat(behaviac::Workspace::EFF_xml);
	
	//LogManager::GetInstance()->SetFlush(true);
	behaviac::Agent::Register<framework::WorldState>();

	behaviac::Agent::RegisterInstanceName<framework::WorldState>();
	framework::WorldState* pWorldState = behaviac::Agent::Create<framework::WorldState>();

	pWorldState->SetIdFlag(kIdMask_Wolrd);

	behaviac::Agent::Register<framework::Ship>();
	behaviac::Agent::Register<framework::Projectile>();
	
	behaviac::Workspace::GetInstance()->ExportMetas("../example/spaceship/data/ships.xml");

	if (!cl.IsProfiling())
	{
		behaviac::Agent::SetIdMask(kIdMask_Wolrd | kIdMask_Opponent);
	}

	behaviac::Config::SetLogging(true);

	printf("game starting...\n");

	/* initialize SDL */
	if (SDL_Init(SDL_INIT_EVERYTHING) != 0)
	{
		printf("SDL_Init Failed : %s\n", SDL_GetError());
	}

	/* create window */
	SDL_Window* window = SDL_CreateWindow("Space Ship",
		SDL_WINDOWPOS_UNDEFINED,
		SDL_WINDOWPOS_UNDEFINED,
		kWIDTH,
		kHEIGHT,
		0);

	SDL_Surface* screen = SDL_GetWindowSurface(window);
	SDL_Renderer* sdlrenderer = SDL_CreateRenderer(window, -1, 0);
	SDL_SetRenderDrawColor(sdlrenderer, 0, 0, 0, 255);

	// Initialize SDL_ttf library
	if (TTF_Init() != 0)
	{
		printf("TTF_Init Failed : %s\n", TTF_GetError());
	}

	// Load a font
	TTF_Font* font = TTF_OpenFont("../example/spaceship/Resources/Fonts/arial.ttf", 14);
	if (font == NULL)
	{
		printf("TTF_OpenFont Failed : %s\n", TTF_GetError());
		TTF_Quit();
	}

	framework::ws = behaviac::Agent::GetInstance<framework::WorldState>(0);

	framework::renderer = BEHAVIAC_NEW framework::Renderer();
	framework::renderer->sdlrenderer = sdlrenderer;

	framework::GameLogic* logic = BEHAVIAC_NEW framework::GameLogic();
	framework::gl = logic;

	GFrameHandler frame_handler;
	frame_handler.set_fps_limit(60);

	//background and player
	{
		framework::GameObject* background = BEHAVIAC_NEW framework::GameObject();
		background->usesPhysics = false;
		background->setSprite("Backgrounds/background", true);

		framework::ws->addBackgroundObject(background);

		framework::Ship* player = behaviac::Agent::Create<framework::Ship>();
		player->SetIdFlag(kIdMask_Player);
		player->setSprite("Hulls/Sample Hull");
		player->isPlayer = true;
		player->projectileBrain = &makeBoringBrain;

		framework::ws->insertObject(player, framework::point(100, 300));
		framework::ws->SetPlayer(player);
	}

	framework::ws->time = SDL_GetTicks();
	framework::ws->ResetSyncSignal();

	bool par_a = false;
	int par_b = 0;

	/* message pump */
	while (!g_gameover)
	{
		HandleInput();

		if (cl.IsProfiling())
		{
			behaviac::Profiler::GetInstance()->BeginFrame();
		}

		frame_handler.limit_frame();
		frame_handler.calculate();

		if (g_level != g_level_last)
		{
			g_level_last = g_level;

			loadlevel(g_level);

			char title[_MAX_PATH];
			string_sprintf(title, "%s - press '0-9' to switch levels", gs_levels[g_level].name);
			SDL_SetWindowTitle(window, title);

			par_a = !par_a;
			par_b++;

			if (framework::ws->GetAI())
			{
				framework::ws->GetAI()->SetVariable("par_a", par_a);
				framework::ws->GetAI()->SetVariable("par_b", par_b);
			}
		}

		logic->step();

		// clear the screen
		SDL_RenderClear(sdlrenderer);

		// render all sprites
		framework::renderer->Render();

		// Write text to surface
		if (framework::ws->GetPlayer())
		{
			char playerHP[_MAX_PATH];
			string_sprintf(playerHP, "Player HP : %d", framework::ws->GetPlayer()->getHealth());
			renderText(sdlrenderer, font, playerHP, kWIDTH - 120, kHEIGHT - 60);

			char aiHP[_MAX_PATH];
			if (framework::ws->GetAI())
			{
				string_sprintf(aiHP, "AI HP : %d", framework::ws->GetAI()->getHealth());
			}
			else
			{
				string_sprintf(aiHP, "AI Dead");
			}
			renderText(sdlrenderer, font, aiHP, kWIDTH - 120, kHEIGHT - 40);
		}

		// Refreshing the screen
		SDL_RenderPresent(sdlrenderer);

		if (cl.IsProfiling())
		{
			behaviac::Profiler::GetInstance()->EndFrame();
		}
	}

	/* cleanup SDL */
	//SDL_DestroyRenderer(sdlrenderer);
	//SDL_DestroyWindow(window);
	SDL_Quit();

	behaviac::Agent::UnRegister<framework::Projectile>();
	behaviac::Agent::UnRegister<framework::Ship>();
	behaviac::Agent::UnRegister<framework::WorldState>();
	behaviac::Agent::Destroy(pWorldState);

	behaviac::Agent::UnRegisterInstanceName<framework::WorldState>();


	uint32_t allocatedSize1 = allocator.GetAllocatedSize();
	int32_t allocDiff = allocatedSize1 - allocatedSize;

	if (cl.IsProfiling())
	{
		const behaviac::string profile_data = behaviac::Profiler::GetInstance()->GetData(true, false);
		behaviac::string profile_data_m = "\n";
		profile_data_m += profile_data;
		profile_data_m += "\n";

		//BEHAVIAC_LOGMSG("\n%s\n", profile_data_m.c_str());
		behaviac::ConsoleOut::PrintLines(profile_data_m.c_str());
	}

	return 0;
}
示例#5
0
	void WorldState::SpawnShip(int level)
	{
		loadlevel(level);
	}
示例#6
0
文件: main.c 项目: filur/dracsgh
void _framefn(int frameDelta)
{
	SDL_Rect r;
	SDL_Rect blitrect;
	int x, y, i, j;
	int red, black;
	char buf[32];
	
	if (level == 0)
	{
		loadlevel();
	}
	
	if (activegoats == 0)
	{
		spawngoats();
	}
	
	red = SDL_MapRGB(screen->format, 255, 0, 0);
	black = SDL_MapRGB(screen->format, 44, 33, 44);
	
	// SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0));
	
	r.x = 0;
	r.y = 0;
	r.w = 16;
	r.h = 16;
	
	for (y = 0; y < 30; ++y)
	{
		r.x = 0;
		
		for (x = 0; x < 40; ++x)
		{
			if (level[y][x] == '.')
			{
				// SDL_FillRect(screen, &r, red);
				
				blitrect.x = r.x;
				blitrect.y = r.y;
				blitrect.w = r.w;
				blitrect.h = r.h;
				
				SDL_BlitSurface(gfx_brick, NULL, screen, &blitrect);
			}
			else
			{
				SDL_FillRect(screen, &r, black);
			}
			
			r.x += 16;
		}
		
		r.y += 16;
	}
	
	playerfn(frameDelta);
	
	if (player.shooting)
	{
		for (i = 0; i < 16; ++i)
		{
			if (mygoats[i] == NULL)
			{
				continue;
			}
			
			if (!mygoats[i]->scared && distance(
				player.rect.x + (player.rect.w / 2),
				player.rect.y + (player.rect.h / 2),
				mygoats[i]->rect.x + (mygoats[i]->rect.w / 2),
				mygoats[i]->rect.y + (mygoats[i]->rect.h / 2)) < 50)
			{
				goat_make_scared(mygoats[i]);
			}
		}
	}
	
	for (i = 0; i < 16; ++i)
	{
		if (mygoats[i] == NULL)
		{
			continue;
		}
		
		if (mygoats[i]->scared && mygoats[i]->animtime <= 0 && distance(
			player.rect.x + (player.rect.w / 2),
			player.rect.y + (player.rect.h / 2),
			mygoats[i]->rect.x + (mygoats[i]->rect.w / 2),
			mygoats[i]->rect.y + (mygoats[i]->rect.h / 2)) < 30)
		{
			free(mygoats[i]);
			mygoats[i] = NULL;
			
			--activegoats;
			--numgoats;
			
			sound_synth_play(sfx_clear_goat1);
			sound_synth_play(sfx_clear_goat2);
			
			player.score += nthlevel * player.hearts;
		}
		else if (mygoats[i]->scared && mygoats[i]->animtime < -2000)
		{
			free(mygoats[i]);
			mygoats[i] = NULL;
			
			--activegoats;
			--numgoats;
		}
	}
	
	if (numgoats == 0)
	{
		for (i = 0; i < 4; ++i)
		{
			SDL_Delay(130);
			
			if (i < 3)
			{
				sound_synth_play(sfx_c4);
			}
			else
			{
				sound_synth_play(sfx_f4);
			}
		}
		
		player.hurting = 0;
		
		SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0));
		SDL_UpdateRect(screen, 0, 0, 0, 0);
		SDL_Delay(650);
		
		newlevelpause = 1;
		
		loadlevel();
		
		return;
	}
	
	for (i = 0; i < 16; ++i)
	{ 
		if (mygoats[i] == NULL)
		{
			continue;
		}
		
		goatfn(mygoats[i], frameDelta);
		
		if (mygoats[i]->scared == 1)
		{
			continue;
		}
		
		if (rand() % 100 > 90)
		{
			mygoats[i]->controls.right = 1;
		}
		if (rand() % 100 > 90)
		{
			mygoats[i]->controls.right = 0;
		}
		if (rand() % 100 > 90)
		{
			mygoats[i]->controls.left = 1;
		}
		if (rand() % 100 > 90)
		{
			mygoats[i]->controls.left = 0;
		}
		if (rand() % 100 > 95)
		{
			mygoats[i]->controls.button1 = 1;
		}
		if (rand() % 100 > 50)
		{
			mygoats[i]->controls.button1 = 0;
		}
	}
	
	for (i = 0; i < 16; ++i)
	{ 
		if (myslimes[i] == NULL)
		{
			continue;
		}
		
		if (!player.hurting && distance(
			player.rect.x + (player.rect.w / 2),
			player.rect.y + (player.rect.h / 2),
			myslimes[i]->rect.x + (myslimes[i]->rect.w / 2),
			myslimes[i]->rect.y + (myslimes[i]->rect.h / 2)) < 30)
		{
			sound_synth_play(sfx_hurting);
			player.hurting = 1;
			
			if (player.hearts > 0)
			{
				if (--player.hearts == 0)
				{
					for (j = 0; j < 5; ++j)
					{
						sound_synth_play(sfx_hurting);
						SDL_Delay(120);
					}
					
					SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0));
					
					fontsurf = TTF_RenderText_Blended(font, "Game Over", (SDL_Color){255, 0, 0});
					
					blitrect.x = 270;
					blitrect.y = 200;
					
					SDL_BlitSurface(fontsurf, NULL, screen, &blitrect);
					SDL_FreeSurface(fontsurf);
					
					sprintf(buf, "Score: %d", player.score);
					
					fontsurf = TTF_RenderText_Blended(font, buf, (SDL_Color){255, 255, 255});
					
					blitrect.x = 260;
					blitrect.y = 230;
					
					SDL_BlitSurface(fontsurf, NULL, screen, &blitrect);
					SDL_FreeSurface(fontsurf);
					
					SDL_UpdateRect(screen, 0, 0, 0, 0);
					SDL_Delay(1000);
					
					level = 0;
					player.hearts = 10;
					player.score = 0;
					nthlevel = 0;
					loadlevel();
					newlevelpause = 1;
					return;
				}
			}
		}
	}
	
	for (i = 0; i < 16; ++i)
	{ 
		if (myslimes[i] == NULL)
		{
			continue;
		}
		
		slimefn(myslimes[i], frameDelta);
	}
	
	
	
	blitrect.x = 18;
	blitrect.y = 18;
	
	SDL_BlitSurface(gfx_goat_count, NULL, screen, &blitrect);
	
	blitrect.x = 44;
	sprintf(buf, "%d", numgoats);
	
	fontsurf = TTF_RenderText_Blended(font, buf, (SDL_Color){255, 255, 255});
	SDL_BlitSurface(fontsurf, NULL, screen, &blitrect);
	SDL_FreeSurface(fontsurf);
	
	sprintf(buf, "%d", player.score);
	
	blitrect.x = 18;
	blitrect.y = 32;
	
	fontsurf = TTF_RenderText_Blended(font, buf, (SDL_Color){255, 255, 255});
	SDL_BlitSurface(fontsurf, NULL, screen, &blitrect);
	SDL_FreeSurface(fontsurf);
	
	blitrect.x = 604;
	
	for (i = 0; i < player.hearts; ++i)
	{
		SDL_BlitSurface(gfx_heart, NULL, screen, &blitrect);
		blitrect.x -= 20;
	}
	
	SDL_UpdateRect(screen, 0, 0, 0, 0);
	
	if (newlevelpause)
	{
		newlevelpause = 0;
		
		blitrect.x = 270;
		blitrect.y = 220;
		blitrect.w = 128;
		blitrect.h = 32;
		
		SDL_FillRect(screen, &blitrect, SDL_MapRGB(screen->format, 0, 0, 0));
		
		sprintf(buf, "Level %d", nthlevel);
		
		fontsurf = TTF_RenderText_Blended(font, buf, (SDL_Color){255, 255, 255});
		
		blitrect.x = 280;
		blitrect.y = 230;
		
		SDL_BlitSurface(fontsurf, NULL, screen, &blitrect);
		SDL_FreeSurface(fontsurf);
		SDL_UpdateRect(screen, 0, 0, 0, 0);
		
		SDL_Delay(400);
		sound_synth_play(sfx_c4);
		SDL_Delay(800);
	}
}
示例#7
0
int main( int argc, char* argv[] )
{
  //Initialisieren
    ZWattribute=ZWgetattribute();
    load_options();
    ZWinitparameter();
    ZWattribute->strech=stretched;
    if (fullscreen)
    {
      ZWattribute->width=resolutionx;
      ZWattribute->height=resolutiony;
      ZWattribute->sdlflags|=SDL_FULLSCREEN;
    }
    else
    {
      ZWattribute->width=windowx;
      ZWattribute->height=windowy;
    }
    ZWattribute->quit_function=quit_function;
    ZWattribute->initflags|=SDL_INIT_AUDIO;
		
		load_mapping();
		
    ZWinitsdl();
    
    int audio_rate = 44100;
    Uint16 audio_format = AUDIO_S16SYS; 
    int audio_channels = 2;
    int audio_buffers = 2048;
    if (Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers))
    {
      printf("Unable to open audio!\n");
      exit(1);
   }
    
    if ((ZWattribute->sdlflags & SDL_FULLSCREEN)==0) //SDL_FULLSCREEN nicht mehr gesetzt? AAAAHHHH!
    {
      fullscreen=0;
      windowx=ZWattribute->width;
      windowy=ZWattribute->height;
      resolutionx=ZWattribute->resolution[0].x;
      resolutiony=ZWattribute->resolution[0].y;
    }
    ZWinitopengl();    
    setup_opengl();
    glHint(GL_POLYGON_SMOOTH_HINT,GL_FASTEST);
    init_var();
        
  //Level laden
    if (argc<2)
    {
      printf("Not enough arguments\n");
      printf("testboard file.opxml [player]\n");
      ZWquitfont();
      ZWquitsdl();      
      return 1;
    }
    if (loadlevel(argv[1])==1)
    {
      printf("File %s not found\n",argv[1]);
      ZWquitfont();
      ZWquitsdl();   
      return 1;
    }  
    refreshsetlist();

  //Minispielliste laden
	  load_minigames();
		save_minigames();

  /*//zu Debugzwecken Set 0 bis 60 ausgeben:
  for (int a=0;a<61;a++)
  {
    if (setbynr[a]==NULL)
      printf("Set %i: NULL\n",a);
    else
      printf("Set %i: \"%s\"\n",a,setbynr[a]->type);  
  }*/

  //Debug
    if (argc>3 && argv[3][0]=='c')
      all_are_cpu=1;

  //Spielvorbereitungen
    if (argc>2)
      playernum=atoi(argv[2]);
    playernum=(playernum-1)%8+1;

		
		if (argc>3 && argv[3][1]=='2')
		{
			playernum=((playernum+1)/2)*2;
			if (playernum<4)
			  playernum=4;
			teamsize=2;
		}
		if (argc>3 && argv[3][1]=='3')
		{
			playernum=6;
			teamsize=3;
		}
		if (argc>3 && argv[3][1]=='4')
		{
			playernum=8;
			teamsize=4;
		}		

    pset startset=getsetbyname((char*)"start");
    if (startset==NULL) startset=firstset;
		prepare_game(startset,1);
		
    
  ZWreset_virtuell_joytick();
  //Controller festlegen:
  for (int a=0;a<playernum;a++)
  {
		if (all_are_cpu)
		  maindata.player[a].joystick_nr=-1;
		else		  
		  maindata.player[a].joystick_nr=a%ZWattribute->realjoystickcount;
  }
	calib_all_controllers();
  //Spiel starten
    Mix_FadeInMusic(backgroundmusic, -1,FADE_IN_TIME);
    ZWattribute->newticks=SDL_GetTicks();
    ZWschleifeex((void(*)(void*))draw_main,(int(*)(void*))calc_main_thread,(int(*)(void*))calc_main,
                 (void*)(&maindata),sizeof(tmaindata));    
    Mix_HaltMusic();
  //alles wieder freigeben
    reset_after_game();
    del_objects();
    del_sounds();
    Mix_CloseAudio();
    ZWquitfont();
    ZWquitsdl();
  return 0;
}
示例#8
0
int main (void)
{
// Golobal Integers
    extern int level;
    extern int lifes;
    extern int score;
    extern int health;
// Local Integers
   register int mapxoff, mapyoff;
   extern int oldpy, oldpx;
   extern int facing;
   extern int jump;
   int n, m;
  // DATAFILE *data;
//initilization    
	allegro_init();	
	install_timer();
	install_keyboard();
    set_color_depth(32);
	set_gfx_mode(MODE, WIDTH, HEIGHT, 0, 0);

//load data
data = load_datafile("test.dat");
    temp = (BITMAP *)data[NEWGUY_BMP].dat;
    for (n=0; n<4; n++)
    player_image[n] = grabframe(temp,43,77,0,0,4,n);
    destroy_bitmap(temp);
    temp2 = (BITMAP *)data[BAT1_BMP].dat;
    for (m=0; m<2; m++)
    bat_img[m] = grabframe(temp2,87,72,0,0,2,m);
    destroy_bitmap(temp2);

    test_img = load_bitmap("test.bmp", NULL);
gameover:
Start();
first:
//initilize Player
    player = malloc(sizeof(SPRITE));
    player->x = 80;
    player->y = 200;
    player->curframe=0;
    player->framecount=0;
    player->framedelay=11;
    player->maxframe=3;
    player->width=player_image[0]->w;
    player->height=player_image[0]->h;
//initilize Bat
    bat = malloc(sizeof(SPRITE));
    bat->x = 170;
    bat->y = 100;
    bat->curframe=0;
    bat->framecount=0;
    bat->framedelay=11;
    bat->maxframe=1;
    bat->width=bat_img[0]->w;
    bat->height=bat_img[0]->h;
    bat->dir = 0;
    bat->xspeed = 0;
//ini test
test = malloc(sizeof(SPRITE));
    test->x = 270;
    test->y = 400;
    test->curframe=0;
    test->framecount=0;
    test->framedelay=11;
    test->maxframe=1;
    test->width=bat_img[0]->w;
    test->height=bat_img[0]->h;
    test->dir = 0;
    test->xspeed = 0;

loadlevel();

    //main loop
	while (!key[KEY_ESC])
	{
      oldpy = player->y; 
      oldpx = player->x;

if (player->x > 3000)
        {level = 2;
		goto first;}

if (lifes == 0)
{lifes = 3;
          goto gameover;}

if (health < 1)
{lifes -=1;
  health =100;
  goto first;}

  updateEnemy(150, 300, test);
  updateEnemy(150, 300, bat);       
  enemycoll(player->x, player->y, bat);       
  keyinput();
//collition control
	if (!facing) 
        { 
            if (collided(player->x, player->y + player->height)) 
                player->x = oldpx; 
                if (collidedobj(player->x, player->y + player->height))
                   {ClearCell(player->x, player->y + player->height); 
                   AddScore();}
                      if (collidedkill(player->x+9, player->y + player->height))
                         {health -= 25;}        
        }
		else 
        { 
            if (collided(player->x + player->width, player->y + player->height)) 
                player->x = oldpx; 
                if (collidedobj(player->x + player->width, player->y + player->height))
                   {ClearCell(player->x + player->width, player->y + player->height);
                   AddScore();}
                      if (collidedkill(player->x + player->width-15, player->y + player->height))
                         {health -= 25;}        
        }
		
        //update the map scroll position
		mapxoff = player->x + player->width/2 - WIDTH/2 + 10;
		mapyoff = player->y + player->height/2 - HEIGHT/2 + 10;
        //avoid moving beyond the map edge
		if (mapxoff < 0) mapxoff = 0;
		if (mapxoff > (mapwidth * mapblockwidth - WIDTH))
            mapxoff = mapwidth * mapblockwidth - WIDTH;
		if (mapyoff < 0) 
            mapyoff = 0;
		if (mapyoff > (mapheight * mapblockheight - HEIGHT)) 
            mapyoff = mapheight * mapblockheight - HEIGHT;

        //draw the background tiles
		MapDrawBG(buffer, mapxoff, mapyoff, 0, 0, WIDTH-1, HEIGHT-1);
        //draw foreground tiles
		MapDrawFG(buffer, mapxoff, mapyoff, 0, 0, WIDTH-1, HEIGHT-1, 0);
        //draw the player's sprite
		if (facing) 
            draw_sprite(buffer, player_image[player->curframe], 
                (player->x-mapxoff), (player->y-mapyoff+1));
		else 
            draw_sprite_h_flip(buffer, player_image[player->curframe], 
                (player->x-mapxoff), (player->y-mapyoff));

        //blit the double buffer 
		vsync();
        acquire_screen();
		if (bat->dir == 1)
           draw_sprite(buffer, bat_img[bat->curframe],(bat->x-mapxoff),(bat->y-mapyoff));
        else
           draw_sprite_h_flip(buffer, bat_img[bat->curframe],(bat->x-mapxoff),(bat->y-mapyoff)); 
        
        draw_sprite(buffer, test_img,(test->x-mapxoff),(test->y-mapyoff));
        textprintf(buffer,font,0,0,9999999,"lifes = %d  Score = %d  Health = %d",lifes,score,health);
        blit(buffer, screen, 0, 0, 0, 0, WIDTH-1, HEIGHT-1);
       	release_screen();

	} //End of game loop




    for (n=0; n<4; n++)
        destroy_bitmap(player_image[n]);
    for (m=0; m<2; m++)
        destroy_bitmap(bat_img[m]);

destroy_bitmap(test_img);

    free(player);
	free(bat);
    free(test);
    destroy_bitmap(buffer);
	MapFreeMem ();
	MapFreeMem ();
    unload_datafile(data);
    allegro_exit();
	return 0;
}
示例#9
0
文件: player.c 项目: miquella/gish
void playerstartmenu(void)
  {
  int count,count2,count3;

  if (playernum==-1)
    return;

  resetmenuitems();

  joymenunum=1;

  while (!menuitem[0].active && !windowinfo.shutdown)
    {
    glClearColor(0.0f,0.0f,0.0f,0.0f);
    glClear(GL_COLOR_BUFFER_BIT);

    numofmenuitems=0;
    createmenuitem(TXT_BACK,0,0,16,1.0f,1.0f,1.0f,1.0f);
    setmenuitem(MO_HOTKEY,SCAN_ESC);

    count=352;
    if (player[playernum].levelnum>0)
      {
      createmenuitem(TXT_CONTINUE,48,count,16,1.0f,1.0f,1.0f,1.0f);
      setmenuitem(MO_HOTKEY,SCAN_C);
      count+=16;
      createmenuitem(TXT_COLLECTION_GAME,48,count,16,1.0f,1.0f,1.0f,1.0f);
      setmenuitem(MO_HOTKEY,SCAN_O);
      count+=16;
      createmenuitem(TXT_NEW_GAME,48,count,16,1.0f,1.0f,1.0f,1.0f);
      setmenuitem(MO_HOTKEY,SCAN_N);
      count+=16;
      createmenuitem(TXT_PRACTICE,48,count,16,1.0f,1.0f,1.0f,1.0f);
      setmenuitem(MO_HOTKEY,SCAN_P);
      count+=16;
      createmenuitem(TXT_REPLAY,48,count,16,1.0f,1.0f,1.0f,1.0f);
      setmenuitem(MO_HOTKEY,SCAN_R);
      count+=16;
#ifndef DEMO
      /*
      if (player[playernum].unlock[0])
        {
        createmenuitem(TXT_SINGLE_LEVEL,48,count,16,1.0f,1.0f,1.0f,1.0f);
        setmenuitem(MO_HOTKEY,SCAN_S);
        count+=16;
        }
      else
      */
        createmenuitemempty();
#endif
#ifndef DEMO
      createmenuitem(TXT_CUSTOM_LEVELS,48,count,16,1.0f,1.0f,1.0f,1.0f);
      setmenuitem(MO_HOTKEY,SCAN_U);
      count+=16;
#endif
      }
    else
      {
      createmenuitem(TXT_NEW_GAME,48,count,16,1.0f,1.0f,1.0f,1.0f);
      setmenuitem(MO_HOTKEY,SCAN_N);
      count+=16;
      createmenuitem(TXT_COLLECTION_GAME,48,count,16,1.0f,1.0f,1.0f,1.0f);
      setmenuitem(MO_HOTKEY,SCAN_O);
      count+=16;
      createmenuitemempty();
      createmenuitem(TXT_PRACTICE,48,count,16,1.0f,1.0f,1.0f,1.0f);
      setmenuitem(MO_HOTKEY,SCAN_P);
      count+=16;
      createmenuitem(TXT_REPLAY,48,count,16,1.0f,1.0f,1.0f,1.0f);
      setmenuitem(MO_HOTKEY,SCAN_R);
      count+=16;
      /*
      if (player[playernum].unlock[0])
        {
        createmenuitem(TXT_SINGLE_LEVEL,48,count,16,1.0f,1.0f,1.0f,1.0f);
        setmenuitem(MO_HOTKEY,SCAN_S);
        count+=16;
        }
      else
      */
        createmenuitemempty();
#ifndef DEMO
      createmenuitem(TXT_CUSTOM_LEVELS,48,count,16,1.0f,1.0f,1.0f,1.0f);
      setmenuitem(MO_HOTKEY,SCAN_U);
      count+=16;
#endif
      }

    checksystemmessages();
    checkkeyboard();
    checkmouse();
    checkjoystick();
    checkmenuitems();

    updateogg();
    checkmusic();
    game.songnum=8;
    soundsimulation(view.position,view.orientation);

    setuptextdisplay();

    glColor4f(1.0f,1.0f,1.0f,1.0f);
    displaybackground(620);

    count2=(player[playernum].levelnum-1)/7+1;
    count3=(player[playernum].levelnum-1)%7+1;
    if (count3==0)
      count3=1;

    if (!player[playernum].gamepassed)
      {
      drawtext(player[playernum].name,(320|TEXT_CENTER),304,16,1.0f,1.0f,1.0f,1.0f);
      if (player[playernum].levelnum>0)
        {
        drawtext(TXT_PLAYER_INFO,(320|TEXT_CENTER),320,12,1.0f,1.0f,1.0f,1.0f,count2,count3,player[playernum].numoflives,player[playernum].totalscore,player[playernum].highscore);
        if (player[playernum].difficulty==0)
          drawtext(TXT_EASY,(320|TEXT_CENTER),332,12,1.0f,1.0f,1.0f,1.0f);
        if (player[playernum].difficulty==1)
          drawtext(TXT_NORMAL,(320|TEXT_CENTER),332,12,1.0f,1.0f,1.0f,1.0f);
        if (player[playernum].difficulty==2)
          drawtext(TXT_HARD,(320|TEXT_CENTER),332,12,1.0f,1.0f,1.0f,1.0f);
        if (player[playernum].difficulty==3)
          drawtext(TXT_LUDICROUS,(320|TEXT_CENTER),332,12,1.0f,1.0f,1.0f,1.0f);
        if (player[playernum].difficulty==4)
          drawtext(TXT_MINI_GISH,(320|TEXT_CENTER),332,12,1.0f,1.0f,1.0f,1.0f);
        }
      }
    else
      {
      drawtext(player[playernum].name,(320|TEXT_CENTER),304,16,1.0f,1.0f,0.0f,1.0f);
      if (player[playernum].levelnum>0)
        {
        drawtext(TXT_PLAYER_INFO,(320|TEXT_CENTER),320,12,1.0f,1.0f,0.0f,1.0f,count2,count3,player[playernum].numoflives,player[playernum].totalscore,player[playernum].highscore);
        if (player[playernum].difficulty==0)
          drawtext(TXT_EASY,(320|TEXT_CENTER),332,12,1.0f,1.0f,0.0f,1.0f);
        if (player[playernum].difficulty==1)
          drawtext(TXT_NORMAL,(320|TEXT_CENTER),332,12,1.0f,1.0f,0.0f,1.0f);
        if (player[playernum].difficulty==2)
          drawtext(TXT_HARD,(320|TEXT_CENTER),332,12,1.0f,1.0f,0.0f,1.0f);
        if (player[playernum].difficulty==3)
          drawtext(TXT_LUDICROUS,(320|TEXT_CENTER),332,12,1.0f,1.0f,0.0f,1.0f);
        if (player[playernum].difficulty==4)
          drawtext(TXT_MINI_GISH,(320|TEXT_CENTER),332,12,1.0f,1.0f,0.0f,1.0f);
        }
      }
    drawmenuitems();

    drawmousecursor(768+font.cursornum,mouse.x,mouse.y,16,1.0f,1.0f,1.0f,1.0f);

    SDL_GL_SwapBuffers();

    if (menuitem[1].active)
      {
      if (player[playernum].levelnum>0)
        {
        game.levelnum=player[playernum].levelnum;
        game.totalscore=player[playernum].totalscore;
        game.difficulty=player[playernum].difficulty;
        game.numoflives=player[playernum].numoflives;
        }
      else
        {
        playerdifficultymenu();
        if (game.difficulty==-1)
          {
          game.difficulty=0;
          goto newgamebypass;
          }

        player[playernum].difficulty=game.difficulty;

        game.levelnum=1;
        game.totalscore=0;
        game.numoflives=5;
        if (player[playernum].difficulty==3)
          {
          game.numoflives=0;
          game.turbomode=1;
          }

        storyscreen();
        }

      game.songnum=-1;
      checkmusic();

      pregamemenu();

      player[playernum].levelnum=game.levelnum;
      player[playernum].totalscore=game.totalscore;
      player[playernum].numoflives=game.numoflives;
      if (player[playernum].highscore<player[playernum].totalscore)
        player[playernum].highscore=player[playernum].totalscore;

#ifdef DEMO
      if (player[playernum].levelnum==6)
        {
        player[playernum].levelnum=0;
        player[playernum].totalscore=0;
        player[playernum].numoflives=5;
        player[playernum].gamepassed=1;
        }
#endif
      if (player[playernum].levelnum==35)
        {
        if (player[playernum].difficulty==1 || player[playernum].difficulty==2)
          player[playernum].unlock[0]=1;
        if (player[playernum].difficulty==2)
          player[playernum].unlock[1]=1;
        if (player[playernum].difficulty==3)
          player[playernum].unlock[2]=1;
        if (player[playernum].difficulty==4)
          player[playernum].unlock[3]=1;
        player[playernum].levelnum=0;
        player[playernum].totalscore=0;
        player[playernum].numoflives=5;
        player[playernum].gamepassed=1;
        }

      //game.difficulty=0;

      //menuitem[0].active=1;

      newgamebypass:;
      }
    if (menuitem[2].active)
      {
      collectionmenu();

      //menuitem[0].active=1;
      }
    if (menuitem[3].active)
      {
      playerdifficultymenu();
      if (game.difficulty==-1)
        {
        game.difficulty=0;
        goto newgamebypass2;
        }

      player[playernum].difficulty=game.difficulty;

      game.levelnum=1;
      game.totalscore=0;
      game.numoflives=5;
      if (player[playernum].difficulty==3)
        {
        game.numoflives=0;
        game.turbomode=1;
        }

      storyscreen();

      game.songnum=-1;
      checkmusic();

      pregamemenu();

      player[playernum].levelnum=game.levelnum;
      player[playernum].totalscore=game.totalscore;
      player[playernum].numoflives=game.numoflives;
      if (player[playernum].highscore<player[playernum].totalscore)
        player[playernum].highscore=player[playernum].totalscore;

#ifdef DEMO
      if (player[playernum].levelnum==6)
        {
        player[playernum].levelnum=0;
        player[playernum].totalscore=0;
        player[playernum].numoflives=5;
        player[playernum].gamepassed=1;
        }
#endif
      if (player[playernum].levelnum==35)
        {
        if (player[playernum].difficulty==1 || player[playernum].difficulty==2)
          player[playernum].unlock[0]=1;
        if (player[playernum].difficulty==2)
          player[playernum].unlock[1]=1;
        if (player[playernum].difficulty==3)
          player[playernum].unlock[2]=1;
        if (player[playernum].difficulty==4)
          player[playernum].unlock[3]=1;
        player[playernum].levelnum=0;
        player[playernum].totalscore=0;
        player[playernum].numoflives=5;
        player[playernum].gamepassed=1;
        }

      //game.difficulty=0;

      //menuitem[0].active=1;

      newgamebypass2:;
      }
    if (menuitem[4].active)
      {
      game.songnum=-1;
      checkmusic();

      game.editing=0;
      game.levelnum=0;
      loadlevel("playroom.lvl");
      gameloop();
      }
    if (menuitem[5].active)
      {
      game.songnum=-1;
      checkmusic();

      replaymenu();
      }
    if (menuitem[6].active)
      {
      singlelevelmenu();
      }
    if (menuitem[7].active)
      {
      custommenu();
      }
    }

  resetmenuitems();
  }
示例#10
0
文件: vsmode.c 项目: miquella/gish
void versusmodemenu(int versusnum)
  {
  int count;
  int unlocked;
  char filename[32];

  unlocked=0;
  for (count=0;count<6;count++)
  if (player[count].unlock[1])
    unlocked=1;

  resetmenuitems();

  joymenunum=1;

  while (!menuitem[0].active && !windowinfo.shutdown)
    {
    glClearColor(0.0f,0.0f,0.0f,0.0f);
    glClear(GL_COLOR_BUFFER_BIT);

    numofmenuitems=0;
    createmenuitem(TXT_EXIT,0,0,16,1.0f,1.0f,1.0f,1.0f);
    setmenuitem(MO_HOTKEY,SCAN_ESC);

    count=250;
    createmenuitem(TXT_LEVEL" 1",(320|TEXT_CENTER),count,20,1.0f,1.0f,1.0f,1.0f);
    setmenuitem(MO_HOTKEY,SCAN_1);
    count+=20;
    createmenuitem(TXT_LEVEL" 2",(320|TEXT_CENTER),count,20,1.0f,1.0f,1.0f,1.0f);
    setmenuitem(MO_HOTKEY,SCAN_2);
#ifdef DEMO
    setmenuitem(MO_HIGHLIGHT,0);
#endif
    count+=20;
    createmenuitem(TXT_LEVEL" 3",(320|TEXT_CENTER),count,20,1.0f,1.0f,1.0f,1.0f);
    setmenuitem(MO_HOTKEY,SCAN_3);
#ifdef DEMO
    setmenuitem(MO_HIGHLIGHT,0);
#endif
    count+=20;
#ifndef DEMO
    if (unlocked)
      {
      createmenuitem(TXT_LEVEL" 4",(320|TEXT_CENTER),count,20,1.0f,1.0f,1.0f,1.0f);
      setmenuitem(MO_HOTKEY,SCAN_4);
      count+=20;
      }
    else
      createmenuitemempty();
#endif
#ifndef DEMO
    count=360;
    if (versusnum==0 || versusnum==1)
      {
      createmenuitem(TXT_LEVEL" 5",(320|TEXT_CENTER),count,20,1.0f,1.0f,1.0f,1.0f);
      setmenuitem(MO_HOTKEY,SCAN_5);
      count+=20;
      createmenuitem(TXT_LEVEL" 6",(320|TEXT_CENTER),count,20,1.0f,1.0f,1.0f,1.0f);
      setmenuitem(MO_HOTKEY,SCAN_6);
      count+=20;
      }
#endif

    checksystemmessages();
    checkkeyboard();
    checkmouse();
    checkjoystick();
    checkmenuitems();

    updateogg();
    checkmusic();
    game.songnum=8;
    soundsimulation(view.position,view.orientation);

    setuptextdisplay();

    glColor4f(1.0f,1.0f,1.0f,1.0f);
    displaybackground(540);

    drawbackground(530+versusnum,(320|TEXT_CENTER),48,192,192,640,480);

    drawtext("2 "TXT_PLAYER,(320|TEXT_CENTER),234,16,1.0f,1.0f,1.0f,1.0f);
    if (versusnum==0 || versusnum==1)
      drawtext("4 "TXT_PLAYER,(320|TEXT_CENTER),344,16,1.0f,1.0f,1.0f,1.0f);

    drawmenuitems();

    drawmousecursor(768+font.cursornum,mouse.x,mouse.y,16,1.0f,1.0f,1.0f,1.0f);

    SDL_GL_SwapBuffers();

    if (versusnum==0)
      strcpy(filename,"bathhouse");
    if (versusnum==1)
      strcpy(filename,"field");
    if (versusnum==2)
      strcpy(filename,"amber");
    if (versusnum==3)
      strcpy(filename,"fight");
    if (versusnum==4)
      strcpy(filename,"dragster");
    if (versusnum==5)
      strcpy(filename,"colvs");
    if (versusnum==6)
      strcpy(filename,"racing");

    if (menuitem[1].active)
      {
      game.songnum=-1;
      checkmusic();

      game.levelnum=0;
      strcat(filename,".lvl");
      loadlevel(filename);
      gameloop();
      }
    if (menuitem[2].active)
      {
      game.songnum=-1;
      checkmusic();

      game.levelnum=0;
      strcat(filename,"2.lvl");
      loadlevel(filename);
      gameloop();
      }
    if (menuitem[3].active)
      {
      game.songnum=-1;
      checkmusic();

      game.levelnum=0;
      strcat(filename,"3.lvl");
      loadlevel(filename);
      gameloop();
      }
    if (menuitem[4].active)
      {
      game.songnum=-1;
      checkmusic();

      game.levelnum=0;
      strcat(filename,"4.lvl");
      loadlevel(filename);
      gameloop();
      }
    if (menuitem[5].active)
      {
      game.songnum=-1;
      checkmusic();

      if (versusnum==0)
        strcpy(filename,"4bath");
      if (versusnum==1)
        strcpy(filename,"4field");

      game.levelnum=0;
      strcat(filename,".lvl");
      loadlevel(filename);
      gameloop();
      }
    if (menuitem[6].active)
      {
      game.songnum=-1;
      checkmusic();

      if (versusnum==0)
        strcpy(filename,"4bath");
      if (versusnum==1)
        strcpy(filename,"4field");

      game.levelnum=0;
      strcat(filename,"2.lvl");
      loadlevel(filename);
      gameloop();
      }
    }

  resetmenuitems();
  }
示例#11
0
void loadstorylevel(int levelnum)
  {
#ifndef DEMO
  if (levelnum==1)
    loadlevel("sewer1.lvl");
  if (levelnum==2)
    loadlevel("sewer2.lvl");
  if (levelnum==3)
    loadlevel("sewer3.lvl");
  if (levelnum==4)
    loadlevel("sewer4.lvl");
  if (levelnum==5)
    loadlevel("sewer5.lvl");
  if (levelnum==6)
    loadlevel("sewer6.lvl");
  if (levelnum==7)
    loadlevel("sewer7.lvl");

  if (levelnum==8)
    loadlevel("cave1.lvl");
  if (levelnum==9)
    loadlevel("cave2.lvl");
  if (levelnum==10)
    loadlevel("cave3.lvl");
  if (levelnum==11)
    loadlevel("cave4.lvl");
  if (levelnum==12)
    loadlevel("cave5.lvl");
  if (levelnum==13)
    loadlevel("cave6.lvl");
  if (levelnum==14)
    loadlevel("cave7.lvl");

  if (levelnum==15)
    loadlevel("hell1.lvl");
  if (levelnum==16)
    loadlevel("hell2.lvl");
  if (levelnum==17)
    loadlevel("hell3.lvl");
  if (levelnum==18)
    loadlevel("hell4.lvl");
  if (levelnum==19)
    loadlevel("hell5.lvl");
  if (levelnum==20)
    loadlevel("hell6.lvl");
  if (levelnum==21)
    loadlevel("hell7.lvl");

  if (levelnum==22)
    loadlevel("egypt1.lvl");
  if (levelnum==23)
    loadlevel("egypt2.lvl");
  if (levelnum==24)
    loadlevel("egypt3.lvl");
  if (levelnum==25)
    loadlevel("egypt4.lvl");
  if (levelnum==26)
    loadlevel("egypt5.lvl");
  if (levelnum==27)
    loadlevel("egypt6.lvl");
  if (levelnum==28)
    loadlevel("egypt7.lvl");

  if (levelnum==29)
    loadlevel("church1.lvl");
  if (levelnum==30)
    loadlevel("church2.lvl");
  if (levelnum==31)
    loadlevel("church3.lvl");
  if (levelnum==32)
    loadlevel("church4.lvl");
  if (levelnum==33)
    loadlevel("church5.lvl");
  if (levelnum==34)
    loadlevel("church6.lvl");
  if (levelnum==64)
    loadlevel("sewer8.lvl");
  if (levelnum==65)
    loadlevel("cave8.lvl");
  if (levelnum==66)
    loadlevel("egypt8.lvl");
  if (levelnum==67)
    loadlevel("death.lvl");
  if (levelnum==68)
    loadlevel("death2.lvl");
#else
  if (levelnum==1)
    loadlevel("demo1.lvl");
  if (levelnum==2)
    loadlevel("demo2.lvl");
  if (levelnum==3)
    loadlevel("demo3.lvl");
  if (levelnum==4)
    loadlevel("demo4.lvl");
  if (levelnum==5)
    loadlevel("demo5.lvl");
#endif
  }