Ejemplo n.º 1
0
static void stop_timer(int id, float dt)
{
    float g[3] = { 0.f, 0.f, 0.f };

    game_update_view(dt);
    game_step(g, dt);

    if (time_state() > 1)
    {
        if (hole_next())
            goto_state(&st_next);
        else
            goto_state(&st_score);
    }
}
Ejemplo n.º 2
0
static void stroke_timer(int id, float dt)
{
    float g[3] = { 0.f, 0.f, 0.f };

    float k;

    if (SDL_GetModState() & KMOD_SHIFT ||
        (joystick && SDL_JoystickGetButton(joystick,
                                           config_get_d(CONFIG_JOYSTICK_BUTTON_B))))
        k = 0.25;
    else
        k = 1.0;

    game_set_rot(stroke_rotate * k);
    game_set_mag(stroke_mag * k);

    game_update_view(dt);
    game_step(g, dt);
}
Ejemplo n.º 3
0
int main(void)
{
    if(SysTick_Config(SYSCLK/TICKS_PER_SECOND)) { //if systick config fails
        while(1); //sleep forever
    }

    game_init(&gameobj, TICKS_PER_SECOND); //Init game state

    while(1) {
        uint64_t curTicks = ticks;
        if(game_step(&gameobj,curTicks-lastTicks)) { //calculate next game step, and pass it the delta time. Returns true if function was blocking
            lastTicks = ticks; //Save actual ticks
        } else {
            lastTicks = curTicks; //Save ticks from before calling game_step
        }
    }

	return 0;
}
Ejemplo n.º 4
0
/*
** This is the process spawned by pthread_create, into which we pass StateInfo.
** Using pthread_self, we relocate the appropriate instance and set up some
** variables for the game, log some stuff to log, send a welcome message, etc.
** We then enter the main game loop, waiting for messages from the client
** which we then handle with game_step. Once the game ends, we remove the
** appropriate instance, close the socket and print to log before finally
** exiting the thread.
*/
void *run_instance(void *param)
{
    /*
    ** Because we can only pass one thing into this function, we pass the
    ** thing with the greatest amount of useful info, the Instances struct. 
    ** We then find  again the target Instance by using the thread_id, 
    ** which we can find out using pthread_self() passed to get_instance().
    */
    StateInfo *state_info = (StateInfo*)param;
    Instance *instance = get_instance(state_info, pthread_self());
    char *correct = instance->code;

    int sock_id = instance->s;
    char *ip4 = instance->ip4;

    char log_buf[LOG_MSG_LEN];

    send_welcome(sock_id);

    // Add our own sentinel for printing purposes.
    char msg[CODE_LENGTH+1];
    
    // Main game loop. We don't have to worry about the len that recv returns
    // because we know we will get 4 chars and these are all that concern us.
    while (recv(sock_id, &msg, CODE_LENGTH, 0))
    {
        msg[CODE_LENGTH] = '\0';
        if (game_step(msg, correct, instance) == 0)
            break;
    }

    remove_instance(state_info, instance->t);
    close(sock_id);
    
    sprintf(log_buf, "(%s)(%d) Client disconnected.\n", ip4, sock_id);
    write_log(log_buf);

    pthread_exit(NULL);
}
Ejemplo n.º 5
0
void game_loop(void) {
    game_update();
    game_draw();
    if (stat == STAT_PLAYING) game_step();
}