opal-phaser 0.1.6 → 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: 4873e726f3744eff28476ab8ebe398f2b4b12001
4
- data.tar.gz: 47f4dd07619d9a6243b903ab6cf5ca20f9aa41ac
3
+ metadata.gz: 8589a0a3e72edb51e873d7999ba396cdf629b778
4
+ data.tar.gz: 2d959cb0539e2f4003f9acee00523a9820fa5efd
5
5
  SHA512:
6
- metadata.gz: e4d43d58ada4ed74e1f975b66a57b64bbb0db8067a772caf436504cbade717dca0e4b64a9b396b868406acacc986455988ecc1b36d6d04ae29d61fb2cfc27c8a
7
- data.tar.gz: 77dfa6968cfdf015710ac6b82588c29cdb595a7eac0c0c375c3ea5a6f123164c056a381be91dfe0bde3b9ea49f2b7dd50bf8e30292781f20493b3bb32bbad9d6
6
+ metadata.gz: 7c931b68ea98a3108dcb6f2965294be18fd65fbbb14a67283239f63401a0aeb7c586345f8eb622603ceb790eb49ebcea0a3ab048cd72c8dd22bcffd61d11a2cc
7
+ data.tar.gz: fce3428b28b12522a962c98bc12c5dbef6f0368b0b34195fa92d018f47b9a27756497c2ccba301dc870335b5d9a57eee3491122732ee4e347cd2929a7850a7f0
@@ -159,29 +159,26 @@ class Game
159
159
  end
160
160
 
161
161
  def run
162
- preload
163
- create_game
164
- update_game
165
-
166
- Phaser::Game.new(width: 800, height: 600, renderer: Phaser::AUTO, parent: '', state: state, transparent: false, antialias: true, physics: nil)
162
+ game = Phaser::Game.new
163
+ state = MainLevel.new(game)
164
+ game.state.add(:main, state, true)
167
165
  end
166
+ end
168
167
 
169
- private
170
-
168
+ class MainLevel < Phaser::State
171
169
  def preload
172
- state.preload do |game|
173
- initialize_entities(game)
174
- entities_call :preload
175
- end
170
+ pp game
171
+ puts "preload"
172
+ initialize_entities
173
+ entities_call :preload
176
174
  end
177
175
 
178
- def create_game
179
- state.create do
180
- entities_call :create
181
- end
176
+ def create
177
+ puts "create"
178
+ entities_call :create
182
179
  end
183
180
 
184
- def update_game
181
+ def update
185
182
  collect_star = proc do |player, star, score|
186
183
  star = Phaser::Sprite.new(star)
187
184
  star.kill
@@ -190,20 +187,24 @@ class Game
190
187
  @score.scoreText.text = "score: #{@score.score}"
191
188
  end
192
189
 
193
- state.update do |game|
194
- game.physics.arcade.collide(@player.player, @platforms.platforms)
195
- game.physics.arcade.collide(@star.stars, @platforms.platforms)
196
- game.physics.arcade.overlap(@player.player, @star.stars, collect_star)
190
+ game.physics.arcade.collide(@player.player, @platforms.platforms)
191
+ game.physics.arcade.collide(@star.stars, @platforms.platforms)
192
+ game.physics.arcade.overlap(@player.player, @star.stars, collect_star)
197
193
 
198
- @player.update
199
- end
194
+ @player.update
200
195
  end
201
196
 
202
- def state
203
- @state ||= Phaser::State.new
197
+ private
198
+
199
+ def collect_star(player, star, score)
200
+ star = Phaser::Sprite.new(star)
201
+ star.kill
202
+
203
+ @score.score += 10
204
+ @score.scoreText.text = "score: #{@score.score}"
204
205
  end
205
206
 
206
- def initialize_entities(game)
207
+ def initialize_entities
207
208
  @sky = Sky.new(game)
208
209
  @platforms = Platforms.new(game)
209
210
  @player = Player.new(game)
@@ -1,3 +1,4 @@
1
+ require 'opal/phaser/core/signal'
1
2
  module Phaser
2
3
  class Animation
3
4
  include Native
@@ -1,3 +1,4 @@
1
+ require 'opal/phaser/animation/animation'
1
2
  module Phaser
2
3
  class AnimationManager
3
4
  include Native
@@ -0,0 +1,10 @@
1
+ module Phaser
2
+ class Camera
3
+ include Native
4
+
5
+ alias_native :x
6
+ alias_native :x=
7
+ alias_native :y
8
+ alias_native :y=
9
+ end
10
+ end
@@ -6,3 +6,4 @@ require 'opal/phaser/core/anchor'
6
6
  require 'opal/phaser/core/group'
7
7
  require 'opal/phaser/core/signal'
8
8
  require 'opal/phaser/core/world'
9
+ require 'opal/phaser/core/stage'
@@ -1,3 +1,12 @@
1
+ require 'opal/phaser/loader/cache'
2
+ require 'opal/phaser/game_objects/game_object_factory'
3
+ require 'opal/phaser/core/world'
4
+ require 'opal/phaser/core/stage'
5
+ require 'opal/phaser/core/state_manager'
6
+ require 'opal/phaser/input/input'
7
+ require 'opal/phaser/math/random_data_generator'
8
+ require 'opal/phaser/core/camera'
9
+
1
10
  module Phaser
2
11
  AUTO = `Phaser.AUTO`
3
12
  WEBGL = `Phaser.WEBGL`
@@ -8,22 +17,21 @@ module Phaser
8
17
 
9
18
  def initialize(arg_hash = {}, &block)
10
19
 
11
- width = arg_hash[:width]
12
- height = arg_hash[:height]
13
- renderer = arg_hash[:renderer]
14
- parent = arg_hash[:parent]
15
- state = arg_hash[:state]
16
- transparent = arg_hash[:transparent]
17
- antialias = arg_hash[:antialias]
18
- physics = arg_hash[:physics]
20
+ width = arg_hash.fetch(:width) { 800 }
21
+ height = arg_hash.fetch(:height) { 600 }
22
+ renderer = arg_hash.fetch(:renderer) { Phaser::AUTO }
23
+ parent = arg_hash.fetch(:parent) { "" }
24
+ state = arg_hash.fetch(:state) { nil }
25
+ transparent = arg_hash.fetch(:transparent) { false }
26
+ antialias = arg_hash.fetch(:antialias) { true }
27
+ physics = arg_hash.fetch(:physics) { nil }
19
28
 
20
29
  if state
21
30
  state.game = self
22
- else
23
- state = State.new(self)
24
31
  end
25
32
 
26
33
  if block_given?
34
+ state = State.new(self) if state.nil?
27
35
  state.instance_eval(&block)
28
36
  end
29
37
 
@@ -33,17 +41,21 @@ module Phaser
33
41
  }
34
42
  end
35
43
 
36
- alias_native :cache, :cache, as: Cache
37
- alias_native :add, :add, as: GameObjectFactory
38
- alias_native :world, :world, as: World
39
- alias_native :physics, :physics, as: Physics
40
- alias_native :input, :input, as: Input
41
- alias_native :time, :time, as: Time
42
- alias_native :rnd, :rnd, as: RandomDataGenerator
43
-
44
+ alias_native :cache, :cache, as: Cache
45
+ alias_native :add, :add, as: GameObjectFactory
46
+ alias_native :world, :world, as: World
47
+ alias_native :stage, :stage, as: Stage
48
+ alias_native :state, :state, as: StateManager
49
+ alias_native :physics, :physics, as: Physics
50
+ alias_native :input, :input, as: Input
51
+ alias_native :time, :time, as: Time
52
+ alias_native :rnd, :rnd, as: RandomDataGenerator
53
+ alias_native :camera, :camera, as: Camera
54
+
55
+ alias_native :make
44
56
  alias_native :load
45
- alias_native :stage
46
57
  alias_native :debug
47
58
  alias_native :width
59
+ alias_native :stage
48
60
  end
49
61
  end
@@ -1,3 +1,4 @@
1
+ require 'opal/phaser/game_objects/sprite'
1
2
  module Phaser
2
3
  class Group
3
4
  include Native
@@ -7,8 +8,13 @@ module Phaser
7
8
  alias_native :enable_body_debug, :enableBodyDebug
8
9
  alias_native :add_child, :addChild
9
10
  alias_native :set_all, :setAll
11
+ alias_native :call_all, :callAll
10
12
  alias_native :children
11
- alias_native :create
13
+ # alias_native :create
14
+ alias_native :create, :create, as: Sprite
15
+ alias_native :destroy
16
+ alias_native :remove
17
+ alias_native :total
12
18
 
13
19
  alias_native :enable_body?, :enableBody
14
20
 
@@ -0,0 +1,9 @@
1
+ module Phaser
2
+ class Stage
3
+ include Native
4
+
5
+ def background_color=(color)
6
+ `#@native.backgroundColor = color`
7
+ end
8
+ end
9
+ end
@@ -1,41 +1,47 @@
1
+ require 'pp'
2
+ require 'opal/phaser/core/game'
1
3
  module Phaser
2
4
  class State
3
- attr_writer :game
5
+ include Native
4
6
  def initialize(game = nil, &block)
5
- @game = game
6
7
  @native = `new Phaser.State`
7
-
8
- @preload = proc {}
9
- @create = proc {}
10
- @update = proc {}
11
- @render = proc {}
8
+ self.game = game
12
9
 
13
10
  if block_given?
14
11
  block.call(@game)
15
12
  end
13
+ super(@native)
14
+ end
15
+
16
+ def game=(g_)
17
+ @game = g_
18
+ `#@native.game = #@game`
16
19
  end
17
20
 
21
+ def game
22
+ @game
23
+ end
18
24
 
19
- def preload(&block)
20
- @preload = proc { block.call(@game) }
25
+ def preload
21
26
  end
22
27
 
23
- def create(&block)
24
- @create = proc { block.call(@game) }
28
+ def create
25
29
  end
26
30
 
27
- def update(&block)
28
- @update = proc { block.call(@game) }
31
+ def update
29
32
  end
30
33
 
31
- def render(&block)
32
- @render = proc { block.call(@game) }
34
+ def render
33
35
  end
34
36
 
35
37
  def to_n
38
+ _preload = proc { preload }
39
+ _create = proc { create }
40
+ _update = proc { update }
41
+ _render = proc { render }
36
42
  %x{
37
- var obj = { preload: #@preload, create: #@create, update: #@update,
38
- render: #@render }
43
+ var obj = { preload: #{_preload}, create: #{_create}, update: #{_update},
44
+ render: #{_render} }
39
45
  }
40
46
 
41
47
  return %x{ obj }
@@ -0,0 +1,7 @@
1
+ module Phaser
2
+ class StateManager
3
+ include Native
4
+
5
+ alias_native :add
6
+ end
7
+ end
@@ -1,11 +1,15 @@
1
1
  module Phaser
2
2
  class World
3
3
  include Native
4
-
4
+
5
5
  alias_native :width
6
6
  alias_native :height
7
-
7
+
8
+ alias_native :set_bounds, :setBounds
9
+
8
10
  alias_native :x_center, :centerX
9
11
  alias_native :y_center, :centerY
12
+ alias_native :random_y, :randomY
13
+ alias_native :random_x, :randomX
10
14
  end
11
15
  end
@@ -0,0 +1,10 @@
1
+ module Phaser
2
+ class BitmapData
3
+ include Native
4
+
5
+ alias_native :draw
6
+ alias_native :rect
7
+ alias_native :fill
8
+ alias_native :canvas
9
+ end
10
+ end
@@ -1,7 +1,22 @@
1
+ require 'opal/phaser/core/signal'
2
+
1
3
  module Phaser
2
4
  class Events
3
5
  include Native
4
-
6
+
5
7
  alias_native :on_input_down, :onInputDown, as: Signal
8
+
9
+ def on(type, context, &block)
10
+ case type.to_sym
11
+ when :up
12
+ `#@native.onInputUp.add(#{block.to_n}, #{context})`
13
+ when :down
14
+ `#@native.onInputDown.add(#{block.to_n}, #{context})`
15
+ when :out
16
+ `#@native.onInputOut.add(#{block.to_n}, #{context})`
17
+ when :over
18
+ `#@native.onInputOver.add(#{block.to_n}, #{context})`
19
+ end
20
+ end
6
21
  end
7
22
  end
@@ -4,4 +4,5 @@ require 'opal/phaser/game_objects/sprite'
4
4
  require 'opal/phaser/game_objects/tile_sprite'
5
5
  require 'opal/phaser/game_objects/text'
6
6
  require 'opal/phaser/game_objects/image'
7
+ require 'opal/phaser/game_objects/bitmap_data'
7
8
  require 'opal/phaser/game_objects/game_object_factory'
@@ -1,3 +1,11 @@
1
+ require 'opal/phaser/game_objects/sprite'
2
+ require 'opal/phaser/core/group'
3
+ require 'opal/phaser/game_objects/text'
4
+ require 'opal/phaser/game_objects/image'
5
+ require 'opal/phaser/game_objects/bitmap_data'
6
+ require 'opal/phaser/tween/tween'
7
+ require 'opal/phaser/game_objects/tile_sprite'
8
+
1
9
  module Phaser
2
10
  class GameObjectFactory
3
11
  include Native
@@ -6,6 +14,7 @@ module Phaser
6
14
  alias_native :group, :group, as: Group
7
15
  alias_native :text, :text, as: Text
8
16
  alias_native :image, :image, as: Image
17
+ alias_native :bitmap_data, :bitmapData, as: BitmapData
9
18
  alias_native :tween, :tween, as: Tween
10
19
  alias_native :tile_sprite, :tileSprite, as: TileSprite
11
20
  end
@@ -1,14 +1,18 @@
1
1
  module Phaser
2
2
  class Image
3
3
  include Native
4
-
4
+
5
5
  alias_native :x
6
6
  alias_native :y
7
7
  alias_native :x=
8
8
  alias_native :y=
9
-
9
+ alias_native :height
10
+
10
11
  alias_native :scale
12
+ alias_native :destroy
11
13
 
14
+ alias_native :load_texture, :loadTexture
15
+
12
16
  def smoothed=(bool)
13
17
  `#@native.smoothed = bool`
14
18
  end
@@ -1,11 +1,19 @@
1
+ require 'opal/phaser/physics/physics'
2
+ require 'opal/phaser/core/anchor'
3
+ require 'opal/phaser/animation/animation_manager'
4
+ require 'opal/phaser/game_objects/events'
5
+
1
6
  module Phaser
2
7
  class Sprite
3
8
  include Native
4
9
 
10
+ alias_native :key
5
11
  alias_native :scale
6
12
  alias_native :bounce
7
13
 
8
14
  alias_native :kill
15
+ alias_native :destroy
16
+ alias_native :play
9
17
 
10
18
  alias_native :visible=
11
19
  alias_native :exists=
@@ -23,15 +31,15 @@ module Phaser
23
31
  def input_enabled=(bool)
24
32
  `#@native.inputEnabled = bool`
25
33
  end
26
-
34
+
27
35
  def smoothed=(bool)
28
36
  `#@native.smoothed = bool`
29
37
  end
30
-
38
+
31
39
  def frame_name=(name)
32
40
  `#@native.frameName = name`
33
41
  end
34
-
42
+
35
43
  alias_native :load_texture, :loadTexture
36
44
 
37
45
  alias_native :body, :body, as: Physics::Arcade::Body
@@ -2,6 +2,8 @@ module Phaser
2
2
  class Text
3
3
  include Native
4
4
 
5
+ alias_native :destroy
6
+
5
7
  def text=(text)
6
8
  `#@native.text = text`
7
9
  end
@@ -1,7 +1,13 @@
1
- class TileSprite
2
- include Native
3
-
4
- alias_native :auto_scroll, :autoScroll
5
- alias_native :stop_scroll, :stopScroll
6
- alias_native :body
1
+ require 'opal/phaser/geometry/point'
2
+ module Phaser
3
+ class TileSprite
4
+ include Native
5
+
6
+ alias_native :auto_scroll, :autoScroll
7
+ alias_native :stop_scroll, :stopScroll
8
+ alias_native :tile_position, :tilePosition, as: Point
9
+ alias_native :destroy
10
+
11
+ alias_native :body
12
+ end
7
13
  end
@@ -0,0 +1,20 @@
1
+ module Phaser
2
+ class Point
3
+ include Native
4
+
5
+ # When its automatically aliased we just pass the object to super
6
+ def initialize(_x = 0, _y = 0)
7
+ if `typeof(#{_x})` == "object"
8
+ super(_x)
9
+ else
10
+ @native = `new Phaser.Point(#{_x}, #{_y})`
11
+ super(@native)
12
+ end
13
+ end
14
+
15
+ alias_native :x
16
+ alias_native :x=
17
+ alias_native :y
18
+ alias_native :y=
19
+ end
20
+ end
@@ -1,13 +1,27 @@
1
+ require 'opal/phaser/input/keyboard'
2
+ require 'opal/phaser/input/pointer'
1
3
  module Phaser
2
4
  class Input
3
5
  include Native
4
-
6
+
5
7
  alias_native :x
6
8
  alias_native :y
7
-
8
- alias_native :keyboard, :keyboard, as: Keyboard
9
-
10
- alias_native :on_down, :onDown, as: Signal
9
+
10
+ alias_native :keyboard, :keyboard, as: Keyboard
11
+ alias_native :mouse_pointer, :mousePointer, as: Pointer
12
+
13
+ def on(type, &block)
14
+ case type.to_sym
15
+ when :down
16
+ `#@native.onDown.add(#{block.to_n})`
17
+ when :up
18
+ `#@native.onUp.add(#{block.to_n})`
19
+ when :tap
20
+ `#@native.onTap.add(#{block.to_n})`
21
+ when :hold
22
+ `#@native.onHold.add(#{block.to_n})`
23
+ end
24
+ end
11
25
  alias_native :active_pointer, :activePointer
12
26
  end
13
27
  end
@@ -2,7 +2,15 @@ module Phaser
2
2
  class Key
3
3
  include Native
4
4
 
5
- alias_native :on_down, :onDown, as: Signal
5
+ def on(type, &block)
6
+ case type.to_sym
7
+ when :down
8
+ `#@native.onDown.add(#{block.to_n})`
9
+ when :up
10
+ `#@native.onUp.add(#{block.to_n})`
11
+ end
12
+ end
13
+
6
14
  alias_native :down?, :isDown
7
15
  end
8
16
  end
@@ -1,16 +1,18 @@
1
+ require 'opal/phaser/input/key'
1
2
  module Phaser
2
3
  class Keyboard
3
4
  include Native
4
-
5
+
5
6
  SPACEBAR = `Phaser.Keyboard.SPACEBAR`
6
7
  LEFT = `Phaser.Keyboard.LEFT`
7
8
  RIGHT = `Phaser.Keyboard.RIGHT`
8
9
  A = `Phaser.Keyboard.A`
9
10
  D = `Phaser.Keyboard.D`
10
-
11
+ ESC = `Phaser.Keyboard.ESC`
12
+
11
13
  alias_native :create_cursor_keys, :createCursorKeys
12
14
  alias_native :remove_key, :removeKey
13
-
15
+
14
16
  alias_native :add_key, :addKey, as: Key
15
17
  end
16
18
  end
@@ -0,0 +1,13 @@
1
+ require 'opal/phaser/geometry/point'
2
+ module Phaser
3
+ class Pointer
4
+ include Native
5
+
6
+ alias_native :down?, :isDown
7
+ alias_native :up?, :isUp
8
+
9
+ alias_native :target_object, :targetObject
10
+
11
+ alias_native :position, :position, as: Point
12
+ end
13
+ end
@@ -1,5 +1,9 @@
1
+ require 'opal/phaser/game_objects/image'
1
2
  module Phaser
2
3
  class Cache
3
4
  include Native
5
+
6
+ alias_native :add_sprite_sheet, :addSpriteSheet
7
+ alias_native :get_image, :getImage, as: Image
4
8
  end
5
9
  end
@@ -1,5 +1,5 @@
1
1
  module Opal
2
2
  module Phaser
3
- VERSION = '0.1.6'
3
+ VERSION = '0.2.0'
4
4
  end
5
5
  end
@@ -15,6 +15,6 @@ Gem::Specification.new do |s|
15
15
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
16
  s.require_paths = ['lib']
17
17
 
18
- s.add_runtime_dependency 'opal'
18
+ s.add_runtime_dependency 'opal', '>= 0.7.2'
19
19
  s.add_development_dependency 'rake'
20
20
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opal-phaser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - George Plymale
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-06 00:00:00.000000000 Z
11
+ date: 2015-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opal
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: 0.7.2
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: 0.7.2
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -69,12 +69,16 @@ files:
69
69
  - lib/opal/phaser/animation/files.rb
70
70
  - lib/opal/phaser/animation/frame.rb
71
71
  - lib/opal/phaser/core/anchor.rb
72
+ - lib/opal/phaser/core/camera.rb
72
73
  - lib/opal/phaser/core/files.rb
73
74
  - lib/opal/phaser/core/game.rb
74
75
  - lib/opal/phaser/core/group.rb
75
76
  - lib/opal/phaser/core/signal.rb
77
+ - lib/opal/phaser/core/stage.rb
76
78
  - lib/opal/phaser/core/state.rb
79
+ - lib/opal/phaser/core/state_manager.rb
77
80
  - lib/opal/phaser/core/world.rb
81
+ - lib/opal/phaser/game_objects/bitmap_data.rb
78
82
  - lib/opal/phaser/game_objects/events.rb
79
83
  - lib/opal/phaser/game_objects/files.rb
80
84
  - lib/opal/phaser/game_objects/game_object_factory.rb
@@ -82,10 +86,12 @@ files:
82
86
  - lib/opal/phaser/game_objects/sprite.rb
83
87
  - lib/opal/phaser/game_objects/text.rb
84
88
  - lib/opal/phaser/game_objects/tile_sprite.rb
89
+ - lib/opal/phaser/geometry/point.rb
85
90
  - lib/opal/phaser/input/files.rb
86
91
  - lib/opal/phaser/input/input.rb
87
92
  - lib/opal/phaser/input/key.rb
88
93
  - lib/opal/phaser/input/keyboard.rb
94
+ - lib/opal/phaser/input/pointer.rb
89
95
  - lib/opal/phaser/loader/cache.rb
90
96
  - lib/opal/phaser/loader/files.rb
91
97
  - lib/opal/phaser/math/files.rb
@@ -120,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
126
  version: '0'
121
127
  requirements: []
122
128
  rubyforge_project:
123
- rubygems_version: 2.4.5
129
+ rubygems_version: 2.2.2
124
130
  signing_key:
125
131
  specification_version: 4
126
132
  summary: Opal access to phaser