0

So im trying to build a simple tetris game in Matlab. I am drawing and updating the figure using the patch method with predefined position vectors for each shape.

So far so good, but when i need to delete a row (when the player fills a row), i am stuck as i don't know how to delete a block from the figure. I tried ROI but i can't delete the underlying patches.

Code that draws figures and patches: ...

figureH = figure('name','TETRIS Game','outerposition',[100 100 500 500],'color','g');
%draw game area
 patch(xBoard+[0,gameWidth,gameWidth,0],yBoard +[0,0,gameHeight,gameHeight],'w');

...

%drawing shape in each step
activeShapePatch = patch((xBoard-1)+min(fcol)+x,yBoard+gameHeight-max(frow)+y,nextShape{1}{4});

nextShape is just a cell array containing x-y vectors for each shape and color- this is for the patch arguments.

mihaa123
  • 1,012
  • 9
  • 19
  • please show some code that reproduces the problem. – Benoit_11 Dec 13 '15 at 21:04
  • I recommend redrawing the whole canvas and completely clear the plot in each in each step – flawr Dec 13 '15 at 21:08
  • 1
    @flawr i would like to avoid that. I am drawing the board with fixed shapes. These contain color information and borders. When i delete 1 row i am left with fragments of previous shapes, and to draw them again will be a pain in the neck – mihaa123 Dec 13 '15 at 21:16
  • 3
    Just again as an alternative suggestion: If you use basic squares as pixels, you can just define a matrix of values, that says which pixel has which colour, and then make a drawing function that just draws the content of this matrix as "pixels" (one square per entry at the corresponding position) – flawr Dec 13 '15 at 21:18

1 Answers1

0

I would need more details but consider storing patch handles into cell, or graphic object array (e.g. init as gobject(3,2) generates a 3x2 graphic object array), and then delete them at wish. In general, using handles and cells,

cell_h_patch{ipatch} = patch(XData, YData, ZData, CData, ...)
...
row = ipatch;
delete(cell_h_patch{row})