所以我目前正在制作PACMAN上的MATLAB程序,但似乎无法弄清楚如何开始在主图上生成地图。我可以使用背景为uint8 RGB的.png文件,但这种情况不允许我注册妨碍PACMAN和鬼魂路径的墙壁。我认为另一种方法是使用0,1和2分别代表黑色空像素,蓝色墙(填充)和点(黄色)的位置创建地图。但是,在尝试执行后一种方法时,我遇到了一个问题,即在switch-case-other方法中为300 x 300矩阵的每个特定索引分配颜色。有关如何继续的建议?任何反应将是不胜感激及以下的是,我已尝试到目前为止创建示例代码:在MATLAB上创建PACMAN背景图
function level = LevelOne()
% the functionality of this function is to generate the walls that
% PACMAN and the ghosts cannot cross
% Create color map
color = [255 75 75; % red 1
153 0 0; % dark red 2
255 255 153; % light yellow 3
255 102 178; % pink 4
0 0 0; % black 5
0 255 255; % light blue 6
0 0 255; % blue 7
255 255 153; % light yellow 8
192 192 192; % silver 9
255 255 255]/255; % white 10
%create general map area
level = zeros(300);
%create location of filled in walls(represented by 1's)
level(18:38,37:70) = 1;
level(65:75,37:70) = 1;
level(300-18:300-38,300-37:300-70) = 1;
level(300-65:300-75,300-37:300-70) = 1;
[x,y] = size(level);
axis([0 x 0 y])
for ii = 1:x
for jj = 1:y
switch level(ii,jj)
case 1 %represents a blue wall
case 0 %represents an empty black space for PACMAN & Ghosts to move through
case 2 %represents the location of the fruit
case 3 %represents the location
otherwise
end
end