Example #1
0
/* Draw the level bar in the middle of level selection screen */
static void draw_level_bar(SDL_Surface *surface, struct dllist *thumbnails,
        int offset) {
    struct dllist *ptr;
    SDL_Rect bar;
    int x,y;

    bar.x = 0; bar.w=screen->w;
    bar.y = screen->h/2 - BAR_HEIGHT/2; bar.h = BAR_HEIGHT;

    SDL_FillRect(surface,&bar,SDL_MapRGB(surface->format,220,220,220));

    /* Draw the selected level */
    x = bar.x + bar.w/2 - level_width(thumbnails->data) + offset;
    y = bar.y+bar.h/2 - THUMBNAIL_HEIGHT/2;
    x += draw_level(surface,thumbnails->data,x,y,bar.x+bar.w-x,1) + THUMBNAIL_SEP;

    /* Draw levels to the right of the selection */
    ptr = thumbnails->next;
    while(ptr && x<bar.x + bar.w) {
        int visible = bar.x + bar.w - x;
        x += draw_level(surface,ptr->data,x,y,visible,0) + THUMBNAIL_SEP;
        ptr=ptr->next;
    }

    /* Draw the levels to the left of the selection */
    ptr = thumbnails->prev;
    x = bar.x + bar.w/2 - level_width(thumbnails->data) + offset;
    while(ptr) {
        int curwidth = level_width(ptr->data);
        x -= curwidth + THUMBNAIL_SEP;
        if(x+curwidth < bar.x) break;
        draw_level(surface,ptr->data,x,y,x+curwidth-bar.x,0);
        ptr = ptr->prev;
    }
}
Example #2
0
bool Game::is_it_reachable(const AxisAlignedBoundingBox& box) const
{
	return detect_collision(AxisAlignedBoundingBox(Zespolona(0, std::numeric_limits<double>::infinity()),
	                                               Zespolona(level_width(), pozycja_gracza().imag() - 400)),
	                        box);
}
Example #3
0
AxisAlignedBoundingBox Game::current_game_area_hitbox() const
{
	return AxisAlignedBoundingBox(Zespolona(0, pozycja_gracza().imag() + 800), Zespolona(level_width(), pozycja_gracza().imag() - 400));
}
Example #4
0
/* Level selection screen. Returns the selected level or NULL if cancelled */
struct LevelFile *select_level(int fade) {
    struct dllist *levels;
    struct LevelFile *selection=NULL;
    SDL_Event event;
    int loop=1,animate=0;
    Uint32 lasttime=0;
    char roundstr[32];

    levels = randomize_level(get_level_thumbnails());

    /* Draw the screen */
    sprintf(roundstr,"Round %d of %d",game_status.total_rounds + 1,
                     game_settings.rounds + game_status.total_rounds);
    if(luola_options.mbg_anim && fade) {
        SDL_Surface *tmp = make_surface(screen,0,0);
        draw_header(tmp,roundstr);
        draw_level_bar(tmp,levels,0);
        fade_from_black(tmp);
        SDL_FreeSurface(tmp);
    } else {
        memset(screen->pixels,0,screen->pitch*screen->h);
        draw_header(screen,roundstr);
        draw_level_bar(screen,levels,0);
        SDL_UpdateRect(screen,0,0,0,0);
    }

    /* Level selection event loop */
    while(loop) {
        enum {DO_NOTHING,MOVE_LEFT,MOVE_RIGHT,CHOOSE,CANCEL} cmd = DO_NOTHING;
        if(animate) {
            if(SDL_PollEvent(&event)==0)
                event.type = SDL_NOEVENT;
        } else {
            SDL_WaitEvent(&event);
        }
        /* Handle event */
        switch(event.type) {
            case SDL_KEYDOWN:
                if (event.key.keysym.sym == SDLK_F11)
                    screenshot ();
                else if (event.key.keysym.sym == SDLK_LEFT)
                    cmd = MOVE_LEFT;
                else if (event.key.keysym.sym == SDLK_RIGHT)
                    cmd = MOVE_RIGHT;
                else if (event.key.keysym.sym == SDLK_ESCAPE)
                    cmd = CANCEL;
                else if(event.key.keysym.sym == SDLK_RETURN) {
                    if((event.key.keysym.mod & (KMOD_LALT|KMOD_RALT)))
                        toggle_fullscreen();
                    else
                        cmd = CHOOSE;
                }
                break;
            case SDL_JOYBUTTONUP:
            case SDL_JOYBUTTONDOWN:
                joystick_button (&event.jbutton);
                break;
            case SDL_JOYAXISMOTION:
                joystick_motion (&event.jaxis, 0);
                break;
            case SDL_QUIT:
                exit(0);
            default:
                break;
        }
        /* Handle action */
        switch(cmd) {
            case DO_NOTHING:
                break;
            case MOVE_LEFT:
                if(levels->prev) {
                    if(luola_options.mbg_anim)
                        animate -= level_width(levels->data) + THUMBNAIL_SEP;
                    levels = levels->prev;
                } else cmd = DO_NOTHING;
                break;
            case MOVE_RIGHT:
                if(levels->next) {
                    levels = levels->next;
                    if(luola_options.mbg_anim)
                        animate += level_width(levels->data) + THUMBNAIL_SEP;
                } else cmd = DO_NOTHING;
                break;
            case CHOOSE:
                selection = ((struct LevelThumbnail*)levels->data)->file;
                loop=0;
                break;
            case CANCEL:
                selection = NULL;
                loop=0;
                break;
        }
        if(cmd == MOVE_LEFT || cmd==MOVE_RIGHT || animate) {
            if(animate!=0) {
                int delta=abs(animate)/16+1;
                lasttime = SDL_GetTicks();
                if(animate<0)
                    animate += delta;
                else
                    animate -= delta;
            }
            draw_level_bar(screen,levels,animate);
            SDL_UpdateRect(screen,0,screen->h/2 - BAR_HEIGHT/2,
                    screen->w,BAR_HEIGHT);
        }

        if (animate) {
            Uint32 delay = SDL_GetTicks () - lasttime;
            if (delay >= GAME_SPEED)
                delay = 0;
            else
                delay = GAME_SPEED - delay;
            SDL_Delay (delay);
        }

    }

    dllist_free(levels,free_level_thumbnail);
    return selection;
}