redmocha 0.3.0-java → 0.3.7-java

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/includes/core.rb +4 -0
  3. data/lib/redmocha.rb +141 -9
  4. metadata +3 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 21deb0287e55cbf40f3e0761d31698435295de8d
4
- data.tar.gz: 7dfab9482d1143066c150e4232fa5b492a5bea1a
3
+ metadata.gz: c3044a3de6047356facf10980193b658b26a0f1b
4
+ data.tar.gz: 921985f068ce2df86878d38ee5decd76177c09ff
5
5
  SHA512:
6
- metadata.gz: 4013e3d3fcc3e07bd9a26f52704b555923138864ec8ac51b2c69f0c037b231a097b8a6bddc1dff1cadb0f64482e4840d76085f50a77f3a897fc816062457df07
7
- data.tar.gz: 211eaf7de9e001894204a395030f982dd35adba05d56df194bb526492d6b480e6e82a5f0978d2cbddc0f6630f41228fa483f89352697cbbcdd6822cd920f857e
6
+ metadata.gz: 1fea984fc1ce18d976c853b69af73f6745e48177e75ae53dbc7351f108c84af39440a3f85c4488715fac935db834b568a89e933b98e74f97f90392353f9302ed
7
+ data.tar.gz: 51e31c4faa7e75bc121bfdd9384709d0b15912a1396efede30cd630ccb72d662117b939c4a4de3d24ad4aba617e177cd58e4682228192c63f343b41aeb189c05
@@ -0,0 +1,4 @@
1
+ include Java
2
+
3
+ module RedMocha
4
+ end
data/lib/redmocha.rb CHANGED
@@ -1,26 +1,158 @@
1
1
  path = File.expand_path(File.dirname(__FILE__))
2
2
  $LOAD_PATH.unshift path
3
-
4
3
  require "java"
4
+
5
+ class String
6
+ def underscore
7
+ self.gsub(/::/, '/').
8
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
9
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
10
+ tr("-", "_").
11
+ downcase
12
+ end
13
+
14
+ def hungarian
15
+ # takes underscore string
16
+ words = self.split("_")
17
+ words.map { |w| if w == words.first then w else w.capitalize end }.join("")
18
+ end
19
+ end
20
+
5
21
  Dir["#{path}/gdxlibs/\*.jar"].each do |jar|
6
22
  require jar.sub("#{path}/", "")
7
23
  end
8
24
 
9
- java_import com.badlogic.gdx.Gdx
10
- java_import com.badlogic.gdx.Game
11
- java_import com.badlogic.gdx.graphics.GL20
12
- java_import com.badlogic.gdx.backends.lwjgl.LwjglApplication
25
+ Dir["#{path}/includes/\*.rb"].each do |rb|
26
+ require_relative rb.sub("#{path}/", "").sub(".rb", "")
27
+ end
13
28
 
14
- class RedMocha < Game
15
- attr_accessor :title, :width, :height
29
+ def rm_import(klass)
30
+ klass = klass.to_s.split("::")
31
+ klass[klass.length-1] = klass.last.underscore.split("_").map { |w| w.upcase }.join("_")
32
+ java_import klass.join("::")
33
+ end
34
+
35
+ def rm_include(interface)
36
+ interface = interface.to_s.split("::")
37
+ interface[interface.length-1] = interface.last.underscore.split("_").map { |w| w.upcase.join("_") }
38
+ include interface.join("::")
39
+ end
40
+
41
+ class RMScreen
42
+ include com.badlogic.gdx.Screen
43
+
44
+ def initialize(game)
45
+ @game = game
46
+ end
47
+
48
+ protected
49
+
50
+ def clear
51
+ com.badlogic.gdx.Gdx.gl.glClearColor(0.0, 0.0, 0.0, 1.0)
52
+ com.badlogic.gdx.Gdx.gl.glClear(com.badlogic.gdx.graphics.GL20::GL_COLOR_BUFFER_BIT)
53
+ end
54
+
55
+ def render(delta)
56
+ @game.batch.begin
57
+ clear
58
+ @game.font.draw(@game.batch, "RedMocha beats white mocha fam!", 20, 20)
59
+ @game.batch.end
60
+ end
61
+
62
+ def show
63
+ end
64
+
65
+ def hide
66
+ end
67
+
68
+ def dispose
69
+ end
70
+
71
+ def pause
72
+ end
73
+
74
+ def resize(width, height)
75
+ end
76
+
77
+ def resume
78
+ end
79
+ end
80
+
81
+ class RMGame < com.badlogic.gdx.Game
82
+ attr_accessor :batch, :font, :title, :width, :height, :screen
16
83
 
84
+ def create
85
+ @batch = com.badlogic.gdx.graphics.g2d.SpriteBatch.new
86
+ @font = com.badlogic.gdx.graphics.g2d.BitmapFont.new
87
+ @screen = RMScreen.new(self)
88
+ self.set_screen(@screen)
89
+ end
90
+
91
+ def render
92
+ super
93
+ end
94
+
95
+ def dispose
96
+ @batch.dispose unless @batch.nil?
97
+ @font.dispose unless @font.nil?
98
+ end
99
+
100
+ def run(config = nil)
101
+ if config.nil?
102
+ com.badlogic.gdx.backends.lwjgl.LwjglApplication.new(self, @title, @width, @height)
103
+ else
104
+ com.badlogic.gdx.backends.lwjgl.LwjglApplication.new(self, config)
105
+ end
106
+ end
107
+
108
+ protected
109
+
17
110
  def initialize(title = "RedMocha Game", width = 800, height = 600)
18
111
  @title = title
19
112
  @width = width
20
113
  @height = height
21
114
  end
115
+ end
22
116
 
23
- def run
24
- LwjglApplication.new(self, @title, @width, @height)
117
+ class RMAdapter < com.badlogic.gdx.ApplicationAdapter
118
+ attr_accessor :title, :width, :height
119
+
120
+ def create(title = "RedMocha Game", width = 800, height = 600)
121
+ @batch = com.badlogic.gdx.graphics.g2d.SpriteBatch.new
122
+ @title = title
123
+ @width = width
124
+ @height = height
25
125
  end
126
+
127
+ def pause
128
+ end
129
+
130
+ def dispose
131
+ @batch.dispose
132
+ end
133
+
134
+ def render
135
+ @batch.begin
136
+ clear
137
+ @batch.end
138
+ end
139
+
140
+ def resize(width, height)
141
+ end
142
+
143
+ def resume
144
+ end
145
+
146
+ def run(config = nil)
147
+ com.badlogic.gdx.backends.lwjgl.LwjglApplication.new(self, config)
148
+ end
149
+
150
+ def clear
151
+ com.badlogic.gdx.Gdx.gl.glClearColor(0.0, 0.0, 0.0, 1.0)
152
+ com.badlogic.gdx.Gdx.gl.glClear(com.badlogic.gdx.graphics.GL20::GL_COLOR_BUFFER_BIT)
153
+ end
154
+ end
155
+
156
+ class RMConfig < com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration
157
+
26
158
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redmocha
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.7
5
5
  platform: java
6
6
  authors:
7
7
  - Julio Berina
@@ -22,6 +22,7 @@ files:
22
22
  - lib/gdxlibs/gdx-sources.jar
23
23
  - lib/gdxlibs/gdx-tools.jar
24
24
  - lib/gdxlibs/gdx.jar
25
+ - lib/includes/core.rb
25
26
  - lib/redmocha.rb
26
27
  homepage: http://rubygems.org/gems/redmocha
27
28
  licenses:
@@ -32,6 +33,7 @@ rdoc_options: []
32
33
  require_paths:
33
34
  - lib
34
35
  - lib/gdxlibs
36
+ - lib/includes
35
37
  required_ruby_version: !ruby/object:Gem::Requirement
36
38
  requirements:
37
39
  - - ">="