Code Monkey home page Code Monkey logo

tinamou's Introduction

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

tinamou's People

Contributors

double-oxygen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

seipy dseeni

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.