opal-phaser 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -1
- data/Gemfile +0 -5
- data/README.md +5 -0
- data/Rakefile +4 -1
- data/demo/README.md +15 -1
- data/demo/app/main.rb +7 -9
- data/lib/opal/phaser/animation/animation.rb +10 -0
- data/lib/opal/phaser/core/game.rb +17 -4
- data/lib/opal/phaser/core/group.rb +1 -0
- data/lib/opal/phaser/core/loader.rb +65 -0
- data/lib/opal/phaser/core/scale_manager.rb +27 -0
- data/lib/opal/phaser/core/signal.rb +1 -0
- data/lib/opal/phaser/core/state_manager.rb +1 -0
- data/lib/opal/phaser/core/world.rb +3 -0
- data/lib/opal/phaser/game_objects/bitmap_data.rb +4 -0
- data/lib/opal/phaser/game_objects/button.rb +7 -0
- data/lib/opal/phaser/game_objects/events.rb +2 -0
- data/lib/opal/phaser/game_objects/files.rb +1 -0
- data/lib/opal/phaser/game_objects/game_object_creator.rb +23 -0
- data/lib/opal/phaser/game_objects/game_object_factory.rb +2 -0
- data/lib/opal/phaser/game_objects/image.rb +5 -1
- data/lib/opal/phaser/game_objects/sprite.rb +16 -0
- data/lib/opal/phaser/geometry/rectangle.rb +9 -0
- data/lib/opal/phaser/input/input.rb +15 -9
- data/lib/opal/phaser/input/key.rb +8 -0
- data/lib/opal/phaser/input/keyboard.rb +2 -0
- data/lib/opal/phaser/input/pointer.rb +2 -0
- data/lib/opal/phaser/loader/cache.rb +2 -0
- data/lib/opal/phaser/math/random_data_generator.rb +2 -1
- data/lib/opal/phaser/physics/physics.rb +19 -6
- data/lib/opal/phaser/tween/easing.rb +17 -0
- data/lib/opal/phaser/tween/files.rb +1 -0
- data/lib/opal/phaser/version.rb +3 -3
- data/opal-phaser.gemspec +3 -1
- data/phaser.js +89590 -0
- data/spec/core/loader_spec.rb +23 -0
- data/spec/html/index.html.erb +9 -0
- data/spec/html/phaser.js +89590 -0
- data/spec/spec_helper.rb +3 -0
- metadata +55 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 950b60cc79497ed967899f2f3a8071d4e9d91a70
|
4
|
+
data.tar.gz: db6c023ecddef90375a1179446a27695930ff5c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e6d63f83e401e573d7021c1b1a186805fe002b8bbc8957c36fe3ee13543346a4cd61f0a492d049205edb44e572536185e0ac928e2c6a137ee5f92a89cfae749c
|
7
|
+
data.tar.gz: 8cfc0784d3a79296a036d27d39eb3ee83e6ba441429227e267cb02c9a58f805332e4b8c1ac6f99a5e4cf8b1eb58b6c8c6bb639251318998f44b02ce4ead6734f
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -13,6 +13,11 @@ If you have not heard of Phaser, check out these links:
|
|
13
13
|
|
14
14
|
Also, to get examples of opal-phaser in action, check out the [opal-phaser-examples repository](https://github.com/orbitalimpact/opal-phaser-examples).
|
15
15
|
|
16
|
+
A few games made with opal-phaser:
|
17
|
+
|
18
|
+
* [Flutterjump](https://github.com/orbitalimpact/flutterjump)
|
19
|
+
* [A pong clone](https://github.com/opengamedev/pong-opal-phaser)
|
20
|
+
|
16
21
|
## Cloning this repository
|
17
22
|
|
18
23
|
```
|
data/Rakefile
CHANGED
@@ -2,7 +2,10 @@ require 'bundler'
|
|
2
2
|
Bundler.require
|
3
3
|
Bundler::GemHelper.install_tasks
|
4
4
|
|
5
|
-
|
5
|
+
require 'opal/rspec/rake_task'
|
6
|
+
Opal::RSpec::RakeTask.new(:default) do |s|
|
7
|
+
s.index_path = 'spec/html/index.html.erb'
|
8
|
+
end
|
6
9
|
|
7
10
|
desc "Build build/opal-phaser.js"
|
8
11
|
task :dist do
|
data/demo/README.md
CHANGED
@@ -1,2 +1,16 @@
|
|
1
1
|
# A demo of opal-phaser
|
2
|
-
This directory is a demo of opal-phaser in action (based on the tutorial here: http://phaser.io/tutorials/making-your-first-phaser-game)
|
2
|
+
This directory is a demo of opal-phaser in action (based on the tutorial here: http://phaser.io/tutorials/making-your-first-phaser-game)
|
3
|
+
|
4
|
+
If you haven't yet, clone the the repository as explained in the
|
5
|
+
[README](https://github.com/salama/opal-phaser) and cd into the demo directory. Then:
|
6
|
+
|
7
|
+
|
8
|
+
```
|
9
|
+
cd demo
|
10
|
+
bundle
|
11
|
+
rackup
|
12
|
+
```
|
13
|
+
|
14
|
+
and go to localhost:9292 (or whatever the server says)
|
15
|
+
|
16
|
+
And enjoy playing your first browser game made in ruby!
|
data/demo/app/main.rb
CHANGED
@@ -37,9 +37,11 @@ class Star
|
|
37
37
|
stars.enable_body = true
|
38
38
|
|
39
39
|
12.times do |n|
|
40
|
-
star =
|
40
|
+
star = @game.add.sprite(n * 70, 0, 'star')
|
41
|
+
@game.physics.arcade.enable(star)
|
41
42
|
star.body.gravity.y = 6
|
42
43
|
star.body.bounce.y = 0.7 + rand * 0.2
|
44
|
+
stars.add(star)
|
43
45
|
end
|
44
46
|
end
|
45
47
|
end
|
@@ -179,18 +181,14 @@ class MainLevel < Phaser::State
|
|
179
181
|
end
|
180
182
|
|
181
183
|
def update
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
184
|
+
game.physics.arcade.collide(@player.player, @platforms.platforms)
|
185
|
+
game.physics.arcade.collide(@star.stars, @platforms.platforms)
|
186
|
+
game.physics.arcade.overlap(@player.player, @star.stars) do |p, s|
|
187
|
+
s.kill
|
186
188
|
@score.score += 10
|
187
189
|
@score.scoreText.text = "score: #{@score.score}"
|
188
190
|
end
|
189
191
|
|
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)
|
193
|
-
|
194
192
|
@player.update
|
195
193
|
end
|
196
194
|
|
@@ -15,6 +15,16 @@ module Phaser
|
|
15
15
|
`#@native.loop = bool`
|
16
16
|
end
|
17
17
|
|
18
|
+
def self.generate_frame_names(args = {})
|
19
|
+
prefix = args[:prefix]
|
20
|
+
start_num = args[:start_num]
|
21
|
+
stop_num = args[:stop_num]
|
22
|
+
suffix = args[:suffix, ""]
|
23
|
+
zeros_padding = args[:zeros_padding, 0]
|
24
|
+
|
25
|
+
`Phaser.Animation.generateFrameNames(prefix, start_num, stop_num, suffix, zeros_padding)`
|
26
|
+
end
|
27
|
+
|
18
28
|
alias_native :is_playing?, :isPlaying
|
19
29
|
end
|
20
30
|
end
|
@@ -1,11 +1,14 @@
|
|
1
1
|
require 'opal/phaser/loader/cache'
|
2
2
|
require 'opal/phaser/game_objects/game_object_factory'
|
3
|
+
require 'opal/phaser/game_objects/game_object_creator'
|
3
4
|
require 'opal/phaser/core/world'
|
4
5
|
require 'opal/phaser/core/stage'
|
5
6
|
require 'opal/phaser/core/state_manager'
|
6
7
|
require 'opal/phaser/input/input'
|
7
8
|
require 'opal/phaser/math/random_data_generator'
|
8
9
|
require 'opal/phaser/core/camera'
|
10
|
+
require 'opal/phaser/core/loader'
|
11
|
+
require 'opal/phaser/core/scale_manager'
|
9
12
|
|
10
13
|
module Phaser
|
11
14
|
AUTO = `Phaser.AUTO`
|
@@ -48,14 +51,24 @@ module Phaser
|
|
48
51
|
alias_native :state, :state, as: StateManager
|
49
52
|
alias_native :physics, :physics, as: Physics
|
50
53
|
alias_native :input, :input, as: Input
|
51
|
-
alias_native :time, :time, as: Time
|
54
|
+
#alias_native :time, :time, as: Time
|
52
55
|
alias_native :rnd, :rnd, as: RandomDataGenerator
|
53
56
|
alias_native :camera, :camera, as: Camera
|
57
|
+
alias_native :scale, :scale, as: ScaleManager
|
54
58
|
|
55
|
-
alias_native :make
|
56
|
-
alias_native :load
|
59
|
+
alias_native :make, :make, as: GameObjectCreator
|
60
|
+
alias_native :load, :load, as: Loader
|
57
61
|
alias_native :debug
|
58
62
|
alias_native :width
|
59
|
-
alias_native :
|
63
|
+
alias_native :paused
|
64
|
+
alias_native :destroy
|
65
|
+
|
66
|
+
def time
|
67
|
+
Phaser::Time.new(`#@native.time`)
|
68
|
+
end
|
69
|
+
|
70
|
+
def paused=(bool)
|
71
|
+
`#@native.paused = bool`
|
72
|
+
end
|
60
73
|
end
|
61
74
|
end
|
@@ -6,6 +6,7 @@ module Phaser
|
|
6
6
|
alias_native :cursor
|
7
7
|
alias_native :physics_body_type, :physicsBodyType
|
8
8
|
alias_native :enable_body_debug, :enableBodyDebug
|
9
|
+
alias_native :add
|
9
10
|
alias_native :add_child, :addChild
|
10
11
|
alias_native :set_all, :setAll
|
11
12
|
alias_native :call_all, :callAll
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module Phaser
|
2
|
+
class Loader
|
3
|
+
include Native
|
4
|
+
|
5
|
+
def initialize(game)
|
6
|
+
if native?(game)
|
7
|
+
super
|
8
|
+
else
|
9
|
+
super(`new Phaser.Loader(#{game.to_n})`)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
alias_native :image
|
14
|
+
alias_native :spritesheet
|
15
|
+
alias_native :atlas
|
16
|
+
alias_native :start
|
17
|
+
|
18
|
+
alias_native :onFileComplete
|
19
|
+
alias_native :onFileError
|
20
|
+
alias_native :onFileStart
|
21
|
+
alias_native :onLoadComplete
|
22
|
+
alias_native :onLoadStart
|
23
|
+
alias_native :atlasJSONArray
|
24
|
+
alias_native :atlasJSONHash
|
25
|
+
alias_native :atlasXML
|
26
|
+
|
27
|
+
alias_native :cross_origin=, :crossOrigin
|
28
|
+
|
29
|
+
def cross_origin=(value)
|
30
|
+
`#@native.crossOrigin = #{value}`
|
31
|
+
end
|
32
|
+
|
33
|
+
def on(type, context, &block)
|
34
|
+
case type.to_sym
|
35
|
+
when :file_complete
|
36
|
+
`#@native.onFileComplete.add(#{block.to_n}, #{context})`
|
37
|
+
when :file_error
|
38
|
+
`#@native.onFileError.add(#{block.to_n}, #{context})`
|
39
|
+
when :file_start
|
40
|
+
`#@native.onFileStart.add(#{block.to_n}, #{context})`
|
41
|
+
when :load_complete
|
42
|
+
`#@native.onLoadComplete.add(#{block.to_n}, #{context})`
|
43
|
+
when :load_start
|
44
|
+
`#@native.onLoadStart.add(#{block.to_n}, #{context})`
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
def self.async_image(game, options = {}, &block)
|
50
|
+
that = new(game)
|
51
|
+
that.async_image(options, &block)
|
52
|
+
that
|
53
|
+
end
|
54
|
+
|
55
|
+
def async_image(options = {}, &block)
|
56
|
+
override = options.fetch(:override) { false }
|
57
|
+
key = options.fetch(:key) { raise ArgumentError, ":key is a required argument for this method" }
|
58
|
+
url = options.fetch(:url) { raise ArgumentError, ":url is a required argument for this method" }
|
59
|
+
self.cross_origin = options[:cross_origin] if options.has_key?(:cross_origin)
|
60
|
+
image(key, url, override)
|
61
|
+
on(:load_complete, options[:context] || self, &block)
|
62
|
+
start
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Phaser
|
2
|
+
class ScaleManager
|
3
|
+
include Native
|
4
|
+
|
5
|
+
# A scale mode that stretches content to fill all available space
|
6
|
+
EXACT_FIT = 0;
|
7
|
+
|
8
|
+
# A scale mode that prevents any scaling
|
9
|
+
NO_SCALE = 1;
|
10
|
+
|
11
|
+
# A scale mode that shows the entire game while maintaining proportions
|
12
|
+
SHOW_ALL = 2;
|
13
|
+
|
14
|
+
# A scale mode that causes the Game size to change - see {@link Phaser.ScaleManager#scaleMode scaleMode}.
|
15
|
+
RESIZE = 3;
|
16
|
+
|
17
|
+
# A scale mode that allows a custom scale factor - see {@link Phaser.ScaleManager#scaleMode scaleMode}.
|
18
|
+
USER_SCALE = 4;
|
19
|
+
|
20
|
+
alias_native :scale_mode, :scaleMode
|
21
|
+
alias_native :refresh
|
22
|
+
|
23
|
+
def scale_mode=(mode)
|
24
|
+
`#@native.scaleMode = #{mode}`
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'opal/phaser/geometry/rectangle'
|
2
|
+
|
1
3
|
module Phaser
|
2
4
|
class World
|
3
5
|
include Native
|
@@ -6,6 +8,7 @@ module Phaser
|
|
6
8
|
alias_native :height
|
7
9
|
|
8
10
|
alias_native :set_bounds, :setBounds
|
11
|
+
alias_native :bounds, :bounds, as: Phaser::Rectangle
|
9
12
|
|
10
13
|
alias_native :x_center, :centerX
|
11
14
|
alias_native :y_center, :centerY
|
@@ -5,4 +5,5 @@ require 'opal/phaser/game_objects/tile_sprite'
|
|
5
5
|
require 'opal/phaser/game_objects/text'
|
6
6
|
require 'opal/phaser/game_objects/image'
|
7
7
|
require 'opal/phaser/game_objects/bitmap_data'
|
8
|
+
require 'opal/phaser/game_objects/button'
|
8
9
|
require 'opal/phaser/game_objects/game_object_factory'
|
@@ -0,0 +1,23 @@
|
|
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
|
+
require 'opal/phaser/game_objects/button'
|
9
|
+
|
10
|
+
module Phaser
|
11
|
+
class GameObjectCreator
|
12
|
+
include Native
|
13
|
+
|
14
|
+
alias_native :sprite, :sprite, as: Sprite
|
15
|
+
alias_native :group, :group, as: Group
|
16
|
+
alias_native :text, :text, as: Text
|
17
|
+
alias_native :image, :image, as: Image
|
18
|
+
alias_native :bitmap_data, :bitmapData, as: BitmapData
|
19
|
+
alias_native :tween, :tween, as: Tween
|
20
|
+
alias_native :tile_sprite, :tileSprite, as: TileSprite
|
21
|
+
alias_native :button, :button, as: Button
|
22
|
+
end
|
23
|
+
end
|
@@ -5,6 +5,7 @@ require 'opal/phaser/game_objects/image'
|
|
5
5
|
require 'opal/phaser/game_objects/bitmap_data'
|
6
6
|
require 'opal/phaser/tween/tween'
|
7
7
|
require 'opal/phaser/game_objects/tile_sprite'
|
8
|
+
require 'opal/phaser/game_objects/button'
|
8
9
|
|
9
10
|
module Phaser
|
10
11
|
class GameObjectFactory
|
@@ -17,5 +18,6 @@ module Phaser
|
|
17
18
|
alias_native :bitmap_data, :bitmapData, as: BitmapData
|
18
19
|
alias_native :tween, :tween, as: Tween
|
19
20
|
alias_native :tile_sprite, :tileSprite, as: TileSprite
|
21
|
+
alias_native :button, :button, as: Button
|
20
22
|
end
|
21
23
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'opal/phaser/core/anchor'
|
1
2
|
module Phaser
|
2
3
|
class Image
|
3
4
|
include Native
|
@@ -7,11 +8,14 @@ module Phaser
|
|
7
8
|
alias_native :x=
|
8
9
|
alias_native :y=
|
9
10
|
alias_native :height
|
11
|
+
alias_native :width
|
12
|
+
alias_native :input
|
10
13
|
|
11
14
|
alias_native :scale
|
12
15
|
alias_native :destroy
|
13
|
-
|
16
|
+
|
14
17
|
alias_native :load_texture, :loadTexture
|
18
|
+
alias_native :anchor, :anchor, as: Anchor
|
15
19
|
|
16
20
|
def smoothed=(bool)
|
17
21
|
`#@native.smoothed = bool`
|
@@ -27,6 +27,9 @@ module Phaser
|
|
27
27
|
alias_native :y
|
28
28
|
alias_native :y=
|
29
29
|
alias_native :width
|
30
|
+
alias_native :height
|
31
|
+
alias_native :right
|
32
|
+
|
30
33
|
|
31
34
|
def input_enabled=(bool)
|
32
35
|
`#@native.inputEnabled = bool`
|
@@ -40,11 +43,24 @@ module Phaser
|
|
40
43
|
`#@native.frameName = name`
|
41
44
|
end
|
42
45
|
|
46
|
+
def auto_cull=(bool)
|
47
|
+
`#@native.autoCull = bool`
|
48
|
+
end
|
49
|
+
|
50
|
+
def check_world_bounds=(bool)
|
51
|
+
`#@native.checkWorldBounds = bool`
|
52
|
+
end
|
53
|
+
|
43
54
|
alias_native :load_texture, :loadTexture
|
44
55
|
|
45
56
|
alias_native :body, :body, as: Physics::Arcade::Body
|
46
57
|
alias_native :anchor, :anchor, as: Anchor
|
47
58
|
alias_native :animations, :animations, as: AnimationManager
|
48
59
|
alias_native :events, :events, as: Events
|
60
|
+
|
61
|
+
def on(type, context, &block)
|
62
|
+
events.on(type, context, &block)
|
63
|
+
end
|
64
|
+
|
49
65
|
end
|
50
66
|
end
|