function galactic(cmd)
%GALACTIC Galactic game
%
% To play this game, type: GALACTIC
%
% Controls:
% Mouse Control ship
% Left click Shoot
% Ctrl+P Pause
%
% During the game, use the game menu to set difficulty and to
% enable/disable sound effects. Only one game can run at a time.
% Galactic was written and tested on Matlab 5.3 (R11), but may
% work with as early as Matlab 5.0 without changes.
%
% This game may be too computationally intense for slower systems.
% Minimum system recommendation: 600 MHz CPU
% Pascal Getreuer 2004-2006
global MODE IMG MAP TSTEP NLIVE GAME SPR SSPR SPRP SPRT ...
HFIG HMENU SNDTMR SND;
ImgX = 80;
ImgY = 120;
if nargin < 1|cmd == 6
ClkV = [0;0;86400;3600;60;1];
KPts([6,7,4,5,8,9,10,11,12]) ...
= [25,25,100,100,40,40,175,400,400];
if nargin == 0
GameInit(ImgY);
HFIG = figure('Name','Galactic','Numbertitle','off','Menubar','none',...
'Color',[0.3 0.3 0.3],'Resize','off','DoubleBuffer','on',...
'Position',[150,150,250,350],'CloseRequestFcn',[mfilename,'(-1)'],...
'Pointer','circle');
tmp = uimenu('Label','&Game');
HMENU(1) = uimenu(tmp,'Label','&Pause');
uimenu(tmp,'Label','&Stop','Callback',[mfilename,'(8)']);
HMENU(2) = uimenu(tmp,'Label','&Beginner','Callback',[mfilename,'(10)'],...
'Separator','on','Checked','on');
HMENU(3) = uimenu(tmp,'Label','&Intermediate','Callback',[mfilename,'(11)']);
HMENU(4) = uimenu(tmp,'Label','&Expert','Callback',[mfilename,'(12)']);
HMENU(5) = uimenu(tmp,'Label','&Custom...','Callback',[mfilename,'(13)']);
HMENU(6) = uimenu(tmp,'Label','S&ound','Callback',[mfilename,'(14)'],'Checked','on','Separator','on');
uimenu(tmp,'Label','&Highscores...','Separator','on','Callback',[mfilename,'(15)']);
uimenu(tmp,'Label','E&xit','Callback',[mfilename,'(-1)'],'Separator','on');
tmp = uimenu('Label','&Help');
uimenu(tmp,'Label','Help &Notes','Callback',['global MODE;if ~MODE,',...
mfilename,'(7);end;msgbox({''Controls:'',',...
''' Mouse Control ship'','' Click Shoot'','''',',...
''' Ctrl+P Pause/Unpause'','''',''Game Options (under game menu):'',',...
''' * Choose beginner, intermediate, expert, or custom difficulty'','' * ',...
'Enable/disable sound effects''},''Help Notes'')']);
uimenu(tmp,'Label','&M-File Info','Callback',['help ',mfilename]);
uimenu(tmp,'Label','&About Galactic','Separator','on','Callback',['global MODE;',...
'if ~MODE,',mfilename,'(7);end;msgbox(''Written by Pascal Getreuer, ',...
'August 2004.'',''About Galactic'')']);
colormap([0,0,0;1,1,1;0.6,0.6,1;0.4,0.4,0.7;1,1,0;0,0.5,0.5;1,0,1;0,1,1;1,0,0;0.4,0.6,0;1,1,1;0,0,0.5]);
set(HFIG,'Position',[150,150,250,350]);
IMG = zeros(ImgY,ImgX);
MAP = IMG;
SPRP = [ImgX/2,ImgY-8,1;1,0,0;floor(rand(1)*(ImgX-20))+2,35,1];
SPRT = [1;2;6];
MODE = 0;
GAME = [0,4];
TSTEP = 0.04;
NLIVE = -1;
drawnow;
tmp = repmat([1,2,3,2,3,6,4,10,9,14,11,16]/11,650,1);
sound(cos((1:7800)'/6).*sin((1:7800)'.*tmp(:))/3,11025);
SNDTMR = (clock)*ClkV+0.76;
set(HFIG,'WindowButtonMotionFcn',[mfilename,'(1)'],'WindowButtonDownFcn',[mfilename,'(5)']);
end
set(HMENU(1),'Label','&Pause','Callback',[mfilename,'(7)'],'Accelerator','P');
feval(mfilename,4);
while ~MODE
FrameStart = (clock)*ClkV;
if NLIVE > 1
NLIVE = NLIVE-1;
if NLIVE == 1
set(HFIG,'WindowButtonDownFcn',[mfilename,'(5)']);
feval(mfilename,4);
end;
end
IMG(:) = 0;
MAP(:) = 0;
SInd = (SPRP(:,1)-1)*ImgY+SPRP(:,2);
for k = length(SPRT):-1:1
IMG(SSPR{SPRT(k)}+SInd(k)) = SPR{SPRT(k)};
MAP(SSPR{SPRT(k)}+SInd(k)) = k;
end
i = find(SPRT == 13);
SPRInd = MAP((SPRP(i,1)-1)*ImgY+SPRP(i,2));
j = find(SPRInd);
if ~isempty(j)
SPRInd = SPRInd(j);
DelSPR = i(SPRT(SPRInd) == 17);
j = find(SPRT(SPRInd) >= 4&SPRT(SPRInd) <= 12);
if ~isempty(j)
DelSPR = [DelSPR;i(j)];
SPRInd = SPRInd(j);
k = find(SPRT(SPRInd) >= 5&SPRT(SPRInd) <= 9);
GAME(1) = GAME(1)+sum(KPts(SPRT(SPRInd(k))));
SPRT(SPRInd(k)) = 21;
k = find(SPRT(SPRInd) == 4);
SPRT(SPRInd(k)) = 5;
k = find(SPRT(SPRInd) >= 10&SPRT(SPRInd) <= 12);
if ~isempty(k)
SPRP(SPRInd(k),3) = SPRP(SPRInd(k),3)-1;
SPRT(SPRInd(k(find(SPRP(SPRInd(k),3) == 4&SPRT(SPRInd(k)) == 11)))) = 12;
k = k(find(SPRP(SPRInd(k),3) <= 0));
j = SPRInd(k);
GAME(1) = GAME(1)+sum(KPts(SPRT(j)));
SPRT(j) = 21;
SPRP(j,:) = SPRP(j,:)+repmat([4,2,0],length(j),1);
SPRP = [SPRP;SPRP(j,:)+repmat([5,0,0],length(j),1)];
SPRT = [SPRT;SPRT(j)];
end
feval(mfilename,4);
end
if ~isempty(DelSPR)
SPRT(DelSPR) = [];
SPRP(DelSPR,:) = [];
i = find(SPRT == 13);
end
end
SPRP(i,2) = SPRP(i,2)-5;
j = i(find(SPRP(i,2) <= 0));
SPRT(j) = [];
SPRP(j,:) = [];
i = find(SPRT >= 14&SPRT <= 16);
SInd = (SPRP(i,1)-1)*ImgY+SPRP(i,2);
j = find(SPRT >= 17);
k = (SPRP(j,1)-1)*ImgY+SPRP(j,2);
if (~isempty(i)&any(MAP(SInd+1+ImgY) == 1))|...
(~isempty(j)&any(MAP([k+4;k+8*ImgY+4;k+4*ImgY+9]) == 1))
SPRT(1) = 1;
SPRT = [SPRT;18];
SPRP(length(SPRT),:) = SPRP(1,:);
set(HFIG,'WindowButtonDownFcn',[mfilename,'(0)']);
GAME(2) = GAME(2)-1;
feval(mfilename,4);
if ~isinf(SNDTMR)
WaitSnd;
sound(SND{4},11025);
SNDTMR = (clock)*ClkV+0.37;
end
end
if ~isempty(i)
SPRP(i,1) = SPRP(i,1)+SPRT(i)-14-1;
SPRP(i,2) = SPRP(i,2)+2;
j = i(SPRP(i,2) > ImgY-3|SPRP(i,1) < 1|SPRP(i,1) > ImgX-3);
SPRT(j) = [];
SPRP(j,:) = [];
end
i = find(SPRT == 17);
SInd = (SPRP(i,1)-1)*ImgY+SPRP(i,2);
if ~isempty(i)
SPRP(i,2) = SPRP(i,2)+2;
j = i(SPRP(i,2) > ImgY-9);
SPRT(j) = [];
SPRP(j,:) = [];
end
i = find(SPRT == 23);
SPRT(i) = [];
SPRP(i,:) = [];
SPRT(SPRT == 22) = 23;
i = find(SPRT == 21);
SPRT(i) = 22;
if ~isempty(i)&(clock)*ClkV > SNDTMR
sound(SND{1},11025);
SNDTMR = (clock)*ClkV+0.05;
end
i = find(SPRT == 20);
if ~isempty(i)
SPRT(i) = [];
SPRP(i,:) = [];
if GAME(2) >= 0
NLIVE = 25;
else
feval(mfilename,8);
end
end
i = find(SPRT == 19);
SPRT(i) = 20;
i = find(SPRT == 18);
SPRT(i) = 19;
if (length(SPRT) < 3|rand(1) < 0.03)&~NLIVE
i = sum(SPRT >= 6&SPRT <= 11);
j = rand(1);
if j < 0.56&i < 12
SPRT = [SPRT;6];
SPRP(length(SPRT),:) = floor([rand(1)*(ImgX-15)+2,rand(1)*50+2,1]);
if (clock)*ClkV > SNDTMR
sound(SND{2},11025);
SNDTMR = (clock)*ClkV+0.28;
end
elseif j < 0.72&i < 8&GAME(1) > 100
SPRT = [SPRT;4];
SPRP(length(SPRT),:) = floor([rand(1)*(ImgX-15)+2,rand(1)*50+2,1]);
if (clock)*ClkV > SNDTMR
sound(SND{2},11025);
SNDTMR = (clock)*ClkV+0.28;
end
elseif j < 0.87&i < 10
SPRT = [SPRT;8];
SPRP(length(SPRT),:) = floor([rand(1)*(ImgX-15)+2,rand(1)*50+2,1]);
if (clock)*ClkV > SNDTMR
sound(SND{2},11025);
SNDTMR = (clock)*ClkV+0.28;
end
elseif sum(SPRT >= 10&SPRT <= 12) <= 1
if j < 0.92&i < 15&GAME(1) > 2500
SPRT = [SPRT;11];
SPRP(length(SPRT),:) = floor([rand(1)*(ImgX-27)+2,rand(1)*50+2,8]);
if (clock)*ClkV > SNDTMR
sound(SND{3},11025);
SNDTMR = (clock)*ClkV+0.37;
end
elseif i > 1&GAME(1) > 600
SPRT = [SPRT;10];
SPRP(length(SPRT),:) = floor([rand(1)*(ImgX-24)+2,rand(1)*50+2,4]);
if (clock)*ClkV > SNDTMR
sound(SND{3},11025);
SNDTMR = (clock)*ClkV+0.37;
end
end
end
end
i = find(SPRT == 6|SPRT == 7);
if ~isempty(i)
SPRP(i,1) = min(max(SPRP(i,1)+floor(rand(length(i),1)*3)-1,1),ImgX-11);
SPRP(i,2) = min(max(SPRP(i,2)+floor(rand(length(i),1)*3)-1,1),ImgY-40);
if rand(1) < 0.01*length(i)&~NLIVE
j = 1+round(rand(1)*(length(i)-1));
SPRT = [SPRT;14+2*round(rand(1))];
SPRP(length(SPRT),:) = SPRP(i(j),:)+[5,6,0];
end
SPRT(i) = min(max(round(SPRT(i)+rand(length(i),1)*1.2-0.6),6),7);
end
i = find(SPRT == 4|SPRT == 5);
Dir = sign(SPRP(1,1)-SPRP(i,1)-3);
SPRP(i,1) = min(max(SPRP(i,1)+floor(rand(length(i),1)*7)-3+Dir,1),ImgX-9);
SPRP(i,2) = min(max(SPRP(i,2)+floor(rand(length(i),1)*3)-1,1),ImgY-40);
if rand(1) < 0.05*length(i)&~NLIVE
j = 1+round(rand(1)*(length(i)-1));
SPRT = [SPRT;14+round(2*rand(2,1))];
SPRP(length(SPRT)+(-1:0),:) = [SPRP(i(j),:);SPRP(i(j),:)]+[5,10,0;5,10,0];
end
i = find(SPRT == 8|SPRT == 9);
if ~isempty(i)
SPRP(i,1) = min(max(SPRP(i,1)+floor(rand(length(i),1)*5)-2,1),ImgX-8


阿里matlab建模师
- 粉丝: 5004
- 资源: 2908
最新资源
- 中风风险预测数据集(70K记录,18特征)CSV
- 2024 年电子游戏销售数据集( 64,000 款游戏,14特征)CSV
- 龙珠数据集(用于问答项目,13K+文件)TXT
- 美国住房数据集(300 行 10 列房地产相关数据)CSV
- 每日食品与营养数据集( 1000 个独特用户的 10000 条食物摄入量数据记录,14特征)CSV
- 基于MATLAB的智能抠图系统:GUI界面与两万字详解文档,基于MATLAB的智能抠图系统:GUI界面与两万字详解文档,基于MATLAB的抠图系统+GUI界面+两万字文档 本程序利用基于学习的抠图方法
- 视觉识别windows程序
- FactoryIO液位PID仿真程序入门指南:使用TIA Portal V15与FactoryIO 2.4.0的梯形图编程实践,FactoryIO液位PID仿真程序:西门子TIA Portal V15
- filezilla服务器和客户端安装包,用于做文件传输测试等
- 内外网DeepSeek部署实战:基于Ollama的多客户端集成与安全强化方案
- PPTFancyScrollView
- Matlab遗传算法实现无人机协同任务分配方案优化:最小代价下的高效路径选择与时间分配策略,基于遗传算法优化无人机任务分配方案:航程与耗时双重考量,matlab:基于遗传算法的多无人机协同任务分配
- 基于西门子PLC与组态王技术,设计八层电梯电气控制系统:智能控制界面与组态画面动画实现,基于西门子PLC与组态王画面的八层电梯电气控制系统设计与动画展示,76#基于西门子plc和组态王八层电梯控制8层
- 内网AI知识库构建:DeepSeek离线部署全攻略,涵盖国产化适配与安全加固
- 基于MATLAB的模拟退火算法优化车辆路径问题的研究:位置定位下的最短路径选择及运输成本最低方案,基于Matlab的模拟退火算法优化VRP路径规划系统:最短路径与成本最低的车辆调度方案,基于matla
- 《互联网时代的项目管理》读书分享PPT
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈


