Guest User

Untitled

a guest
Feb 20th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. require 'rubygame'
  2.  
  3. include Rubygame
  4. TTF.setup
  5.  
  6. class Display
  7. def initialize
  8. @queue = Queue.instance()
  9. @font = TTF.new("data/fonts/freesansbold.ttf",15)
  10. @width = 800
  11. @height = 600
  12. @screen = Rubygame::Screen.set_mode([@width,@height],0, [Rubygame::HWSURFACE, Rubygame::DOUBLEBUF])
  13. @text = []
  14. end
  15. def render_text
  16. y = 0
  17. skip = @font.line_skip()
  18. @screen.fill([30,70,30])
  19. @text.each do |string|
  20. render = @font.render("#{[string]}",true,[200,200,200])
  21. render.blit(@screen,[0,y])
  22. y += skip
  23. end
  24. end
  25. def add text
  26. @text << text
  27. end
  28. def update
  29. @screen.flip()
  30. @queue.get.each do |event|
  31. case event
  32. when Rubygame::QuitEvent
  33. exit
  34. when Rubygame::KeyDownEvent
  35. if event.key == Rubygame::K_ESCAPE
  36. exit
  37. end
  38. end
  39. end
  40. end
  41. end
  42.  
  43. class Main
  44. #The menu method is the main menu of the game.
  45. def initialize
  46. @file = Game_File.new
  47. @option = Game_Option.new
  48. @stage = Game_Stage.new
  49. @display = Display.new
  50. menu
  51. end
  52. def menu
  53. @display.add("Hello user, welcome to the program. What could you like to do?")
  54. @display.add("Creation: Press \"c\" to start creation.")
  55. @display.add("Load: Press \"l\" to load a game.")
  56. @display.add("Credit: Press \"c\" to see credit.")
  57. @display.render_text
  58. q = Queue.instance()
  59. while (1)
  60. @display.update
  61. q.get.each do |event|
  62. case event
  63. when Rubygame::KeyDownEvent
  64. if event.key == Rubygame::K_C
  65.  
  66. end
  67. end
  68. end
  69. Main.new
Add Comment
Please, Sign In to add comment