Advertisement
Guest User

thing but new

a guest
Jun 24th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Julia 6.84 KB | None | 0 0
  1. module Canyon
  2.  
  3. using ..Ahorn, Maple
  4.  
  5. @mapdef Entity "canyon/spinorb" SpinOrb(x::Integer, y::Integer)
  6. @mapdef Entity "canyon/pushblock" PushBlock(x::Integer, y::Integer)
  7. @mapdef Entity "canyon/toggleblock" ToggleBlock(x1::Integer, y1::Integer, x2::Integer=x1+16, y2::Integer=y1, width::Integer=16, height::Integer=16)
  8.  
  9. const placements = Ahorn.PlacementDict(
  10.     "Spin Orb (Canyon)" => Ahorn.EntityPlacement(
  11.         SpinOrb,
  12.         "point"
  13.     ),
  14.     "Push Block (Canyon)" => Ahorn.EntityPlacement(
  15.         PushBlock,
  16.         "point",
  17.         Dict{String, Any}(
  18.             "stickyTop" => false,
  19.             "stickyBottom" => false,
  20.             "stickyLeft" => false,
  21.             "stickyRight" => false
  22.         )
  23.     ),
  24.     "Toggle Block (Canyon)" => Ahorn.EntityPlacement(
  25.         ToggleBlock,
  26.         "rectangle",
  27.         Dict{String, Any}()
  28.     )
  29. )
  30.  
  31. Ahorn.nodeLimits(entity::ToggleBlock) = 1, -1
  32. Ahorn.minimumSize(entity::ToggleBlock) = 16, 16
  33. Ahorn.resizable(entity::ToggleBlock) = true, true
  34.  
  35. function Ahorn.selection(entity::ToggleBlock)
  36.     nodes = get(entity.data, "nodes", ())
  37.     x, y = Ahorn.position(entity)
  38.  
  39.     width = Int(get(entity.data, "width", 32))
  40.     height = Int(get(entity.data, "height", 32))
  41.  
  42.     res = Ahorn.Rectangle[Ahorn.Rectangle(x, y, width, height)]
  43.    
  44.     for node in nodes
  45.         nx, ny = Int.(node)
  46.  
  47.         push!(res, Ahorn.Rectangle(nx, ny, width, height))
  48.     end
  49.  
  50.     return res
  51. end
  52.  
  53. frame = "objects/swapblock/blockRed"
  54. midResource = "objects/swapblock/midBlockRed00"
  55.  
  56. function renderSingleToggleBlock(ctx::Ahorn.Cairo.CairoContext, x::Number, y::Number, width::Number, height::Number)
  57.     midSprite = Ahorn.getSprite(midResource, "Gameplay")
  58.    
  59.     tilesWidth = div(width, 8)
  60.     tilesHeight = div(height, 8)
  61.  
  62.     for i in 2:tilesWidth - 1
  63.         Ahorn.drawImage(ctx, frame, x + (i - 1) * 8, y, 8, 0, 8, 8)
  64.         Ahorn.drawImage(ctx, frame, x + (i - 1) * 8, y + height - 8, 8, 16, 8, 8)
  65.     end
  66.  
  67.     for i in 2:tilesHeight - 1
  68.         Ahorn.drawImage(ctx, frame, x, y + (i - 1) * 8, 0, 8, 8, 8)
  69.         Ahorn.drawImage(ctx, frame, x + width - 8, y + (i - 1) * 8, 16, 8, 8, 8)
  70.     end
  71.  
  72.     for i in 2:tilesWidth - 1, j in 2:tilesHeight - 1
  73.         Ahorn.drawImage(ctx, frame, x + (i - 1) * 8, y + (j - 1) * 8, 8, 8, 8, 8)
  74.     end
  75.  
  76.     Ahorn.drawImage(ctx, frame, x, y, 0, 0, 8, 8)
  77.     Ahorn.drawImage(ctx, frame, x + width - 8, y, 16, 0, 8, 8)
  78.     Ahorn.drawImage(ctx, frame, x, y + height - 8, 0, 16, 8, 8)
  79.     Ahorn.drawImage(ctx, frame, x + width - 8, y + height - 8, 16, 16, 8, 8)
  80.  
  81.     Ahorn.drawImage(ctx, midSprite, x + div(width - midSprite.width, 2), y + div(height - midSprite.height, 2))
  82. end
  83.  
  84. function renderToggleBlock(ctx::Ahorn.Cairo.CairoContext, width::Number, height::Number)
  85.     midSprite = Ahorn.getSprite(midResource, "Gameplay")
  86.    
  87.     nodes = get(entity.data, "nodes", ())
  88.  
  89.     tilesWidth = div(width, 8)
  90.     tilesHeight = div(height, 8)
  91.  
  92.     for node in nodes
  93.         nx, ny = Int.(node)
  94.  
  95.         for i in 2:tilesWidth - 1
  96.             Ahorn.drawImage(ctx, frame, nx + (i - 1) * 8, ny, 8, 0, 8, 8)
  97.             Ahorn.drawImage(ctx, frame, nx + (i - 1) * 8, ny + height - 8, 8, 16, 8, 8)
  98.         end
  99.    
  100.         for i in 2:tilesHeight - 1
  101.             Ahorn.drawImage(ctx, frame, nx, ny + (i - 1) * 8, 0, 8, 8, 8)
  102.             Ahorn.drawImage(ctx, frame, nx + width - 8, ny + (i - 1) * 8, 16, 8, 8, 8)
  103.         end
  104.    
  105.         for i in 2:tilesWidth - 1, j in 2:tilesHeight - 1
  106.             Ahorn.drawImage(ctx, frame, nx + (i - 1) * 8, ny + (j - 1) * 8, 8, 8, 8, 8)
  107.         end
  108.    
  109.         Ahorn.drawImage(ctx, frame, nx, ny, 0, 0, 8, 8)
  110.         Ahorn.drawImage(ctx, frame, nx + width - 8, ny, 16, 0, 8, 8)
  111.         Ahorn.drawImage(ctx, frame, nx, ny + height - 8, 0, 16, 8, 8)
  112.         Ahorn.drawImage(ctx, frame, nx + width - 8, ny + height - 8, 16, 16, 8, 8)
  113.    
  114.         Ahorn.drawImage(ctx, midSprite, nx + div(width - midSprite.width, 2), ny + div(height - midSprite.height, 2))
  115.     end
  116. end
  117.  
  118. function Ahorn.renderSelectedAbs(ctx::Ahorn.Cairo.CairoContext, entity::ToggleBlock, room::Maple.Room)
  119.     sprite = get(entity.data, "sprite", "block")
  120.  
  121.     width = Int(get(entity.data, "width", 32))
  122.     height = Int(get(entity.data, "height", 32))
  123.  
  124.     px, py = Ahorn.position(entity)
  125.  
  126.     for node in get(entity.data, "nodes", ())
  127.         nx, ny = Int.(node)
  128.  
  129.         theta = atan(py - ny, px - nx)
  130.         Ahorn.drawArrow(ctx, px, py, nx + cos(theta) * 8, ny + sin(theta) * 8, Ahorn.colors.selection_selected_fc, headLength=6)
  131.  
  132.         px, py = nx, ny
  133.     end
  134.  
  135.     renderToggleBlock(ctx, width, height)
  136. end
  137.  
  138. function Ahorn.renderAbs(ctx::Ahorn.Cairo.CairoContext, entity::ToggleBlock, room::Maple.Room)
  139.     sprite = get(entity.data, "sprite", "block")
  140.  
  141.     startX, startY = Int(entity.data["x"]), Int(entity.data["y"])
  142.  
  143.     width = Int(get(entity.data, "width", 32))
  144.     height = Int(get(entity.data, "height", 32))
  145.  
  146.     renderSingleToggleBlock(ctx, startX, startY, width, height)
  147. end
  148.  
  149. function Ahorn.selection(entity::SpinOrb)
  150.     x, y = Ahorn.position(entity)
  151.  
  152.     return Ahorn.getSpriteRectangle("objects/canyon/spinorb/idle00.png", x, y, jx=0.5, jy=0.5)
  153. end
  154.  
  155. function Ahorn.selection(entity::PushBlock)
  156.     x, y = Ahorn.position(entity)
  157.  
  158.     return Ahorn.getSpriteRectangle("objects/canyon/pushblock/idle.png", x, y, jx=0.5, jy=0.5)
  159. end
  160.  
  161. listOfTextures = ["objects/canyon/pushblock/stickyGoo00", "objects/canyon/pushblock/stickyGoo01", "objects/canyon/pushblock/stickyGoo02", "objects/canyon/pushblock/stickyGoo03"]
  162.  
  163. topTexture = rand(listOfTextures)
  164. bottomTexture = rand(listOfTextures)
  165. leftTexture = rand(listOfTextures)
  166. rightTexture = rand(listOfTextures)
  167.  
  168. Ahorn.render(ctx::Ahorn.Cairo.CairoContext, entity::SpinOrb) = Ahorn.drawSprite(ctx, "objects/canyon/spinorb/idle00.png", 0, 0, jx=0.5, jy=0.5)
  169.  
  170. function Ahorn.render(ctx::Ahorn.Cairo.CairoContext, entity::PushBlock)
  171.     Ahorn.drawSprite(ctx, "objects/canyon/pushblock/idle.png", 0, 0, jx=0.5, jy=0.5)
  172.     stickyTop = get(entity.data, "stickyTop", false)
  173.     stickyBottom = get(entity.data, "stickyBottom", false)
  174.     stickyRight = get(entity.data, "stickyRight", false)
  175.     stickyLeft = get(entity.data, "stickyLeft", false)
  176.     if (stickyTop)
  177.         Ahorn.drawImage(ctx, topTexture, -32 / 2, -32 / 2)
  178.     end
  179.     if (stickyBottom)
  180.         Ahorn.Cairo.save(ctx)
  181.         Ahorn.scale(ctx, 1, -1)
  182.         Ahorn.drawImage(ctx, bottomTexture, -32 / 2, -32 / 2)
  183.         Ahorn.Cairo.restore(ctx)
  184.     end
  185.     if (stickyRight)
  186.         Ahorn.Cairo.save(ctx)
  187.         Ahorn.rotate(ctx, pi/2)
  188.         Ahorn.drawImage(ctx, rightTexture, -32 / 2, -32 / 2)
  189.         Ahorn.Cairo.restore(ctx)
  190.     end
  191.     if (stickyLeft)
  192.         Ahorn.Cairo.save(ctx)
  193.         Ahorn.rotate(ctx, -pi/2)
  194.         Ahorn.drawImage(ctx, leftTexture, -32 / 2, -32 / 2)
  195.         Ahorn.Cairo.restore(ctx)
  196.     end
  197. end
  198.  
  199. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement