Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. module Graphics
  2.  
  3. Sfml_Draw = Win32API.new('WOM32', 'sfml_draw', 'pllllll', 'i')
  4. Sfml_Draw_Rectangle = Win32API.new('WOM32', 'sfml_draw_rectangle', 'lllllllll', 'l')
  5. Sfml_Draw_Text = Win32API.new('WOM32', 'sfml_draw_text', 'plllllllllll', 'l')
  6. Sfml_Display = Win32API.new('WOM32', 'sfml_display', '', 'l')
  7. Sfml_Clear = Win32API.new('WOM32', 'sfml_clear', '', 'l')
  8.  
  9. DRAW_TYPE_NORMAL = 0
  10. DRAW_TYPE_RECTANGLE = 1
  11. DRAW_TYPE_TEXT = 2
  12.  
  13. module_function
  14.  
  15. @sprites = []
  16.  
  17. def self.load_texture(path)
  18. s = Win32API.new('WOM32', 'sfml_load_texture', 'p', 'p').call path
  19. size = [s.split(';')[0].to_i, s.split(';')[1].to_i]
  20. return size
  21. end
  22.  
  23. def draw(filename, rec_x, rec_y, width, height, x, y)
  24. result = Sfml_Draw.call filename, rec_x, rec_y, width, height, x, y
  25. end
  26.  
  27. def fill_rect(r, g, b, a, x, y, width, height, thickness)
  28. result = Sfml_Draw_Rectangle.call r, g, b, a, x, y, width, height, thickness
  29. end
  30.  
  31. def draw_text(str, x, y, size, r, g, b, a, bold, underline, italic, regular)
  32. result = Sfml_Draw_Text.call str, x, y, size, r, g, b, a, bold, underline, italic, regular
  33. end
  34.  
  35. def display
  36. result = Sfml_Display.call
  37. end
  38.  
  39. def clear
  40. result = Sfml_Clear.call
  41. end
  42.  
  43. def update
  44. clear
  45. #
  46. sprlist = @sprites.clone
  47.  
  48. #test = Tick.tackPrecise
  49.  
  50. sprlist.sort! { |a,b| a.z <=> b.z }
  51.  
  52. sprlist.map!{|spr|;
  53. if spr.visible && !spr.bitmap.nil?
  54. spr.bitmap.draws.each{|draw|;
  55. if draw.type == DRAW_TYPE_NORMAL
  56. draw(draw.filepath, draw.rect.x, draw.rect.y, draw.rect.width, draw.rect.height, spr.x + draw.x, spr.y + draw.y)
  57. elsif draw.type == DRAW_TYPE_RECTANGLE
  58. #fill_rect(draw.r, draw.g, draw.b, draw.a, draw.x, draw.y, draw.width, draw.height, draw.thickness)
  59. elsif draw.type == DRAW_TYPE_TEXT
  60. draw_text(draw.text, spr.x + draw.x, spr.y + draw.y, draw.size, draw.r, draw.g, draw.b, draw.a, draw.bold, draw.underlined, draw.italic, draw.regular)
  61. end
  62. }
  63. end
  64. }
  65.  
  66. #test2 = Tick.tackPrecise
  67.  
  68. #p "AH"
  69. #p test2 - test
  70.  
  71. display
  72. end
  73.  
  74. def self.newSpr(spr)
  75. @sprites = [] if @sprites.nil?
  76. @sprites.push(spr)
  77. end
  78. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement