所以我目前正在製作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