gosu_grid 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cb67d7d038f1af2dd1995feaab620a5170ebef04
4
+ data.tar.gz: 47df4d111a3de8f8bc28f07ff6ee0f5093a2828f
5
+ SHA512:
6
+ metadata.gz: 08884a83ec764070e599e9434c6adec5fac80b9e490593e7b2a15c54176de59b6755a34f5a9497cf30521a476867a4ed6a383f89bcb731b18a43cb4facfa96af
7
+ data.tar.gz: 958213e2198b8cae49fb102d054fa76b380ac35903772a92fc9eed3e78559f62a68b193c87f20d704564c040ea396568517f41f744cfaef7d332a70f1076ba8d
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1 @@
1
+ export PATH=$PWD/bin:$PATH
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in gosu_grid.gemspec
4
+ gem 'gosu'
5
+
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Anton Shemerey
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # Gosu::Grid
2
+
3
+ This gem just provides some methods to get game grid, fill it with cells, and
4
+ move stuff around. You can easely modify it for your needs. Feel free to
5
+ contribute in this project if you find it useful or interesting.
6
+
7
+ ![](https://raw.githubusercontent.com/shemerey/gosu_grid/master/assets/gosu_grid_example.png)
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'gosu_grid'
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install gosu_grid
22
+
23
+ ## Usage
24
+
25
+ #### How to Draw default grid
26
+
27
+ ```ruby
28
+ class GridGameExample < Gosu::Window
29
+ def initialize
30
+ super(540, 320, false)
31
+ @grid = Gosu::Grid.new(self)
32
+ @grid.default_cell = DeadCell.new(self, 0, 0)
33
+ end
34
+
35
+ def draw
36
+ @grid.draw && sleep(0.05)
37
+ end
38
+ end
39
+ ```
40
+
41
+ more examples [here](example)
42
+
43
+ ## Contributing
44
+
45
+ 1. Fork it ( https://github.com/shemerey/gosu_grid/fork )
46
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
47
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
48
+ 4. Push to the branch (`git push origin my-new-feature`)
49
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new
5
+
6
+ task :default => :spec
7
+ task :test => :spec
8
+
9
+ task :console do
10
+ require 'pry'
11
+ require 'gosu/grid'
12
+ ARGV.clear
13
+ Pry.start
14
+ end
Binary file
Binary file
Binary file
data/example/grid ADDED
@@ -0,0 +1,71 @@
1
+ #!/usr/bin/env ruby
2
+ # vim:fen:fdm=marker:fmr={{{,}}}:fdl=0:fdc=1:ts=2:sw=2:sts=2:nu
3
+
4
+ lib = File.expand_path('../../lib', __FILE__)
5
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
+
7
+ require 'gosu'
8
+ require 'gosu/all'
9
+
10
+ class LiveCell < Gosu::Grid::Cell
11
+ def size
12
+ tiles.first.width
13
+ end
14
+
15
+ private
16
+
17
+ def tiles
18
+ @tiles ||= Gosu::Image.load_tiles(window, 'assets/live_cells.png', 18, 18, true)
19
+ end
20
+
21
+ def object
22
+ tiles[Gosu::milliseconds / 50 % tiles.size];
23
+ end
24
+ end
25
+
26
+ class DeadCell < Gosu::Grid::Cell
27
+ def size
28
+ object.width
29
+ end
30
+
31
+ private
32
+
33
+ def object
34
+ @object ||= Gosu::Image.new(window, 'assets/dead_cell.png', true)
35
+ end
36
+ end
37
+
38
+ class GridGameExample < Gosu::Window
39
+ def initialize
40
+ super(540, 325, false)
41
+
42
+ self.caption = "Gosu Grid"
43
+
44
+ @grid = Gosu::Grid.new(self)
45
+ @grid.default_cell = DeadCell.new(self, 0, 0)
46
+
47
+ @live = LiveCell.new(self, 5, 6)
48
+ @grid.cells << @live
49
+ end
50
+
51
+ def needs_cursor?; true; end
52
+
53
+ def button_down(id)
54
+ close if id == Gosu::KbEscape
55
+ end
56
+
57
+ def update
58
+ @live.left! if button_down? Gosu::KbLeft
59
+ @live.down! if button_down? Gosu::KbDown
60
+ @live.up! if button_down? Gosu::KbUp
61
+ @live.right! if button_down? Gosu::KbRight
62
+ end
63
+
64
+ def draw
65
+ @grid.draw && sleep(0.05)
66
+ end
67
+ end
68
+
69
+ if __FILE__ == $PROGRAM_NAME
70
+ GridGameExample.new.show
71
+ end
data/gosu_grid.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'gosu/all'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'gosu_grid'
8
+ spec.version = Gosu::Grid::VERSION
9
+ spec.authors = ['Anton Shemerey']
10
+ spec.email = ['shemerey@gmail.com']
11
+ spec.summary = %q{Gosu::Grid simple game grids}
12
+ spec.description = %q{This gem provide basic functional to draw game grid and move stuff around}
13
+ spec.homepage = 'https://github.com/shemerey/gosu_grid'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_runtime_dependency 'gosu'
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.6'
24
+ spec.add_development_dependency 'rubocop'
25
+ spec.add_development_dependency 'rake'
26
+ spec.add_development_dependency 'rspec'
27
+ spec.add_development_dependency 'pry'
28
+ end
data/lib/gosu/all.rb ADDED
@@ -0,0 +1,6 @@
1
+ require 'gosu'
2
+ require 'matrix'
3
+ require 'gosu/grid'
4
+ require 'gosu/grid/cell'
5
+ require 'gosu/grid/version'
6
+
data/lib/gosu/grid.rb ADDED
@@ -0,0 +1,66 @@
1
+ require 'gosu/all'
2
+
3
+ class Gosu::Grid
4
+ attr_reader :window, :cells
5
+
6
+ attr_accessor :x, :y, :z
7
+ attr_accessor :default_cell, :rows, :columns
8
+
9
+ def initialize(window)
10
+ @window, @cells = window, []
11
+ end
12
+
13
+ def default_cell
14
+ @default_cell || raise(NotImplementedError, 'You have to define bacground cell')
15
+ end
16
+
17
+ def x
18
+ @x ||= 0
19
+ end
20
+
21
+ def y
22
+ @y ||= 0
23
+ end
24
+
25
+ def z
26
+ @z ||= 0
27
+ end
28
+
29
+ def rows
30
+ @rows ||= default_rows
31
+ end
32
+
33
+ def columns
34
+ @columns ||= default_columns
35
+ end
36
+
37
+ def draw
38
+ default_cells.each do |cell|
39
+ cell.draw
40
+ end
41
+
42
+ cells.each do |cell|
43
+ cell.draw
44
+ end
45
+ end
46
+
47
+ private
48
+
49
+ def default_rows
50
+ (window.width / default_cell.size).to_i
51
+ end
52
+
53
+ def default_columns
54
+ (window.height / default_cell.size).to_i
55
+ end
56
+
57
+ def default_cells
58
+ @default_cells ||= Matrix.build(rows, columns) do |row, column|
59
+ default_cell.dup.tap do |cell|
60
+ cell.row = row
61
+ cell.column = column
62
+ end
63
+ end
64
+ end
65
+ end
66
+
@@ -0,0 +1,52 @@
1
+ require 'gosu/all'
2
+
3
+ class Gosu::Grid::Cell
4
+ attr_reader :window
5
+ attr_accessor :row, :column
6
+
7
+ def initialize(window, row, column)
8
+ @window, @row, @column = window, row, column
9
+ yield if block_given?
10
+ end
11
+
12
+ def object
13
+ raise NotImplementedError, 'You have to define object to draw'
14
+ end
15
+
16
+ def right!(step = 1)
17
+ self.row += step
18
+ end
19
+
20
+ def left!(step = 1)
21
+ self.row -= step
22
+ end
23
+
24
+ def up!(step = 1)
25
+ self.column -= step
26
+ end
27
+
28
+ def down!(step = 1)
29
+ self.column += step
30
+ end
31
+
32
+ def x
33
+ size * row
34
+ end
35
+
36
+ def y
37
+ size * column
38
+ end
39
+
40
+ def z
41
+ 0
42
+ end
43
+
44
+ def draw
45
+ object.draw(x, y, z)
46
+ end
47
+
48
+ def size
49
+ object.width
50
+ end
51
+ end
52
+
@@ -0,0 +1,3 @@
1
+ class Gosu::Grid
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe Gosu::Grid::Cell do
4
+
5
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe Gosu::Grid do
4
+
5
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'ostruct'
3
+ require 'bundler/setup'
4
+ require 'gosu/all'
5
+
6
+ Dir[File.expand_path(File.join(File.dirname(__FILE__),'support','**','*.rb'))].each {|f| require f}
7
+
8
+ RSpec.configure do |config|
9
+
10
+ end
metadata ADDED
@@ -0,0 +1,150 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gosu_grid
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Anton Shemerey
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: gosu
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: This gem provide basic functional to draw game grid and move stuff around
98
+ email:
99
+ - shemerey@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - .gitignore
105
+ - .rspec
106
+ - .rvm/hooks/after_cd
107
+ - Gemfile
108
+ - LICENSE.txt
109
+ - README.md
110
+ - Rakefile
111
+ - assets/dead_cell.png
112
+ - assets/gosu_grid_example.png
113
+ - assets/live_cells.png
114
+ - example/grid
115
+ - gosu_grid.gemspec
116
+ - lib/gosu/all.rb
117
+ - lib/gosu/grid.rb
118
+ - lib/gosu/grid/cell.rb
119
+ - lib/gosu/grid/version.rb
120
+ - spec/gosu/grid/cell_spec.rb
121
+ - spec/gosu/grid_spec.rb
122
+ - spec/spec_helper.rb
123
+ homepage: https://github.com/shemerey/gosu_grid
124
+ licenses:
125
+ - MIT
126
+ metadata: {}
127
+ post_install_message:
128
+ rdoc_options: []
129
+ require_paths:
130
+ - lib
131
+ required_ruby_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - '>='
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - '>='
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ requirements: []
142
+ rubyforge_project:
143
+ rubygems_version: 2.2.2
144
+ signing_key:
145
+ specification_version: 4
146
+ summary: Gosu::Grid simple game grids
147
+ test_files:
148
+ - spec/gosu/grid/cell_spec.rb
149
+ - spec/gosu/grid_spec.rb
150
+ - spec/spec_helper.rb