mancala

Mancala is a Crystal SFML lib for Activity Management

Mancala

Mancala name is inspired from one of the oldest known games to still be widely played today.

It's goal is to simplify the creation of a multi-view SFML app in Crystal Lang.

Installation

  1. Add the dependency to your shard.yml:

    dependencies:
      mancala:
        github: alex-lairan/mancala
    
  2. Add crsfml to your project.

  3. Run shards install

Usage

First, require the shard :

require "mancala"

Then, create a context for our game :

struct Context
  property texture = Mancala::Resource(SF::Texture).new
end

Now you can create a controller :

mode = SF::VideoMode.new(width, height)
window = SF::RenderWindow.new(mode, name, SF::Style::Fullscreen)

context = Context.new

controller = Mancala::Controller(Context).new(window, context)

Let's register some activities !

class Menu < Mancala::Activity(Context)
end

class Game < Mancala::Activity(Context)
end

controller.register(:game) { |controller| Game.new(controller) }
controller.register(:menu) { |controller| Menu.new(controller) }

Finally, push an activity !

controller.push(:menu)

This controller need to be called on your program loop.

This is an example :

clock = SF::Clock.new

while window.open?
  dt = clock.restart

  while event = @window.poll_event
    controller.handle_event(event)
  end

  controller.update(dt)

  controller.render

  window.display
end

Contributing

  1. Fork it (https://github.com/alex-lairan/mancala/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

Repository

mancala

Owner
Statistic
  • 3
  • 0
  • 0
  • 1
  • 0
  • over 5 years ago
  • March 10, 2019
License

MIT License

Links
Synced at

Wed, 06 Nov 2024 15:54:38 GMT

Languages