opal-phaser 0.0.2

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: 9e78699bcf6efc6c0806584d265da70faf71241d
4
+ data.tar.gz: e491344e6cfc27faa65fc2e6b1a3b1e51a8db31f
5
+ SHA512:
6
+ metadata.gz: c5677cd0dcdb5108f67a0e6975b85b5c346803fb369798f2793dcf0d5c66f256d6168d7b31bad9f564478a7dfb0ea92983e857a6b0835ad5c8e4e92d708def77
7
+ data.tar.gz: 193107f75c41d0366cf4c4d90718acefdd9465343f8cd575241e00bfdbad63023aef5d7f16e558618f87fc9eb2ef4a625214fcc77e66111e6ec7e79a377340e1
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ prepros.cfg
2
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
3
+
data/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # opal-phaser
2
+
3
+ [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/orbitalimpact/opal-phaser?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
4
+
5
+ <img align="right" width="250" src="https://raw.githubusercontent.com/orbitalimpact/opal-phaser/master/common/images/logo.png">
6
+
7
+ The goal of this project is to completely wrap the Phaser api in opal, to allow developers to write HTML5 and WebGL games entirely from ruby code.
8
+
9
+ If you have not heard of Phaser, check out these links:
10
+
11
+ * Phaser: https://github.com/photonstorm/phaser
12
+ * Phaser Examples: https://github.com/photonstorm/phaser-examples
13
+
14
+ ## Cloning this repository
15
+
16
+ ```
17
+ $ git clone https://github.com/orbitalimpact/opal-phaser
18
+ ```
19
+
20
+ ## Getting involved
21
+
22
+ To contribute to this project, follow the steps below.
23
+
24
+ 1. Fork the repo ( https://github.com/orbitalimpact/opal-phaser-examples/fork )
25
+ 2. Create your feature branch (`git checkout -b new-branch`)
26
+ 3. Commit your changes (`git commit -am 'description of commit'`)
27
+ 4. Push to the branch (`git push origin new-branch`)
28
+ 5. Create a Pull Request
29
+
30
+ ## Licenses
31
+
32
+ Phaser and all examples are released under the MIT License: http://opensource.org/licenses/MIT
33
+
34
+ opal-phaser is released under the Berkeley Software Distribution (BSD) 3-Clause License: http://opensource.org/licenses/BSD-3-Clause
35
+
36
+ Copyright (c) 2014, Orbital Impact
37
+ All rights reserved.
data/Rakefile ADDED
@@ -0,0 +1,45 @@
1
+ require 'bundler'
2
+ Bundler.require
3
+ Bundler::GemHelper.install_tasks
4
+
5
+ # require 'opal/rspec/rake_task'
6
+
7
+ desc "Build build/opal-phaser.js"
8
+ task :dist do
9
+ require 'fileutils'
10
+ FileUtils.mkdir_p 'build'
11
+
12
+ src = Opal::Builder.build('opal-phaser')
13
+ min = uglify src
14
+ gzp = gzip min
15
+
16
+ File.open('build/opal-phaser.js', 'w+') do |out|
17
+ out << src
18
+ end
19
+
20
+ puts "development: #{src.size}, minified: #{min.size}, gzipped: #{gzp.size}"
21
+ end
22
+
23
+ # Used for uglifying source to minify
24
+ def uglify(str)
25
+ IO.popen('uglifyjs', 'r+') do |i|
26
+ i.puts str
27
+ i.close_write
28
+ return i.read
29
+ end
30
+ rescue Errno::ENOENT
31
+ $stderr.puts '"uglifyjs" command not found (install with: "npm install -g uglify-js")'
32
+ nil
33
+ end
34
+
35
+ # Gzip code to check file size
36
+ def gzip(str)
37
+ IO.popen('gzip -f', 'r+') do |i|
38
+ i.puts str
39
+ i.close_write
40
+ return i.read
41
+ end
42
+ rescue Errno::ENOENT
43
+ $stderr.puts '"gzip" command not found, it is required to produce the .gz version'
44
+ nil
45
+ end
Binary file
data/demo/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ #Gemfile
2
+ source 'https://rubygems.org'
3
+
4
+ gem 'sinatra'
5
+ gem 'opal-phaser', path: '..'
data/demo/Gemfile.lock ADDED
@@ -0,0 +1,37 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ opal-phaser (0.0.1)
5
+ opal (~> 0.6.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ hike (1.2.3)
11
+ json (1.8.1)
12
+ multi_json (1.10.1)
13
+ opal (0.6.3)
14
+ source_map
15
+ sprockets
16
+ rack (1.6.0)
17
+ rack-protection (1.5.3)
18
+ rack
19
+ sinatra (1.4.5)
20
+ rack (~> 1.4)
21
+ rack-protection (~> 1.4)
22
+ tilt (~> 1.3, >= 1.3.4)
23
+ source_map (3.0.1)
24
+ json
25
+ sprockets (2.12.3)
26
+ hike (~> 1.2)
27
+ multi_json (~> 1.0)
28
+ rack (~> 1.0)
29
+ tilt (~> 1.1, != 1.3.0)
30
+ tilt (1.4.1)
31
+
32
+ PLATFORMS
33
+ ruby
34
+
35
+ DEPENDENCIES
36
+ opal-phaser!
37
+ sinatra
data/demo/app/main.rb ADDED
@@ -0,0 +1,97 @@
1
+ require 'opal'
2
+ require 'opal-phaser'
3
+
4
+ class Game
5
+ def initialize
6
+ @player = nil
7
+ @platforms = nil
8
+ @cursors = nil
9
+ @stars = nil
10
+
11
+ @phaser = Phaser::Game.new(800, 654) do |state|
12
+ state.preload do |game|
13
+ game.load.image('sky', 'assets/sky.png')
14
+ game.load.image('ground', 'assets/platform.png')
15
+ game.load.image('star', 'assets/star.png')
16
+ game.load.spritesheet('dude', 'assets/dude.png', 32, 48)
17
+ end
18
+
19
+ state.create do |game|
20
+ @score = 0
21
+ game.physics.startSystem(Phaser::Physics::ARCADE)
22
+ game.add.sprite(0, 0, 'sky')
23
+
24
+ @platforms = game.add.group()
25
+ @platforms.enableBody = true
26
+
27
+ ground = @platforms.create(0, game.world.height - 64, 'ground')
28
+
29
+ ground.scale.setTo(2, 2)
30
+ ground.body.immovable = true
31
+
32
+ ledge = @platforms.create(400, 400, 'ground')
33
+ ledge.body.immovable = true
34
+
35
+ ledge = @platforms.create(-150, 250, 'ground')
36
+ ledge.body.immovable = true
37
+
38
+ @player = game.add.sprite(32, game.world.height - 150, 'dude', 4)
39
+
40
+ game.physics.arcade.enable(@player)
41
+
42
+ @player.body.bounce.y = 0.2
43
+ @player.body.gravity.y = 300
44
+ @player.body.collideWorldBounds = true
45
+
46
+ @player.animations.add('left', [0, 1, 2, 3], 10, true)
47
+ @player.animations.add('right', [5, 6, 7, 8], 10, true)
48
+
49
+ @stars = game.add.group()
50
+ @stars.enableBody = true
51
+
52
+ 12.times do |i|
53
+ star = @stars.create(i*70, 0, 'star')
54
+
55
+ star.body.gravity.y = 300
56
+ star.body.bounce.y = 0.7 + rand * 0.2
57
+ end
58
+
59
+ @scoreText = game.add.text(16, 16, 'score: 0', { fontSize: '32px', fill: '#000' })
60
+
61
+ @cursors = game.input.keyboard.createCursorKeys()
62
+ end
63
+
64
+ state.update do |game|
65
+ game.physics.arcade.collide(@player, @platforms);
66
+ game.physics.arcade.collide(@stars, @platforms);
67
+
68
+ collectStar = proc do |player, star|
69
+ %x{ star.kill() }
70
+ @score += 10
71
+ @scoreText.text = "Score: #@score"
72
+ end
73
+ game.physics.arcade.overlap(@player, @stars, collectStar, nil, self);
74
+
75
+ @player.body.velocity.x = 0
76
+
77
+ if @cursors.left.isDown
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
87
+
88
+ if @cursors.up.isDown && @player.body.touching.down
89
+ @player.body.velocity.y = -350
90
+ end
91
+ end
92
+ end
93
+ end
94
+
95
+ def collectStar
96
+ end
97
+ end
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
data/demo/block.png ADDED
Binary file
data/demo/config.ru ADDED
@@ -0,0 +1,20 @@
1
+ # config.ru
2
+ require 'bundler'
3
+ Bundler.require
4
+
5
+ opal = Opal::Server.new { |s|
6
+ s.append_path 'app'
7
+ s.append_path 'assets'
8
+
9
+ s.main = 'main'
10
+ }
11
+
12
+ map '/assets' do
13
+ run opal.sprockets
14
+ end
15
+
16
+ get '/' do
17
+ send_file 'index.html'
18
+ end
19
+
20
+ run Sinatra::Application
data/demo/index.html ADDED
@@ -0,0 +1,18 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset= "utf-8" />
5
+ <title>Opal-Phaser</title>
6
+ <link rel="stylesheet" href="style.css">
7
+ <script src="//cdnjs.cloudflare.com/ajax/libs/phaser/2.2.1/phaser.js"></script>
8
+ <script src="/assets/main.js"></script>
9
+ </head>
10
+
11
+ <body>
12
+ <script>
13
+ window.onload = function() {
14
+ Opal.Game.$new()
15
+ }
16
+ </script>
17
+ </body>
18
+ </html>
data/demo/main.js ADDED
@@ -0,0 +1,15 @@
1
+ // This file is just a sanity check to see if this demo works in plain JS
2
+
3
+ function Game () {
4
+ this.game = new Phaser.Game(800, 600, Phaser.AUTO, "", { preload: preload, create: create });
5
+
6
+ function preload () {
7
+ this.game.load.image("logo", "phaser.png");
8
+ }
9
+
10
+ function create () {
11
+ this.logo = this.game.add.sprite(100, 100, "logo");
12
+ }
13
+ }
14
+
15
+ phaserGame = new Game();
data/demo/phaser.png ADDED
Binary file
data/demo/style.css ADDED
@@ -0,0 +1,5 @@
1
+ body {
2
+ margin: 0;
3
+ padding: 0;
4
+ background-color: #000000;
5
+ }
@@ -0,0 +1,36 @@
1
+ require 'native'
2
+ module Phaser
3
+ AUTO = %x{ Phaser.AUTO }
4
+
5
+ class Game
6
+ include ::Native
7
+ def initialize(width, height, renderer = Phaser::AUTO,
8
+ parent = '', state = nil, transparent = false, antialias = true,
9
+ physics = nil, &block)
10
+
11
+ if state
12
+ state.game = self
13
+ else
14
+ state = State.new(self)
15
+ end
16
+
17
+ if block_given?
18
+ state.instance_eval(&block)
19
+ end
20
+
21
+ _native = %x{
22
+ new Phaser.Game(width, height, renderer, parent, #{state.to_n}, transparent,
23
+ antialias, physics)
24
+ }
25
+ super(_native)
26
+ end
27
+
28
+ alias_native :load, :load
29
+ alias_native :add, :add
30
+ alias_native :world, :world
31
+ alias_native :physics, :physics
32
+ alias_native :input, :input
33
+
34
+ end
35
+
36
+ end
@@ -0,0 +1,44 @@
1
+ module Phaser
2
+ class State
3
+ attr_writer :game
4
+ def initialize(game = nil, &block)
5
+ @game = game
6
+ @native = %x{ new Phaser.State() }
7
+
8
+ @preload = proc {}
9
+ @create = proc {}
10
+ @update = proc {}
11
+ @render = proc {}
12
+
13
+ if block_given?
14
+ block.call(@game)
15
+ end
16
+ end
17
+
18
+
19
+ def preload(&block)
20
+ @preload = proc { block.call(@game) }
21
+ end
22
+
23
+ def create(&block)
24
+ @create = proc { block.call(@game) }
25
+ end
26
+
27
+ def update(&block)
28
+ @update = proc { block.call(@game) }
29
+ end
30
+
31
+ def render(&block)
32
+ @render = proc { block.call(@game) }
33
+ end
34
+
35
+ def to_n
36
+ %x{
37
+ var obj = { preload: #@preload, create: #@create, update: #@update,
38
+ render: #@render }
39
+ }
40
+
41
+ return %x{ obj }
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,2 @@
1
+ require 'opal/phaser/core/state'
2
+ require 'opal/phaser/core/game'
@@ -0,0 +1,5 @@
1
+ module Phaser
2
+ module Physics
3
+ ARCADE = %x{Phaser.Physics.ARCADE}
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module Opal
2
+ module Phaser
3
+ VERSION = '0.0.2'
4
+ end
5
+ end
@@ -0,0 +1,9 @@
1
+ if RUBY_ENGINE == 'opal'
2
+ require 'opal/phaser/core'
3
+ require 'opal/phaser/physics'
4
+ else
5
+ require 'opal'
6
+ require 'opal/phaser/version'
7
+
8
+ Opal.append_path File.expand_path('../..', __FILE__).untaint
9
+ end
@@ -0,0 +1 @@
1
+ require 'opal/phaser'
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/opal/phaser/version', __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'opal-phaser'
6
+ s.version = Opal::Phaser::VERSION
7
+ s.author = 'George Plymale'
8
+ s.email = 'george@orbitalimpact.com'
9
+ s.homepage = 'http://github.com/orbitalimpact/opal-phaser'
10
+ s.summary = 'Opal access to phaser'
11
+ s.description = 'Opal DOM library for phaser'
12
+
13
+ s.files = `git ls-files`.split("\n")
14
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.require_paths = ['lib']
17
+
18
+ s.add_runtime_dependency 'opal', '~> 0.6.0'
19
+ s.add_development_dependency 'yard'
20
+ s.add_development_dependency 'rake'
21
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: opal-phaser
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - George Plymale
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: opal
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.6.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.6.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: yard
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: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Opal DOM library for phaser
56
+ email: george@orbitalimpact.com
57
+ executables: []
58
+ extensions: []
59
+ extra_rdoc_files: []
60
+ files:
61
+ - ".gitignore"
62
+ - Gemfile
63
+ - README.md
64
+ - Rakefile
65
+ - common/images/logo.png
66
+ - demo/Gemfile
67
+ - demo/Gemfile.lock
68
+ - demo/app/main.rb
69
+ - demo/assets/baddie.png
70
+ - demo/assets/diamond.png
71
+ - demo/assets/dude.png
72
+ - demo/assets/firstaid.png
73
+ - demo/assets/platform.png
74
+ - demo/assets/sky.png
75
+ - demo/assets/star.png
76
+ - demo/block.png
77
+ - demo/config.ru
78
+ - demo/index.html
79
+ - demo/main.js
80
+ - demo/phaser.png
81
+ - demo/style.css
82
+ - lib/opal-phaser.rb
83
+ - lib/opal/phaser.rb
84
+ - lib/opal/phaser/core.rb
85
+ - lib/opal/phaser/core/game.rb
86
+ - lib/opal/phaser/core/state.rb
87
+ - lib/opal/phaser/physics.rb
88
+ - lib/opal/phaser/version.rb
89
+ - opal-phaser.gemspec
90
+ homepage: http://github.com/orbitalimpact/opal-phaser
91
+ licenses: []
92
+ metadata: {}
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 2.2.2
110
+ signing_key:
111
+ specification_version: 4
112
+ summary: Opal access to phaser
113
+ test_files: []
114
+ has_rdoc: