So first we start off by needing to package everything up nicely in a single jar file so it appears as though we're just using java. Unfortunately this comes with a bit of a space cost. And that space is that of jruby the complete jar is ~20mb you can find them at http://jruby.org/downloads so no way to avoid this although you can do something like write an install script that downloads it and then puts your source into it afterwards.
Ok once you have the jar file you will add your code to it and it will become your executable from java.
Make a copy of the complete jar.
$ cp jruby-complete-9.0.5.0.jar mygame.jar
Create a file that jruby will launch called jar-bootstrap.rb
#!/usr/bin/env ruby
puts "Hello, I am jar-bootstrap.rb from inside the jar file"
Update the jar (-u) by first modifying the manifest to run a specific java class using option -e to override the Main-Class entry in the manifest already inside the jar.
$ jar ufe mygame.jar org.jruby.JarBootstrapMain
Then you can use the -u option to add files to the jar file or update existing ones.
$ jar uf mygame.jar jar-bootstrap.rb
Then viola:
$ java -jar mygame.jar
Hello, I am jar-bootstrap.rb from inside the jar file.
Ok we've entered the ruby~java land woot woot.
Now for lets rubify java to do our game-logics bidding!!!
Lets switch the jar-bootstrap.rb to load our game which we will start in a game.rb file:
jar-boostrap.rb becomes
#!/usr/bin/env ruby
require './game.rb'
Then we make our game.rb file with a simple example of loading a java swing window and rendering loop
game.rb is
#!/usr/bin/env ruby
include Java
import javax.swing.JFrame
import javax.swing.JPanel
import java.awt.BorderLayout
import java.awt.Dimension
class MyDrawPane < JPanel
def initialize
super
setDoubleBuffered true
setPreferredSize Dimension.new(800,600)
end
def paintComponent(g)
g = g.create
g.drawString 'Hello from ruby', 0, self.height / 2
g.dispose
end
end
class MyGame < JFrame
def initialize
super "My Game Window Title"
self.setLayout BorderLayout.new
self.add ::MyDrawPane.new
self.setDefaultCloseOperation JFrame::EXIT_ON_CLOSE
self.pack
self.setLocationRelativeTo nil
self.setVisible true
end
end
MyGame.new
And with all this we have a simple window to start from but now we can use the power of ruby to rule the world. Uh I mean we'll use the power of ruby to make games...
...to rule the world...
So this is all great but maybe we want easier iterations with our game development because updating the jar all the time isn't that fast. So for development just execute your game.rb file from jruby directly. You can use the original one you downloaded.
$ java -jar ../jruby-complete-9.0.5.0.jar game.rb
Or if you use rvm or rbenv then just execute the game script. And Q.E.D.
9 comments:
Thank you.Well it was nice post and very helpful information on Ruby on Rails Online Course Bangalore
Smm panel
smm panel
iş ilanları
instagram takipçi satın al
hirdavatciburada.com
beyazesyateknikservisi.com.tr
SERVİS
tiktok jeton hilesi
kadıköy mitsubishi klima servisi
tuzla lg klima servisi
tuzla alarko carrier klima servisi
tuzla daikin klima servisi
kadıköy alarko carrier klima servisi
üsküdar arçelik klima servisi
pendik samsung klima servisi
ataşehir samsung klima servisi
beykoz beko klima servisi
Good content. You write beautiful things.
vbet
sportsbet
vbet
taksi
hacklink
mrbahis
mrbahis
sportsbet
hacklink
dijital kartvizit
referans kimliği nedir
binance referans kodu
referans kimliği nedir
bitcoin nasıl alınır
resimli magnet
PK3D
hatay
kars
mardin
samsun
urfa
RBDSCN
https://saglamproxy.com
metin2 proxy
proxy satın al
knight online proxy
mobil proxy satın al
2QK4M3
rv
شركة تسليك مجاري بالدمام NQaGJQrJI1
Post a Comment