basic.rb 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. ## $Id$
  2. ##
  3. ## Flexlay - A Generic 2D Game Editor
  4. ## Copyright (C) 2004 Ingo Ruhnke <grumbel@gmx.de>
  5. ##
  6. ## This program is free software: you can redistribute it and/or modify
  7. ## it under the terms of the GNU General Public License as published by
  8. ## the Free Software Foundation, either version 3 of the License, or
  9. ## (at your option) any later version.
  10. ##
  11. ## This program is distributed in the hope that it will be useful,
  12. ## but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ## GNU General Public License for more details.
  15. ##
  16. ## You should have received a copy of the GNU General Public License
  17. ## along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. ## A basic tile editor that should act as example for other games, use
  19. ## it to fork your own code.
  20. $datadir = ""
  21. ## First we try to read a config file to set some variables
  22. $config_file = File.expand_path("~/.flexlay/basic.rb")
  23. if File.exist?($config_file) then
  24. require $config_file
  25. end
  26. BACKGROUND_LAYER = 1
  27. INTERACTIVE_LAYER = 2
  28. FOREGROUND_LAYER = 3
  29. ## Load Flexlay library
  30. require "flexlay_wrap"
  31. include Flexlay_wrap
  32. require "flexlay.rb"
  33. require "basic_gui.rb"
  34. require "basic_level.rb"
  35. ## Init Flexlay itself
  36. flexlay = Flexlay.new()
  37. flexlay.init()
  38. ## Initialize Tools
  39. class Controller
  40. attr_reader :tilemap_paint_tool, :tilemap_select_tool, :zoom_tool, :objmap_select_tool, :recent_files
  41. def initialize()
  42. @tilemap_paint_tool = TileMapPaintTool.new()
  43. @tilemap_select_tool = TileMapSelectTool.new()
  44. @zoom_tool = ZoomTool.new()
  45. @objmap_select_tool = ObjMapSelectTool.new()
  46. @recent_files = []
  47. end
  48. def set_tilemap_paint_tool()
  49. $gui.workspace.set_tool(@tilemap_paint_tool.to_tool())
  50. $gui.set_tilemap_paint_tool()
  51. end
  52. def set_tilemap_select_tool()
  53. $gui.workspace.set_tool(@tilemap_select_tool.to_tool())
  54. $gui.set_tilemap_select_tool()
  55. end
  56. def set_zoom_tool()
  57. $gui.workspace.set_tool(@zoom_tool.to_tool())
  58. $gui.set_zoom_tool()
  59. end
  60. def set_objmap_select_tool()
  61. $gui.workspace.set_tool(@objmap_select_tool.to_tool())
  62. $gui.set_objmap_select_tool()
  63. end
  64. end
  65. $controller = Controller.new()
  66. $mysprite = make_sprite("../data/images/icons16/stock_paste-16.png")
  67. $resources = CL_ResourceManager.new("../data/flexlay.xml")
  68. $tileset = Tileset.new(32)
  69. $tileset.add_tile(1, Tile.new(make_pixelbuffer("../data/images/icons16/stock_paste-16.png")))
  70. $tileset.add_tile(2, Tile.new(make_pixelbuffer("../data/images/icons24/stock_jump-to.png")))
  71. $tileset.add_tile(3, Tile.new(make_pixelbuffer_from_resource("tile1", $resources),
  72. make_sprite_from_resource("tile1", $resources)))
  73. $tileset.add_tile(4, Tile.new(make_pixelbuffer_from_resource("tile2", $resources),
  74. make_sprite_from_resource("tile2", $resources)))
  75. ## Create some basic GUI
  76. $gui = GUI.new()
  77. $gui.workspace.set_tool($controller.tilemap_paint_tool.to_tool());
  78. startlevel = Level.new(100, 50)
  79. startlevel.activate($workspace)
  80. $gui.run()
  81. flexlay.deinit()
  82. # EOF #