コード例 #1
0
ファイル: maze.c プロジェクト: briansherman/Maze
/* standard display function */
void
display(void)
{ 
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  
  // GLfloat light1_position[] = {(GLfloat)(eyeX/1000), (GLfloat)(eyeY/1000), (GLfloat)(eyeZ/1000), 1.0};
  // GLfloat light1_direction[] = {(GLfloat)((eyeX + cos(theta))/1000), (GLfloat)((eyeY+sin(theta))/1000), (GLfloat)(lookZ/1000), 1.0};
  // glLightfv(GL_LIGHT1, GL_SPOT_DIRECTION, light1_direction);
  // glLightfv(GL_LIGHT1, GL_POSITION, light1_position);
  //printf("%f %f",eyeX,eyeY);
  //printf("\n");
  
  if(!topView){
    GLfloat light1_position[] = {(GLfloat)(eyeX), (GLfloat)(eyeY), (GLfloat)(eyeZ)/3, 1.0};
    GLfloat light1_direction[] = {(GLfloat)(cos(theta)), (GLfloat)(sin(theta)), (eyeZ)/3, 1.0};
    glLightfv(GL_LIGHT1, GL_SPOT_DIRECTION, light1_direction);
    glLightfv(GL_LIGHT1, GL_POSITION, light1_position);
  }else{
    GLfloat light1_position[] = {0, 0, 1, 1.0};
    GLfloat light1_direction[] = {0, 0, 1, 1.0};
    glLightfv(GL_LIGHT1, GL_SPOT_DIRECTION, light1_direction);
    glLightfv(GL_LIGHT1, GL_POSITION, light1_position);
  }
  draw_maze();
  fflush(stdout);
  glutSwapBuffers();
}
コード例 #2
0
ファイル: MazeSolverApp.cpp プロジェクト: arcticmatt/CS2
/**
 * @brief Renders everything; called once on startup
 * and then to animate solver moves.
 */
void MazeSolverApp::OnRender()
{
    SDL_FillRect(surf, NULL, SDL_MapRGB(surf->format, 0, 0, 0));
    draw_maze();
    draw_path();
    SDL_Flip(surf);
}
コード例 #3
0
/*
 * domaze:
 *	Draw the maze on this level.
 */
do_maze()
{
	reg int least;
	reg struct room *rp;
	reg struct linked_list *item;
	reg struct object *obj;
	int cnt;
	bool treas;
	coord tp;

	for (rp = rooms; rp < &rooms[MAXROOMS]; rp++) {
		rp->r_flags = ISGONE;		/* kill all rooms */
		rp->r_fires = NULL;		/* no fires */
	}
	rp = &rooms[0];				/* point to only room */
	rp->r_flags = ISDARK;			/* mazes always dark */
	rp->r_pos.x = 0;			/* room fills whole screen */
	rp->r_pos.y = 1;
	rp->r_max.x = cols - 1;
	rp->r_max.y = lines - 3;
	draw_maze();				/* put maze into window */
	/*
	 * add some gold to make it worth looking for 
	 */
	item = spec_item(GOLD, NULL, NULL, NULL);
	obj = OBJPTR(item);
	obj->o_count *= (rnd(5) + 5);		/* add in one large hunk */
	attach(lvl_obj, item);
	cnt = 0;
	do {
	    rnd_pos(rp, &tp);
	} until (mvinch(tp.y, tp.x) == FLOOR || cnt++ > 5000);
	mvaddch(tp.y, tp.x, GOLD);
	obj->o_pos = tp;
	/*
	 * add in some food to make sure he has enough
	 */
	item = spec_item(FOOD, NULL, NULL, NULL);
	obj = OBJPTR(item);
	attach(lvl_obj, item);
	do {
	    rnd_pos(rp, &tp);
	} until (mvinch(tp.y, tp.x) == FLOOR || cnt++ > 5000);
	mvaddch(tp.y, tp.x, FOOD);
	obj->o_pos = tp;
	if (rnd(100) < 40) {			/* treasure type maze */
		treas = TRUE;
		least = 10;
		debug("treasure maze");
	}
	else {					/* normal maze level */
		least = 5;
		treas = FALSE;
	}
	genmonsters(least, treas);
}
コード例 #4
0
ファイル: pacman.c プロジェクト: AbhijitParate/TOS
void init_pacman(WINDOW* wnd, int num_ghosts)
{
    pacman_wnd = wnd;
    pacman_wnd->width = MAZE_WIDTH;
    pacman_wnd->height = MAZE_HEIGHT + 1;
    pacman_wnd->cursor_char = GHOST_CHAR;

    draw_maze();

    int j;
    for (j = 0; j < num_ghosts; j++)
        create_new_ghost();
}
コード例 #5
0
ファイル: pacman.c プロジェクト: wangyanxing/tos
void init_pacman(WINDOW* wnd, int num_ghosts)
{
    pacman_wnd = wnd;
    pacman_wnd->width = MAZE_WIDTH;
    pacman_wnd->height = MAZE_HEIGHT + 1;
    pacman_wnd->cursor_char = GHOST_CHAR;

    draw_maze();

    int i;
    for (i = 0; i < num_ghosts; i++) {
        create_process(ghost_proc, 3, 0, "Ghost");
    }
    return;
}
コード例 #6
0
ファイル: pacman.c プロジェクト: marzigolbaz/tos
void init_pacman(WINDOW* wnd, int num_ghosts)
{
    if (wnd->height < MAZE_HEIGHT || wnd->width < MAZE_WIDTH)
    {
        wprintf(wnd, "Window too small\n");
        return;
    }

    pacman_wnd = wnd;
    // pacman_wnd->width = MAZE_WIDTH;
    // pacman_wnd->height = MAZE_HEIGHT + 1;
    // pacman_wnd->cursor_char = GHOST_CHAR;

    draw_maze();

    int j;
    for (j = 0; j < num_ghosts; j++)
        create_process(ghost_proc, 3, 0, "Ghost");
}
コード例 #7
0
ファイル: game_features.c プロジェクト: aliclubb/misc-tools
int process_key_up(int y, int x, int level, int have_key)
{
	int wall, c;
	move(--y, x); // Move the cursor up by one
	switch(wall = inch())
	{
		case '#' : move(++y, x); break;
		case '+' :
		{
			if(have_key == 1)
			{
				unlock();
				have_key--;
				move(++y, x);
			}
			else
			{
				move(22, 0);
				deleteln();
				mvprintw(22, 0, "This door appears to be locked.... You need a key.");
				move(++y, x);
			}
			break;
		}
		case ' ' :
		{
			move(++y, x);
			addch(' ');
			move(--y, x);
			addch('@');
			move(++y, x);
			break;
		}
		case 'o' :
		{
			level_completed(level++);
			switch(c = getch())
			{
				case 'c' : draw_maze(++level); break; // Continue and render next level.
				case 'q' : endwin(); return 0; break; // Close ncurses window
			}
			break;
		}
		case 'E' :
		{
			have_key++;
			move(22, 0);
			deleteln();
			mvprintw(22, 0, "You picked up a rusty key....");
			move(++y, x);
			addch(' ');
			move(--y, x);
			addch('@');
			move(y, x);
			break;
		}
	}
	refresh();
	return(y);
	return(x);
}
コード例 #8
0
ファイル: main.c プロジェクト: pcoutin/mazeoftorment
int
main(int argc, char *argv[])
{
   SDL_Window  *window;
   CLC_CONFIG  config;
   Uint8       *kbdstate;
   SDL_Event   e;
   PLAYER      *me;
   PLAYER      *player;
   Uint32      time;
   IPaddress   srv_ip;
   TCPsocket   srv_sock;
   Uint16      magic;
   int         i;
   SDLNet_SocketSet srv_sset;
   char myname[PNAME_SIZE];
   unsigned char myno;

   if (SDL_Init(SDL_INIT_TIMER | SDL_INIT_VIDEO | SDL_INIT_EVENTS) == -1)
   {
      fprintf(stderr, "SDL_Init: %s\n", SDL_GetError());
      exit(EXIT_FAILURE);
   }

   if (SDLNet_Init() == -1)
   {
      fprintf(stderr, "SDLNet_Init: %s\n", SDLNet_GetError());
      exit(EXIT_FAILURE);
   }

   parsecfg(&config);

   /*
    * Get player name.
    */
   printf("Wow such name: ");
   fgets(myname, PNAME_SIZE, stdin);

   for (i = 0; i < PNAME_SIZE; i++)
   {
      if (myname[i] == '\n')
      {
         myname[i] = '\0';
         break;
      }
   }


   /*
    * Connect to server!
    */
   if (SDLNet_ResolveHost(&srv_ip, config.defaultsrv,
            atoi(config.defaultport)))
   {
      fprintf(stderr, "SDLNet_ResolveHost: %s\n", SDLNet_GetError());
      exit(EXIT_FAILURE);
   }


   /*
    * Bind socket!
    */
   if (!(srv_sock = SDLNet_TCP_Open(&srv_ip)))
   {
      fprintf(stderr, "SDLNet_TCP_Open: %s\n", SDLNet_GetError());
      exit(EXIT_FAILURE);
   }


   /*
    * Add (a single) server socket to srv_sset for cheap hack for checking
    * the server socket's state.
    */
   srv_sset = SDLNet_AllocSocketSet(1);

   if (!srv_sset)
   {
      printf("SDLNet_AllocSocketSet: %s\n", SDLNet_GetError());
      exit(EXIT_FAILURE);
   }

   SDLNet_TCP_AddSocket(srv_sset, srv_sock);


   /*
    * Get maze, add connecting players to buffer and wait until the game
    * begins.
    */

   getmaze(srv_sock);

   window = SDL_CreateWindow(
         "MAZE OF TORMENT",
         SDL_WINDOWPOS_UNDEFINED,
         SDL_WINDOWPOS_UNDEFINED,
         config.win_width,
         config.win_height,
         config.win_flags
   );

   SDL_GetWindowSize(window, &config.win_width, &config.win_height);

   if (window == NULL)
   {
      fprintf(stderr, "Could not create window: %s\n",
            SDL_GetError());
      exit(EXIT_FAILURE);
   }

   renderer = SDL_CreateRenderer(window, -1, config.renderflags);

   hsprite  = loadPic("img/predator.gif");
   psprite  = loadPic("img/prey.gif");
   black    = loadPic("img/black.gif");

   /*
    * Initialize maze, and send player name.
    */
   MAZE.X = (config.win_width - MAZE.w * 16) / 2;
   MAZE.Y = (config.win_height - MAZE.h * 16) / 2;

   SDLNet_TCP_Send(srv_sock, myname, PNAME_SIZE);


   /*
    * Initialize maze and get the LOCAL player, then the REMOTE players.
    */

   SDLNet_TCP_Recv(srv_sock, &myno, 1);
   player = calloc(1, sizeof(PLAYER));

   if (!((magic = getshort(srv_sock)) == ADD_PLAYER))
   {
      printf("server not sending players\n!");
      exit(EXIT_FAILURE);
   }

   unsigned char hunter = addp(player, srv_sock);

   choose_hunter(player, hunter);
   me = choose_player(player, myno);

   SDL_SetRenderDrawColor(renderer, 0, 255, 255, 255);
   draw_maze(MAZE.X, MAZE.Y);

   PLAYER *temp;

   for (temp = player->next; temp != NULL; temp = temp->next)
   {
      printf("drew player %d\n", temp->playerno);
      drawPlayer(temp);
   }
   
   printf("starting game!!\n");
   /*
    * Game loop!
    */
   
   for (;;)
   {
      time = SDL_GetTicks();

      /*
       * Poll the  network in each frame. Because.
       */

      int result, numready = SDLNet_CheckSockets(srv_sset, 0);

      if (numready == -1)
      {
         printf("SDLNet_CheckSockets: %s\n", SDLNet_GetError());
         perror("SDLNet_CheckSockets");
      }
      else if (numready)
      {
         unsigned char packet;
         unsigned char pnum, movx, movy;

         printf("srv socket is ready!!\n");

         if ((result = SDLNet_TCP_Recv(srv_sock, &packet, 2)) == 2)
         {
            switch (SDLNet_Read16(&packet))
            {
               case PLAYER_MOV:
                  puts("PLAYER_MOV");
                  pnum = getshort(srv_sock);
                  movx = getshort(srv_sock);
                  movy = getshort(srv_sock);

                  printf("player %d moved to (%d,%d)\n",
                              pnum, movx, movy);
                  movePlayer(choose_player(player,pnum), movx, movy);
                  break;

               case PLAYER_WIN:
                  puts("PLAYER_WIN");
                  break;

               case PLAYER_DC:
                  puts("PLAYER_DC");
                  pnum = getshort(srv_sock);
                  printf("Player %d disconnected!!\n", pnum);
                  removep(choose_player(player,pnum));
                  break;

               case PLAYER_DIE:
                  puts("PLAYER_DIE");
                  pnum = getshort(srv_sock);

                  if (pnum == myno)
                  {
                     puts("YOU ARE DEAD\nGAME OVER");
                     goto exit;
                  }
                  printf("Player %d deaded!!!!!\n", pnum);
                  removep(choose_player(player, pnum));
                  break;

            }
         }
         else if (result <= 0)
         {
            fprintf(stderr, "SDLNet_TCP_Recv: %s\n", SDLNet_GetError());
            fprintf(stderr, "Lost connection to the server?\n");
            break;
         }
      }

      /*
       * Poll for keys
       */
      if (SDL_PollEvent(&e))
      {
         if (e.type == SDL_QUIT)
         {
            break;
         }

         kbdstate = (Uint8 *) SDL_GetKeyboardState(NULL);

         if (kbdstate[SDL_SCANCODE_Q])
         {
            break;
         }

         local_player_update(srv_sock, me, player, SDL_GetKeyboardState(NULL));
      }

      SDL_SetRenderDrawColor(renderer, 0, 255, 255, 255);
      SDL_RenderPresent(renderer);

      if (20 > (SDL_GetTicks() - time))
      {
         SDL_Delay(20 - (SDL_GetTicks() - time));
      }
   }

exit:
   SDL_DestroyTexture(psprite.texture);
   SDL_DestroyTexture(hsprite.texture);
   SDL_DestroyTexture(black.texture);
   free(player);
   free(MAZE.data);

   SDL_DestroyWindow(window);

   SDLNet_Quit();
   SDL_Quit();

   return 0;
}