Advertisement
Guest User

First isometric tilemap attempt ¦ QWeb Ltd

a guest
Sep 25th, 2016
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Import mojo ' Graphics etc
  2.  
  3. Function Main()
  4.     ' Create an instance of the Game class
  5.     New Game
  6. End
  7.  
  8. Class Game Extends App
  9.     ' Globals
  10.     Field tiles:Image[5]
  11.     Field isomap:=[New Tile[5], New Tile[5], New Tile[5], New Tile[5], New Tile[5]]
  12.  
  13.     Global tilemap:Int[][] =    [
  14.         [1, 2, 1, 1, 1],
  15.         [1, 2, 1, 1, 1],
  16.         [1, 2, 1, 1, 1],
  17.         [3, 4, 3, 3, 3],
  18.         [1, 2, 1, 1, 1]         ]
  19.  
  20.     Field playerX:Float = 1
  21.     Field playerY:Float = 3
  22.  
  23.     Field zoom:Float = .5
  24.  
  25.     ' Called when an instance of the class is created
  26.     Method OnCreate()
  27.         SetUpdateRate 30
  28.  
  29.         tiles[1] = LoadImage("tile-grass.png")
  30.         tiles[2] = LoadImage("tile-path-v.png")
  31.         tiles[3] = LoadImage("tile-path-h.png")
  32.         tiles[4] = LoadImage("tile-path-hv.png")
  33.  
  34.         tiles[1].SetHandle(64, 64)
  35.         tiles[2].SetHandle(64, 64)
  36.         tiles[3].SetHandle(64, 64)
  37.         tiles[4].SetHandle(64, 64)
  38.     End
  39.  
  40.     ' Called via an infinite loop behind the scenes
  41.     Method OnUpdate()
  42.         If KeyDown(KEY_UP) And zoom < 1 Then zoom += .025
  43.         If KeyDown(KEY_DOWN) And zoom > .25 Then zoom -= .025
  44.  
  45.         For Local x = 0 To 4
  46.             For Local y = 0 To 4
  47.                 isomap[x][y] = New Tile
  48.                 isomap[x][y].x = (x + playerX) * (128 * zoom) - (y + playerY) * (128 * zoom)
  49.                 isomap[x][y].y = ((x - playerX) * (128 * zoom) + (y - playerY) * (128 * zoom)) / 2
  50.             Next
  51.         Next
  52.     End
  53.  
  54.     ' Called via an infinite loop behind the scenes after everything else
  55.     Method OnRender()
  56.         ' Clear the screen
  57.         Cls 0, 0, 0
  58.  
  59.         ' Then redraw
  60.         For Local x = 0 To 4
  61.             For Local y = 0 To 4
  62.                 DrawImage tiles[tilemap[x][y]], isomap[x][y].x + DeviceWidth() / 2, isomap[x][y].y + DeviceHeight() / 2, 0, (2 * zoom), (1 * zoom)
  63.             Next
  64.         Next
  65.  
  66.         DrawPoint DeviceWidth() / 2, DeviceHeight() / 2
  67.     End
  68. End
  69.  
  70. Class Tile
  71.     Field x:Float
  72.     Field y:Float
  73. End
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement