smalruby 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of smalruby might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fa28b7b90c3b367e69c381f63c600e9a51d0bcca
4
- data.tar.gz: 2ecf984ee583d7876501a390b9094c3f511a15d1
3
+ metadata.gz: 7b4e041e1339e93000745877678c14cef4a65259
4
+ data.tar.gz: 008b2e5051dbb6bb5c18a7f23befd3d7a68d9bc1
5
5
  SHA512:
6
- metadata.gz: 466edcdba9b9da5d83b708fcf35d0a228c1d8e22f8a31e2f7fde45abca91586e3d530f519cdc9aa6d7c941bfadd5e5fb8d949749190a4be6b032f886a1ff4445
7
- data.tar.gz: 4c95e2202fe00353cd7d5d006f51cd7b8328e409adf1b4ac067ea0a2c4fa585e8a2cca620c3d4db1b93096db5c03d9dbcfb0b0bc20dd4ec83455feaa45165880
6
+ metadata.gz: a063982bd0fa45e6aa5aa591899e15c501884ca2736c4c93fcceaec61c6b7325783535455a4c42c9ce22e9bd5334c5522bf5f89d4428a63c578cb35819188672
7
+ data.tar.gz: 67ed9dd5e0ac013130194208b35df444d7940387006a31d758ee9f86d364e5952b4dda1d13bc6f2d536b691f575fba1efc42ee7d8f390bc100c0dd0437b843e7
data/.rubocop.yml CHANGED
@@ -37,3 +37,6 @@ SymbolName:
37
37
 
38
38
  StringLiterals:
39
39
  Enabled: false
40
+
41
+ EndOfLine:
42
+ Enabled: false
data/LEGAL CHANGED
@@ -6,7 +6,8 @@ smalruby's license (see the file LICENSE) except some files
6
6
  mentioned below.
7
7
 
8
8
  assets/car1.png, assets/car2.png, assets/car3.png, assets/car4.png,
9
- assets/cat1.png, assets/cat2.png, assets/cat3.png, assets/frog1.png:
9
+ assets/cat1.png, assets/cat2.png, assets/cat3.png, assets/frog1.png,
10
+ samples/extra_car.png:
10
11
 
11
12
  These are downloaded from ICON HOIHOI http://iconhoihoi.oops.jp/.
12
13
 
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # smalruby
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/smalruby.png)](http://badge.fury.io/rb/smalruby)
4
+ [![Build Status](https://travis-ci.org/smalruby/smalruby.png?branch=master)](https://travis-ci.org/smalruby/smalruby)
5
+
3
6
  smalruby is a 2D game development library. This is part of "Smalruby"
4
7
  project that is a learning ruby programming environment for kids.
5
8
 
data/Rakefile CHANGED
@@ -36,7 +36,7 @@ end
36
36
 
37
37
  task :rubocop do
38
38
  files = `git ls-files | grep -e '.rb$' | grep -v '^samples/'`
39
- sh "rubocop -d #{files.split(/\s+/m).join(' ')}"
39
+ sh "rubocop #{files.split(/\s+/m).join(' ')}"
40
40
  end
41
41
 
42
42
  task :default => [:rubocop, :spec]
@@ -13,6 +13,7 @@ module Smalruby
13
13
 
14
14
  attr_accessor :event_handlers
15
15
  attr_accessor :threads
16
+ attr_accessor :checking_hit_targets
16
17
 
17
18
  def initialize(option = {})
18
19
  opt = {
@@ -30,6 +31,7 @@ module Smalruby
30
31
 
31
32
  @event_handlers = {}
32
33
  @threads = []
34
+ @checking_hit_targets = []
33
35
 
34
36
  self.scale_x = 1.0
35
37
  self.scale_y = 1.0
@@ -52,6 +54,11 @@ module Smalruby
52
54
  self.y += @vector[:y] * val
53
55
  end
54
56
 
57
+ # ( )歩後ろに動かす
58
+ def move_back(val = 1)
59
+ move(-val)
60
+ end
61
+
55
62
  # 振り返る
56
63
  def turn
57
64
  @vector[:x] *= -1
@@ -61,14 +68,16 @@ module Smalruby
61
68
 
62
69
  # もし端に着いたら、跳ね返る
63
70
  def turn_if_reach_wall
64
- max_width = Window.width - image.width
65
- if self.x < 0
66
- self.x = 0
67
- turn
68
- elsif self.x >= max_width
69
- self.x = max_width - 1
70
- turn
71
- end
71
+ turn if reach_wall?
72
+ end
73
+
74
+ # ( )度回転する
75
+ def rotate(angle)
76
+ radian = angle * Math::PI / 180
77
+ x, y = @vector[:x], @vector[:y]
78
+ @vector[:x] = x * Math.cos(radian) - y * Math.sin(radian)
79
+ @vector[:y] = x * Math.sin(radian) + y * Math.cos(radian)
80
+ self.angle = (self.angle + angle) % 360
72
81
  end
73
82
 
74
83
  # @!endgroup
@@ -104,10 +113,16 @@ module Smalruby
104
113
 
105
114
  # @!group 調べる
106
115
 
116
+ # 距離
107
117
  def distance(x, y)
108
- res = Math.sqrt((self.x + center_x - x).abs**2 +
109
- (self.y + center_y - y).abs**2).to_i
110
- return res
118
+ Math.sqrt((self.x + center_x - x).abs**2 +
119
+ (self.y + center_y - y).abs**2).to_i
120
+ end
121
+
122
+ # 端に着いた
123
+ def reach_wall?
124
+ self.x < 0 || self.x >= (Window.width - image.width) ||
125
+ self.y < 0 || self.y >= (Window.height - image.height)
111
126
  end
112
127
 
113
128
  # @!endgroup
@@ -144,8 +159,13 @@ module Smalruby
144
159
  h = EventHandler.new(self, options, &block)
145
160
  @event_handlers[event] << h
146
161
 
147
- if Smalruby.started?
148
- @threads << h.call
162
+ case event
163
+ when :start
164
+ @threads << h.call if Smalruby.started?
165
+ when :hit
166
+ @checking_hit_targets << options
167
+ @checking_hit_targets.flatten!
168
+ @checking_hit_targets.uniq!
149
169
  end
150
170
  end
151
171
 
@@ -182,6 +202,19 @@ module Smalruby
182
202
  end
183
203
  end
184
204
 
205
+ def hit
206
+ # TODO: なんでもいいからキャラクターに当たった場合に対応する
207
+ @checking_hit_targets &= World.instance.objects
208
+ objects = check(@checking_hit_targets)
209
+ return if objects.empty?
210
+ @event_handlers[:hit].try(:each) do |h|
211
+ if h.options.length == 0 && !h.options.any? { |o| objects.include?(o) }
212
+ next
213
+ end
214
+ @threads << h.call(objects)
215
+ end
216
+ end
217
+
185
218
  def alive?
186
219
  return @threads.any?(&:alive?)
187
220
  end
@@ -200,7 +233,10 @@ module Smalruby
200
233
  private
201
234
 
202
235
  def asset_path(name)
203
- return File.expand_path("../../../assets/#{name}", __FILE__)
236
+ program_path = Pathname($PROGRAM_NAME).expand_path(Dir.pwd)
237
+ paths = [Pathname("../#{name}").expand_path(program_path),
238
+ Pathname("../../../assets/#{name}").expand_path(__FILE__)]
239
+ paths.find { |path| path.file? }.to_s
204
240
  end
205
241
 
206
242
  def new_font(size)
@@ -1,5 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
  module Smalruby
4
- VERSION = '0.0.3'
4
+ VERSION = '0.0.4'
5
5
  end
data/lib/smalruby.rb CHANGED
@@ -2,6 +2,8 @@
2
2
  require 'smalruby/version'
3
3
  require 'active_support/all'
4
4
  require 'dxruby'
5
+ require 'English'
6
+ require 'pathname'
5
7
 
6
8
  require 'smalruby/world'
7
9
  require 'smalruby/color'
@@ -84,6 +86,8 @@ module Smalruby
84
86
 
85
87
  key_down_and_push
86
88
 
89
+ hit
90
+
87
91
  world.objects.delete_if do |o|
88
92
  if !o.alive?
89
93
  o.join
@@ -150,6 +154,14 @@ module Smalruby
150
154
  end
151
155
  end
152
156
  end
157
+
158
+ def hit
159
+ world.objects.each do |o|
160
+ if o.respond_to?(:hit)
161
+ o.hit
162
+ end
163
+ end
164
+ end
153
165
  end
154
166
  end
155
167
 
data/samples/car.rb CHANGED
@@ -11,5 +11,5 @@ car1.on(:start) do
11
11
  end
12
12
 
13
13
  car1.on(:click) do
14
- turn
14
+ rotate(45)
15
15
  end
@@ -0,0 +1,13 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'smalruby'
3
+
4
+ car1 = Character.new(x: 0, y: 0, costume: 'extra_car.png')
5
+
6
+ car1.on(:start) do
7
+ loop do
8
+ move(5)
9
+ if reach_wall?
10
+ turn
11
+ end
12
+ end
13
+ end
Binary file
@@ -0,0 +1,33 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'smalruby'
3
+
4
+ car1 = Character.new(x: 0, y: 0, costume: 'car1.png')
5
+ car2 = Character.new(x: 639, y: 0, costume: 'car2.png')
6
+
7
+ car1.on(:start) do
8
+ loop do
9
+ move(5)
10
+ if reach_wall?
11
+ turn
12
+ end
13
+ end
14
+ end
15
+
16
+ car1.on(:hit, car2) do
17
+ move_back(20)
18
+ turn
19
+ end
20
+
21
+ car2.on(:start) do
22
+ loop do
23
+ move(10)
24
+ if reach_wall?
25
+ turn
26
+ end
27
+ end
28
+ end
29
+
30
+ car2.on(:hit, car1) do
31
+ move_back(20)
32
+ turn
33
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smalruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kouji Takao
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-07 00:00:00.000000000 Z
11
+ date: 2014-01-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -223,7 +223,10 @@ files:
223
223
  - samples/canvas.rb
224
224
  - samples/car.rb
225
225
  - samples/console.rb
226
+ - samples/costume.rb
227
+ - samples/extra_car.png
226
228
  - samples/finding_cars.rb
229
+ - samples/hit_car.rb
227
230
  - samples/piano.rb
228
231
  - smalruby.gemspec
229
232
  - spec/lib/smalruby/color_spec.rb
@@ -249,7 +252,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
249
252
  version: '0'
250
253
  requirements: []
251
254
  rubyforge_project:
252
- rubygems_version: 2.0.3
255
+ rubygems_version: 2.0.14
253
256
  signing_key:
254
257
  specification_version: 4
255
258
  summary: 2D game development library for kids.