最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Matlab實(shí)現(xiàn)簡易紀(jì)念碑谷游戲的示例代碼

 更新時(shí)間:2022年03月03日 15:13:08   作者:slandarer  
《紀(jì)念碑谷》是USTWO公司開發(fā)制作的解謎類手機(jī)游戲,在游戲中,通過探索隱藏小路、發(fā)現(xiàn)視力錯(cuò)覺以及躲避神秘的烏鴉人來幫助沉默公主艾達(dá)走出紀(jì)念碑迷陣。本文將用Matlab編寫簡易版的紀(jì)念碑谷游戲,感興趣的可以了解一下

按上下左右鍵(↑↓←→)移動(dòng)物塊

按AD鍵轉(zhuǎn)動(dòng)視角

游戲效果如圖所示原本無法通過的路徑經(jīng)過視角調(diào)整即可通過

完整代碼

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

到此這篇關(guān)于Matlab實(shí)現(xiàn)簡易紀(jì)念碑谷游戲的示例代碼的文章就介紹到這了,更多相關(guān)Matlab紀(jì)念碑谷游戲內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • C++實(shí)現(xiàn)LeetCode(41.首個(gè)缺失的正數(shù))

    C++實(shí)現(xiàn)LeetCode(41.首個(gè)缺失的正數(shù))

    這篇文章主要介紹了C++實(shí)現(xiàn)LeetCode(41.首個(gè)缺失的正數(shù)),本篇文章通過簡要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下
    2021-07-07
  • 字典樹的基本知識(shí)及使用C語言的相關(guān)實(shí)現(xiàn)

    字典樹的基本知識(shí)及使用C語言的相關(guān)實(shí)現(xiàn)

    這篇文章主要介紹了字典樹的基本知識(shí)及使用C語言的相關(guān)實(shí)現(xiàn),這也是ACM等計(jì)算機(jī)考試和競(jìng)賽題目的基本知識(shí),需要的朋友可以參考下
    2015-08-08
  • C++編輯距離(動(dòng)態(tài)規(guī)劃)

    C++編輯距離(動(dòng)態(tài)規(guī)劃)

    這篇文章主要介紹了C++編輯距離(動(dòng)態(tài)規(guī)劃),編輯距離是指兩個(gè)字符串之間,由一個(gè)轉(zhuǎn)成另一個(gè)所需的最少編輯操作次數(shù),限免詳細(xì)內(nèi)容,需要的小伙伴可以參考一下
    2022-01-01
  • C++符號(hào)優(yōu)先級(jí)(詳細(xì)整理)

    C++符號(hào)優(yōu)先級(jí)(詳細(xì)整理)

    C++符號(hào)優(yōu)先級(jí),我詳細(xì)整理了一下。需要的朋友可以過來參考下。希望對(duì)大家有所幫助
    2013-10-10
  • 詳解如何使用C++寫一個(gè)線程安全的單例模式

    詳解如何使用C++寫一個(gè)線程安全的單例模式

    這篇文章主要為大家詳細(xì)介紹了如何使用C++寫一個(gè)線程安全的單例模式,文中的示例代碼講解詳細(xì),具有一定的學(xué)習(xí)價(jià)值,感興趣的小伙伴可以了解一下
    2022-10-10
  • 正確理解C++的構(gòu)造函數(shù)和析構(gòu)函數(shù)

    正確理解C++的構(gòu)造函數(shù)和析構(gòu)函數(shù)

    在C++的學(xué)習(xí)中,可以把類當(dāng)作一個(gè)模具,類實(shí)例化出來的對(duì)象就是根據(jù)這個(gè)模具所產(chǎn)生的實(shí)體,對(duì)象看作是自己創(chuàng)建的一個(gè)新的數(shù)據(jù)類型。本文主要介紹了類對(duì)象通過拷貝函數(shù)進(jìn)行初始化,分析類對(duì)象的內(nèi)存模型,以及通過this指針實(shí)現(xiàn)更復(fù)雜的功能。最后介紹了析構(gòu)函數(shù)的基礎(chǔ)知識(shí)
    2021-06-06
  • 深入單鏈表的快速排序詳解

    深入單鏈表的快速排序詳解

    本篇文章是對(duì)單鏈表的快速排序進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
    2013-05-05
  • c++中的const_cast用法大全

    c++中的const_cast用法大全

    const_cast轉(zhuǎn)換符是用來移除變量的const或volatile限定符。對(duì)于后者,我不是太清楚,因?yàn)樗婕暗搅硕嗑€程的設(shè)計(jì),今天重點(diǎn)給大家介紹c++中的const_cast用法大全,需要的朋友參考下吧
    2021-07-07
  • C語言帶頭雙向循環(huán)鏈表的示例代碼

    C語言帶頭雙向循環(huán)鏈表的示例代碼

    這篇文章主要介紹了如何利用C語言實(shí)現(xiàn)帶頭雙向循環(huán)鏈表,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-11-11
  • 手把手教你如何一眼分辨是C還是C++

    手把手教你如何一眼分辨是C還是C++

    在很大程度上,C++是C的超集,這意味著一個(gè)有效的C程序也是一個(gè)有效的C++程序,下面這篇文章主要給大家介紹了關(guān)于如何一眼分辨是C還是C++的相關(guān)資料,需要的朋友可以參考下
    2023-02-02

最新評(píng)論

永登县| 增城市| 梁山县| 偃师市| 博罗县| 宁南县| 桂东县| 金阳县| 会理县| 白山市| 刚察县| 沂源县| 普陀区| 清流县| 蚌埠市| 娄烦县| 吉木萨尔县| 沧州市| 静海县| 井陉县| 水城县| 介休市| 桃园县| 保靖县| 无锡市| 龙南县| 专栏| 平利县| 吴旗县| 雷山县| 张家界市| 徐州市| 邛崃市| 陈巴尔虎旗| 高安市| 北宁市| 通渭县| 霞浦县| 拉萨市| 南雄市| 揭东县|