<em>Mac</em>Book项目 2009年学校开始实施<em>Mac</em>Book项目,所有师生配备一本<em>Mac</em>Book,并同步更新了校园无线网络。学校每周进行电脑技术更新,每月发送技术支持资料,极大改变了教学及学习方式。因此2011
2021-06-01 09:32:01
按上下左右鍵(↑↓←→)移動物塊
按AD鍵轉動視角
遊戲效果:如圖所示原本無法通過的路徑經過視角調整即可通過
完整程式碼
function maze4 global maze; global GUI; global role; GUI.fig=figure('units','pixels',... 'position',[350 100 500 500],... 'Numbertitle','off',... 'name','maze',... 'Color',[0 0 0],... 'resize','off'); % 'menubar','none',... GUI.axes=axes('Units','pixels',... 'parent',GUI.fig,... 'Color',[0.05 0.05 0.05],... 'Position',[0 0 500 500],... 'Box','on', ... 'XLim',[0 10],... 'YLim',[0 10],... 'ZLim',[-1 8],... 'XColor',[0.05 0.05 0.05],... 'YColor',[0.05 0.05 0.05],... 'ZColor',[0.05 0.05 0.05],... 'xtick',[],'ytick',[],'ztick',[]); hold on;axis equal plotcube([10 10,0.5],[0 0 -0.5],1,[0.85 0.85 0.87]); maze.layer0.map=ones(10,10); maze.layer1.map=[0 0 0 0 0 0 0 0 0 0; 0 0 0 0 0 0 1 0 0 0; 0 0 0 0 0 0 0 0 0 0; 0 0 0 0 0 1 0 0 0 0; 0 0 0 0 0 0 0 0 0 0; 0 0 0 1 0 0 0 0 0 0; 0 0 0 0 0 0 0 0 0 0; 0 0 0 0 0 0 0 0 0 1; 0 0 0 0 0 0 0 0 0 0; 0 0 1 0 0 0 0 1 0 0]; maze.layer2.map=[0 0 0 0 0 0 0 0 0 0; 0 0 0 0 0 0 1 0 0 0; 0 0 0 0 0 1 0 0 0 0; 0 0 0 0 0 0 0 0 0 0; 0 1 1 0 0 0 0 0 0 0; 0 0 1 1 0 0 0 0 0 0; 0 0 0 0 0 0 0 0 0 0; 0 0 0 0 0 0 0 0 0 1; 0 0 0 0 0 0 0 0 0 0; 0 0 1 0 0 0 0 1 0 0]; maze.layer3.map=[0 0 0 0 0 0 0 0 0 0; 0 0 0 0 0 1 1 0 0 0; 0 0 0 0 0 0 0 0 0 0; 0 0 0 0 0 0 0 0 0 0; 0 0 0 0 0 0 0 0 0 0; 0 0 0 1 0 0 0 0 0 0; 0 0 0 0 0 0 0 0 0 0; 0 0 0 0 0 0 0 0 0 1; 0 0 0 0 0 0 0 0 0 0; 0 0 1 0 0 0 0 1 0 0]; maze.layer4.map=[0 0 0 0 0 0 0 0 0 1; 0 0 0 0 0 0 1 0 0 1; 0 0 0 0 0 0 0 0 0 1; 0 0 0 0 0 0 0 0 0 0; 0 0 0 0 0 0 0 0 0 0; 0 0 0 0 0 0 0 0 1 0; 0 0 0 0 0 0 0 0 0 0; 1 0 0 0 0 0 0 0 0 1; 0 0 0 0 0 0 0 0 0 0; 0 0 1 0 0 0 0 1 0 0]; maze.layer5.map=[0 0 0 0 0 0 0 0 0 1; 0 0 0 0 0 0 0 0 0 1; 0 0 0 0 0 0 0 0 0 0; 0 0 0 0 0 0 0 0 0 0; 0 0 0 0 0 0 0 0 1 0; 0 0 0 0 0 0 0 0 1 0; 0 0 0 0 0 0 0 0 0 0; 0 0 0 0 0 0 0 0 0 1; 1 0 0 0 0 0 0 0 0 0; 0 1 0 0 0 0 0 1 0 0]; maze.layer6.map=[0 0 0 0 0 0 0 0 0 1; 1 1 1 0 0 0 0 0 0 0; 1 0 0 0 0 0 0 0 0 0; 1 0 0 0 0 1 0 0 0 0; 1 1 0 0 0 1 0 0 0 0; 0 0 0 0 0 1 0 0 0 1; 0 0 0 0 0 1 0 0 0 1; 0 0 0 0 1 0 0 1 0 1; 0 0 0 0 1 0 0 1 0 0; 1 0 0 0 1 1 1 1 0 0]; maze.layer7.map=zeros(10,10); maze.layer8.map=zeros(10,10); for i=1:6 [x,y]=find(maze.(['layer',num2str(i)]).map==1); maze.(['layer',num2str(i)]).cube.num=sum(sum(maze.(['layer',num2str(i)]).map)); maze.(['layer',num2str(i)]).cube.pos=[x,y,ones(maze.(['layer',num2str(i)]).cube.num,1).*i]; maze.(['layer',num2str(i)]).cube.color=[0.85 0.85 0.95]; maze.(['layer',num2str(i)]).cube.size=[1 1 1]; maze.(['layer',num2str(i)]).cube.alpha=1; tempSize =maze.(['layer',num2str(i)]).cube.size; tempPos =maze.(['layer',num2str(i)]).cube.pos; tempAlpha=maze.(['layer',num2str(i)]).cube.alpha; tempColor=maze.(['layer',num2str(i)]).cube.color; tempNum =maze.(['layer',num2str(i)]).cube.num; arrayfun(@(i)plotcube(tempSize,tempPos(i,:)-tempSize,tempAlpha,tempColor),1:tempNum); end ax=GUI.axes; ax.CameraPosition=[39.4959 -29.1496 71.8289]; maze.scene=0; moveDirect=[-1 0 0;0 1 0;1 0 0;0 -1 0]; role.pos=[1,1,1]; role.cubex=[0 1 1 0 0 0;1 1 0 0 1 1;1 1 0 0 1 1;0 1 1 0 0 0]; role.cubey=[0 0 1 0 0 0;0 1 1 1 0 0;0 1 1 1 1 1;0 0 1 0 1 1]; role.cubez=[0 0 0 0 0 1;0 0 0 0 0 1;1 1 1 1 0 1;1 1 1 1 0 1]; fill3(role.cubex+role.pos(1)-1,... role.cubey+role.pos(2)-1,... role.cubez+role.pos(3)-1,[0.65 0.65 0.87],'tag','role') fill3(role.cubex+1-1,... role.cubey+10-1,... role.cubez+7-1,[0.85 0.65 0.67]) while(0) pause(2) disp(ax.CameraPosition) end set(gcf, 'KeyPressFcn', @key); function key(~,event) tempRolePos=role.pos; switch event.Key case 'uparrow',tempRolePos=role.pos+moveDirect(1,:); case 'rightarrow',tempRolePos=role.pos+moveDirect(2,:); case 'downarrow',tempRolePos=role.pos+moveDirect(3,:); case 'leftarrow',tempRolePos=role.pos+moveDirect(4,:); case 'a' for j=1:30 pause(0.02) tempCamPos=ax.CameraPosition; ax.CameraPosition(1)=tempCamPos(1)*cos(pi/60)-tempCamPos(2)*sin(pi/60); ax.CameraPosition(2)=tempCamPos(1)*sin(pi/60)+tempCamPos(2)*cos(pi/60); end maze.scene=mod(maze.scene+1,4); moveDirect=[moveDirect(end,:);moveDirect(1:3,:)]; case 'd' for j=1:30 pause(0.02) tempCamPos=ax.CameraPosition; ax.CameraPosition(1)=tempCamPos(1)*cos(-pi/60)-tempCamPos(2)*sin(-pi/60); ax.CameraPosition(2)=tempCamPos(1)*sin(-pi/60)+tempCamPos(2)*cos(-pi/60); end maze.scene=mod(maze.scene+3,4); moveDirect=[moveDirect(2:end,:);moveDirect(1,:)]; end switch maze.scene case 0,ax.CameraPosition=[39.4959 -29.1496 71.8289]; case 2,ax.CameraPosition=[-39.8792 27.4237 70.6419]; end switch maze.scene case 0 switch 1 case all(tempRolePos==changePos(role.pos,tempRolePos,0)) role.pos=changePos(role.pos,tempRolePos,0); case specialChange(tempRolePos,[-1 2 -2],[0 1 0]) case specialChange(tempRolePos,[-2 1 -2],[-1 0 0]) case all(tempRolePos+[0 0 1]==changePos(role.pos,tempRolePos+[0 0 1],1)) role.pos=changePos(role.pos,tempRolePos+[0 0 1],1); case all(tempRolePos+[0 0 -1]==changePos(role.pos,tempRolePos+[0 0 -1],-1)) role.pos=changePos(role.pos,tempRolePos+[0 0 -1],-1); end case 1 switch 1 case all(tempRolePos+[0 0 1]==changePos(role.pos,tempRolePos+[0 0 1],1)) role.pos=changePos(role.pos,tempRolePos+[0 0 1],1); case all(tempRolePos==changePos(role.pos,tempRolePos,0)) role.pos=changePos(role.pos,tempRolePos,0); case all(tempRolePos+[0 0 -1]==changePos(role.pos,tempRolePos+[0 0 -1],-1)) role.pos=changePos(role.pos,tempRolePos+[0 0 -1],-1); end case 2 switch 1 case all(tempRolePos==changePos(role.pos,tempRolePos,0)) role.pos=changePos(role.pos,tempRolePos,0); case specialChange(tempRolePos,[-3 1 3],[-1 0 0]) case specialChange(tempRolePos,[2 -2 -2],[0 -1 0]) case all(tempRolePos+[0 0 1]==changePos(role.pos,tempRolePos+[0 0 1],1)) role.pos=changePos(role.pos,tempRolePos+[0 0 1],1); case all(tempRolePos+[0 0 -1]==changePos(role.pos,tempRolePos+[0 0 -1],-1)) role.pos=changePos(role.pos,tempRolePos+[0 0 -1],-1); end case 3 switch 1 case all(tempRolePos+[0 0 1]==changePos(role.pos,tempRolePos+[0 0 1],1)) role.pos=changePos(role.pos,tempRolePos+[0 0 1],1); case all(tempRolePos==changePos(role.pos,tempRolePos,0)) role.pos=changePos(role.pos,tempRolePos,0); case all(tempRolePos+[0 0 -1]==changePos(role.pos,tempRolePos+[0 0 -1],-1)) role.pos=changePos(role.pos,tempRolePos+[0 0 -1],-1); end end delete(findobj('tag','role')); fill3(role.cubex+role.pos(1)-1,... role.cubey+role.pos(2)-1,... role.cubez+role.pos(3)-1,[0.65 0.65 0.87],'tag','role') end function bool=specialChange(tempRolePos,spDir,Dir) bool=0; dir=[0 0 -1;0 0 0;0 0 1]; switch 1 case role.pos(3)~=1&&role.pos(3)+spDir(3)-1~=1&&sum(abs(tempRolePos-role.pos-Dir))==0&&all(role.pos+spDir+dir(1,:)==changePos(role.pos,role.pos+spDir+dir(1,:),-1)) role.pos=changePos(role.pos,role.pos+spDir+dir(1,:),-1);bool=1; case role.pos(3)~=1&&role.pos(3)+spDir(3)~=1&&sum(abs(tempRolePos-role.pos-Dir))==0&&all(role.pos+spDir+dir(2,:)==changePos(role.pos,role.pos+spDir+dir(2,:),0)) role.pos=changePos(role.pos,role.pos+spDir+dir(2,:),0);bool=1; case role.pos(3)~=1&&role.pos(3)+spDir(3)+1~=1&&sum(abs(tempRolePos-role.pos-Dir))==0&&all(role.pos+spDir+dir(3,:)==changePos(role.pos,role.pos+spDir+dir(3,:),1)) role.pos=changePos(role.pos,role.pos+spDir+dir(3,:),1);bool=1; case role.pos(3)~=1&&role.pos(3)-spDir(3)+1~=1&&sum(abs(tempRolePos-role.pos+Dir))==0&&all(role.pos-spDir-dir(1,:)==changePos(role.pos,role.pos-spDir-dir(1,:),-1)) role.pos=changePos(role.pos,role.pos-spDir-dir(1,:),1);bool=1; case role.pos(3)~=1&&role.pos(3)-spDir(3)~=1&&sum(abs(tempRolePos-role.pos+Dir))==0&&all(role.pos-spDir-dir(2,:)==changePos(role.pos,role.pos-spDir-dir(2,:),0)) role.pos=changePos(role.pos,role.pos-spDir-dir(2,:),0);bool=1; case role.pos(3)~=1&&role.pos(3)-spDir(3)-1~=1&&sum(abs(tempRolePos-role.pos+Dir))==0&&all(role.pos-spDir-dir(3,:)==changePos(role.pos,role.pos-spDir-dir(3,:),1)) role.pos=changePos(role.pos,role.pos-spDir-dir(3,:),-1);bool=1; end end function newPos=changePos(oriPos,objPos,ydir) newPos=oriPos; if all(objPos(1:2)>=1&objPos(1:2)<=10)&&objPos(3)<=7&&objPos(3)>=1 switch ydir case 1 if maze.(['layer',num2str(objPos(3))]).map(objPos(1),objPos(2))==0&&... maze.(['layer',num2str(objPos(3)-1)]).map(objPos(1),objPos(2))==1&&... (oriPos(3)+1>=8||maze.(['layer',num2str(oriPos(3)+1)]).map(oriPos(1),oriPos(2))==0) newPos=objPos; end case 0 if maze.(['layer',num2str(objPos(3))]).map(objPos(1),objPos(2))==0&&... maze.(['layer',num2str(objPos(3)-1)]).map(objPos(1),objPos(2))==1 newPos=objPos; end case -1 if maze.(['layer',num2str(objPos(3))]).map(objPos(1),objPos(2))==0&&... maze.(['layer',num2str(objPos(3)-1)]).map(objPos(1),objPos(2))==1&&... maze.(['layer',num2str(objPos(3)+1)]).map(objPos(1),objPos(2))==0 newPos=objPos; end end end end function plotcube(varargin) % PLOTCUBE - Display a 3D-cube in the current axes % % PLOTCUBE(EDGES,ORIGIN,ALPHA,COLOR) displays a 3D-cube in the current axes % with the following properties: % * EDGES : 3-elements vector that defines the length of cube edges % * ORIGIN: 3-elements vector that defines the start point of the cube % * ALPHA : scalar that defines the transparency of the cube faces (from 0 % to 1) % * COLOR : 3-elements vector that defines the faces color of the cube % % Example: % >> plotcube([5 5 5],[ 2 2 2],.8,[1 0 0]); % >> plotcube([5 5 5],[10 10 10],.8,[0 1 0]); % >> plotcube([5 5 5],[20 20 20],.8,[0 0 1]); % Default input arguments inArgs = { ... [10 56 100] , ... % Default edge sizes (x,y and z) [10 10 10] , ... % Default coordinates of the origin point of the cube .7 , ... % Default alpha value for the cube's faces [1 0 0] ... % Default Color for the cube }; % Replace default input arguments by input values inArgs(1:nargin) = varargin; % Create all variables [edges,origin,alpha,clr] = deal(inArgs{:}); XYZ = { ... [0 0 0 0] [0 0 1 1] [0 1 1 0] ; ... [1 1 1 1] [0 0 1 1] [0 1 1 0] ; ... [0 1 1 0] [0 0 0 0] [0 0 1 1] ; ... [0 1 1 0] [1 1 1 1] [0 0 1 1] ; ... [0 1 1 0] [0 0 1 1] [0 0 0 0] ; ... [0 1 1 0] [0 0 1 1] [1 1 1 1] ... }; XYZ = mat2cell(... cellfun( @(x,y,z) x*y+z , ... XYZ , ... repmat(mat2cell(edges,1,[1 1 1]),6,1) , ... repmat(mat2cell(origin,1,[1 1 1]),6,1) , ... 'UniformOutput',false), ... 6,[1 1 1]); cellfun(@patch,XYZ{1},XYZ{2},XYZ{3},... repmat({clr},6,1),... repmat({'FaceAlpha'},6,1),... repmat({alpha},6,1)... ); view(3); end end
到此這篇關於Matlab實現簡易紀念碑谷遊戲的範例程式碼的文章就介紹到這了,更多相關Matlab紀念碑谷遊戲內容請搜尋it145.com以前的文章或繼續瀏覽下面的相關文章希望大家以後多多支援it145.com!
相關文章
<em>Mac</em>Book项目 2009年学校开始实施<em>Mac</em>Book项目,所有师生配备一本<em>Mac</em>Book,并同步更新了校园无线网络。学校每周进行电脑技术更新,每月发送技术支持资料,极大改变了教学及学习方式。因此2011
2021-06-01 09:32:01
综合看Anker超能充系列的性价比很高,并且与不仅和iPhone12/苹果<em>Mac</em>Book很配,而且适合多设备充电需求的日常使用或差旅场景,不管是安卓还是Switch同样也能用得上它,希望这次分享能给准备购入充电器的小伙伴们有所
2021-06-01 09:31:42
除了L4WUDU与吴亦凡已经多次共事,成为了明面上的厂牌成员,吴亦凡还曾带领20XXCLUB全队参加2020年的一场音乐节,这也是20XXCLUB首次全员合照,王嗣尧Turbo、陈彦希Regi、<em>Mac</em> Ova Seas、林渝植等人全部出场。然而让
2021-06-01 09:31:34
目前应用IPFS的机构:1 谷歌<em>浏览器</em>支持IPFS分布式协议 2 万维网 (历史档案博物馆)数据库 3 火狐<em>浏览器</em>支持 IPFS分布式协议 4 EOS 等数字货币数据存储 5 美国国会图书馆,历史资料永久保存在 IPFS 6 加
2021-06-01 09:31:24
开拓者的车机是兼容苹果和<em>安卓</em>,虽然我不怎么用,但确实兼顾了我家人的很多需求:副驾的门板还配有解锁开关,有的时候老婆开车,下车的时候偶尔会忘记解锁,我在副驾驶可以自己开门:第二排设计很好,不仅配置了一个很大的
2021-06-01 09:30:48
不仅是<em>安卓</em>手机,苹果手机的降价力度也是前所未有了,iPhone12也“跳水价”了,发布价是6799元,如今已经跌至5308元,降价幅度超过1400元,最新定价确认了。iPhone12是苹果首款5G手机,同时也是全球首款5nm芯片的智能机,它
2021-06-01 09:30:45