Manual.adoc 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  1. Forest2D user manual
  2. ====================
  3. Forest2D is a 2d tile-based cross platform game engine
  4. written primarily in Lua using the Lua-SDL2 binding.
  5. It is intended for simple 2d tile-based games providing
  6. graphics, audio, collision detection, sprites,
  7. tilemaps, gui, animation and more.
  8. Global variables.
  9. ~~~~~~~~~~~~~~~~~
  10. [source,lua]
  11. ----
  12. Forest2D.WINDOW_WIDTH -- default value 640
  13. Forest2D.WINDOW_HEIGHT -- default value 480
  14. Forest2D.TextureList -- default value {}
  15. ----
  16. Functions.
  17. ~~~~~~~~~~
  18. [source,lua]
  19. ----
  20. Forest2D:Init()
  21. ----
  22. Used to initialize engine.
  23. Arguments
  24. ~~~~~~~~~
  25. None.
  26. Returns
  27. ~~~~~~~
  28. *true* on success, *nil* on failure.
  29. [source,lua]
  30. ----
  31. Forest2D.TextureList:Load(Renderer, Directory)
  32. ----
  33. Used to load textures from a given directory into the Forest2D.TextureList table
  34. Arguments
  35. ~~~~~~~~~
  36. - *Renderer* an SDL https://github.com/Tangent128/luasdl2/wiki/Sdl-RendererObject[Renderer] object.
  37. - *Directory* the path of the desired directory repersented as a string
  38. Returns
  39. ~~~~~~~
  40. *nil*.
  41. [source,lua]
  42. ----
  43. Forest2D.TextureList:Push(Texture)
  44. ----
  45. Used to push a texture onto the Forest2D.TextureList table
  46. Arguments
  47. ~~~~~~~~~
  48. *Texture* an SDL2 Texture
  49. Returns
  50. ~~~~~~~
  51. *nil*.
  52. [source,lua]
  53. ----
  54. Forest2D.TextureList:Pop()
  55. ----
  56. Used to pop a texture off the Forest2D.TextureList table
  57. Arguments
  58. ~~~~~~~~~
  59. None.
  60. Returns
  61. ~~~~~~~
  62. *nil*.
  63. [source,lua]
  64. ----
  65. Forest2D:CreateSDLWindow(Title, Icon)
  66. ----
  67. You must set the variables Forest2D.WINDOW_WIDTH and Forest2D.WINDOW_HEIGHT before calling this function otherwise the default values of 640x480 will be used.
  68. Arguments
  69. ~~~~~~~~~
  70. - *Title* the window title
  71. - *Icon* the location of a .bmp file used for the window icon
  72. Returns
  73. ~~~~~~~
  74. An SDL https://github.com/Tangent128/luasdl2/wiki/Sdl-WindowObject[Window] object or *nil*
  75. [source,lua]
  76. ----
  77. Forest2D:CreateSDLRenderer(window)
  78. ----
  79. Arguments
  80. ~~~~~~~~~
  81. - *window* an SDL window
  82. Returns
  83. ~~~~~~~
  84. An SDL https://github.com/Tangent128/luasdl2/wiki/Sdl-RendererObject[Renderer] object or *nil*
  85. [source,lua]
  86. ----
  87. Forest2D:Quit()
  88. ----
  89. Quits Forest2D.
  90. Arguments
  91. ~~~~~~~~~
  92. None.
  93. Returns
  94. ~~~~~~~
  95. *nil*.
  96. [source,lua]
  97. ----
  98. Forest2D.EventHandler.New(Delay)
  99. ----
  100. Arguments
  101. ~~~~~~~~~
  102. - *Delay* the delay in ms between checking for events.
  103. Returns
  104. ~~~~~~~
  105. A Forest2D *EventHandler* object.
  106. [source,lua]
  107. ----
  108. EventHandler.DisableEvent(EventID, Time)
  109. ----
  110. Arguments
  111. ~~~~~~~~~
  112. - *EventID* the event to be disabled.
  113. - *Time* the time in ms for the event to be disabled.
  114. Returns
  115. ~~~~~~~
  116. *nil*.
  117. [source,lua]
  118. ----
  119. EventHandler.Reset()
  120. ----
  121. Resets the status of all events.
  122. Arguments
  123. ~~~~~~~~~
  124. None.
  125. Returns
  126. ~~~~~~~
  127. *nil*.
  128. [source,lua]
  129. ----
  130. GetCurrentMouseTile(Ycord, Xcord, Camera)
  131. ----
  132. Takes the mouse coordinates and translates them into tile coordinates.
  133. Arguments
  134. ~~~~~~~~~
  135. - *Ycord* the y mouse position
  136. - *Xcord* the x mouse position
  137. - *CameraY* the Y position of the camera
  138. - *CameraX* the X position of the camera
  139. Returns
  140. ~~~~~~~
  141. A table containing the mouse tile coordinates like so {MTileY, MTileX}.
  142. [source,lua]
  143. ----
  144. Forest2D.Audio.New(Audiofile, Channel, SampleRate, NumberOfChannels)
  145. ----
  146. Arguments
  147. ~~~~~~~~~
  148. - *Audiofile* the file of which to play.
  149. - *Channel* the channel of which to play.
  150. - *SampleRate* the sample rate.
  151. - *NumberOfChannels* the number of audio channels to open.
  152. Returns
  153. ~~~~~~~
  154. A Forest2D *Audio* object.
  155. [source,lua]
  156. ----
  157. Audio:Play()
  158. ----
  159. Plays the *Audio* object if the channel is free.
  160. Arguments
  161. ~~~~~~~~~
  162. None.
  163. Returns
  164. ~~~~~~~
  165. *nil*.
  166. [source,lua]
  167. ----
  168. Forest2D.TileAnimation.New(Renderer, AnimationFile)
  169. ----
  170. Creates a new Forest2D *TileAnimation* object.
  171. Arguments
  172. ~~~~~~~~~
  173. - *Renderer* an SDL https://github.com/Tangent128/luasdl2/wiki/Sdl-RendererObject[Renderer] object.
  174. - *TileAnimationFile* can be the location of a tile animation file or an SDL https://github.com/Tangent128/luasdl2/wiki/Sdl-TextureObject[Texture] object.
  175. Returns
  176. ~~~~~~~
  177. A Forest2D *TileAnimation* object.
  178. [source,lua]
  179. ----
  180. TileAnimation.Play(Renderer, DestRect, Speed, RunAsLoop, Camera)
  181. ----
  182. Plays the tile animation.
  183. Arguments
  184. ~~~~~~~~~
  185. - *Renderer* an SDL https://github.com/Tangent128/luasdl2/wiki/Sdl-RendererObject[Renderer] object.
  186. - *DestRect* an SDL https://github.com/Tangent128/luasdl2/wiki/Sdl-Rect[Rect] object.
  187. - *Speed* the time in ms it takes to increment a frame.
  188. - *RunAsLoop* a boolean value self explanatory.
  189. Returns
  190. ~~~~~~~
  191. *nil*.
  192. [source,lua]
  193. ----
  194. TileAnimation.PlayTile(Renderer, x, y, Speed, RunAsLoop, Camera)
  195. ----
  196. Plays the tile animation at a specific tile.
  197. A Forest2D *World* object must exist for this function to be used
  198. Arguments
  199. ~~~~~~~~~
  200. - *Renderer* an SDL https://github.com/Tangent128/luasdl2/wiki/Sdl-RendererObject[Renderer] object.
  201. - *x* the x tile coordinate on the tilemap
  202. - *y* the y tile coordinate on the tilemap
  203. - *Speed* the time in ms it takes to increment a frame.
  204. - *RunAsLoop* a boolean value self explanatory.
  205. - *Camera* an optional Forest2D camera object used if the frame needs to be rendered relative to the camera
  206. Returns
  207. ~~~~~~~
  208. *nil*.
  209. [source,lua]
  210. ----
  211. TileAnimation.PlayFrame(Renderer, DestRect, Frame, Camera)
  212. ----
  213. Plays a specific frame of the TileAnimation object.
  214. Arguments
  215. ~~~~~~~~~
  216. - *Renderer* an SDL https://github.com/Tangent128/luasdl2/wiki/Sdl-RendererObject[Renderer] object.
  217. - *DestRect* an SDL https://github.com/Tangent128/luasdl2/wiki/Sdl-Rect[Rect] object.
  218. - *Frame* the frame of which to display.
  219. - *Camera* an optional Forest2D camera object used if the frame needs to be rendered relative to the camera.
  220. Returns
  221. ~~~~~~~
  222. *nil*.
  223. [source,lua]
  224. ----
  225. Forest2D.World.TileAnimationset.New(Renderer, TileAnimationsetFile, TileAnimationsetCfgFile)
  226. ----
  227. Creates a new Forest2D *TileAnimationset* object.
  228. Arguments
  229. ~~~~~~~~~
  230. - *Renderer* an SDL https://github.com/Tangent128/luasdl2/wiki/Sdl-RendererObject[Renderer] object.
  231. - *TileAnimationsetFile* the location of the TileAnimationset file.
  232. - *TileAnimationsetCfgFile* the location of the TileAnimationset configuration file.
  233. Returns
  234. ~~~~~~~
  235. A Forest2D *TileAnimationset* object.
  236. [source,lua]
  237. ----
  238. Forest2D.World.Tileset.New(Renderer, TilesetFile)
  239. ----
  240. Creates a new Forest2D *Tileset* object.
  241. Arguments
  242. ~~~~~~~~~
  243. - *Renderer* an SDL https://github.com/Tangent128/luasdl2/wiki/Sdl-RendererObject[Renderer] object.
  244. - *TilesetFile* the location of the Tileset file.
  245. Returns
  246. ~~~~~~~
  247. A Forest2D *Tileset* object.
  248. [source,lua]
  249. ----
  250. Forest2D.World.New(Renderer, Tileset, TileAnimationset, TileSize, SizeW, SizeZ, SizeY, SizeX)
  251. ----
  252. Creates a new Forest2D *World* object. +
  253. Note that *World* is a special object, only one *World* object should exist at once and the *World* must be freed when done with.
  254. Arguments
  255. ~~~~~~~~~
  256. - *Renderer* an SDL https://github.com/Tangent128/luasdl2/wiki/Sdl-RendererObject[Renderer] object.
  257. - *Tileset* a *Tileset* object that will contain all tiles to be used on the tilemap.
  258. - *TileAnimationset* a *TileAnimationset* object that will contain all animations to be used on the tilemap.
  259. - *TileSize* the tile size.
  260. - *SizeW* the maximum w coordinate (the 4th dimension).
  261. - *SizeZ* the maximum z coordinate.
  262. - *SizeY* the maximum y coordinate.
  263. - *SizeX* the maximum x coordinate.
  264. Returns
  265. ~~~~~~~
  266. A Forest2D *World* object.
  267. [source,lua]
  268. ----
  269. World:Free()
  270. ----
  271. Free's the *World* from memory.
  272. Arguments
  273. ~~~~~~~~~
  274. None.
  275. Returns
  276. ~~~~~~~
  277. *nil*.
  278. [source,lua]
  279. ----
  280. World.SpriteList.Push(Sprite)
  281. ----
  282. Push an item onto the SpriteList.
  283. Arguments
  284. ~~~~~~~~~
  285. Sprite a Forest2D *Sprite* object.
  286. Returns
  287. ~~~~~~~
  288. *nil*.
  289. [source,lua]
  290. ----
  291. World.SpriteList.Pop()
  292. ----
  293. Pop an item from the SpriteList.
  294. Arguments
  295. ~~~~~~~~~
  296. None.
  297. Returns
  298. ~~~~~~~
  299. *nil*.
  300. [source,lua]
  301. ----
  302. World:Load(Worldfile, SpriteListFile)
  303. ----
  304. Loads a .world and SpriteList file.
  305. Arguments
  306. ~~~~~~~~~
  307. - *Worldfile* the location of the .world file.
  308. - *SpriteListFile* the location of the SpriteList file.
  309. Returns
  310. ~~~~~~~
  311. *nil*.
  312. [source,lua]
  313. ----
  314. World:Save(Worldfile, SpriteListFile)
  315. ----
  316. Saves a .world and SpriteList file.
  317. Arguments
  318. ~~~~~~~~~
  319. - *Worldfile* the location of the .world file.
  320. - *SpriteListFile* the location of the SpriteList file.
  321. Returns
  322. ~~~~~~~
  323. *nil*.
  324. [source,lua]
  325. ----
  326. World:Render(Z)
  327. ----
  328. Renders a layer of the *World*
  329. Arguments
  330. ~~~~~~~~~
  331. - *Z* the layer of which to render
  332. Returns
  333. ~~~~~~~
  334. *nil*.
  335. [source,lua]
  336. ----
  337. World:GetTile(W, Z, Y, X, Member)
  338. ----
  339. Arguments
  340. ~~~~~~~~~
  341. - *Z* the z coordinate.
  342. - *Y* the y coordinate.
  343. - *X* the x coordinate.
  344. - *W* the W coordinate the 4th dimension.
  345. - *Member* the member to access at the given coordinates.
  346. Returns
  347. ~~~~~~~
  348. The value of the Member at the given coordinates.
  349. [source,lua]
  350. ----
  351. World:SetTile(W, Z, Y, X, Value, Member)
  352. ----
  353. Arguments
  354. ~~~~~~~~~
  355. - *Z* the z coordinate.
  356. - *Y* the y coordinate.
  357. - *X* the x coordinate.
  358. - *W* the W coordinate the 4th dimension.
  359. - *Value* the value to set.
  360. - *Member* the member to set the value of.
  361. Returns
  362. ~~~~~~~
  363. *nil*.
  364. [source,lua]
  365. ----
  366. Sprite.New(Y, X, W, H, TextureID, AnimationTable)
  367. ----
  368. Creates a new *Sprite* object
  369. Arguments
  370. ~~~~~~~~~
  371. - *Y* the y coordinate.
  372. - *X* the x coordinate.
  373. - *W* the sprites width
  374. - *H* the sprites height
  375. - *TextureID* the index used to determine the sprites texture from the Forest2D.TextureList table.
  376. - *AnimationTable* an optional table parameter specifying how the sprite will be animated +
  377. and with which textures from the Forest2D.TextureList table using the attributes: +
  378. AnimationTable.LoopStatus, AnimationTable.Speed, AnimationTable.Indicies, +
  379. example: AnimationTable.LoopStatus = false, AnimationTable.Speed = 500, +
  380. AnimationTable.Indicies = {4, 5, 6, 7, 8} the Indicies table is used to specificy the textures +
  381. in Forest2D.TextureList to be used in the animation in the given order.
  382. Returns
  383. ~~~~~~~
  384. A *Sprite* object.
  385. [source,lua]
  386. ----
  387. GUI.NewWindow(Renderer, Rect, ColorRGB, Alpha, TitleBar)
  388. ----
  389. Arguments
  390. ~~~~~~~~~
  391. - *Renderer* an SDL https://github.com/Tangent128/luasdl2/wiki/Sdl-RendererObject[Renderer] object.
  392. - *Rect* an SDL https://github.com/Tangent128/luasdl2/wiki/Sdl-Rect[Rect] object to set the width, height, x position and y position of the window.
  393. - *ColorRGB* a hexadecimal number between 0x000000 and 0xFFFFFF to set the color of the window.
  394. - *Alpha* a number between 0 and 255 to set the transparency of the window.
  395. - *TitleBar* a table that is defined like so:
  396. [source,lua]
  397. local TitleBar = {color = 0xAA55FF, alpha = 210, text = "MyWindow", textcolor = 0xFFFFFF, selectable = true, uncloseable = false}
  398. Returns
  399. ~~~~~~~
  400. A Forest2D *Window* object.
  401. [source,lua]
  402. ----
  403. GUI.NewLabel(Window, Renderer, Rect, TTFfile, FontRes, Text, ColorRGB)
  404. ----
  405. Arguments
  406. ~~~~~~~~~
  407. - *Window* a Forest2D *Window* object (optional)
  408. - *Renderer* an SDL https://github.com/Tangent128/luasdl2/wiki/Sdl-RendererObject[Renderer] object.
  409. - *Rect* an SDL https://github.com/Tangent128/luasdl2/wiki/Sdl-Rect[Rect] object to set the width, height, x position and y position of the *Label* inside of the window.
  410. - *TTFfile* an optional custom True Type Font file to be applied to the *Label*.
  411. - *FontRest* the font resolution.
  412. - *Text* the string of text for the label to contain.
  413. - *TextColor* a hexadecimal number between 0x000000 and 0xFFFFFF to set the color of the *Label*.
  414. Returns
  415. ~~~~~~~
  416. A Forest2D *Label* object.
  417. [source,lua]
  418. ----
  419. GUI.NewButton(Window, Renderer, Rect, Text, TextColor, BackgroundColor)
  420. ----
  421. Arguments
  422. ~~~~~~~~~
  423. - *Window* a Forest2D *Window* object (optional)
  424. - *Renderer* an SDL https://github.com/Tangent128/luasdl2/wiki/Sdl-RendererObject[Renderer] object.
  425. - *Rect* an SDL https://github.com/Tangent128/luasdl2/wiki/Sdl-Rect[Rect] object to set the width, height, x position and y position of the *Button* inside of the window.
  426. - *Text* the string of text for the button to contain.
  427. - *TextColor* a hexadecimal number between 0x000000 and 0xFFFFFF to set the color of the *Button*.
  428. - *BackgroundColor* a hexadecimal number between 0x000000 and 0xFFFFFF to set the background color of the *Button*.
  429. Returns
  430. ~~~~~~~
  431. A Forest2D *Button* object.
  432. [source,lua]
  433. ----
  434. GUI.NewMenu(Renderer, Buttons, Rect, Title, Txtcolor, BGcolor, BGalpha)
  435. ----
  436. Arguments
  437. ~~~~~~~~~
  438. - *Renderer* an SDL https://github.com/Tangent128/luasdl2/wiki/Sdl-RendererObject[Renderer] object.
  439. - *Buttons* a table containing 1 or more Forest2D *Buttons* which can be declaired using this format +
  440. [source,lua]
  441. ----
  442. local Item1 = Forest2D.GUI.NewButton(nil, Renderer, nil, "item1", 0x000000, 0xFFFFFF)
  443. ----
  444. - *Rect* an SDL https://github.com/Tangent128/luasdl2/wiki/Sdl-Rect[Rect] object
  445. - *Title* a string to be the title of the menu
  446. - *TxtColor* a hexadecimal number between 0x000000 and 0xFFFFFF to be the text color
  447. - *BGcolor* a hexadecimal number between 0x000000 and 0xFFFFFF to be the background color
  448. - BGalpha a number between 0 and 255 to set the transparency of the background
  449. [source,lua]
  450. ----
  451. Window:Add(Object)
  452. ----
  453. Adds a GUI object to a *Window*.
  454. Arguments
  455. ~~~~~~~~~
  456. - *Object* the GUI object to add to the window.
  457. Returns
  458. ~~~~~~~
  459. *nil*.
  460. [source,lua]
  461. ----
  462. Window:Render(EventHandler)
  463. ----
  464. Displays the *Window* and all objects contained in said *Window*.
  465. Arguments
  466. ~~~~~~~~~
  467. A Forest2D EventHandler object (needed to keep track of mouse input)
  468. Returns
  469. ~~~~~~~
  470. *nil*.
  471. [source,lua]
  472. ----
  473. Window:Move(x,y)
  474. ----
  475. Moves the *Window*.
  476. Arguments
  477. ~~~~~~~~~
  478. - *x* the change to apply to the x coordinate
  479. - *y* the change to apply to the y coordinate
  480. Returns
  481. ~~~~~~~
  482. *nil*.
  483. [source,lua]
  484. ----
  485. Window:Scale(w,h)
  486. ----
  487. Scales the *Window* and its objects.
  488. Arguments
  489. ~~~~~~~~~
  490. - *w* the change to apply to the windows width.
  491. - *h* the change to apply to the windows height.
  492. Returns
  493. ~~~~~~~
  494. *nil*.