feed_bo 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e79efc257bf5eeed749f09b5e713143b7338c2ca
4
+ data.tar.gz: e428e2290badc31c3edf7ee72a465d3871754be9
5
+ SHA512:
6
+ metadata.gz: b7f97cf4c7d18eef65136edfcf05462418b355e1553d3fe92fcc5bb26cc10de3d5c58e02422b3b5ce3707a4dc9a5fc8d961c92a02086ef5f2408f6c69f867068
7
+ data.tar.gz: 737af7406e09e4253c66ab72ae4a31818ffbfd5cd6acfd3cb53c189eb377c3e8701d3819b6ab67704c6bcfa323fbea18e772a8b50a056cb12ced5863c06f63e0
data/.DS_Store ADDED
Binary file
data/.gitignore ADDED
@@ -0,0 +1,17 @@
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
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in feed_bo.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Jannes Köhler
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,29 @@
1
+ # FeedBo
2
+
3
+ FeedBo is a virtual robot written in ruby. FeedBo is designed to learn coding by playing.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'feed_bo'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install feed_bo
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/feed_bo.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'feed_bo/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "feed_bo"
8
+ spec.version = FeedBo::VERSION
9
+ spec.authors = ["Jannes Köhler"]
10
+ spec.email = ["janneskoehler@gmail.com"]
11
+ spec.description = %q{Feed Bo is a computer game written in ruby.}
12
+ spec.summary = %q{Feed Bo is designed to learn coding by playing.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
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_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+
24
+ spec.add_runtime_dependency "builder"
25
+ end
data/lib/.DS_Store ADDED
Binary file
@@ -0,0 +1,18 @@
1
+ module FeedBo
2
+ class Balloon < Element
3
+
4
+ def draw
5
+ s = Level::FIELD_SIZE
6
+ @svg.circle id: 'balloon', cx: s/2, cy: s/2, r: s/2, stroke: 'black', fill: 'blue'
7
+ end
8
+
9
+ def hit
10
+ @level.points += 1
11
+
12
+ @svg.animateTransform attributeName: "transform", type: "scale", from: "1", to: "0",
13
+ begin: @level.step*Level::STEP_DUR, dur: 0.05, additive: 'sum', fill: 'freeze'
14
+ @svg.animateMotion by: "#{Level::FIELD_SIZE/2},#{Level::FIELD_SIZE/2}", begin: @level.step*Level::STEP_DUR, dur: 0.05, fill: 'freeze'
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,21 @@
1
+ module FeedBo
2
+ module Drawable
3
+
4
+ attr_accessor :svg, :position, :start_position
5
+
6
+ def initialize
7
+ super
8
+ @svg = ::Builder::XmlMarkup.new
9
+ @position = [(Level::WIDTH/2).round, (Level::HEIGHT/2).round]
10
+ end
11
+
12
+ def draw
13
+ s = Level::FIELD_SIZE
14
+ @svg.circle cx: s/2, cy: s/2, r: s/2, style: 'stroke: black; fill: black'
15
+ end
16
+
17
+ def perform_step
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,16 @@
1
+ module FeedBo
2
+ class Element
3
+
4
+ include Drawable
5
+
6
+ attr_accessor :level
7
+ attr_accessor :block_position
8
+
9
+ def initialize(position=nil)
10
+ super()
11
+ @block_position = false
12
+ @position = position if position
13
+ end
14
+
15
+ end
16
+ end
@@ -0,0 +1,114 @@
1
+ module FeedBo
2
+ class Level
3
+
4
+ WIDTH = 10
5
+ HEIGHT = 10
6
+ FIELD_SIZE = 60
7
+ STEP_DUR = 0.4
8
+ TOTAL_STEPS = 100
9
+
10
+ attr_accessor :elements, :robot, :step, :points, :target_points, :id
11
+
12
+ def initialize
13
+ @elements = []
14
+ @step = 0
15
+ @frame = 0
16
+ @points = 0
17
+ @target_points = 1
18
+ @id = 0
19
+ @svg = ::Builder::XmlMarkup.new
20
+ end
21
+
22
+ def build
23
+ end
24
+
25
+ def run
26
+ (@elements + [@robot]).each do |e|
27
+ e.start_position = e.position.dup
28
+ e.draw
29
+ end
30
+ @robot.run
31
+ @robot.continue
32
+ return draw
33
+ end
34
+
35
+ def perform_step
36
+ @elements.each { |e| e.perform_step }
37
+ @step += 1
38
+ end
39
+
40
+ def add(element)
41
+ element.level = self
42
+ @elements << element
43
+ end
44
+
45
+ def robot=(robot)
46
+ @robot = robot
47
+ @robot.level = self
48
+ end
49
+
50
+ def draw
51
+ # @svg.instruct! :xml, version: '1.0', encoding: 'UTF-8', standalone: 'no'
52
+ # @svg.declare! :DOCTYPE, :svg, :PUBLIC, "-//W3C//DTD SVG 1.1//EN", "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"
53
+
54
+ @svg.svg width: WIDTH*FIELD_SIZE, height: HEIGHT*FIELD_SIZE, version: "1.1", xmlns: "http://www.w3.org/2000/svg" do
55
+ draw_grid
56
+ (@elements + [@robot]).each do |e|
57
+ @svg.g transform: "translate(#{e.start_position[0]*FIELD_SIZE},#{e.start_position[1]*FIELD_SIZE})" do
58
+ @svg << e.svg.target!
59
+ end
60
+ end
61
+ if @points == @target_points
62
+ @svg.g transform: "translate(#{WIDTH*FIELD_SIZE/2-200},#{HEIGHT*FIELD_SIZE/2-100})", visibility: "hidden" do
63
+ @svg.rect width: 400, height: 200, stroke: 'blue', fill: 'white'
64
+ @svg.text 'Level completed!', x: 25, y: 120, :'font-family' => "Verdana", :'font-size' => 40, fill: "blue"
65
+ @svg.set attributeName: "visibility", to: "visible", begin: @step*STEP_DUR
66
+ end
67
+ end
68
+ end
69
+
70
+ # File.open("level#{@id}.svg", "w") do |f|
71
+ # f << @svg.target!
72
+ # end
73
+ return @svg.target!
74
+ end
75
+
76
+ def position_blocked?(pos)
77
+ return true if pos[0] < 0 or pos[1] < 0 or pos[0] > WIDTH-1 or pos[1] > HEIGHT-1
78
+ return @elements.any? do |e|
79
+ e.block_position and Level.distance(e.position, pos) == 0
80
+ end
81
+ end
82
+
83
+ def finish?
84
+ return (@points == @target_points or @step == TOTAL_STEPS)
85
+ end
86
+
87
+ def self.distance(pos1, pos2)
88
+ return (pos1[0] - pos2[0]).abs + (pos1[1] - pos2[1]).abs
89
+ end
90
+
91
+ def self.advanced_distance(pos1, pos2)
92
+ # todo
93
+ end
94
+
95
+ def self.vector_sum(vec1, vec2)
96
+ [vec1, vec2].transpose.map { |e| e.reduce(:+) }
97
+ end
98
+
99
+ protected
100
+
101
+ def draw_grid
102
+ (WIDTH-1).times do |i|
103
+ stroke_width = (i+1) % 5 == 0 ? 0.3 : 0.2
104
+ @svg.line x1: FIELD_SIZE*(i+1), y1: 0, x2: FIELD_SIZE*(i+1), y2: HEIGHT * FIELD_SIZE, style: "stroke: grey; stroke-width: #{stroke_width}"
105
+ end
106
+ (HEIGHT-1).times do |i|
107
+ stroke_width = (i+1) % 5 == 0 ? 0.3 : 0.2
108
+ @svg.line x1: 0, y1: FIELD_SIZE*(i+1), x2: WIDTH * FIELD_SIZE, y2: FIELD_SIZE*(i+1), style: "stroke: grey; stroke-width: #{stroke_width}"
109
+ end
110
+ @svg.rect x: 0, y: 0, width: WIDTH*FIELD_SIZE, height: HEIGHT*FIELD_SIZE, style: "stroke: black; fill: none"
111
+ end
112
+
113
+ end
114
+ end
@@ -0,0 +1,159 @@
1
+ module FeedBo
2
+ class Robot
3
+
4
+ include Drawable
5
+ include Transformable
6
+
7
+ attr_accessor :level
8
+
9
+ def initialize
10
+ super
11
+ @moving = false
12
+ end
13
+
14
+ def draw
15
+ @svg.g transform: "scale(#{Level::FIELD_SIZE.to_f / 100})" do
16
+ @svg.path style: "display:inline;fill:#2a7fff;stroke:none;stroke-width:1;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none",
17
+ d: "m 53.534888,33.83317 c -2.250486,1.97534 -2.801298,6.26126 1.487997,6.23876 3.167284,2.13094 4.982697,-1.20939 3.222035,-3.53103 -1.256073,-1.9221 -2.455915,-6.91569 -4.710032,-2.70773 z"
18
+ @svg.path style: "display:inline;fill:#2a7fff;stroke:none;stroke-width:1;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none",
19
+ d: "m 50.741934,47.03468 c 0.169514,4.9045 -1.606266,14.0017 4.27701,6.4786 1.709147,-1.3005 5.167741,0.5999 5.06235,-2.7533 1.083709,-4.33243 -1.161154,-3.9438 -4.505326,-3.93291 -3.328453,-2.16676 -5.744643,-7.71707 -4.834034,0.20761 z"
20
+ @svg.path style: "display:inline;fill:#2a7fff;stroke:none;stroke-width:1;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none",
21
+ d: "m 56.288473,59.46808 c -1.873711,1.1074 -5.882985,0.7316 -4.465964,4.0124 -0.2201,3.2296 4.09056,6.3835 5.704,2.4389 1.00974,-2.118 3.121602,-7.2302 -1.238036,-6.4513 z"
22
+ @svg.path style: "display:inline;fill:#00ffff;stroke:none;stroke-width:1;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none",
23
+ d: "m 54.77882,38.99021 c -6.149877,0.74647 -2.077266,11.89177 3.080315,8.02313 2.69963,-2.47779 0.746124,-8.10159 -3.080315,-8.02313 z"
24
+ @svg.path style: "display:inline;fill:#00ffff;stroke:none;stroke-width:1;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none",
25
+ d: "m 55.890888,52.15318 c -5.442631,-0.2182 -5.796824,10.1184 0.16927,8.644 3.70033,-1.2286 4.455928,-8.2253 -0.16927,-8.644 z"
26
+ @svg.path style: "display:inline;fill:#99ff55;stroke:none;stroke-width:1;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none",
27
+ d: "m 37.387343,22.41616 c -14.44718,0.63326 -22.771441,16.24125 -21.550394,29.17632 -0.277181,12.7929 9.95217,27.4376 24.138647,25.8816 6.170273,-0.6485 11.351605,-4.6671 14.970529,-9.428 -4.452157,-7.3436 -2.947794,-16.6634 -2.999612,-24.88811 0.276584,-3.93181 0.75605,-7.96443 2.718151,-11.47298 C 50.66731,26.27352 44.394155,22.12346 37.387343,22.41616 Z"
28
+ @svg.path style: "display:inline;fill:#00ff00;stroke:none;stroke-width:1;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none",
29
+ d: "M 18.784785,16.48976 C 12.57128,15.63677 4.0781114,16.78772 2.279024,23.89781 2.5973705,41.45475 1.5775224,59.14528 2.6864452,76.63328 c 2.373724,7.2892 11.3942248,6.7956 17.5705638,6.4504 16.691087,-0.3113 33.522431,0.7114 50.12946,-0.4606 C 90.086874,79.73758 103.41347,57.42858 96.353624,39.06515 91.421612,23.92934 74.853381,14.35325 59.025721,16.51081 45.612087,16.49651 32.19843,16.46301 18.784785,16.48971 Z m 19.446342,6.68626 c 8.303701,-0.0886 15.238641,6.35901 18.759412,13.2251 2.056718,9.65927 2.656458,20.20546 -1.10222,29.19746 -4.663333,6.0921 -11.451899,12.1085 -19.883292,10.7418 -13.69514,-2.0885 -20.248204,-17.4194 -18.784998,-29.49466 0.532483,-11.14305 8.581939,-23.73137 21.011098,-23.6697 z"
30
+ @svg.path style: "display:inline;fill:#44aa00;stroke:none;stroke-width:1;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none",
31
+ d: "m 11.691023,96.95448 c -0.691514,-1.9025 -0.650026,-5.6903 0.08072,-7.3686 l 0.141756,-0.3257 26.784684,-0.032 26.784685,-0.032 0.16771,0.2866 c 0.741106,1.2665 0.834332,5.345 0.167074,7.3084 l -0.230149,0.677 -26.854904,0 -26.854903,0 -0.186675,-0.5135 z"
32
+ @svg.path style: "display:inline;fill:#44aa00;stroke:none;stroke-width:1;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none",
33
+ d: "M 11.640777,10.17889 C 10.949263,8.2763001 10.990751,4.4886701 11.721497,2.8102101 l 0.141759,-0.3255899 26.784683,-0.0321 26.784684,-0.0321 0.16771,0.28659 c 0.741105,1.2664499 0.834332,5.3449499 0.167074,7.3082498 l -0.23015,0.67718 -26.854904,0 -26.854903,0 -0.186674,-0.51359 z"
34
+ @svg.path style: "fill:none;stroke:#000000;stroke-width:3.82572675;stroke-miterlimit:4;stroke-dasharray:none",
35
+ d: "m 1.9128634,49.18748 0,25.2221 c 0,4.8989 4.637128,8.8426 10.3943236,8.8426 l 52.007241,0 a 33.684581,33.576641 0 0 0 0.08656,0.01 33.684581,33.576641 0 0 0 0.122049,-0.01 l 1.821409,0 c 1.090874,0 2.142617,-0.1419 3.128989,-0.4047 a 33.684581,33.576641 0 0 0 28.613639,-33.169 33.684581,33.576641 0 0 1 -0.004,-0.4919"
36
+
37
+ @svg.rect rx: "1.9857054", ry: "5.1384492", y: "88.22226", x: "10.126063", height: "10.276898", width: "57.089027",
38
+ style: "fill:none;stroke:#000000;stroke-width:3.00169158;stroke-miterlimit:4;stroke-dasharray:none"
39
+ @svg.path style: "fill:none;stroke:#000000;stroke-width:2.16155505;stroke-miterlimit:4;stroke-dasharray:none",
40
+ d: "m 50.910761,49.45898 a 4.139694,16.706279 0 0 0 -0.0075,1.0351 4.139694,16.706279 0 0 0 0.01068,1.1811 4.139694,16.706279 0 0 0 0.05008,1.6587 4.139694,16.706279 0 0 0 0.09009,1.6276 4.139694,16.706279 0 0 0 0.130312,1.5852 4.139694,16.706279 0 0 0 0.17031,1.5253 4.139694,16.706279 0 0 0 0.205346,1.4479 4.139694,16.706279 0 0 0 0.240439,1.359 4.139694,16.706279 0 0 0 0.273008,1.2544 4.139694,16.706279 0 0 0 0.30303,1.1387 4.139694,16.706279 0 0 0 0.330601,1.0091 4.139694,16.706279 0 0 0 0.353133,0.8737 4.139694,16.706279 0 0 0 0.37068,0.7269 4.139694,16.706279 0 0 0 0.390702,0.5722 4.139694,16.706279 0 0 0 0.4007,0.4137 4.139694,16.706279 0 0 0 0.408239,0.2494 4.139694,16.706279 0 0 0 0.413235,0.083 4.139694,16.706279 0 0 0 0.293032,-0.043 4.139694,16.706279 0 0 0 0.410728,-0.201 4.139694,16.706279 0 0 0 0.162801,-0.1469 29.688722,26.328456 0 0 0 0.608577,-0.7094 4.139694,16.706279 0 0 0 0.025,-0.035 4.139694,16.706279 0 0 0 0.378207,-0.6824 4.139694,16.706279 0 0 0 0.358132,-0.8313 4.139694,16.706279 0 0 0 0.335609,-0.9723 4.139694,16.706279 0 0 0 0.313058,-1.1019 4.139694,16.706279 0 0 0 0.280505,-1.2216 4.139694,16.706279 0 0 0 0.250455,-1.33 4.139694,16.706279 0 0 0 0.217886,-1.4228 4.139694,16.706279 0 0 0 0.177825,-1.504 4.139694,16.706279 0 0 0 0.142688,-1.5678 4.139694,16.706279 0 0 0 0.102658,-1.6179 4.139694,16.706279 0 0 0 0.06248,-1.6529 4.139694,16.706279 0 0 0 0.02005,-1.6663 4.139694,16.706279 0 0 1 -0.0082,-1.034"
41
+ @svg.path style: "fill:none;stroke:#000000;stroke-width:2.8934989;stroke-miterlimit:4;stroke-dasharray:none",
42
+ d: "m 16.300782,48.91248 a 21.638489,26.477488 0 0 0 -0.04671,1.7375 21.638489,26.477488 0 0 0 21.638146,26.4781 21.638489,26.477488 0 0 0 16.9761,-10.1033 3.0171969,16.800843 0 0 1 -0.118641,0.1477 3.0171969,16.800843 0 0 1 -0.299361,0.2022 3.0171969,16.800843 0 0 1 -0.213582,0.043 3.0171969,16.800843 0 0 1 -0.301185,-0.084 3.0171969,16.800843 0 0 1 -0.297536,-0.2508 3.0171969,16.800843 0 0 1 -0.292065,-0.4161 3.0171969,16.800843 0 0 1 -0.284759,-0.5754 3.0171969,16.800843 0 0 1 -0.270156,-0.731 3.0171969,16.800843 0 0 1 -0.257378,-0.8787 3.0171969,16.800843 0 0 1 -0.240963,-1.0148 3.0171969,16.800843 0 0 1 -0.220857,-1.145 3.0171969,16.800843 0 0 1 -0.198979,-1.2617 3.0171969,16.800843 0 0 1 -0.175237,-1.3667 3.0171969,16.800843 0 0 1 -0.149681,-1.4561 3.0171969,16.800843 0 0 1 -0.124124,-1.5338 3.0171969,16.800843 0 0 1 -0.09493,-1.5941 3.0171969,16.800843 0 0 1 -0.06571,-1.6369 3.0171969,16.800843 0 0 1 -0.03648,-1.6681 3.0171969,16.800843 0 0 1 -0.0071,-1.1877 3.0171969,16.800843 0 0 1 0.01461,-1.6778 3.0171969,16.800843 0 0 1 4.69e-4,-0.025"
43
+ @svg.ellipse transform: "matrix(-0.84627381,0.5327482,0.18301786,0.98310959,0,0)",
44
+ ry: "3.6780479", rx: "3.4933834", cy: "83.254036", cx: "-47.43858", style: "fill:none;stroke:#000000;stroke-width:2.79142904;stroke-miterlimit:4;stroke-dasharray:none"
45
+ @svg.path style: "fill:none;stroke:#000000;stroke-width:3.82572675;stroke-miterlimit:4;stroke-dasharray:none",
46
+ d: "m 1.9128634,50.81258 0,-25.22215 c 0,-4.89894 4.637128,-8.8426 10.3943236,-8.8426 l 52.007241,0 a 33.684581,33.576641 0 0 1 0.08656,-0.005 33.684581,33.576641 0 0 1 0.122049,0.005 l 1.821409,0 c 1.090874,0 2.142617,0.14193 3.128989,0.40479 a 33.684581,33.576641 0 0 1 28.613639,33.16886 33.684581,33.576641 0 0 0 -0.004,0.4919"
47
+ @svg.rect rx: "1.9857054", ry: "5.1384492", y: "-11.777795", x: "10.126063",
48
+ height: "10.276898", width: "57.089027", transform: "scale(1,-1)",
49
+ style: "fill:none;stroke:#000000;stroke-width:3.00169158;stroke-miterlimit:4;stroke-dasharray:none"
50
+ @svg.path style: "fill:none;stroke:#000000;stroke-width:2.16155505;stroke-miterlimit:4;stroke-dasharray:none",
51
+ d: "m 50.910761,50.54098 a 4.139694,16.706279 0 0 1 -0.0075,-1.0351 4.139694,16.706279 0 0 1 0.01068,-1.181 4.139694,16.706279 0 0 1 0.05008,-1.65871 4.139694,16.706279 0 0 1 0.09009,-1.62767 4.139694,16.706279 0 0 1 0.130312,-1.58514 4.139694,16.706279 0 0 1 0.17031,-1.52525 4.139694,16.706279 0 0 1 0.205346,-1.44788 4.139694,16.706279 0 0 1 0.240439,-1.35897 4.139694,16.706279 0 0 1 0.273008,-1.2546 4.139694,16.706279 0 0 1 0.30303,-1.13861 4.139694,16.706279 0 0 1 0.330601,-1.00908 4.139694,16.706279 0 0 1 0.353133,-0.87377 4.139694,16.706279 0 0 1 0.37068,-0.72685 4.139694,16.706279 0 0 1 0.390702,-0.57221 4.139694,16.706279 0 0 1 0.4007,-0.41369 4.139694,16.706279 0 0 1 0.408239,-0.24937 4.139694,16.706279 0 0 1 0.413235,-0.0832 4.139694,16.706279 0 0 1 0.293032,0.0425 4.139694,16.706279 0 0 1 0.410728,0.20104 4.139694,16.706279 0 0 1 0.162801,0.14693 29.688722,26.328456 0 0 1 0.608577,0.70945 4.139694,16.706279 0 0 1 0.025,0.0349 4.139694,16.706279 0 0 1 0.378207,0.68237 4.139694,16.706279 0 0 1 0.358132,0.83124 4.139694,16.706279 0 0 1 0.335609,0.97237 4.139694,16.706279 0 0 1 0.313058,1.10187 4.139694,16.706279 0 0 1 0.280505,1.22173 4.139694,16.706279 0 0 1 0.250455,1.32998 4.139694,16.706279 0 0 1 0.217886,1.42279 4.139694,16.706279 0 0 1 0.177825,1.50393 4.139694,16.706279 0 0 1 0.142688,1.56776 4.139694,16.706279 0 0 1 0.102658,1.61802 4.139694,16.706279 0 0 1 0.06248,1.65292 4.139694,16.706279 0 0 1 0.02005,1.6663 4.139694,16.706279 0 0 0 -0.0082,1.0339"
52
+ @svg.path style: "fill:none;stroke:#000000;stroke-width:2.8934989;stroke-miterlimit:4;stroke-dasharray:none",
53
+ d: "m 16.300782,51.08748 a 21.638489,26.477488 0 0 1 -0.04671,-1.7375 21.638489,26.477488 0 0 1 21.638146,-26.478 21.638489,26.477488 0 0 1 16.9761,10.10326 3.0171969,16.800843 0 0 0 -0.118641,-0.14775 3.0171969,16.800843 0 0 0 -0.299361,-0.20217 3.0171969,16.800843 0 0 0 -0.213582,-0.0427 3.0171969,16.800843 0 0 0 -0.301185,0.0836 3.0171969,16.800843 0 0 0 -0.297536,0.25079 3.0171969,16.800843 0 0 0 -0.292065,0.41604 3.0171969,16.800843 0 0 0 -0.284759,0.57543 3.0171969,16.800843 0 0 0 -0.270156,0.73097 3.0171969,16.800843 0 0 0 -0.257378,0.87871 3.0171969,16.800843 0 0 0 -0.240963,1.01479 3.0171969,16.800843 0 0 0 -0.220857,1.14505 3.0171969,16.800843 0 0 0 -0.198979,1.26171 3.0171969,16.800843 0 0 0 -0.175237,1.36666 3.0171969,16.800843 0 0 0 -0.149681,1.45609 3.0171969,16.800843 0 0 0 -0.124124,1.53387 3.0171969,16.800843 0 0 0 -0.09493,1.59412 3.0171969,16.800843 0 0 0 -0.06571,1.63689 3.0171969,16.800843 0 0 0 -0.03648,1.66804 3.0171969,16.800843 0 0 0 -0.0071,1.1878 3.0171969,16.800843 0 0 0 0.01461,1.6778 3.0171969,16.800843 0 0 0 4.69e-4,0.025"
54
+ @svg.ellipse transform: "matrix(-0.84627381,-0.5327482,0.18301786,-0.98310959,0,0)",
55
+ ry: "3.6780479", rx: "3.4933834", cy: "-7.7939568", cx: "-67.128883",
56
+ style: "fill:none;stroke:#000000;stroke-width:2.79142904;stroke-miterlimit:4;stroke-dasharray:none"
57
+ end
58
+ end
59
+
60
+ def draw_old
61
+ s = Level::FIELD_SIZE
62
+ @svg.polygon points: "0,0 #{s},#{s/2} 0,#{s}", style: "stroke: black; fill: red"
63
+ end
64
+
65
+ def run
66
+ end
67
+
68
+ def continue
69
+ until @level.finish?
70
+ perform_move if @moving
71
+ @level.perform_step
72
+ end
73
+ end
74
+
75
+ protected
76
+
77
+ def move(steps=nil)
78
+ return false if @level.finish?
79
+ @moving = true
80
+ if steps
81
+ steps.times do
82
+ move
83
+ end
84
+ @moving = false
85
+ else
86
+ perform_move
87
+ @level.perform_step
88
+ end
89
+ end
90
+
91
+ def stop
92
+ @moving = false
93
+ end
94
+
95
+ def perform_move
96
+ if hit_positions.none? { |p| @level.position_blocked? p }
97
+ @level.elements.select { |e| hit_positions.include? e.position }.each do |e|
98
+ e.hit if e.respond_to? :hit
99
+ end
100
+ @position = Level.vector_sum(@position, movement)
101
+ animate_move
102
+ end
103
+ end
104
+
105
+ def movement
106
+ x = case @direction
107
+ when 0,4 then 0
108
+ when 1,2,3 then 1
109
+ when 5,6,7 then -1
110
+ end
111
+ y = case @direction
112
+ when 2,6 then 0
113
+ when 3,4,5 then 1
114
+ when 7,0,1 then -1
115
+ end
116
+ return [x, y]
117
+ end
118
+
119
+ def hit_positions
120
+ positions = [Level.vector_sum(@position, movement)]
121
+ if @direction.odd?
122
+ positions << Level.vector_sum(@position, [movement[0],0])
123
+ positions << Level.vector_sum(@position, [0,movement[1]])
124
+ end
125
+ return positions
126
+ end
127
+
128
+ def animate_move
129
+ @svg.animateMotion values: "0,0; #{movement[0]*Level::FIELD_SIZE},#{movement[1]*Level::FIELD_SIZE}",
130
+ begin: "#{@level.step*Level::STEP_DUR}s", dur: "#{Level::STEP_DUR}s", additive: 'sum', fill: 'freeze'
131
+ end
132
+
133
+ def turn(steps)
134
+ step = steps > 0 ? 1 : -1
135
+ steps.abs.times do
136
+ return false if @level.finish?
137
+ @direction += step
138
+ @direction = @direction % 8
139
+ animate_turn(step)
140
+ @level.perform_step
141
+ end
142
+ end
143
+
144
+ def turn_right(steps=1)
145
+ turn steps
146
+ end
147
+
148
+ def turn_left(steps=1)
149
+ turn -1 * steps
150
+ end
151
+
152
+ def animate_turn(step)
153
+ s = Level::FIELD_SIZE
154
+ @svg.animateTransform attributeName: 'transform', type: 'rotate', values: "0,#{s/2},#{s/2}; #{step*45},#{s/2},#{s/2}",
155
+ begin: "#{@level.step*Level::STEP_DUR}s", dur: "#{Level::STEP_DUR}s", additive: 'sum', fill: 'freeze'
156
+ end
157
+
158
+ end
159
+ end
@@ -0,0 +1,54 @@
1
+ module FeedBo
2
+ module Transformable
3
+
4
+ attr_accessor :direction
5
+
6
+ def initialize
7
+ super
8
+ @direction = 2
9
+ end
10
+
11
+ def move_frame
12
+ x_movement = case @direction
13
+ when 0,4 then 0
14
+ when 1,2,3 then 1
15
+ when 5,6,7 then -1
16
+ end
17
+ y_movement = case @direction
18
+ when 2,6 then 0
19
+ when 3,4,5 then 1
20
+ when 7,0,1 then -1
21
+ end
22
+ unless @level.position_blocked? @position[0]+0.25*x_movement, @position[1]+0.25*y_movement
23
+ @position[0] += 0.25 * x_movement
24
+ @position[1] += 0.25 * y_movement
25
+ end
26
+ end
27
+
28
+ def turn_left_frame(speed=1)
29
+ @direction -= 0.25 * speed
30
+ @direction += 8 if @direction < 0
31
+ rotate(-11.25 * speed)
32
+ end
33
+
34
+ def turn_right_frame(speed=1)
35
+ @direction += 0.25 * speed
36
+ @direction -= 8 if @direction >= 8
37
+ rotate(11.25 * speed)
38
+ end
39
+
40
+ protected
41
+
42
+ def rotate(degrees)
43
+ radians = degrees * Math::PI / 180
44
+ s = Level::FIELD_SIZE / 2
45
+ @points.map! { |p| [p[0]-s, p[1]-s] }
46
+ @points.map! do |p|
47
+ [ Math.cos(radians) * p[0] - Math.sin(radians) * p[1],
48
+ Math.sin(radians) * p[0] + Math.cos(radians) * p[1] ]
49
+ end
50
+ @points.map! { |p| [p[0]+s, p[1]+s] }
51
+ end
52
+
53
+ end
54
+ end
@@ -0,0 +1,3 @@
1
+ module FeedBo
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,14 @@
1
+ module FeedBo
2
+ class Wall < Element
3
+
4
+ def initialize
5
+ super
6
+ @block_position = true
7
+ end
8
+
9
+ def draw
10
+ @svg.rect width: Level::FIELD_SIZE, height: Level::FIELD_SIZE, style: "stroke: black; fill: brown"
11
+ end
12
+
13
+ end
14
+ end
data/lib/feed_bo.rb ADDED
@@ -0,0 +1,17 @@
1
+ require "feed_bo/version"
2
+
3
+ require "feed_bo/drawable"
4
+ require "feed_bo/transformable"
5
+ require "feed_bo/element"
6
+ require "feed_bo/level"
7
+ require "feed_bo/robot"
8
+ require "feed_bo/wall"
9
+ require "feed_bo/balloon"
10
+
11
+ module FeedBo
12
+
13
+ def self.evaluate(code)
14
+ eval code
15
+ end
16
+
17
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: feed_bo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jannes Köhler
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-09-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: builder
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Feed Bo is a computer game written in ruby.
56
+ email:
57
+ - janneskoehler@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .DS_Store
63
+ - .gitignore
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - feed_bo.gemspec
69
+ - lib/.DS_Store
70
+ - lib/feed_bo.rb
71
+ - lib/feed_bo/balloon.rb
72
+ - lib/feed_bo/drawable.rb
73
+ - lib/feed_bo/element.rb
74
+ - lib/feed_bo/level.rb
75
+ - lib/feed_bo/robot.rb
76
+ - lib/feed_bo/transformable.rb
77
+ - lib/feed_bo/version.rb
78
+ - lib/feed_bo/wall.rb
79
+ homepage: ''
80
+ licenses:
81
+ - MIT
82
+ metadata: {}
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ requirements: []
98
+ rubyforge_project:
99
+ rubygems_version: 2.0.3
100
+ signing_key:
101
+ specification_version: 4
102
+ summary: Feed Bo is designed to learn coding by playing.
103
+ test_files: []