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建模师
- 粉丝: 3642
- 资源: 2807
最新资源
- 基于javaweb的网上拍卖系统,采用Spring + SpringMvc+Mysql + Hibernate+ JSP技术
- polygon-mumbai
- Chrome代理 switchyOmega
- GVC-全球价值链参与地位指数,基于ICIO表,(Wang等 2017a)计算方法
- 易语言ADS指纹浏览器管理工具
- 易语言奇易模块5.3.6
- cad定制家具平面图工具-(FG)门板覆盖柜体
- asp.net 原生js代码及HTML实现多文件分片上传功能(自定义上传文件大小、文件上传类型)
- whl@pip install pyaudio ERROR: Failed building wheel for pyaudio
- Constantsfd密钥和权限集合.kt
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈