terminal_game_engine 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f6c929b4edebdc771f660f1d814c1487018e813f
4
- data.tar.gz: 2fa244fc2b24b6759283a87545e4b8c473a0112d
3
+ metadata.gz: 5d5e89be3b16dac322f0d73efaca372e026d0d5e
4
+ data.tar.gz: 81e5e68033fb0d9f567bc980fc609acd7027eaff
5
5
  SHA512:
6
- metadata.gz: 6145fa6de0cfb0d7eaa3b6bd951d2461612c77d65ba45ca8d5f8858acec5541da0dac7c0bb9b22915ef0c095dd607c8d6db532db6cc8355f6e1e0e871ee0db38
7
- data.tar.gz: 106a35ce83d7f4a01df5d6c66df5d878a87577c16bcb8eb80be4d31b17e386ce9898797c1d732b2a916f7f1480d39853c97edbda9773910bdd13b3e97be6a26f
6
+ metadata.gz: 9cf2c7b404b247dd2b3a72fdfb47079056ea58f93171eb4c9347e4b6775f5af1b484bb8f1cd6fdb3d782a078e0411a79053da934b0834fe9fbdf8b3e9440ce1d
7
+ data.tar.gz: 4961ccefbaff0971b9439375aba1d743ab67256ae959a73fb67f83ad0a49df9697a2188b674a7ed742662d359381819d87262356fd44f5ebf0ddb71716829c0e
data/README.markdown CHANGED
@@ -16,6 +16,31 @@ Or install it yourself as:
16
16
 
17
17
  $ gem install terminal_game_engine
18
18
 
19
+ ## Usage
20
+
21
+ ``` ruby
22
+ require 'terminal_game_engine'
23
+
24
+ TerminalGameEngine.run do
25
+ on_tick do |tick|
26
+ width = tick.to_s.length
27
+ height = 1
28
+ frame = TerminalGameEngine::Frame.new width, height
29
+
30
+ frame.draw 0, 0, tick.to_s
31
+
32
+ on_input do |key_code|
33
+ case key_code
34
+ when TerminalGameEngine::Input::Keys::CTRL_C
35
+ exit
36
+ end
37
+ end
38
+
39
+ frame.render
40
+ end
41
+ end
42
+ ```
43
+
19
44
  ## License
20
45
 
21
46
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/examples/counter.rb CHANGED
@@ -1,32 +1,33 @@
1
1
  require_relative '../lib/terminal_game_engine'
2
2
 
3
- TerminalGameEngine::Frame.setup
4
-
5
- TerminalGameEngine::Engine.tick do |tick|
6
- number = tick.to_s
7
-
8
- height = 3
9
- width = number.length + 2
10
-
11
- frame = TerminalGameEngine::Frame.new width, height
12
-
13
- # draw number
14
- frame.draw_center 1, number
15
-
16
- # draw corners
17
- frame.draw 0, 0, '+'
18
- frame.draw 0, height-1, '+'
19
- frame.draw width-1, 0, '+'
20
- frame.draw width-1, height-1, '+'
21
-
22
- TerminalGameEngine::Input.call do |key|
23
- case key
24
- when 'q'.ord, TerminalGameEngine::Input::Keys::ESCAPE, TerminalGameEngine::Input::Keys::CTRL_C
25
- exit
26
- else
27
- frame.draw_center 1, key.to_s
3
+ TerminalGameEngine.run do
4
+ on_tick do |tick|
5
+ number = tick.to_s
6
+
7
+ height = 3
8
+ width = number.length + 2
9
+
10
+ frame = TerminalGameEngine::Frame.new width, height
11
+
12
+ # draw number
13
+ frame.draw_center 1, number
14
+
15
+ # draw corners
16
+ frame.draw 0, 0, '+'
17
+ frame.draw 0, height-1, '+'
18
+ frame.draw width-1, 0, '+'
19
+ frame.draw width-1, height-1, '+'
20
+
21
+ on_input do |key_code|
22
+ case key_code
23
+ when 'q'.ord, TerminalGameEngine::Input::Keys::ESCAPE, TerminalGameEngine::Input::Keys::CTRL_C
24
+ exit
25
+ else
26
+ frame.draw 0, 1, ' ' * (number.length + 1)
27
+ frame.draw_center 1, key_code.chr
28
+ end
28
29
  end
29
- end
30
30
 
31
- frame.render
31
+ frame.render
32
+ end
32
33
  end
@@ -1,4 +1,9 @@
1
1
  Dir[File.dirname(__FILE__) + "/**/*.rb"].each { |f| require f }
2
2
 
3
3
  module TerminalGameEngine
4
+ def self.run(*args, &block)
5
+ TerminalGameEngine::Frame.setup
6
+
7
+ EngineProxy.new(*args).instance_eval &block
8
+ end
4
9
  end
@@ -0,0 +1,21 @@
1
+ class TerminalGameEngine::EngineProxy
2
+ def initialize(tick_sleep: nil)
3
+ @tick_sleep = tick_sleep
4
+ end
5
+
6
+ def on_tick(&block)
7
+ TerminalGameEngine::Engine.tick *tick_args, &block
8
+ end
9
+
10
+ def on_input(&block)
11
+ TerminalGameEngine::Input.call &block
12
+ end
13
+
14
+ private
15
+
16
+ def tick_args
17
+ args = []
18
+ args << ({tick_sleep: @tick_sleep}) if @tick_sleep
19
+ args
20
+ end
21
+ end
@@ -1,3 +1,3 @@
1
1
  module TerminalGameEngine
2
- VERSION = '0.1.2'
2
+ VERSION = '0.2.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: terminal_game_engine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Odin Dutton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-15 00:00:00.000000000 Z
11
+ date: 2016-07-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -70,6 +70,7 @@ files:
70
70
  - examples/counter.rb
71
71
  - lib/terminal_game_engine.rb
72
72
  - lib/terminal_game_engine/engine.rb
73
+ - lib/terminal_game_engine/engine_proxy.rb
73
74
  - lib/terminal_game_engine/frame.rb
74
75
  - lib/terminal_game_engine/input.rb
75
76
  - lib/terminal_game_engine/network.rb