No description
Find a file
2019-03-29 12:23:38 +09:00
docs 🐛 Positive -> Natural 2018-10-01 13:52:43 +09:00
src 🐛 prevent GUI app from raising IOError 2019-03-29 12:23:38 +09:00
tests 🎊 initial commit! 2018-04-04 14:12:52 +09:00
.gitignore 🎊 initial commit! 2018-04-04 14:12:52 +09:00
LICENSE 🎊 initial commit! 2018-04-04 14:12:52 +09:00
README.md 📝 fix README.md 2018-12-30 13:51:55 +09:00
tinamou.nimble 🔧 use SDL_WINDOW_FULLSCREEN_DESKTOP 2018-09-30 20:55:52 +09:00

Tinamou

Game Library in Nim with SDL2

How to Use

  1. Prepare this library.
    • Add requires "tinamou" in your .nimble file.
  2. import tinamou module.
  3. Create scenes. (See How to Make Scenes)
  4. Do startGame.
  5. That is all!

Documentation

See https://gh.double-oxygen.net/tinamou/tinamou.html

How to Make Scenes

All you have to do first in order to make a scene is extend BaseScene.

# Example
import tinamou
import colors

type
  ExScene = ref object of BaseScene
    count: Natural

  ExScene2 = ref object of BaseScene

  ExScene3 = ref object of BaseScene

Then override the methods.

proc newExScene(): ExScene =
  new result

method init(self: ExScene, tools: Tools, info: SharedInfo) =
  # Scene initialization should be written in `init` method.
  self.count = 0

  tools.imageManager.setImage("imageName", "res/img/example.png")
  tools.imageManager.setSprite("spriteName", "res/img/sprite.png", spriteWidth = 32, spriteHeight = 32)

  tools.soundManager.setMusic("bgmName", "res/music/example.ogg")
  tools.soundManager.setEffect("seName", "res/se/example.wav")

  tools.soundManager.getMusic("bgmName").play()

method update(self: ExScene, tools: Tools, actions: Actions): Transition =
  # What the scene do each frames should be written in `update` method.
  # This method returns scene transition.
  result = stay()

  inc self.count

  if actions.keyboard.isPressed(SPACE):
    result = next("ex2")
  elif self.count >= 1200:
    result = next("ex3")
  elif actions.mouse.isPressed(RIGHT):
    tools.soundManager.getEffect("seName").play()

method draw(self: ExScene, painter: Painter, tools: Tools, actions: Actions) =
  # Output to the screen should be written in `draw` method.
  painter.clear(colWhite)

  painter.drawImage(tools.imageManager.getImage("imageName"), 100, 50, 100, 80)
  painter.drawImage(tools.imageManager.getImage("spriteName"), 200, 10, spriteNum = 2)

  painter.setFont("res/fonts/example.ttf", 48)
  painter.text($actions.mouse.getPosition(), 150, 50).fill(colBlack)

And then register all scenes into scene manager. When starting the game, give the second argument of startGame the initial scene ID.

when isMainModule:
  let scenes = newSceneManager()
  scenes.setScene("ex1", newExScene())
  scenes.setScene("ex2", newExScene2())
  scenes.setScene("ex3", newExScene3())

  startGame(sceneManager = scenes, firstSceneId = "ex1", title = "Tinamou Example", width = 1200, height = 800, showFPS = true)

License

MIT
See LICENSE.

Copyright (c) 2018 Double_oxygeN