void game_init(int ai) { static int once = 1; int x, y; BITMAP *tmp; int bc = makecol(200, 150, 50); clear_to_color(screen, makecol(0, 0, 0)); textout_centre(screen, font, "Generating&Caching Data", SCREEN_W / 2, 0, -1); textout_centre(screen, font, "May take a while", SCREEN_W / 2, SCREEN_H / 2, -1); textout_centre(screen, font, "(about 10 minutes for first run,", SCREEN_W / 2, SCREEN_H / 2 + 20, -1); textout_centre(screen, font, "about 1 minute every first game,", SCREEN_W / 2, SCREEN_H / 2 + 40, -1); textout_centre(screen, font, "few seconds else)", SCREEN_W / 2, SCREEN_H / 2 + 60, -1); if (once) { once = 0; animdata[0] = load_gfx("gravburn", 48); animdata[1] = load_gfx("shock", 48); animdata[2] = load_gfx("fireball", 48); animdata[3] = load_gfx("wheel", 48); animdata[4] = load_gfx("glow", 32); { int a; for (a = 0; a < ANIMS; a++) { anim[a] = 0; animlen[a] = dat_length(animdata[a]); } } tower = dat[TOWER_BMP].dat; explosion = dat[EXPLOSION_WAV].dat; radiating = dat[RADIATING_WAV].dat; teleport = dat[TELEPORT_WAV].dat; bonus = dat[BONUS_WAV].dat; nuclearegg = dat[NUCLEAREGG_BMP].dat; launcher = dat[LAUNCHER_BMP].dat; bonuspic[0] = dat[BONUS0_BMP].dat; bonuspic[1] = dat[BONUS1_BMP].dat; bonuspic[2] = dat[BONUS2_BMP].dat; map = create_bitmap(SCREEN_W, SCREEN_H); } ignore[0] = 0; ignore[1] = 0; think[0] = 0; think[1] = 0; memorized[0] = 0; memorized[1] = 0; AI[0] = 0; if (ai) AI[1] = 1; else AI[1] = 0; power[0] = 0; power[1] = 0; bonusnum = 0; life[0] = 100; life[1] = 100; go = 0; turn = 0; tmp = create_bitmap_ex(32, SCREEN_W, SCREEN_H); draw_back(tmp); for (y = 0; y < 16; y++) { for (x = 0; x < 16; x++) { hills[y][x] = rnd(); } } basex[0] = 4 * TW + TW / 2; basey[0] = 4 * TH + TH / 2; basex[1] = 12 * TW + TW / 2; basey[1] = 12 * TH + TH / 2; hills[4][4] = 1; hills[5][4] = 1; hills[5][5] = 1; hills[4][5] = 1; hills[12][12] = 1; hills[13][12] = 1; hills[13][13] = 1; hills[12][13] = 1; x = rnd() * 16; y = rnd() * 16; for (y = 0; y < MH; y++) { for (x = 0; x < MW; x++) { int c = 0; int t; float height = get_height(x, y); float h = 0, z = height * ZZZ; for (h = height, t = 0; z > 0 && t < 2; z--, h -= 1.0 / (float)ZZZ, t++) { int r, g, b; float l; if (h < 0.2) { float p = h / 0.2; r = 0; g = 100 * p; b = 155 + 100 * p; } else if (h < 0.5) { float p = (h - 0.2) / 0.3; r = 0; g = 100 + 155 * p; b = 255 - 155 * p; } else if (h < 0.8) { float p = (h - 0.5) / 0.3; r = 200 * p; g = 255 - 155 * p; b = 100; } else { float p = (h - 0.8) / 0.2; r = 200; g = 100 + 100 * p; b = 100 + 100 * p; } l = get_height(x + 1, y) - get_height(x, y + 1); r = r + l * 2000 + (rnd() - 0.5) * 20; g = g + l * 2000 + (rnd() - 0.5) * 20; b = b + l * 2000 + (rnd() - 0.5) * 20; c = makecol32(M(r), M(g), M(b)); if (y == MH - 1 && h < height) c = bc; putpixel(tmp, 88 + x, y + WINT - z, c); } } } { float filter[3][3] = { {0.025, 0.145, 0.025}, {0.145, 0.320, 0.145}, {0.025, 0.145, 0.025} }; for (y = 0; y < SCREEN_H; y++) { for (x = 0; x < SCREEN_W; x++) { int i = 0, j = 0; float r = 0, g = 0, b = 0; for (i = -1; i <= 1; i++) { for (j = -1; j <= 1; j++) { int c = getpixel(tmp, x + j, y + i); if (c < 0) c = makecol32(0, 0, 0); r += getr32(c) * filter[1 + i][1 + j]; g += getg32(c) * filter[1 + i][1 + j]; b += getb32(c) * filter[1 + i][1 + j]; } } putpixel(map, x, y, makecol(r, g, b)); } } } destroy_bitmap(tmp); ballx = 240; bally = 240; balldx = 0; balldy = 0; }
void install() { if(!load_pal("data/game.pal",game_pal)) { printf("Error - Couldn't load game palette !\n"); exit(-1); } if(!(font = create_font())) { printf("Error - Couldn't create FONT structure !\n"); exit(-1); } if(!load_fnt("data/font.fnt",font)) { printf("Error - Couldn't load game font !\n"); exit(-1); } if(!(screen_buffer = create_bitmap(320,200))) { printf("Error - Couldn't create screen buffer !\n"); exit(-1); } if(!(court = create_bitmap(1,1))) { close13h(); printf("Error - Couldn't create bitmap !\n"); exit(-1); } if(!load_gfx("data/court.gfx",court)) { close13h(); printf("Error - Couldn't load bitmap !\n"); exit(-1); } if(!(logo = create_bitmap(1,1))) { close13h(); printf("Error - Couldn't create bitmap !\n"); exit(-1); } if(!load_gfx("data/pong.gfx",logo)) { close13h(); printf("Error - Couldn't load bitmap !\n"); exit(-1); } if(!(logo_c = create_bitmap(1,1))) { close13h(); printf("Error - Couldn't create bitmap !\n"); exit(-1); } if(!load_gfx("data/pong_c.gfx",logo_c)) { close13h(); printf("Error - Couldn't load bitmap !\n"); exit(-1); } if(!(bar_left = create_bitmap(1,1))) { close13h(); printf("Error - Couldn't create bitmap !\n"); exit(-1); } if(!load_gfx("data/bar_l.gfx",bar_left)) { close13h(); printf("Error - Couldn't load bitmap !\n"); exit(-1); } if(!(bar_right = create_bitmap(1,1))) { close13h(); printf("Error - Couldn't create bitmap !\n"); exit(-1); } if(!load_gfx("data/bar_r.gfx",bar_right)) { close13h(); printf("Error - Couldn't load bitmap !\n"); exit(-1); } if(!(ball[0] = create_bitmap(1,1))) { close13h(); printf("Error - Couldn't create bitmap !\n"); exit(-1); } if(!load_gfx("data/ball1.gfx",ball[0])) { close13h(); printf("Error - Couldn't load bitmap !\n"); exit(-1); } if(!(ball[1] = create_bitmap(1,1))) { close13h(); printf("Error - Couldn't create bitmap !\n"); exit(-1); } if(!load_gfx("data/ball2.gfx",ball[1])) { close13h(); printf("Error - Couldn't load bitmap !\n"); exit(-1); } init13h(); install_keyboard(); install_timer(MS2D(10),timer); set_palette(game_pal); clear_bitmap(screen_buffer,0); draw_screen_buffer(screen_buffer); }
int main(int argc, char *argv[]) { if (argc != 2) { printf("Usage: %s file.cgl\n", argv[0]); exit(-1); } SDL_Surface *screen; SDL_Surface *gfx = load_gfx("data/GRAVITY.GFX"); if (!gfx) { fprintf(stderr, "read_gfx: %s\n", SDL_GetError()); abort(); } SDL_Surface *png = load_png("font.png"); if (!png) { fprintf(stderr, "load_png: %s\n", SDL_GetError()); abort(); } SDL_Surface *osd = load_png("osd.png"); if (!osd) { fprintf(stderr, "load_png: %s\n", SDL_GetError()); abort(); } struct cgl *cgl = read_cgl(argv[1], NULL); if (!cgl) { fprintf(stderr, "read_cgl: %s\n", SDL_GetError()); abort(); } cgl_preprocess(cgl); cg_init(cgl); make_collision_map(gfx, cmap); if (SDL_Init(SDL_INIT_VIDEO) != 0) { fprintf(stderr, "SDL failed: %s\n", SDL_GetError()); abort(); } screen = SDL_SetVideoMode(SCREEN_W, SCREEN_H, 0, MODE); gl_resize_viewport(screen->w, screen->h); struct texmgr *ttm = tm_request_texture(gfx); struct texmgr *fnt = tm_request_texture(png); struct texmgr *otm = tm_request_texture(osd); gl_init(cgl, ttm, fnt, otm); int t = SDL_GetTicks(), nt = t, time = t, fr = 0; running = 1; mouse = 0; SDL_Event e; while (running) { while (SDL_PollEvent(&e)) process_event(&e); time = SDL_GetTicks(); nt = time - t; cg_step(cgl, time / 1000.0); if (nt > 100) { printf("%d frames in %d ms - %.1f fps\n", gl.frame - fr, nt, (float)(gl.frame - fr) / nt * 1000); if (cgl->status == Lost) printf("Dead. Game over!"); if (cgl->status == Victory) printf("You won!"); fflush(stdout); t += nt; fr = gl.frame; } gl.cam.nx = cgl->ship->x + SHIP_W/2.0; gl.cam.ny = cgl->ship->y + SHIP_H/2.0; gl_update_window(time / 1000.0); } free_cgl(cgl); return 0; }