int cl_change_map(char *map_name, int gamemode) { client.screenpos.x = 0; client.screenpos.y = 0; client.health = 0; /* To make sure statusbar updates */ client.map_target_active = 0; draw_load_screen(client.loadscreen); /* Load the map */ if( !(map = map_load(client.map, L_BASE|L_OBJECT|L_TOPLEVEL|L_TEXT, MAP))){ printf("** ERROR LOADING MAP %s! **\n", client.map); cl_network_disconnect(); client.state = MENU; /* Go back to menu */ return 0; } /* Load tileset and store pixmap id's in tileset tables */ maptext_init(map->text_root); tileset_load(map->tileset); preload_entities(map_name, gamemode); client.state = GAME_JOIN; /* Status of JOINING on the server */ cl_netmsg_send_ready(); /* Request to be ACTIVE on the server */ cl_net_finish(); /* Clear the map buffer if map doesn't take up the entire buffer as there will still be stuff there from the last map */ if( map->width < client.view_w || map->height < client.view_h ) clear_area(win.map_buf, 0, 0, client.view_w, client.view_h, "black"); return 1; }
/* load the images with the right scaleing */ void game_start () { int p, i; menu_displaytext ("Loading..", "Please Wait"); bman.players_nr_s = 0; bman.playnum += 1; for (p = 0; p < MAX_PLAYERS; p++) { if (PS_IS_used (players[p].state)) { bman.players_nr_s++; if (players[p].gfx_nr == -1) { players[p].gfx = NULL; players[p].state &= (0xff - (PSF_alife + PSF_playing)); } else { players[p].state |= PSF_alife + PSF_playing; players[p].gfx = &gfx.players[players[p].gfx_nr]; } } else players[p].state = 0; players[p].bombs_n = bman.start_bombs; players[p].range = bman.start_range; players[p].speed = bman.start_speed; players[p].collect_shoes = 0; players[p].special.type = SP_nothing; players[p].special.use = 0; players[p].special.clear = 0; players[p].m = 0; players[p].old.x = 0; players[p].old.y = 0; bman.updatestatusbar = 1; players[p].frame = 0.0f; players[p].d = 0; players[p].pos.x = 0.0; players[p].pos.y = 0.0; players[p].tunnelto = 0.0f; players[p].ready = 0; // add reset nbrKilled value players[p].nbrKilled = 0; /* all types of illnes turn them off */ for (i = 0; i < PI_max; i++) players[p].ill[i].to = 0.0f; // reset bombs for (i = 0; i < MAX_BOMBS; i++) { players[p].bombs[i].state = BS_off; players[p].bombs[i].ex_nr = -1; players[p].bombs[i].fdata = 0; players[p].bombs[i].dest.x = 0; players[p].bombs[i].dest.y = 0; players[p].bombs[i].mode = BM_normal; players[p].bombs[i].id.p = p; players[p].bombs[i].id.pIgnition = p; players[p].bombs[i].id.b = i; players[p].pos.x = 0; players[p].pos.x = 0; } } flitems_reset (); init_map_tileset (); tileset_load (map.tileset, -1, -1); gfx_load_players (gfx.block.x, gfx.block.y); snd_load (map.tileset); snd_music_start (); map.state = MS_normal; bman.timeout = bman.init_timeout; s_calctimesync (); // to clean up the timesyc s_calctimesync (); // data run this twice if (GT_MP_PTPM) net_send_servermode (); };
int main(int argc, char* argv[]) { // our demo variables World* demoworld = 0; Camera* democamera = 0; Tileset* demotileset = 0; Renderer* demorenderer = 0; // init SDL if (SDL_Init(SDL_INIT_EVERYTHING) < 0) { fprintf(stderr, "SDL Library Initialization Failed!\n\tSDL Error: %s\n", SDL_GetError()); exit(1); } atexit(SDL_Quit); // create the window if (!SDL_SetVideoMode(SCREEN_W, SCREEN_H, SCREEN_BPP, SDL_HWSURFACE | SDL_DOUBLEBUF)) { fprintf(stderr, "SDL Screen Initialization Failed! %dx%d@%dbpp\nSDL Error: %s\n", SCREEN_W, SCREEN_H, SCREEN_BPP, SDL_GetError()); exit(1); } // set the window caption SDL_WM_SetCaption("Basic SDL Map Editor Example Demo -- by Richard Marks <*****@*****.**>", 0); // create our keyboard handler Keyboard* keyboard = keyboard_create(); // load the world demoworld = world_load("example_demo.map"); if (!demoworld) { fprintf(stderr, "unable to load the world file!\n"); exit(1); } // load the tileset demotileset = tileset_load("example_demo.png", 32, 32); if (!demotileset) { fprintf(stderr, "unable to load the tileset file!\n"); exit(1); } // create the camera democamera = camera_create( // anchor position of the camera is at 32,32 on the screen 32, 32, // the camera view is 30 x 22 tiles 30, 22, // need to tell the camera the size of the tiles demotileset->width, demotileset->height); // create the renderer demorenderer = renderer_create(demoworld, demotileset, democamera); // pre-render the scene renderer_pre_render(demorenderer); fprintf(stderr, "\nstarting main loop...\n\n"); // start the main loop SDL_Event event; bool running = true; int startticks = SDL_GetTicks(); int mainlooptimer = SDL_GetTicks(); while(running) { // check for our window being closed while(SDL_PollEvent(&event)) { if (SDL_QUIT == event.type) { running = false; } } // update our keyboard handler keyboard_update(keyboard); // start timing our code startticks = SDL_GetTicks(); // check for our controls // ESC and Q quits if (keyboard->key[SDLK_ESCAPE] || keyboard->key[SDLK_q]) { running = false; } const unsigned int CAMERASPEED = 16; // W and up arrow if (keyboard->key[SDLK_w] || keyboard->key[SDLK_UP]) { if (democamera->inpixels->y > 0) { democamera->inpixels->y -= CAMERASPEED; } } // S and down arrow if (keyboard->key[SDLK_s] || keyboard->key[SDLK_DOWN]) { if (democamera->inpixels->y < demorenderer->scene->h - democamera->inpixels->h) { democamera->inpixels->y += CAMERASPEED; } } // A and left arrow if (keyboard->key[SDLK_a] || keyboard->key[SDLK_LEFT]) { if (democamera->inpixels->x > 0) { democamera->inpixels->x -= CAMERASPEED; } } // D and right arrow if (keyboard->key[SDLK_d] || keyboard->key[SDLK_RIGHT]) { if (democamera->inpixels->x < demorenderer->scene->w - democamera->inpixels->w) { democamera->inpixels->x += CAMERASPEED; } } // render our scene renderer_render(demorenderer); // flip our double buffer SDL_Flip(SDL_GetVideoSurface()); // lock our framerate to roughly 30 FPS int tickdiff = SDL_GetTicks() - startticks; if (tickdiff < 33) { SDL_Delay(33 - tickdiff); } } int tickdiff = SDL_GetTicks() - mainlooptimer; fprintf(stderr, "finished after %d ticks!\n\n", tickdiff); // destroy our pointers tileset_destroy(demotileset); renderer_destroy(demorenderer); world_destroy(demoworld); camera_destroy(democamera); keyboard_destroy(keyboard); return 0; }