예제 #1
0
void laserdisc_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
{
	switch (id)
	{
		case TID_VBI_FETCH:
		{
			// wait for previous read and decode to finish
			process_track_data();

			// update current track based on slider speed
			update_slider_pos();

			// update the state
			add_and_clamp_track(player_update(m_metadata[m_fieldnum], m_fieldnum, machine().time()));

			// flush any audio before we read more
			m_stream->update();

			// start reading the track data for the next round
			m_fieldnum ^= 1;
			read_track_data();
			break;
		}
	}
}
예제 #2
0
/*
 * Update game variables
 */
void update(void)
{
    // Calculate the elapsed time between frames
    double current_time = Wallclock();
    double delta_time = current_time - g_dLastTime;
    g_dLastTime = current_time;

    // Update if the game isn't paused
    if( !g_bPause )
    {
        // Update player movement
        player_update(delta_time);

        // Update jeep movement
        g_pModelJeep.rotation += 0.05;
        g_pModelJeep.position[0] = sin(ToRad(g_pModelJeep.rotation)) * 20.0f;
        g_pModelJeep.position[1] = cos(ToRad(g_pModelJeep.rotation)) * 20.0f;

        // Update camera movement
        camera_update(delta_time, player_getRotation());
    }

    // Redraw the scene
    glutPostRedisplay();
    Sleep(1);
}
예제 #3
0
파일: ifitron.c 프로젝트: QrshR/inf1060-he
int main (int argc, char* argv[]) {
  if (argc > 1) args_handle (argc, argv);

  if(tron.user_name[0] == 0) {
    char *tmp = getlogin();
    if(tmp == NULL) {
      ifitron_abort("No username provided and attempts to fetch it automatically, failed.\n");
    }
    strcpy(tron.user_name, tmp);
  }

  if(get_server_mode() == 2) {
    while(TRUE) {
      int result = play_multiplayer();
      if(result == -1)
        break;
    }
    engine_exit();
    ifitron_exit();
  }

  if(client_host_addr != NULL) { //Connect to the server
    int sd = connect_to_server();
    if(sd == -1) {
      ifitron_abort("Couldn't connect to the server.\n");
    }else{
      set_client_socket_descriptor(sd);
    }
  }

  engine_init ();
  engine_show_main_menu ();
  ifitron_init ();
	
  while (TRUE) {
    if (tron.is_alive == FALSE) 
      ifitron_game_over ();
    
    engine_get_game_input();
    player_update(get_tron());
    
    player_increase_size (get_tron(), 1);
    player_increase_score (get_tron(), game.level);
	  
    if (tron.score % 50 == 0 && game.level < 9) game.level++;

    if (player_hit_self(get_tron()) == TRUE  || player_hit_borders(get_tron()) == TRUE)
      tron.is_alive = FALSE;

    engine_show_screen ();
  }
  return 0;
}
예제 #4
0
gint
render_camera(gpointer data)
{
  GdkPixbuf *pixbuf = NULL;
  GdkPixbuf *blobbuf= NULL;
  GdkGC         *gc = NULL;
  GtkWidget *drawing_area = GTK_WIDGET(data);
  uint16_t i;

  gc = GTK_WIDGET(drawing_area)->style->fg_gc[GTK_WIDGET_STATE(GTK_WIDGET(drawing_area))];

  player_update();

  if (g_blob_count > 0)
  {
    // Draw the blobs
    blobbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, false, 8, 1, 1);
    for (i=0; i< g_blob_count; ++i)
    {
      // shift the color by 8-bits to account for the alpha channel
      gdk_pixbuf_fill(blobbuf, g_blobs[i].color << 8);

      gdk_pixbuf_composite(blobbuf,
                           g_pixbuf,
                           g_blobs[i].left,
                           g_blobs[i].top,
                           abs(g_blobs[i].right - g_blobs[i].left),
                           abs(g_blobs[i].top   - g_blobs[i].bottom),
                           1, 1, 1, 1, GDK_INTERP_NEAREST, 128);
    }
    gdk_pixbuf_unref(blobbuf);
  }

  // scale everything at the end
  if ((g_width==g_window_width)&&(g_height==g_window_height))
  { // we don't need to worry about scaling
    gdk_draw_pixbuf(GTK_WIDGET(drawing_area)->window, gc,
                    g_pixbuf, 0, 0, 0, 0, g_width, g_height,
                    GDK_RGB_DITHER_NONE, 0, 0);
  }
  else
  {
    pixbuf = gdk_pixbuf_scale_simple(g_pixbuf, g_window_width,
                                     g_window_height, GDK_INTERP_BILINEAR);
    gdk_draw_pixbuf(GTK_WIDGET(drawing_area)->window, gc,
                    pixbuf, 0, 0, 0, 0, g_window_width, g_window_height,
                    GDK_RGB_DITHER_NONE, 0, 0);
    gdk_pixbuf_unref(pixbuf);
  }

  return TRUE;
}
예제 #5
0
int main(void) {
	int i;
	char choice;
	char quit;

	main_init();

	quit = FALSE;
	do {
		choice = title_page();

		switch (choice) {
		case (0) :
		case (1) :
			gPlayers = choice + 1;
			break;
		case (2) :
			continue;
		default :
			quit = TRUE;
		};

		if (!quit) {
			game_reset();

			// main game loop
			do {
				key_check();

				for (i = 0; i != gPlayers; ++i) {
					player_key_check(i);
					player_stack_linecheck(i);
					player_update(i);
				}

				screen_draw();
				blit(gBuff, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
			} while (gWinner == 0);

			record_scores();
			table_display();
		}
	} while (!quit);

	table_display();
	main_exit();
	return 0;
}
예제 #6
0
파일: main.c 프로젝트: gsrr/Python
/**	The main function - contains the main loop of the game.
 *
 *
 *	@note I tried to make this function as clear as possible, so anyone
 *        could understaing the whole game logic starting by here. @n
 *        Have fun with the source code!
 */
 int main (int argc, char* argv[])
{
	if (argc > 1)
		args_handle (argc, argv);

	engine_init ();
	engine_show_main_menu ();
	nsnake_init ();

	while (TRUE == TRUE)
	{
		if (snake.is_alive == FALSE)
			nsnake_game_over ();

		engine_get_game_input ();

		player_update ();
		fruit_update_bonus ();

		if (player_hit_fruit () == TRUE)
		{
			// Is this score arbitrary?
			player_increase_score (game.level*3 + fruit.bonus);
			player_increase_size (2);
			fruit_init ();
		}

		if (player_hit_self () == TRUE)
			snake.is_alive = FALSE;

		if (player_collided_with_borders () == TRUE)
			snake.is_alive = FALSE;

		engine_show_screen ();
	}


	// Even though we have this here, the game always quits during
	// the main loop
	engine_exit ();
	nsnake_exit ();
	return 0;
}
예제 #7
0
파일: game.c 프로젝트: mjard/ShmupEngine
void 
shmup_game_update(shmup_game *g, double t, double dt)
{				
	
	bullet *b;
	static int mx, my;
	glfwGetMousePos(&mx, &my);
	g->emitter.x = (double) mx;
	g->emitter.y = (double) g->window_height-my;
	
	if (glfwGetMouseButton(GLFW_MOUSE_BUTTON_LEFT))
		shmup_game_fire(g, 40, 0, v2zero, v2zero, v2zero);
	
	if (glfwGetMouseButton(GLFW_MOUSE_BUTTON_RIGHT))
		shmup_game_fire(g, 40, 1, v2zero, v2zero, v2zero);
	
	if (glfwGetKey('1')) 
		g->render_type=1;
	
	if (glfwGetKey('2')) 
		g->render_type=2;
		
	player_update(g, &g->player[0], dt);
	/* 
	 * be careful with this pointer, as this data may be moved by the 
	 * bpool_resize function! Make sure it points to the right place.
	 */
	 
	b = g->bpool->bdata;
	
	/* do updates */
	for (int i=0; i < g->bpool->n_active; ++i) {
		bullet_update(&b[i], dt);
	}
	
	/* do collisions */
	for (int i=0; i < g->bpool->n_active; ++i) {
		
		if (!point_vs_aabb(b[i].pos, v2zero, v2(g->window_width, g->window_height)))
			bpool_deactivate(g->bpool, i--); 
	}	
}
예제 #8
0
파일: inputfd.c 프로젝트: JeroenDeDauw/teg
/* shows the status of the players */
TEG_STATUS clitok_status( char *str)
{
	CPLAYER j,*j_tmp;
	PARSER p;
	DELIM igualador={ ':', ':', ':' };
	DELIM separador={ '/', '/', '/' };

	int i;

	player_flush();

	if( strlen(str)==0 )
		goto ok;

	p.igualador = &igualador;
	p.separador = &separador;
	p.data = str;


	do {
		if( (i=parser_call( &p )) ) {
			if( aux_status( &j, p.token ) != TEG_STATUS_SUCCESS )
				goto error;

			if( player_whois( j.numjug, &j_tmp ) == TEG_STATUS_SUCCESS )
				player_update( &j );
			else
				player_ins( &j );
		}
	} while( i && p.hay_otro);
ok:
	gui_status();
	return TEG_STATUS_SUCCESS;
error:
	textmsg(M_ERR,"Error in clitok_status()");
	return TEG_STATUS_PARSEERROR;
}
예제 #9
0
파일: entities.c 프로젝트: jayschwa/q2pro
/*
==================
CL_DeltaFrame

A valid frame has been parsed.
==================
*/
void CL_DeltaFrame(void)
{
    centity_t           *ent;
    entity_state_t      *state;
    int                 i, j;
    int                 framenum;

    // getting a valid frame message ends the connection process
    if (cls.state == ca_precached)
        set_active_state();

    // set server time
    framenum = cl.frame.number - cl.serverdelta;
    cl.servertime = framenum * CL_FRAMETIME;
#if USE_FPS
    cl.keyservertime = (framenum / cl.framediv) * BASE_FRAMETIME;
#endif

    // rebuild the list of solid entities for this frame
    cl.numSolidEntities = 0;

    // initialize position of the player's own entity from playerstate.
    // this is needed in situations when player entity is invisible, but
    // server sends an effect referencing it's origin (such as MZ_LOGIN, etc)
    ent = &cl_entities[cl.frame.clientNum + 1];
    Com_PlayerToEntityState(&cl.frame.ps, &ent->current);

    for (i = 0; i < cl.frame.numEntities; i++) {
        j = (cl.frame.firstEntity + i) & PARSE_ENTITIES_MASK;
        state = &cl.entityStates[j];

        // set current and prev
        entity_update(state);

        // fire events
        entity_event(state->number);
    }

    if (cls.demo.recording && !cls.demo.paused && !cls.demo.seeking && CL_FRAMESYNC) {
        CL_EmitDemoFrame();
    }

    if (cls.demo.playback) {
        // this delta has nothing to do with local viewangles,
        // clear it to avoid interfering with demo freelook hack
        VectorClear(cl.frame.ps.pmove.delta_angles);
    }

    if (cl.oldframe.ps.pmove.pm_type != cl.frame.ps.pmove.pm_type) {
        IN_Activate();
    }

    player_update(&cl.oldframe, &cl.frame, 1);

#if USE_FPS
    if (CL_FRAMESYNC)
        player_update(&cl.oldkeyframe, &cl.keyframe, cl.framediv);
#endif

    CL_CheckPredictionError();

    SCR_SetCrosshairColor();
}
예제 #10
0
파일: game.c 프로젝트: RainbowLyte/ProjetC
void game_display(struct game* game) {
	assert(game);

	int map_w, map_h;

	window_clear();

	if(game->nb_player == 1) {
		map_w = map_get_width(level_get_curr_map(game->curr_level));
		map_h = map_get_height(level_get_curr_map(game->curr_level));
		for(int i = 0; i < map_w; i++)
			for(int j = 0; j < map_h+2; j++)
				window_display_image(sprite_get_empty(), i * SIZE_BLOC, j * SIZE_BLOC);
	}

	level_display(game_get_curr_level(game));

	monster_display(level_get_curr_map(game->curr_level));

	bomb_display(game, level_get_curr_map(game->curr_level));

	game_banner_display(game);

	if(game->nb_player == 1) { // Single player
		struct player* player = game->players[0];

		// Always display
		player_display(player);

		if(game->game_state == PLAYING) {
			player_move(game, player, level_get_curr_map(game->curr_level));
			monster_move(game, level_get_curr_map(game->curr_level), player);

			player_update(player);
			monster_update(level_get_curr_map(game->curr_level));
		}
	}
	else { // Multi player
		struct player* players_in_order[game->nb_player];
		for(int i=0; i<game->nb_player; i++)
			players_in_order[i] = game->players[i];
		game_order_players_array(game, players_in_order);

		for(int i = 0; i < game->nb_player; i++) {

			player_display(players_in_order[i]);

			if(game->game_state == PLAYING) {
				player_move(game, players_in_order[i], level_get_curr_map(game->curr_level));

				player_update(players_in_order[i]);
			}
		} // end for each player


	} // end Multi player

	if(game->game_state == PLAYING) {

		bomb_update(level_get_curr_map(game->curr_level));

	}
	else if(game->game_state == PAUSED) {
		map_w = map_get_width(level_get_curr_map(game->curr_level));
		map_h = map_get_height(level_get_curr_map(game->curr_level));
		int mid_w = map_w / 2 * SIZE_BLOC + map_w%2 * SIZE_BLOC / 2;
		int mid_h = map_h / 2 * SIZE_BLOC + map_h%2 * SIZE_BLOC / 2;
		menu_display(mid_w, mid_h);

	}
	window_refresh();
}
예제 #11
0
파일: skios.c 프로젝트: ryonagana/skios2
int game_loop(){


    unsigned redraw = 0;

    game_rect t;
    rect_Zero(&t);
    sprite_sheet = gamespr_create("ski1.bmp");

    animation_init();
    init_player();
    start_new_game(0);


    while(!mainloop){

        ALLEGRO_EVENT e;
        ALLEGRO_TIMEOUT timeout;
        int i;

        al_init_timeout(&timeout, 0.06);

        bool  late = al_wait_for_event_until(g_queue, &e, &timeout);





        if(late){
            switch(e.type){
                case ALLEGRO_EVENT_DISPLAY_CLOSE:
                    mainloop = 1;
                    break;

                 case ALLEGRO_EVENT_KEY_UP:
                        player_poll_kbd_up(&e);
                 break;

                 case ALLEGRO_EVENT_KEY_DOWN:
                        player_poll_kbd_dn(&e);
                 break;

                case ALLEGRO_EVENT_TIMER:

                /* main clock updates 1/60ms (60FPS LOCK) */
                    if(e.timer.source == g_timer){
                        particle_list = particles_clean(particle_list, 0);
                        particles_update(particle_list);
                        player_update_screen();
                        player_update(&ski_player, &playfield);



                        for(i = 1; i < MAX_SPRITES; i++){
                           update_enemy(i);
                        }

                        update_enemy_behavior(gobj_list, &playfield);

                        redraw =  1;
                    }

                     /* update for the chronomenter run every 100ms only) */
                    if( e.timer.source == timer_chrono){
                        HUD_UpdateChrono();
                        DMSG("%d", al_get_timer_count(timer_chrono));




                    }

                    break;
            }


            if( redraw == 1 && al_event_queue_is_empty(g_queue)){
                    redraw = 0;
                    al_clear_to_color(WHITE_COLOR);


                    particles_draw(NULL, particle_list);
                    player_draw(ski_player.object->position.x, ski_player.object->position.y );

                    for(i = 1; i < MAX_OBJECTS; i++){
                         int enemy_type = gobj_list[i].type;
                         draw_enemy(enemy_type, i, 0,0, gobj_list[i].position.x, gobj_list[i].position.y, 32,32);

                    }

                    HUD_create_stats_box();
                    al_flip_display();
            }
        }

    }

    HUD_destroy();
    unload_spritesheets();
    window_deinit();
    particle_list = particles_clean(particle_list, PARTICLES_ALL_CLEAN);
    return EXIT_SUCCESS;
}
예제 #12
0
파일: ifitron.c 프로젝트: QrshR/inf1060-he
int play_multiplayer(void) {
  int sd = connect_to_server();
  if(sd == -1) {
    ifitron_abort("Couldn't connect to the server.\n");
  }else
    set_client_socket_descriptor(sd);

  engine_init();
  engine_show_main_menu();
  
  //initiate
  multiplayer_init(get_tron());
  player_t *opponent = malloc(sizeof(player_t));
  
  if(opponent == NULL) {
    ifitron_abort("Error allocating memory for the opponent in play_multiplayer().\n");
  }
  
  multiplayer_init(opponent);
  
  if(send_game_init(sd, MULTIPLE_PLAYER_TYPE + (game.level - 1), 0, 
                    0, 0, 0, 0, tron.user_name) == -1) 
    ifitron_abort("send_game_init encountered an error.\n");
  
  //Receive init. In case someone initiated sooner and level is something other
  //than what this player requested.
  byte game_type;
  int x, y;
  int ox, oy;
  char buf[25];
  
  if(receive_game_init(sd, &game_type, &get_tron()->opponents,
                       &x, &y, &ox, &oy, buf) == -1) 
    ifitron_abort("Something went wrong receiving_game_init()\n");
    
  game.level = game_type - MULTIPLE_PLAYER_TYPE;
  player_increase_size(&tron, 1);
  update_player_coordinates(&tron, x, y); 
  
  player_increase_size(opponent, 1);
  update_player_coordinates(opponent, ox, oy);
  
  //wait for start.
  if(receive_game_start(sd) == -1) 
    ifitron_abort("Something went wrong receiving game start.\n");
  
  while(TRUE) {
    engine_get_game_input();
    
    player_increase_size(get_tron(), 1);
    player_update(get_tron());
    
    player_increase_score(get_tron(), game.level);
    
    if(tron.score % 50 == 0 && game.level < 9) game.level++;
    
    if(send_game_update(sd, get_tron()->body[0].x, get_tron()->body[0].y) == -1) 
      ifitron_abort("send_game_update encountered an error.\n");
    
    //Check if end or update is coming
    int size = 5;
    char buf[5];
    if(read(sd, buf, size) == -1) 
      ifitron_abort("Error reading end or update.\n");
    
    if(buf[2] == GAME_UPDATE) {
      player_increase_size(opponent, 1);
      update_player_coordinates(opponent, buf[3], buf[4]);
      player_increase_score(opponent, game.level);
      
    }else if(buf[2] == GAME_END) {
      //free opponent's memory
      if(opponent->body != NULL) 
        free(opponent->body);
      free(opponent);
      
      //close the connection
      close_server_connection(sd);
      ifitron_game_over();
      return 0;
    }
    //Draw the map with the players
    multiplayer_show_screen (opponent);
  }
}
예제 #13
0
/**
 * Update the state
 * 
 * @param  pGame The game's context
 * @return       GFMRV_OK, GFMRV_ARGUMENTS_BAD, ...
 */
gfmRV intro_update_game(gameCtx *pGame) {
    gfmRV rv;
    introCtx *pIntro;
    gfmInputState reset;
    int nreset;
    
    // Sanitize arguments
    ASSERT(pGame, GFMRV_ARGUMENTS_BAD);
    ASSERT(pGame->pState, GFMRV_ARGUMENTS_BAD);
    // Get the current state
    pIntro = (introCtx*)(pGame->pState);
    
    if (player_isAlive(pIntro->pPl) == GFMRV_FALSE) {
        pIntro->state = intro_gameover;
        rv = gfmText_setText(pGame->common.pText, docWin, strlen(docWin),
                1/*doCopy*/);
        ASSERT_NR(rv == GFMRV_OK);
    }
    else if (doc_isAlive(pIntro->pDoc) == GFMRV_FALSE) {
        pIntro->state = intro_gameover;
        rv = gfmText_setText(pGame->common.pText, dinoWin, strlen(dinoWin),
                1/*doCopy*/);
        ASSERT_NR(rv == GFMRV_OK);
    }
    
    rv = gfm_getKeyState(&reset, &nreset, pGame->pCtx, pGame->resetHnd);
    ASSERT_NR(rv == GFMRV_OK);
    if ((reset & gfmInput_justPressed) == gfmInput_justPressed) {
        pGame->state = state_reset;
        return GFMRV_OK;
    }
    
    // Update the player
    rv = player_update(pIntro->pPl, pGame);
    ASSERT_NR(rv == GFMRV_OK);
    // Update the doc
    rv = doc_update(pIntro->pDoc, pGame);
    ASSERT_NR(rv == GFMRV_OK);
    // Update the bullet
    rv = gfmSprite_update(pIntro->pBullet1, pGame->pCtx);
    ASSERT_NR(rv == GFMRV_OK);
    rv = gfmSprite_update(pIntro->pBullet2, pGame->pCtx);
    ASSERT_NR(rv == GFMRV_OK);
    
    // Collide everything
    do {
        int height, width;
        
        // Initialize the quadtree, making it a little bigger than the screen
        rv = gfm_getCameraDimensions(&width, &height, pGame->pCtx);
        ASSERT_NR(rv == GFMRV_OK);
        rv = gfmQuadtree_initRoot(pGame->common.pQt, -2/*x*/, -2/*y*/,
                width + 4, height + 4, 4/*maxDepth*/, 6/*maxNodes*/);
        ASSERT_NR(rv == GFMRV_OK);
        
        // Populate the quadtree with the tilemap's hitboxes
        rv = gfmQuadtree_populateTilemap(pGame->common.pQt,
                pGame->common.pTMap);
        ASSERT_NR(rv == GFMRV_OK);
        
        // Collides the player against the world
        rv =  player_collide(pIntro->pPl, pGame);
        ASSERT_NR(rv == GFMRV_OK);
        // Collides the doc against the world
        rv = doc_collide(pIntro->pDoc, pGame);
        ASSERT_NR(rv == GFMRV_OK);
        // Collide the bullet against the world
        rv = gfmQuadtree_collideSprite(pGame->common.pQt, pIntro->pBullet1);
        ASSERT_NR(rv == GFMRV_QUADTREE_OVERLAPED || rv == GFMRV_QUADTREE_DONE);
        // If a collision was detected, handle it and continue the operation
        if (rv == GFMRV_QUADTREE_OVERLAPED) {
            rv = collide(pGame->common.pQt);
            ASSERT_NR(rv == GFMRV_OK);
        }
        rv = gfmQuadtree_collideSprite(pGame->common.pQt, pIntro->pBullet2);
        ASSERT_NR(rv == GFMRV_QUADTREE_OVERLAPED || rv == GFMRV_QUADTREE_DONE);
        // If a collision was detected, handle it and continue the operation
        if (rv == GFMRV_QUADTREE_OVERLAPED) {
            rv = collide(pGame->common.pQt);
            ASSERT_NR(rv == GFMRV_OK);
        }
    } while (0);
    
    rv = GFMRV_OK;
__ret:
    return rv;
}
예제 #14
0
파일: game.c 프로젝트: rolfrm/Galaglitch
void game_iteration(controller controller, float dt, game_data * gd){
  physics_update(gd, dt);
  ai_update(gd, dt);
  player_update(gd, controller, dt);
}
예제 #15
0
/**
 * Update the current frame, as many times as it's accumulated
 */
static void ps_update() {
    GFraMe_event_update_begin();
        GFraMe_object *pObj;
        GFraMe_ret rv;
        int  h, w;
        
        if (gv_getValue(BOSS_ISDEAD) >= 4) {
            if (_timerTilCredits == 0) {
                timer_stop();
                audio_playVictory();
            }
            else if (_timerTilCredits > 5000) {
                _psRunning = 0;
            }
            _timerTilCredits += GFraMe_event_elapsed;
            if (_timerTilCredits >= 2000)
                return;
        }
        else if (gv_nIsZero(SWITCH_MAP)) {
            return;
        }
        else if (_ps_text) {
            textWnd_update(GFraMe_event_elapsed);
            return;
        }
        
#ifdef DEBUG
        _updCalls++;
#endif
        pObj = 0;
        
        // Check if any player should teleport
        player_checkTeleport(p1);
        player_checkTeleport(p2);
        
        // Update everything
        map_update(m, GFraMe_event_elapsed);
        rg_updateMobs(GFraMe_event_elapsed);
        rg_updateObjects(GFraMe_event_elapsed);
        rg_updateBullets(GFraMe_event_elapsed);
        player_update(p1, GFraMe_event_elapsed);
        player_update(p2, GFraMe_event_elapsed);
        ui_update(GFraMe_event_elapsed);
        signal_update(GFraMe_event_elapsed);
        
        // Collide everythin against everything else
        map_getDimensions(m, &w, &h);
        
        rv = qt_initCol(-8, -8, w + 16, h + 16);
        GFraMe_assertRet(rv == GFraMe_ret_ok, "Error initializing collision",
            __err_ret);
        
        rv = rg_qtAddWalls();
        GFraMe_assertRet(rv == GFraMe_ret_ok, "Error adding map to collision",
            __err_ret);
        
        rv = rg_qtAddObjects();
        GFraMe_assertRet(rv == GFraMe_ret_ok, "Error adding object to quadtree",
            __err_ret);
        
        rv = rg_qtAddMob();
        GFraMe_assertRet(rv == GFraMe_ret_ok, "Error adding mob to quadtree",
            __err_ret);
        
        rv = rg_qtAddEvents();
        GFraMe_assertRet(rv == GFraMe_ret_ok, "Error adding events to quadtree",
            __err_ret);
        
        rv = rg_qtAddBullets();
        GFraMe_assertRet(rv == GFraMe_ret_ok, "Error adding bullets to quadtree",
            __err_ret);
        
        rv = qt_addPl(p1);
        GFraMe_assertRet(rv == GFraMe_ret_ok, "Error adding player to quadtree",
            __err_ret);
        
        rv = qt_addPl(p2);
        GFraMe_assertRet(rv == GFraMe_ret_ok, "Error adding player to quadtree",
            __err_ret);
        
        // Collide both players, manually
        col_onPlayer(p1, p2);
        col_onPlayer(p2, p1);
        
        // Collide the carried player (if any) against the map
        if (player_isBeingCarried(p1))
            player_getObject(&pObj, p1);
        else if (player_isBeingCarried(p2))
            player_getObject(&pObj, p2);
        // Fix a bug that would let players clip into ceilings
        if (pObj)
            rg_collideObjWall(pObj);
        
        // Update camera
        cam_setPosition();
        
        // If the player is trying to switch maps, do it
        if (player_cmpDestMap(p1, p2) == GFraMe_ret_ok) {
            gv_setValue(SWITCH_MAP, 1);
            return;
        }
        
        if (!player_isAlive(p1) && !player_isInsideMap(p1)) {
            GFraMe_ret rv;
            
            // Recover previous state
            rv = gv_load(SAVEFILE);
            GFraMe_assertRet(rv == GFraMe_ret_ok, "Error loading map", __err_ret);
            // Increase death counter
            gv_inc(PL1_DEATH);
            // Save death counter
            gv_setValue(GAME_TIME, timer_getTime());
            rv = gv_save(SAVEFILE);
            GFraMe_assertRet(rv == GFraMe_ret_ok, "Error saving map", __err_ret);
            // Force reload
            gv_setValue(SWITCH_MAP, 1);
        }
        if (!player_isAlive(p2) && !player_isInsideMap(p2)) {
            GFraMe_ret rv;
            // Recover previous state
            rv = gv_load(SAVEFILE);
            GFraMe_assertRet(rv == GFraMe_ret_ok, "Error loading map", __err_ret);
            // Increase death counter
            gv_inc(PL2_DEATH);
            // Save death counter
            gv_setValue(GAME_TIME, timer_getTime());
            rv = gv_save(SAVEFILE);
            GFraMe_assertRet(rv == GFraMe_ret_ok, "Error saving map", __err_ret);
            // Force reload
            gv_setValue(SWITCH_MAP, 1);
        }
    GFraMe_event_update_end();
    
    return;
__err_ret:
    gl_running = 0;
    return;
}
예제 #16
0
파일: game.c 프로젝트: xymostech/FPSGame
void update() {
	player_selfupdate(my_player, my_world, my_server);
	player_update(my_player, my_world);
	world_update(my_world, my_server);
	server_handle_updates(my_server, my_player, my_world);
}
예제 #17
0
void 
shmup_game_update(shmup_game *g, double t, double dt)
{
	static int tick = 0;
	static int mx, my;
	int i;
	ENetEvent event;
	ENetPacket *packet;
	bullet *b;
	
	tick++;
	
	while (enet_host_service(g->host, &event, 0) > 0) {
		switch (event.type) {
			case ENET_EVENT_TYPE_CONNECT:
				printf("A new client connected from %x:%u.\n", 
					event.peer->address.host,
					event.peer->address.port);
				
//				sprintf(event.peer->data, "client %x.", event.peer->address.host);				
				g->player[g->num_players].pos = v2(g->window_width/2, g->window_height/2);
				g->player[g->num_players].vel = v2zero;
				g->player[g->num_players].acc = v2zero;
				g->num_players++;
				break;
			case ENET_EVENT_TYPE_RECEIVE:
				g->player[1].keyflags = (short) *event.packet->data;
//				event.packet->dataLength,
//				event.packet->data,
//				event.peer->data,
//				event.channelID);
				enet_packet_destroy(event.packet);
				break;				
			case ENET_EVENT_TYPE_DISCONNECT:
				printf("%s disconected.\n", event.peer->data);
				/* Reset the peer's client information. */				
				event.peer->data = NULL;
				break;
			case ENET_EVENT_TYPE_NONE:
				break;
		}
	}

	glfwGetMousePos(&mx, &my);
	g->emitter.x = (double) mx;
	g->emitter.y = (double) g->window_height-my;
	
	if (glfwGetMouseButton(GLFW_MOUSE_BUTTON_LEFT))
		shmup_game_fire(g, 40, 0, v2zero, v2zero, v2zero);
	
	if (glfwGetMouseButton(GLFW_MOUSE_BUTTON_RIGHT))
		shmup_game_fire(g, 40, 1, v2zero, v2zero, v2zero);
	
	if (glfwGetKey('1')) 
		g->render_type = 1;
	
	if (glfwGetKey('2')) 
		g->render_type = 2;
	
	g->player->keyflags = KF_NONE;
	if (glfwGetKey('A')) g->player->keyflags |= KF_MOV_L;
	if (glfwGetKey('D')) g->player->keyflags |= KF_MOV_R;
	if (glfwGetKey('W')) g->player->keyflags |= KF_MOV_U;
	if (glfwGetKey('S')) g->player->keyflags |= KF_MOV_D;
	if (glfwGetKey(GLFW_KEY_SPACE)) g->player->keyflags |= KF_FIR_1;
	
	for (i=0; i < g->num_players; i++) {
		player_update(g, &g->player[i], dt);
	}
		
	b = g->bpool->bdata;
	/* 
	 * be careful with this pointer, as this data may be moved by the 
	 * bpool_resize function! Make sure it points to the right place.
	 */	 
	
	/* do updates */
	for (i=0; i < g->bpool->n_active; i++) {
		bullet_update(&b[i], dt);
	}
	
	/* do collisions */
	for (i=0; i < g->bpool->n_active; i++) {		
		if (!point_vs_aabb(b[i].pos, v2zero, v2(g->window_width, g->window_height)))
			bpool_deactivate(g->bpool, i--); 
	}

	
	if (g->network_type == CLIENT) {
		packet = enet_packet_create(&g->player->keyflags, sizeof(short), ENET_PACKET_FLAG_RELIABLE);	
		enet_peer_send(g->peer, 0, packet);
	} else {
		packet = enet_packet_create(&g->player->keyflags, sizeof(short), ENET_PACKET_FLAG_RELIABLE);	
		enet_host_broadcast(g->host, 0, packet);
	}

}