Beispiel #1
0
int main(int argc, char **argv)
{
    SDL_Surface *screen, *background,
                *pause_text, *press_enter_text, *game_over_text;

    const SDL_VideoInfo *video_info;
    Uint32 frame_start, frame_end = 0, game_frame_end = 0;

    systems_init();

    screen = SDL_SetVideoMode(800, 600, 0, SDL_HWSURFACE|SDL_DOUBLEBUF);
    video_info = SDL_GetVideoInfo();

    create_images(&press_enter_text, &pause_text, &game_over_text, &background);
    create_entities();

    for(;;) {
        start_frame(&frame_start, &frame_end);

        if(check_SDL_events())
            break;

        draw_background(background, screen, video_info);

        update_entities(game_frame_end  );

        if(is_paused()) {
            if(is_game_over()) {
                draw_centered(screen, video_info, game_over_text);
            } else if(is_started()) {
                draw_centered(screen, video_info, pause_text);
            } else {
                draw_centered(screen, video_info, press_enter_text);
            }
        }

        SDL_Flip(screen);

        finish_frame(&frame_start, &frame_end, &game_frame_end);
    }

    SDL_FreeSurface(background);
    SDL_FreeSurface(pause_text);
    SDL_FreeSurface(press_enter_text);

    systems_shutdown();
    return 0;
}
Beispiel #2
0
void
draw_highscore_table(float base_x, float base_y, float spread)
{
	int i, t;
	const int item_height = 3*fri->char_height/2;
	const int viewport_width = 800;
	const int viewport_height = 600;
	static const int column_limit[] = {
		.5*80,		/* ordinal */
		.5*280,		/* name */
		.5*460,		/* score */
		.5*640,		/* wave */
		.5*800,		/* rank */
	};
	static const char *ordinal[] = {
		"1ST", "2ND", "3RD", "4TH", "5TH",
		"6TH", "7TH", "8TH", "9TH", "10TH" };
	float y;
	const float SPREAD_FUDGE = 25;

	glPushAttrib(GL_ALL_ATTRIB_BITS);

	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	glLoadIdentity();
	glOrtho(0.f, viewport_width, viewport_height, 0.f, -1.f, 1.f);

	glMatrixMode(GL_MODELVIEW);
        glPushMatrix();
        glLoadIdentity();

	glColor3f(.8, .8, 1.);

#define CALC_Y(n) \
	y = base_y + (n)*item_height - spread*SPREAD_FUDGE*((NUM_HIGHSCORES + 3) - (n));

	CALC_Y(0)

	draw_centered(base_x, base_x + column_limit[4],
	  y, "* * *   H A L L   O F   F A M E   * * *");

	CALC_Y(2)

	draw_centered(base_x + column_limit[0], base_x + column_limit[1],
	  y, "NAME");
	draw_centered(base_x + column_limit[1], base_x + column_limit[2],
	  y, "SCORE");
	draw_centered(base_x + column_limit[2], base_x + column_limit[3],
	  y, "LEVEL");
	draw_centered(base_x + column_limit[3], base_x + column_limit[4],
	  y, "RANK");

	t = get_cur_ticks(); /* the purpose of which will be apparent momentarily. */

	for (i = 0; i < NUM_HIGHSCORES; i++) {
		const struct rank *r = score_to_rank(highscore_table[i].score);

		CALC_Y(i + 3)

		if (i == last_highscore) {
			float s = .5f + .5f*sin(.2f*t); /* ... there you go. */
			glColor3f(s*.6 + (1.f - s), s*.6 + (1.f - s), 1.);
		} else {
			glColor3f(.6, .6, 1.);
		}

		draw_right_justified(base_x + column_limit[0], y, "%s",
		  ordinal[i]);

		/* name */
		draw_centered(base_x + column_limit[0],
		  base_x + column_limit[1], y, "%s",
		  highscore_table[i].name);

		/* score */
		draw_score(base_x + column_limit[2], y,
		  highscore_table[i].score);

		/* wave */
		draw_centered(base_x + column_limit[2],
		  base_x + column_limit[3], y, "%d/%d",
		  highscore_table[i].level,
		  highscore_table[i].wave);

		/* rank */
		glColor3f(r->color[0], r->color[1], r->color[2]);
		draw_centered(base_x + column_limit[3],
		  base_x + column_limit[4], y, r->description);

		y += item_height;
	}

	glMatrixMode(GL_MODELVIEW);
	glPopMatrix();

	glMatrixMode(GL_PROJECTION);
	glPopMatrix();

	glMatrixMode(GL_MODELVIEW);

	glPopAttrib();
}
void tower::draw() const {
    unsigned int hoffset=get_bitmap_height(attributes->bitmap)/2;
    draw_centered(attributes->bitmap,position.first,position.second-hoffset);
}