How to use multiple axes simultaneously using functions.

1 view (last 30 days)
Guys, I am working on classic snake game. I want to play it virtually using object detection techniques. I used virtual code which represents a 3*3 matrix (square grids).
The virtual code helps me to identify the place of the object detected in that 3*3 plot. The code shown below is used to split the grids in 3*3. The resolution I've used is 320x240.
data=getsnapshot(vid);
pause(0.1);
imC=rgb2gray(data);
imC(:,105:110)=0;
imC(75:80,:)=0;
imC(:,215:220)=0;
imC(160:165,:)=0;
I need to integrate this with the classic snake game which I've got from mathworks site. I'm facing a problem while using both axes simultaneously. I don't how to use functions for separate axes.
I have created two axes, one for snake game and the other one for virtual code. The game has to work according to the directions I've moved using the object. For that I need to call the game function in to the virtual.
Here I've shown the display commands of virtual code.
if x ~= 0 && y ~= 0
if x < 75 && y < 105
disp('one');
imC(1:75,1:105 )=0;
elseif x < 75 && y < 215 && y>110 %%Two
disp('two');
imC(1:75,110:215)=0;
elseif x < 75 && y >215 && y < 320%%Three
disp('Three');
imC(1:75,215:320)=0;
elseif x > 80 && y< 105 &&x < 160%%Four
disp('Four');
imC(80:160,1:105)=0;
elseif x > 80 && x<160 && y>110 && y<215
disp('five');
imC(80:160,110:215)=0;
elseif x > 80 && x<160 && y>220 && y<320
disp('six');
imC(80:160,220:320)=0;
elseif x > 165 && y<105
disp('seven');
imC(160:240,1:105)=0;
elseif x > 165 && y>110 && y<215
disp('eight');
imC(160:240,110:215)=0;
elseif x > 165 && y<320 && y>220
disp('nine');
imC(160:240,220:320)=0;
end
subplot(2,2,1); imshow(imC);
pause(0.1);
else
end
x=0;y=0;
I need only 2nd (UP), 4th(LEFT), 6th(RIGHT) and 8th(DOWN) of these 9 boxes and I need to place the directions for the snake here.
Please help me to integrate these two coding and to use functions to enable two axes simultaneously.
  1 Comment
Guru
Guru on 24 Mar 2015
I would be happy, if you send me a solution with an example code for using function or the edited code of this which you want to work without error. Thanks in advance.

Sign in to comment.

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!