[ Pobierz całość w formacie PDF ]
.zmap_sprite();xpos = (-si->orglng + blockade_frame->scenario()->platform(i).longitude()) * si->pixperlng *scale - spr->width() / 2;ypos = (si->orglat - blockade_frame->scenario()->platform(i).latitude()) * si->pixperlat *scale - spr->height() / 2;short xdel = xpos - spr->xpos();short ydel = ypos - spr->ypos();spr->move(xdel, ydel);}}}//--------------------------------------------------------------// MapWindow:: W M L B u t t o n D o w n// Handle button down events in this windowvoid MapWindow::WMLButtonDown(RTMessage msg){short x = msg.LP.Lo;short y = msg.LP.Hi;366 ChapterBLOCKADE A Game of Modern Naval Simulation9mouse_captured = 1;SetCapture(HWindow);xlast = x;ylast = y;spr_current = marker;if(zoomed) spr_current = zmarker;spr_current->active();spr_current->update();mouse_at(x,y);}//--------------------------------------------------------------// MapWindow:: W M M o u s e M o v e// Handle mouse movements in this windowvoid MapWindow::WMMouseMove(RTMessage msg){if(!mouse_captured) return;short x = msg.LP.Lo;short y = msg.LP.Hi;mouse_at(x,y);}//--------------------------------------------------------------// MapWindow:: W M L B u t t o n U p// Handle button up event.void MapWindow::WMLButtonUp(RTMessage msg){if(!mouse_captured) return;short x = msg.LP.Lo;short y = msg.LP.Hi;mouse_at(x,y);spr_current->inactive();Scenario::refresh = 1;spr_current = NULL;// Clear the status messageLPSTR msgtxt = blockade_frame->status_window()->get_msgbuf(1);msgtxt[0] =   ;msgtxt[1] =  \0 ;blockade_frame->status_window()->set_text(msgtxt, 1, 1);continues367 Programming Windows Games with Borland C++Listing 9.7.continued// Release the mouseReleaseCapture();mouse_captured = 0;}//--------------------------------------------------------------// MapWindow:: m o u s e _ a t// Display appropriate information for mouse at (x,y)void MapWindow::mouse_at(short x, short y){if(!mouse_captured) return;if(spr_current == NULL) return;ScenarioInfo *si = blockade_frame->scenario_info();Platform *po = blockade_frame->scenario()->our_ship();float scale = 1.0;if(zoomed) scale = si->mapzoom;// Convert (x,y) into (lng,lat)float lng = (anim->xbmp_origin() + x) / si->pixperlng /scale + si->orglng;float lat = - (anim->ybmp_origin() + y) / si->pixperlat /scale + si->orglat;// Find range from player s ship and the heading relative to// northfloat xdist = lng - po->longitude();float ydist = lat - po->latitude();float rng;float brg;if(xdist == 0 && ydist == 0){rng = 0;brg = 0;}else{rng = sqrt(xdist*xdist + ydist*ydist) * DEG2NM;brg = atan2(xdist, ydist) * RAD_TO_DEG;}if(brg name();LPSTR msgtxt = blockade_frame->status_window()->get_msgbuf(1);short len = sprintf(msgtxt, Platform: %s  Range: %.2f  Bearing: %.2f , nm, rng, brg);blockade_frame->status_window()->set_text(msgtxt, len, 1);// Move the marker spriteshort xdel = anim->xbmp_origin() + x- spr_current->xpos()- spr_current->width() / 2;short ydel = anim->ybmp_origin() + y- spr_current->ypos()- spr_current->height() / 2;spr_current->move(xdel, ydel);}//--------------------------------------------------------------// MapWindow:: p l a t f o r m _ a t// Find platform at specified positionPlatform* MapWindow::platform_at(float lat, float lng){int i, np = blockade_frame->scenario()->numplatform();Platform *rp = NULL;for(i = 0; i scenario()->platform(i));if(!p->is_active()) continue;Sprite *spr = p->map_sprite();if(zoomed) spr = p->zmap_sprite();if(!spr->is_active()) continue;if((fabs(lat - p->latitude()) longitude()) scenario()->make_sprites(hdc);The init function creates a TBStatic window where useful informationis displayed during the game.The PolarWindow class handles mouse button press events occurring inits window.The member function WMLButtonDown handles these events.When you press the left mouse button with the mouse pointer on thepolar view, Windows calls WMLButtonDown, which gets the coordinatesof the mouse, converts them to range and bearing, and calls theplatform_at function to determine the platform, if any, at that location.Then WMLButtonDown displays a marker at that point and a message in aTBStatic window showing the range and bearing from your ship to the370 ChapterBLOCKADE A Game of Modern Naval Simulation9location of the button press and the name of the platform, if any, atthat location.The disp_mission function is called by init to display a description ofthe current mission.This text is loaded by the Scenario::init functionand kept in the static array Scenario::mission_description.The draw_wpncover function is used as a callback function by a spritethat displays the sectors where the current weapon can be used [ Pobierz całość w formacie PDF ]

  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • funlifepok.htw.pl
  •