REM ***********************************************
REM Title: 2D Map Zoom
REM Author: Phaelax
REM Downloaded from: http://dbcc.zimnox.com/
REM ***********************************************
 
 
type ImageScaleProperties
   sprt as integer
   originalWidth as integer
   originalHeight as integer
   originalX as integer
   originalY as integer
   scale as float
   img as integer
endtype
 
load image "tile.jpg", 1
 
 
rem setup a tile map
global mapWidth = 2
global mapHeight = 2
global mapOffsetX = 0
global mapOffsetY = 0
 
dim map(mapWidth, mapHeight) as ImageScaleProperties
 
tileWidth = 128
tileHeight = 128
 
rem set default map properties for each scalable tile
s = 0
for y = 0 to mapHeight-1
   for x = 0 to mapWidth-1
      inc s,1
      map(x,y).sprt = s
      map(x,y).scale = 1.0
      map(x,y).originalWidth = tileWidth
      map(x,y).originalHeight = tileHeight
      map(x,y).originalX = x*tileWidth
      map(x,y).originalY = y*tileHeight
      map(x,y).img = 1
      sprite s, mapOffsetX+map(x,y).originalX, mapOffsetY+map(x,y).originalY, map(x,y).img
   next x
next y
 
sync on
sync rate 60
 
DO
 
   if mousemovex() or mousemovey()
      mapOffsetX = mousex()
      mapOffsetY = mousey()
      for y = 0 to mapHeight-1
         for x = 0 to mapWidth-1
            gosub _resizeSprite
         next x
      next y
   endif
 
 
   if upkey()
      for y = 0 to mapHeight-1
         for x = 0 to mapWidth-1
            map(x,y).scale = map(x,y).scale + 0.01
            gosub _resizeSprite
         next x
      next y
   endif
 
   if downkey()
      for y = 0 to mapHeight-1
         for x = 0 to mapWidth-1
            map(x,y).scale = map(x,y).scale - 0.01
            gosub _resizeSprite
         next x
      next y
   endif
 
 
   sync
LOOP
 
 
_resizeSprite:
   w# = map(x,y).originalWidth
   w# = w# * map(x,y).scale
   h# = map(x,y).originalHeight
   h# = h# * map(x,y).scale
   size sprite map(x,y).sprt, w#, h#
 
   wx# = (w#*mapWidth - map(x,y).originalWidth*mapWidth)/2
   hy# = (h#*mapHeight - map(x,y).originalHeight*mapHeight)/2
   offX = x*map(x,y).originalWidth * map(x,y).scale - wx#
   offY = y*map(x,y).originalHeight * map(x,y).scale - hy#
   sprite map(x,y).sprt, mapOffsetX+offX, mapOffsetY+offY, map(x,y).img
RETURN