[alt.sources.wanted] Programming a Mah-Jongg type game

sung@ceco.ceco.com (Sung Han) (05/17/91)

Howdy everyone,

    First off, I know that this question probably belongs in a group like
rec.games.programmer, but since we don't get that group here at our site,
please, no flames!

    Now for my question - I know that everyone and his cousin has written a
Mah-jongg/Taipei type of tile-removal game at one time, and I'm trying to
do the same (a rite of passage, if you will).  However, I'm stuck on the
problem of figuring out how to redraw tiles whenever a tile is deleted.  The
problem is that since the tiles are stacked several levels high, and seen from
an angle, they can overlap each other in weird ways - and I'm hard pressed to
figure out which tiles to redraw and in what manner.  At first I had thought
that this would be a pretty simple problem, but it's turning out to be more
difficult than I had imagined.

    So, if you understand my problem, could you please tell me whether this is
really an easy thing to do, and I'm just missing something?  Or is it truly a
complicated procedure, not to be tried by a mere amateur?  Any hints, ideas, 
algorithms, or (especially) source code would be greatly appreciated.

    Oh, and I'm using SunView right now, not that it should matter much - but
I could also use X or MS-Windows.
-- 
! Sung Han @ Commonwealth Edison Corp., Chicago, Illinois
!
! sung@ceco.ceco.com, or
! uunet!ceco.ceco.com!sung

lance@motcsd.csd.mot.com (lance.norskog) (05/20/91)

sung@ceco.ceco.com (Sung Han) writes:
>    Now for my question - I know that everyone and his cousin has written a
>Mah-jongg/Taipei type of tile-removal game at one time, and I'm trying to
>do the same (a rite of passage, if you will).  However, I'm stuck on the
>problem of figuring out how to redraw tiles whenever a tile is deleted.  The
>problem is that since the tiles are stacked several levels high, and seen from
>an angle, they can overlap each other in weird ways - and I'm hard pressed to
>figure out which tiles to redraw and in what manner.  

Well, you can paint all tiles from bottom to top, or "back to front"
as its called in computer graphics.  Starting from the top of the stack,
you decide the list of tiles you want to paint, i.e. if 4 overshadows 3,
remove three from the list.  Now, paint the bottom up to the top.

To cut down on screen I/O, you can do a z-buffer algorithm where you
build a "virtual screen" where each dot is a tile number or background.  
You then just paint the screen, reading each dot code number and looking
up the appropriate pixel from your background or tile bitmaps.

Lance

towfiq@FTP.COM (Mark Towfiq) (05/22/91)

>>>>> On 17 May 91 16:33:01 GMT, sung@ceco.ceco.com (Sung Han) said:

Sung> The problem is that since the tiles are stacked several levels
Sung> high, and seen from an angle, they can overlap each other in
Sung> weird ways - and I'm hard pressed to figure out which tiles to
Sung> redraw and in what manner.  At first I had thought that this
Sung> would be a pretty simple problem, but it's turning out to be
Sung> more difficult than I had imagined.

If I understand your question correctly, I think there is an easy way
to do this, yes.  The key is realizing that you don't need to do a
full perspective-type schema.  It is fine to just assume that every
tile obscures the view of other tiles in the exact same way.  So,
let's say that the point of view of the viewer is down and to the left
of the board, and there is a light source behind the viewer.  So, if
you remove a tile, it will reveal the tile underneath it, as well as
the tile above it (or the tile underneath THAT), and the tile to its
right (or the tile underneath THAT).  I can't draw what I mean to you,
but my basic point (unless *I'm* missing something) is that each
removal of a tile reveals the exact same space, no matter where it is
located, and thus you just have to redraw a certain region around the
tile.

Hope this helps,
Mark

--
Mark Towfiq, FTP Software, Inc.                                  towfiq@FTP.COM
Work No.: +1 617 246 0900			      Home No.: +1 617 488 2818

  "The Earth is but One Country, and Mankind its Citizens" -- Baha'u'llah