home *** CD-ROM | disk | FTP | other *** search
/ Game Programming - All in One (3rd Edition) / game_prog_all_in_one_3rd_ed.iso / software / Mappy / mapwin14 / luascr / Placer.lua < prev    next >
Encoding:
Text File  |  2003-10-17  |  949 b   |  37 lines

  1. -- Example Placer script
  2. -- called when the mouse moves and a button pressed that is set to Placer.lua
  3.  
  4. function main ()
  5.  local x = mappy.getValue (mappy.MOUSEBLOCKX)
  6.  local y = mappy.getValue (mappy.MOUSEBLOCKY)
  7.  
  8.  local blk = mappy.getValue (mappy.CURANIM)
  9.  if (blk == -1) then
  10.   blk = mappy.getValue (mappy.CURBLOCK)
  11.  else
  12. -- setBlock need anims in the format below (ie: anim 1 should be a value of -2)
  13.   blk = -(blk+1)
  14.  end
  15.  
  16. -- Place a '+' of blocks at current position
  17.  if x > 0 then
  18.   mappy.setBlock (x-1, y, blk)
  19.  end
  20.  if y > 0 then
  21.   mappy.setBlock (x, y-1, blk)
  22.  end
  23.  mappy.setBlock (x, y, blk)
  24.  if x < (mappy.getValue (mappy.MAPWIDTH)-1) then
  25.   mappy.setBlock (x+1, y, blk)
  26.  end
  27.  if y < (mappy.getValue (mappy.MAPHEIGHT)-1) then
  28.   mappy.setBlock (x, y+1, blk)
  29.  end
  30. end
  31.  
  32. test, errormsg = pcall( main )
  33. if not test then
  34.     mappy.msgBox("Error ...", errormsg, mappy.MMB_OK, mappy.MMB_ICONEXCLAMATION)
  35. end
  36.  
  37.