Created
March 23, 2012 02:50
-
-
Save awostenberg/2166358 to your computer and use it in GitHub Desktop.
Non-functional translation of the 5th JMonkey Tutorial to JRuby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This file was translated from Java to JRuby (as well as using some of | |
# JRuby's dynamicness to get rid of repetition) from the tutorial at | |
# http://jmonkeyengine.org/wiki/doku.php/jme3:beginner:hello_simpleapplication | |
require 'java' | |
# Import some JMonkey classes from a list | |
%w[ | |
app.SimpleApplication | |
material.Material | |
math.Vector3f | |
scene.Geometry | |
scene.shape.Box | |
math.ColorRGBA | |
input.KeyInput | |
input.MouseInput | |
input.controls.ActionListener | |
input.controls.AnalogListener | |
input.controls.KeyTrigger | |
input.controls.MouseButtonTrigger | |
].each {|jclass| java_import "com.jme3.#{jclass}"} | |
class HelloJME3 < SimpleApplication | |
def initialize | |
@running = true | |
end | |
def simpleInitApp | |
b = Box.new(Vector3f::ZERO, 1, 1, 1) | |
player = Geometry.new("Player", b) | |
mat = Material.new(asset_manager, "Common/MatDefs/Misc/Unshaded.j3md") | |
mat.set_color("Color", ColorRGBA::Blue) | |
player.set_material(mat) | |
root_node.attach_child(player) | |
register_keys | |
end | |
def register_keys | |
input_manager.add_mapping("Pause", KeyTrigger.new(KeyInput::KEY_P)) | |
input_manager.add_mapping("Left", KeyTrigger.new(KeyInput::KEY_J)) | |
input_manager.add_mapping("Right", KeyTrigger.new(KeyInput::KEY_K)) | |
input_manager.add_mapping("Rotate", KeyTrigger.new(KeyInput::KEY_SPACE), | |
MouseButtonTrigger.new(MouseInput::BUTTON_LEFT)) | |
l = lambda { |name, pressed, tpf| puts "Something happened" if name == 'Pause' && !pressed } | |
input_manager.add_listener(l, ['Left', 'Right', 'Rotate']) | |
end | |
def simpleUpdate(*args) | |
#puts @running | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for sharing! It'd be interesting too see the other tutorials if you got them translated too, thank you!