opal-phaser 0.0.4 → 0.1.0
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 +4 -4
- data/demo/app/main.rb +191 -68
- data/demo/config.ru +4 -0
- data/demo/index.html +1 -1
- data/lib/opal/phaser/core.rb +12 -2
- data/lib/opal/phaser/core/animation.rb +23 -0
- data/lib/opal/phaser/core/animation_manager.rb +9 -0
- data/lib/opal/phaser/core/cache.rb +5 -0
- data/lib/opal/phaser/core/frame.rb +5 -0
- data/lib/opal/phaser/core/game.rb +26 -18
- data/lib/opal/phaser/core/game_object_factory.rb +10 -0
- data/lib/opal/phaser/core/group.rb +18 -0
- data/lib/opal/phaser/core/image.rb +10 -0
- data/lib/opal/phaser/core/physics.rb +16 -2
- data/lib/opal/phaser/core/sprite.rb +28 -0
- data/lib/opal/phaser/core/state.rb +1 -1
- data/lib/opal/phaser/core/text.rb +9 -0
- data/lib/opal/phaser/core/tween.rb +4 -0
- data/lib/opal/phaser/version.rb +1 -1
- metadata +13 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ba2df4d99da9e4b3ea41300062f9d44d9aeac31e
|
4
|
+
data.tar.gz: 635d8e5cfb6d3929fa9e4b5aeb9c8f96c8315df5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 67169bb7c05f882b8320c3195ea81354b5e51cc81b6657ca31fb750c10aedd5abbf532f3eaba9024020a2826d5f3e06f9b5ff9cbee50ae95a59ae4af69e2cc90
|
7
|
+
data.tar.gz: e862e90ddb873a15c5f7e02a7b1b061d407cd309ff9d9a68386edc510919f56bdccde11babaa7e0dcb275fd3074ce04a95785166e11fc1fb12d9ab98d26efa6e
|
data/demo/app/main.rb
CHANGED
@@ -1,97 +1,220 @@
|
|
1
1
|
require 'opal'
|
2
2
|
require 'opal-phaser'
|
3
|
+
require 'pp'
|
3
4
|
|
4
|
-
class
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
@
|
5
|
+
class Score
|
6
|
+
attr_accessor :score
|
7
|
+
attr_reader :scoreText
|
8
|
+
|
9
|
+
def initialize(game)
|
10
|
+
@game = game
|
11
|
+
end
|
12
|
+
|
13
|
+
def preload
|
14
|
+
# nothing in here for this class
|
15
|
+
end
|
16
|
+
|
17
|
+
def create
|
18
|
+
@score = 0
|
19
|
+
@scoreText = @game.add.text(16, 16, 'score: 0', {fontSize: '32px', fill: '#000'})
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class Star
|
24
|
+
attr_accessor :stars
|
25
|
+
|
26
|
+
def initialize(game)
|
27
|
+
@sprite_key = 'star'
|
28
|
+
@sprite_url = 'assets/star.png'
|
29
|
+
@game = game
|
30
|
+
end
|
31
|
+
|
32
|
+
def preload
|
33
|
+
@game.load.image(@sprite_key, @sprite_url)
|
34
|
+
end
|
35
|
+
|
36
|
+
def create
|
37
|
+
@stars = @game.add.group
|
38
|
+
stars.enable_body = true
|
39
|
+
|
40
|
+
12.times do |n|
|
41
|
+
star = stars.create(n * 70, 0, 'star')
|
42
|
+
star.body.gravity.y = 6
|
43
|
+
star.body.bounce.y = 0.7 + rand * 0.2
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
class Sky
|
49
|
+
def initialize(game)
|
50
|
+
@sprite_key = 'sky'
|
51
|
+
@sprite_url = 'assets/sky.png'
|
52
|
+
@game = game
|
53
|
+
end
|
54
|
+
|
55
|
+
def preload
|
56
|
+
@game.load.image(@sprite_key, @sprite_url)
|
57
|
+
end
|
58
|
+
|
59
|
+
def create
|
60
|
+
@game.add.sprite(0, 0, @sprite_key)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
class Platforms
|
65
|
+
attr_accessor :platforms
|
66
|
+
|
67
|
+
def initialize(game)
|
68
|
+
@sprite_key = 'ground'
|
69
|
+
@sprite_url = 'assets/platform.png'
|
70
|
+
@game = game
|
71
|
+
end
|
72
|
+
|
73
|
+
def preload
|
74
|
+
@game.load.image(@sprite_key, @sprite_url)
|
75
|
+
end
|
76
|
+
|
77
|
+
def create
|
78
|
+
@game.physics.start_system(Phaser::Physics::ARCADE)
|
79
|
+
@platforms = @game.add.group
|
80
|
+
@platforms.enable_body = true
|
10
81
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
game.load.image('star', 'assets/star.png')
|
16
|
-
game.load.spritesheet('dude', 'assets/dude.png', 32, 48)
|
17
|
-
end
|
82
|
+
create_ground
|
83
|
+
create_ledge(400, 400)
|
84
|
+
create_ledge(-150, 250)
|
85
|
+
end
|
18
86
|
|
19
|
-
|
20
|
-
@score = 0
|
21
|
-
game.physics.startSystem(Phaser::Physics::ARCADE)
|
22
|
-
game.add.sprite(0, 0, 'sky')
|
87
|
+
private
|
23
88
|
|
24
|
-
|
25
|
-
|
89
|
+
def create_ground
|
90
|
+
ground = @platforms.create(0, @game.world.height - 64, @sprite_key)
|
91
|
+
ground.scale.setTo(2, 2)
|
92
|
+
ground.body.immovable = true
|
93
|
+
end
|
26
94
|
|
27
|
-
|
95
|
+
def create_ledge(x, y)
|
96
|
+
ledge = @platforms.create(x, y, @sprite_key)
|
97
|
+
ledge.body.immovable = true
|
98
|
+
end
|
99
|
+
end
|
28
100
|
|
29
|
-
|
30
|
-
|
101
|
+
class Player
|
102
|
+
attr_accessor :player
|
31
103
|
|
32
|
-
|
33
|
-
|
104
|
+
def initialize(game)
|
105
|
+
@game = game
|
34
106
|
|
35
|
-
|
36
|
-
|
107
|
+
@sprite_key = 'dude'
|
108
|
+
@sprite_url = 'assets/dude.png'
|
37
109
|
|
38
|
-
|
110
|
+
@x = 32
|
111
|
+
@y = @game.world.height - 150
|
112
|
+
end
|
39
113
|
|
40
|
-
|
114
|
+
def preload
|
115
|
+
@game.load.spritesheet(@sprite_key, @sprite_url, 32, 48)
|
116
|
+
end
|
41
117
|
|
42
|
-
|
43
|
-
|
44
|
-
@player.body.collideWorldBounds = true
|
118
|
+
def create
|
119
|
+
@player = @game.add.sprite(@x, @y, @sprite_key)
|
45
120
|
|
46
|
-
|
47
|
-
@player.animations.add('right', [5, 6, 7, 8], 10, true)
|
121
|
+
@game.physics.arcade.enable(@player)
|
48
122
|
|
49
|
-
|
50
|
-
|
123
|
+
player.body.bounce.y = 0.2
|
124
|
+
player.body.gravity.y = 300
|
125
|
+
player.body.collideWorldBounds = true
|
51
126
|
|
52
|
-
|
53
|
-
|
127
|
+
player.animations.add('left', [0, 1, 2, 3], 10, true)
|
128
|
+
player.animations.add('right', [5, 6, 7, 8], 10, true)
|
129
|
+
end
|
54
130
|
|
55
|
-
|
56
|
-
|
57
|
-
|
131
|
+
def update
|
132
|
+
cursors = @game.input.keyboard.createCursorKeys
|
133
|
+
movement(cursors)
|
134
|
+
end
|
58
135
|
|
59
|
-
|
136
|
+
def movement(cursors)
|
137
|
+
player.body.velocity.x = 0
|
138
|
+
|
139
|
+
case
|
140
|
+
when cursors.left.isDown
|
141
|
+
player.body.velocity.x = -150
|
142
|
+
player.animations.play('left')
|
143
|
+
when cursors.right.isDown
|
144
|
+
player.body.velocity.x = 150
|
145
|
+
player.animations.play('right')
|
146
|
+
else
|
147
|
+
player.animations.stop
|
148
|
+
player.frame = 4
|
149
|
+
end
|
60
150
|
|
61
|
-
|
62
|
-
|
151
|
+
if cursors.up.isDown && player.body.touching.down
|
152
|
+
player.body.velocity.y = -350
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
63
156
|
|
64
|
-
|
65
|
-
|
66
|
-
|
157
|
+
class Game
|
158
|
+
def initialize
|
159
|
+
run
|
160
|
+
end
|
67
161
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
end
|
73
|
-
game.physics.arcade.overlap(@player, @stars, collectStar, nil, self)
|
162
|
+
def run
|
163
|
+
preload
|
164
|
+
create_game
|
165
|
+
update_game
|
74
166
|
|
75
|
-
|
167
|
+
Phaser::Game.new(width: 800, height: 600, renderer: Phaser::AUTO, parent: '', state: state, transparent: false, antialias: true, physics: nil)
|
168
|
+
end
|
76
169
|
|
77
|
-
|
78
|
-
@player.body.velocity.x = -150
|
79
|
-
@player.animations.play('left')
|
80
|
-
elsif @cursors.right.isDown
|
81
|
-
@player.body.velocity.x = 150
|
82
|
-
@player.animations.play('right')
|
83
|
-
else
|
84
|
-
@player.animations.stop
|
85
|
-
@player.frame = 4
|
86
|
-
end
|
170
|
+
private
|
87
171
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
172
|
+
def preload
|
173
|
+
state.preload do |game|
|
174
|
+
initialize_entities(game)
|
175
|
+
entities_call :preload
|
92
176
|
end
|
93
177
|
end
|
94
178
|
|
95
|
-
def
|
179
|
+
def create_game
|
180
|
+
state.create do
|
181
|
+
entities_call :create
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
def update_game
|
186
|
+
collect_star = proc do |player, star, score|
|
187
|
+
star = Phaser::Sprite.new(star)
|
188
|
+
star.kill
|
189
|
+
|
190
|
+
@score.score += 10
|
191
|
+
@score.scoreText.text = "score: #{@score.score}"
|
192
|
+
end
|
193
|
+
|
194
|
+
state.update do |game|
|
195
|
+
game.physics.arcade.collide(@player.player, @platforms.platforms)
|
196
|
+
game.physics.arcade.collide(@star.stars, @platforms.platforms)
|
197
|
+
game.physics.arcade.overlap(@player.player, @star.stars, collect_star)
|
198
|
+
|
199
|
+
@player.update
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
def state
|
204
|
+
@state ||= Phaser::State.new
|
205
|
+
end
|
206
|
+
|
207
|
+
def initialize_entities(game)
|
208
|
+
@sky = Sky.new(game)
|
209
|
+
@platforms = Platforms.new(game)
|
210
|
+
@player = Player.new(game)
|
211
|
+
@star = Star.new(game)
|
212
|
+
@score = Score.new(game)
|
213
|
+
|
214
|
+
@entities ||= [@sky, @platforms, @player, @star, @score]
|
215
|
+
end
|
216
|
+
|
217
|
+
def entities_call(method)
|
218
|
+
@entities.each { |e| e.send(method) }
|
96
219
|
end
|
97
220
|
end
|
data/demo/config.ru
CHANGED
data/demo/index.html
CHANGED
data/lib/opal/phaser/core.rb
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
require 'native'
|
2
|
+
|
1
3
|
require 'opal/phaser/core/state'
|
2
|
-
require 'opal/phaser/core/
|
3
|
-
require 'opal/phaser/core/
|
4
|
+
require 'opal/phaser/core/physics'
|
5
|
+
require 'opal/phaser/core/group'
|
6
|
+
require 'opal/phaser/core/animation'
|
7
|
+
require 'opal/phaser/core/animation_manager'
|
8
|
+
require 'opal/phaser/core/sprite'
|
9
|
+
require 'opal/phaser/core/image'
|
10
|
+
require 'opal/phaser/core/text'
|
11
|
+
require 'opal/phaser/core/cache'
|
12
|
+
require 'opal/phaser/core/game_object_factory'
|
13
|
+
require 'opal/phaser/core/game'
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Phaser
|
2
|
+
|
3
|
+
# An Animation instance contains a single animation and the controls to play it.
|
4
|
+
# It is created by the AnimationManager, consists of Animation.Frame objects and belongs to a single Game Object such as a Sprite.
|
5
|
+
#
|
6
|
+
# @see http://docs.phaser.io/Phaser.Animation.html
|
7
|
+
class Animation
|
8
|
+
include Native
|
9
|
+
attr_accessor :native
|
10
|
+
|
11
|
+
# @param game [Phaser.Game] A reference to the currently running game.
|
12
|
+
# @param parent [Phaser.Sprite] A reference to the owner of this Animation.
|
13
|
+
# @param name [String] The unique name for this animation, used in playback commands.
|
14
|
+
# @param frame_data [Phaser.FrameData] The FrameData object that contains all frames used by this Animation.
|
15
|
+
# @param frames [Array<Integer>, Array<String>] An array of numbers or strings indicating which frames to play in which order.
|
16
|
+
# @param frame_rate [Integer] [frameRate=60] The speed at which the animation should play. The speed is given in frames per second.
|
17
|
+
# @param loop [True, False] [loop=false] Whether or not the animation is looped or just plays once.
|
18
|
+
def initialize(game, parent, name, frameData, frames, frameRate = 60, _loop = false)
|
19
|
+
@native_game = game
|
20
|
+
@native = `new Phaser.Animation(#@native_game, parent, name, frameData, frames, frameRate, _loop)`
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -1,14 +1,21 @@
|
|
1
|
-
require 'native'
|
2
1
|
module Phaser
|
3
|
-
AUTO
|
4
|
-
WEBGL
|
5
|
-
CANVAS =
|
2
|
+
AUTO = `Phaser.AUTO`
|
3
|
+
WEBGL = `Phaser.WEBGL`
|
4
|
+
CANVAS = `Phaser.CANVAS`
|
6
5
|
|
7
6
|
class Game
|
8
|
-
include
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
include Native
|
8
|
+
|
9
|
+
def initialize(arg_hash = {}, &block)
|
10
|
+
|
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]
|
12
19
|
|
13
20
|
if state
|
14
21
|
state.game = self
|
@@ -20,21 +27,22 @@ module Phaser
|
|
20
27
|
state.instance_eval(&block)
|
21
28
|
end
|
22
29
|
|
23
|
-
|
30
|
+
@native = %x{
|
24
31
|
new Phaser.Game(width, height, renderer, parent, #{state.to_n}, transparent,
|
25
32
|
antialias, physics)
|
26
33
|
}
|
27
|
-
super(_native)
|
28
34
|
end
|
29
35
|
|
30
|
-
alias_native :
|
31
|
-
alias_native :add,
|
32
|
-
alias_native :world, :world
|
33
|
-
alias_native :stage, :stage
|
34
|
-
alias_native :physics, :physics
|
35
|
-
alias_native :debug, :debug
|
36
|
-
alias_native :input, :input
|
36
|
+
alias_native :cache, :cache, as: Cache
|
37
|
+
alias_native :add, :add, as: GameObjectFactory
|
37
38
|
|
39
|
+
alias_native :load
|
40
|
+
alias_native :world
|
41
|
+
alias_native :stage
|
42
|
+
alias_native :physics, :physics, as: Physics
|
43
|
+
alias_native :debug
|
44
|
+
alias_native :input
|
45
|
+
alias_native :width
|
46
|
+
alias_native :time
|
38
47
|
end
|
39
|
-
|
40
48
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Phaser
|
2
|
+
class Group
|
3
|
+
include Native
|
4
|
+
|
5
|
+
alias_native :cursor
|
6
|
+
alias_native :physics_body_type, :physicsBodyType
|
7
|
+
alias_native :enable_body_debug, :enableBodyDebug
|
8
|
+
alias_native :add_child, :addChild
|
9
|
+
alias_native :children
|
10
|
+
alias_native :create
|
11
|
+
|
12
|
+
alias_native :enable_body?, :enableBody
|
13
|
+
|
14
|
+
def enable_body=(bool)
|
15
|
+
`#@native.enableBody = bool`
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -1,5 +1,19 @@
|
|
1
1
|
module Phaser
|
2
|
-
|
3
|
-
|
2
|
+
class Physics
|
3
|
+
include Native
|
4
|
+
|
5
|
+
class Arcade
|
6
|
+
class Body
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
ARCADE = `Phaser.Physics.ARCADE`
|
11
|
+
P2JS = `Phaser.Physics.P2JS`
|
12
|
+
NINJA = `Phaser.Physics.NINJA`
|
13
|
+
BOX2D = `Phaser.Physics.BOX2D`
|
14
|
+
|
15
|
+
alias_native :start_system, :startSystem
|
16
|
+
alias_native :arcade
|
17
|
+
|
4
18
|
end
|
5
19
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Phaser
|
2
|
+
class Sprite
|
3
|
+
include Native
|
4
|
+
|
5
|
+
alias_native :anchor
|
6
|
+
alias_native :events
|
7
|
+
alias_native :scale
|
8
|
+
alias_native :body
|
9
|
+
alias_native :bounce
|
10
|
+
|
11
|
+
alias_native :kill
|
12
|
+
|
13
|
+
alias_native :visible=
|
14
|
+
alias_native :exists=
|
15
|
+
alias_native :alive=
|
16
|
+
alias_native :frame=
|
17
|
+
|
18
|
+
alias_native :z
|
19
|
+
alias_native :z=
|
20
|
+
alias_native :x
|
21
|
+
alias_native :x=
|
22
|
+
alias_native :y
|
23
|
+
alias_native :y=
|
24
|
+
alias_native :width
|
25
|
+
|
26
|
+
alias_native :animations, :animations, as: AnimationManager
|
27
|
+
end
|
28
|
+
end
|
data/lib/opal/phaser/version.rb
CHANGED
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.0
|
4
|
+
version: 0.1.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-
|
11
|
+
date: 2015-03-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: opal
|
@@ -79,9 +79,19 @@ files:
|
|
79
79
|
- lib/opal-phaser.rb
|
80
80
|
- lib/opal/phaser.rb
|
81
81
|
- lib/opal/phaser/core.rb
|
82
|
+
- lib/opal/phaser/core/animation.rb
|
83
|
+
- lib/opal/phaser/core/animation_manager.rb
|
84
|
+
- lib/opal/phaser/core/cache.rb
|
85
|
+
- lib/opal/phaser/core/frame.rb
|
82
86
|
- lib/opal/phaser/core/game.rb
|
87
|
+
- lib/opal/phaser/core/game_object_factory.rb
|
88
|
+
- lib/opal/phaser/core/group.rb
|
89
|
+
- lib/opal/phaser/core/image.rb
|
83
90
|
- lib/opal/phaser/core/physics.rb
|
91
|
+
- lib/opal/phaser/core/sprite.rb
|
84
92
|
- lib/opal/phaser/core/state.rb
|
93
|
+
- lib/opal/phaser/core/text.rb
|
94
|
+
- lib/opal/phaser/core/tween.rb
|
85
95
|
- lib/opal/phaser/version.rb
|
86
96
|
- opal-phaser.gemspec
|
87
97
|
homepage: http://github.com/orbitalimpact/opal-phaser
|
@@ -103,7 +113,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
103
113
|
version: '0'
|
104
114
|
requirements: []
|
105
115
|
rubyforge_project:
|
106
|
-
rubygems_version: 2.
|
116
|
+
rubygems_version: 2.4.5
|
107
117
|
signing_key:
|
108
118
|
specification_version: 4
|
109
119
|
summary: Opal access to phaser
|