📄 staker.m
字号:
function staker
%STAKER Starts a game of Staker.
% See file 'help.txt' for complete game information.
% FOR EDITING PURPOSES:
% The nesting order of functions is as follows:
%
% staker
% initialize_intro
% callback_intro
% initialize_main
% update_main
% callback_main
% initialize_profile
% update_profile
% callback_profile
% create_profile
% callback_create
% shop_armory
% callback_shop
% edit_preferences
% callback_edit
% generate_terrain
% add_terrain
% initialize_game
% update_game
% callback_game
% update_barrel
% resize_game
% mouse_game
% activate_mouse
% track_mouse
% update_pointer
% generate_terrain_edges
% update_limits
% update_controls
% update_compass
% post_message
% render_bomb
% render_explosion
% end_game
% callback_end
% display_quit
% callback_quit
% display_help
% callback_help
% bomb_error
% callback_error
% add_game_data
% update_game_data
% reset_game_data
% game2str
% num2arsenal
% make_axes
% make_button
% make_check
% make_edit
% make_figure
% make_list
% make_menu
% make_panel
% make_slider
% make_text
% plot_line
% plot_patch
% plot_surface
% plot_text
% default_preferences
% default_player_data
% initialize_bomb_data
% staker_data
% air_density
% water_density
% num2money
% str2rgb
% within_axes
% normrand
% unit
% cross
% rotation_matrix
%
% Author: Ken Eaton
% Last modified: 3/31/08
%--------------------------------------------------------------------------
% Make sure Staker hasn't been started yet:
currentSetting = get(0,'ShowHiddenHandles');
set(0,'ShowHiddenHandles','on');
if (~isempty(findobj('Tag','STAKER_INTRO','-or','Tag','STAKER_MAIN'))),
disp('Staker has already been started.');
set(0,'ShowHiddenHandles',currentSetting);
return;
end
set(0,'ShowHiddenHandles',currentSetting);
% Initialize constants shared across nested functions:
BOMB_VERSION = '0.5';
MAX_CHARS = 23;
MAX_PLAYERS = 2;
BOMB_DATA = initialize_bomb_data;
N_BOMBS = length(BOMB_DATA);
MAX_BOMBS = 20;
LOCATION_LIST = {'Highlands'};
N_MAP = 101;
MAP_LIMIT = 16000; % ft
HORIZON_LIMIT = 10*MAP_LIMIT; % ft
MAP_DELTA = 2*MAP_LIMIT/(N_MAP-1); % ft
MIN_HEIGHT = -5000; % ft
MAX_HEIGHT = 29000; % ft (above sea level)
SLOPE_LIMIT = 1; % ft/ft
TREE_LINE = 10000; % ft (above sea level)
SNOW_LINE = 18000; % ft (above sea level)
MIN_ORBIT_ANGLE = pi/40; % radians
MAX_ORBIT_ANGLE = 19*pi/40; % radians
MAX_ROTATION_ANGLE = atan(MAP_LIMIT/(sqrt(3)*(MAP_LIMIT+50))); % radians
CAMERA_RADIUS = 2*MAP_LIMIT/sin(MAX_ROTATION_ANGLE); % ft
MIN_VIEW_ANGLE = 1; % degrees
MAX_VIEW_ANGLE = 30; % degrees
CAMERA_DEFAULT = {CAMERA_RADIUS.*...
[sqrt(2).*cos(pi/12).*[-0.5 -0.5] sin(pi/12)],...
CAMERA_RADIUS.*sqrt(1-cos(0.1)).*...
[sin(pi/12-0.05).*[1 1] sqrt(2)*cos(pi/12-0.05)],...
[sqrt(2).*sin(pi/12-0.1).*[0.5 0.5] cos(pi/12-0.1)],...
MAX_VIEW_ANGLE};
MAX_MUZZLE_VELOCITY = 3000; % ft/sec
G = [0 0 -32.17405]; % ft/sec^2
MAX_DELTA_T = 0.25*MAP_DELTA/MAX_MUZZLE_VELOCITY; % sec
SCALE_DELTA_T = 0.25;
N_BLAST = 50;
N_IMAGE = 1000;
N_PIXELS = N_IMAGE^2;
SCREEN_SIZE = get(0,'ScreenSize');
[stackTrace,stackIndex] = dbstack('-completenames');
STAKER_PATH = fileparts(stackTrace(stackIndex).file);
TEXTURE_PATH = fullfile(STAKER_PATH,'textures');
STATUS_FILE = fullfile(STAKER_PATH,'status.stkr');
STATUS_FIELDS = {'version'; 'preferences'; 'suspendedGames'; ...
'nGamesPlayed'};
PROFILE_FIELDS = {'version'; 'ID'; 'file'; 'name'; 'earnings'; ...
'record'; 'class'; 'unlocked'; 'arsenal'; 'used'; ...
'isCurrent'; 'capacity'; 'position'; 'settings'; ...
'camera'};
% Initialize variables shared across nested functions:
currentGame = 0;
profiles = cell(1,MAX_PLAYERS);
players = [];
nPlayers = 0;
currentPlayer = 0;
nMoves = 0;
hMain = [];
updateMainFcn = [];
hGame = [];
updateGameFcn = [];
locationIndex = 1;
locationValue = [];
mapGenerationState = [];
mapX = [];
mapY = [];
mapZ = [];
mapC = [];
horizonZ = [];
edgeColor = [];
isWater = false;
waterLevel = [];
windVector = [];
timeOfDay = [];
% Initialize game status and preferences:
rand('twister',sum(100.*clock));
if exist(STATUS_FILE,'file'),
try
status = load(STATUS_FILE,'-mat');
catch
bomb_error([],'corruptedFile','status.stkr');
return;
end
if (~isequal(fieldnames(status),STATUS_FIELDS)),
bomb_error([],'badFileContents','status.stkr','.stkr');
return;
end
else
status = struct('version',BOMB_VERSION,...
'preferences',default_preferences,...
'suspendedGames',[],'nGamesPlayed',0);
save(STATUS_FILE,'-struct','status','-mat');
end
fontName = status.preferences.fontName;
fontSize = status.preferences.fontSize;
textColor = status.preferences.textColor;
backColor = status.preferences.backColor;
panelColor = status.preferences.panelColor;
accentColor = status.preferences.accentColor;
sliderColor = status.preferences.sliderColor;
azimuthGain = status.preferences.azimuthGain;
elevationGain = status.preferences.elevationGain;
rotationGain = status.preferences.rotationGain;
zoomGain = status.preferences.zoomGain;
useLocalTime = status.preferences.useLocalTime;
trajectoryStep = status.preferences.trajectoryStep;
blastStep = status.preferences.blastStep;
% Display game introduction:
initialize_intro;
%~~~Begin nested functions~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
%------------------------------------------------------------------------
function initialize_intro
%
% Initializes the introduction figure window.
%
%------------------------------------------------------------------------
% Create introduction text:
introText = {'"A new start..."','',...
[' In a not-too-distant, clich',char(233),' ',...
'future, the Earth becomes uninhabitable. Desperate ',...
'to survive, humans spread throughout the solar ',...
'system, forming colonies on Mars, Europa, and ',...
'numerous other worlds. With time, the Earth once ',...
'again becomes suitable for life, and so begins the ',...
'rush to recolonize! Numerous government, ',...
'corporate, and freelance organizations fight to ',...
'stake their claim, battling tooth and nail to ',...
'secure any and all plots of land they can.'],'',...
'Do you have the skill to win back the world?'};
% Create introduction figure window:
hFigure = make_figure([1+(SCREEN_SIZE(3:4)-[300 300])./2 300 300],...
'CloseRequestFcn',@callback_intro,...
'Name',['Staker v',BOMB_VERSION],...
'Tag','STAKER_INTRO');
% Create uicontrol objects:
make_panel(hFigure,[1 1 300 300]);
make_panel(hFigure,[10 45 282 247],'BackgroundColor',backColor,...
'BorderType','beveledin');
hText = make_text(hFigure,[11 46 280 245],...
'BackgroundColor',backColor,'FontWeight','normal',...
'String','');
introText = textwrap(hText,introText);
introText = sprintf('%s\n',introText{:});
make_button(hFigure,[216 11 75 25],'Callback',@callback_intro,...
'String','Continue','Tag','CONTINUE');
timerIntro = timer('BusyMode','queue','ExecutionMode','fixedRate',...
'ObjectVisibility','off','Period',0.05,...
'Tag','TIMER','TasksToExecute',length(introText),...
'TimerFcn',@callback_intro);
% Start introduction:
set(hFigure,'Visible','on');
drawnow;
start(timerIntro);
%----------------------------------------------------------------------
function callback_intro(source,event)
%
% Callback function for introduction uicontrols.
%
%----------------------------------------------------------------------
switch get(source,'Tag'),
case {'CONTINUE','STAKER_INTRO'},
stop(timerIntro);
delete(timerIntro);
delete(hFigure);
drawnow;
initialize_main;
set(hMain,'Visible','on');
drawnow;
case 'TIMER',
set(hText,'String',introText(1:get(timerIntro,'TasksExecuted')));
drawnow;
end
end
end
%------------------------------------------------------------------------
function initialize_main
%
% Initializes the main menu figure window.
%
%------------------------------------------------------------------------
% Create main menu figure window:
updateMainFcn = @update_main;
hMain = make_figure([1+(SCREEN_SIZE(3:4)-[390 445])./2 390 445],...
'CloseRequestFcn',@callback_main,...
'Name',['Staker v',BOMB_VERSION,' Main Menu'],...
'Tag','STAKER_MAIN');
% Create suspended game panel:
make_panel(hMain,[1 386 390 60]);
make_text(hMain,[11 416 140 20],'String','Suspended games:');
hSuspended = make_menu(hMain,[21 396 350 20],...
'Callback',@callback_main,...
'String',[{'none'}; game2str],...
'Tag','SUSPENDED');
% Create location panel:
make_panel(hMain,[1 326 390 60]);
make_text(hMain,[11 356 140 20],'String','Location:');
hLocation = make_menu(hMain,[21 336 100 20],...
'Callback',@callback_main,...
'String',[{'none'; 'random'}; LOCATION_LIST],...
'Tag','LOCATION');
% Create profile panel:
make_panel(hMain,[1 46 390 280]);
make_text(hMain,[11 296 140 20],'String','Player profiles:');
updateProfileFcns = cell(1,MAX_PLAYERS);
initialize_profile(1);
initialize_profile(2);
% Create button panel:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -