Exemplo n.º 1
0
void World::initResource()
{
	// skybox
	skybox.init("SkyBox", Const::SKYBOX_SIZE);
	// ring
	ring.init("Ring", Const::RING_SCALE);
	// particles
	Particles::loadResource();
	initPlanets();
	initShips();
	initBullets();
}
Exemplo n.º 2
0
int main(int argc, char *argv[])
{
    int i;
    float r = 0;
    Space *space;
    Entity *cube1,*cube2;
    char bGameLoopRunning = 1;
    Vec3D cameraPosition = {-10,3,0};
    Vec3D cameraRotation = {180,0,180};
    SDL_Event e;
    Obj *bgobj;
    Sprite *bgtext;

	//my variables
	Ship *playerShip;
	int specMode;
    
    init_logger("gametest3d.log");
    if (graphics3d_init(1024,768,1,"gametest3d",33) != 0)
    {
        return -1;
    }
    model_init();
    obj_init();
    entity_init(255);
	initShips();
    
    bgobj = obj_load("models/mountainvillage.obj");
    bgtext = LoadSprite("models/mountain_text.png",1024,1024);
    
    //cube1 = newCube(vec3d(0,0,0),"Cubert");
    //cube2 = newCube(vec3d(10,0,0),"Hobbes");
    
    //cube1->body.velocity.x = 0.1;
    
    space = space_new();
    space_set_steps(space,100);
    
    space_add_body(space,&cube1->body);
    space_add_body(space,&cube2->body);

	//my variables
	specMode = 0;
	numShips = 0;
	shipVel = 0;
	shipRot = 0;
	turretRot = 0;
	gunElev = 0;
	realTurrRot = 0;

	playerShip = spawnShip(space, vec3d(-10,0,0), 1);

    while (bGameLoopRunning)
    {
		updateAllShipPos();
		for (i = 0; i < 100;i++)
        {
			space_do_step(space);
        }
		updateAllShipComp();
		applyGrav();
		if(specMode == 0)
		{
			cameraPosition.x = playerShip->hull->body.position.x;
			cameraPosition.y = (playerShip->hull->body.position.y + 5);
			cameraPosition.z = playerShip->hull->body.position.z;
		}

        while ( SDL_PollEvent(&e) ) 
        {
            if (e.type == SDL_QUIT)
            {
                bGameLoopRunning = 0;
            }
            else if (e.type == SDL_KEYDOWN)
            {
                if (e.key.keysym.sym == SDLK_ESCAPE)
                {
                    bGameLoopRunning = 0;
                }
                else if (e.key.keysym.sym == SDLK_SPACE)
                {
                    cameraPosition.z++;
                }
                else if (e.key.keysym.sym == SDLK_z)
                {
                    cameraPosition.z--;
                }
                else if (e.key.keysym.sym == SDLK_w)
                {
                    vec3d_add(
                        cameraPosition,
                        cameraPosition,
                        vec3d(
                            -sin(cameraRotation.z * DEGTORAD),
                            cos(cameraRotation.z * DEGTORAD),
                            0
                        ));
                }
                else if (e.key.keysym.sym == SDLK_s)
                {
                    vec3d_add(
                        cameraPosition,
                        cameraPosition,
                        vec3d(
                            sin(cameraRotation.z * DEGTORAD),
                            -cos(cameraRotation.z * DEGTORAD),
                            0
                        ));
                }
                else if (e.key.keysym.sym == SDLK_d)
                {
                    vec3d_add(
                        cameraPosition,
                        cameraPosition,
                        vec3d(
                            cos(cameraRotation.z * DEGTORAD),
                            sin(cameraRotation.z * DEGTORAD),
                            0
                        ));
                }
                else if (e.key.keysym.sym == SDLK_a)
                {
                    vec3d_add(
                        cameraPosition,
                        cameraPosition,
                        vec3d(
                            -cos(cameraRotation.z * DEGTORAD),
                            -sin(cameraRotation.z * DEGTORAD),
                            0
                        ));
                }
                else if (e.key.keysym.sym == SDLK_LEFT)
                {
                    cameraRotation.y -= 1;
                }
                else if (e.key.keysym.sym == SDLK_RIGHT)
                {
                    cameraRotation.y += 1;
                }
                else if (e.key.keysym.sym == SDLK_UP)
                {
                    cameraRotation.x += 1;
                }
                else if (e.key.keysym.sym == SDLK_DOWN)
                {
                    cameraRotation.x -= 1;
                }
				

				
				else if (e.key.keysym.sym == SDLK_y && shipVel < 0.4)
                {
                    shipVel += 0.1;
                }
				else if (e.key.keysym.sym == SDLK_h && shipVel > 0.05)
                {
                    shipVel -= 0.1;
                }
				else if (e.key.keysym.sym == SDLK_j)
                {
                    shipRot += 0.5;
					if(shipRot >= 360){shipRot -= 360;}
                }
				else if (e.key.keysym.sym == SDLK_g)
                {
                    shipRot -= 0.5;
					if(shipRot < 0){shipRot += 360;}
                }
				else if (e.key.keysym.sym == SDLK_m && turretRot < 135)
                {
                    turretRot += 1;
                }
				else if (e.key.keysym.sym == SDLK_b && turretRot > -135)
                {
                    turretRot -= 1;
                }
				else if (e.key.keysym.sym == SDLK_o && gunElev < 50)
                {
                    gunElev += 0.5;
                }
				else if (e.key.keysym.sym == SDLK_l && gunElev > -5)
                {
                    gunElev -= 0.5;
                }
				else if (e.key.keysym.sym == SDLK_q)
                {
					if(specMode == 0){specMode = 1;}
					else {specMode = 0;}
                }
				else if (e.key.keysym.sym == SDLK_p)
                {
					fireBullet(space, playerShip->gun->body.position, realTurrRot, gunElev, 0.5, -1);
				}
				else if (e.key.keysym.sym == SDLK_x)
                {
					fireBullet(space, playerShip->hull->body.position, shipRot, 0, 0, -2);
				}
				else if (e.key.keysym.sym == SDLK_1)
                {
					startLevel(space, 1);
				}
				else if (e.key.keysym.sym == SDLK_2)
                {
					startLevel(space, 2);
				}
				else if (e.key.keysym.sym == SDLK_3)
                {
					startLevel(space, 3);
				}
            }
        }
		 
        graphics3d_frame_begin();
        
        glPushMatrix();
        set_camera(
            cameraPosition,
            cameraRotation);
        
        entity_draw_all();
		//updateAllShipModels();
        obj_draw(
            bgobj,
            vec3d(0,0,2),
            vec3d(90,90,0),
            vec3d(5,5,5),
            vec4d(1,1,1,1),
            bgtext
        );
        
        if (r > 360)r -= 360;
        glPopMatrix();
        /* drawing code above here! */
        graphics3d_next_frame();
    } 
    return 0;
}
Exemplo n.º 3
0
/**
 * This function gets called from within init_game
 * It is called repeatedly if we are the server, else
 * it is just called once.
 */
void do_gameplay(const int sock, int fire)
{
  int x,y,res,win_status=0;
  char msg[100];

  for (int i=0; i<BOARD_SIZE; ++i) {
    for (int j=0; j<BOARD_SIZE; ++j) {
      player_shots[i][j] = UNTOUCHED;
      peer_shots[i][j] = UNTOUCHED;
    }
  }


  initShips();
  display_boards();

  Ship sh;
  do {
    if (fire == 1) { /*you're the attacker*/
      mvwprintw(status_win,1,1,"It's your turn!                    ");
      wrefresh(status_win);
            
      fire = 0;
      return_cords(&x, &y);
      res = do_fire(sock, x, y);


      place_hit_or_mis(player_win,res, x, y, false);
      switch (res) {
      case 0:
        mvwprintw(status_win,2,1,"Missed!                                    ");
        wrefresh(status_win);
        break;
      case 1:
        mvwprintw(status_win,2,1,"You hit them!                              ");
        wrefresh(status_win);
        /* play_boom("You hit them!"); */
        /* display_boards(); */
        break;
      case -1:
        mvwprintw(status_win,2,1,"You sunk them!                             ");
        wrefresh(status_win);
        /* play_boom("You sunk them!"); */
        /* display_boards(); */
        break;
      case -2:
        win_status = 1;
        mvwprintw(status_win,2,1,"Game over!                        ");
        wrefresh(status_win);
        fire = -1;
        break;
      }

    } else { /*you're the defender*/
      keypad(stdscr, FALSE);
      curs_set(0); // Set cursor invisible
      mvwprintw(status_win,1,1,"Waiting for other player to fire...");
      wrefresh(status_win);
      res = do_receive(sock);


      refresh();
      if (res == 0) {
        //wclear(status_win);
        mvwprintw(status_win,2,1,"They missed!                                ");
        //mvwprintw(status_win,5,1,"It's your turn!");
        wrefresh(status_win);
      } else if (res < 0) { //negative res indicates sunken ship
        sh = getShipById(-1*res); /* what a hack... */
        //wclear(status_win);
        mvwprintw(status_win,2,1,"They sunk your %s!               ", sh.name);
        /* play_boom("They sunk you!"); */
        /* display_boards(); */
        //mvwprintw(status_win,5,1,"It's your turn!");
        wrefresh(status_win);
      } else if (res==100);//do nothing...the game is over
      else {
        sh = getShipById(res);
        //wclear(status_win);
        mvwprintw(status_win,2,1,"They hit your %s!                ", sh.name);
        /* play_boom("They hit you!"); */
        /* display_boards(); */
        //mvwprintw(status_win,5,1,"It's your turn!");
        wrefresh(status_win);
      }
      mvwprintw(status_win,1,1,"It's your turn!                               ");
      fire = (check_game_over() == 1) ? -1 : 1;
      refresh();
    }
  } while(fire > -1);

  sprintf(msg, "Game over! You %s!\nPress any key to view battlefields.", win_status ? "won" : "lost");
  show_message_box(msg);
  getch();
  exchange_shipsets(sock);
  show_battlefields();
}
Exemplo n.º 4
0
/**
 * Documentation here
 */
void main_menu()
{


  MENU *my_menu;
  /* Order here doesn't matter. Name (the first item in each of these
     "pairs") does. If you change the name, change the selection
     handling code towards the end of this function. */
  char *my_choices[] = {
    "Create","(Create new termship game)",
    "Join", "(Join existing termship game on network)",
    "Exit", "",
    (char *)NULL, (char *)NULL
  };
  ITEM **my_items;
  int n_choices = ARRAY_SIZE(my_choices)/2;

  /* some testing modes: */
#ifdef TEST_SHIPS
  initShips();
  return;
#endif

  keypad(stdscr, TRUE);
  curs_set(0); // make cursor invisible
  noecho();
  title_screen();

  clear();

  my_items = (ITEM **)calloc(n_choices,sizeof(ITEM *));
  for (int i=0; my_choices[i*2]!=NULL; ++i) {
    /* i*2 since we're iterating in pairs */
    my_items[i] = new_item(my_choices[(i*2)], my_choices[(i*2)+1]);
  }

  my_menu = new_menu(my_items);
  set_menu_mark(my_menu, "   * ");
  post_menu(my_menu);
  refresh();

  int c;
  while ((c = getch()) != 10) {
    switch (c) {
    case KEY_DOWN:
      menu_driver(my_menu, REQ_DOWN_ITEM);
      break;
    case KEY_UP:
      menu_driver(my_menu, REQ_UP_ITEM);
      break;
    }
  }
  ITEM *cur = current_item(my_menu);
  const char *selected_name = item_name(cur);
  
  /* delete the menu, free resources */
  for (int i=0; i<n_choices-1; ++i) {
    free_item(my_items[i]);
  }
  /* free(my_items); */
  unpost_menu(my_menu);
  free_menu(my_menu);

  if (0==strcmp(selected_name, "Create")) {
    user_mode = SERVER_MODE;
    get_text_string_from_centered_panel("Enter your name",
                    global_user_name,
                    MAX_NAME);
    init_game(user_mode);
  } else if (0==strcmp(selected_name, "Join")) {
    user_mode = CLIENT_MODE;
    get_text_string_from_centered_panel("Enter your name",
                    global_user_name,
                    MAX_NAME);
    init_game();
  }

  return;
}