Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion bin/roflbalt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,26 @@

require "roflbalt"

Game.new.run

# JRuby doesn't play nice with STDIN.read_nonblock right now
# see http://jira.codehaus.org/browse/JRUBY-5165
# So for now, lets have a Control Panel for our jumping man!
if RUBY_PLATFORM == "java"
if RUBY_VERSION == '1.8.7'
STDERR.puts <<WARNING
WARNING: Your helo ain't going to look right in JRUBY and 1.8 mode.
Try setting JRUBY_OPTS before your next rofl copter chase:
export JRUBY_OPTS==--1.9

Press enter to continue, or CTRL+C to quit
WARNING
end
STDIN.gets

jruby_game_lib = File.expand_path("../lib", File.dirname(__FILE__)) + '/jruby_game.rb'
puts "JRuby detected - loading #{ jruby_game_lib }"
require jruby_game_lib
JRubyGame.new.run
else
Game.new.run
end
47 changes: 47 additions & 0 deletions lib/jruby_game.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
require 'java'

import javax.swing.JFrame
import javax.swing.JLabel
import java.awt.event.KeyListener
import java.awt.Dimension

CONTROL_WIDTH = 400
CONTROL_HEIGHT = 400

class JRubyGame < Game
def initialize
setup_frame
super
end

def setup_frame
@frame = JFrame.new("ROFL Control")
@frame.default_close_operation = JFrame::EXIT_ON_CLOSE
jlabel = JLabel.new("'q' to Quit, 'n' for New, 'Any Key' for jump!")
@frame.add jlabel
@frame.pack
@frame.set_size( Dimension.new( CONTROL_WIDTH, CONTROL_HEIGHT ) )
# Listen for keystrokes, play notes
@frame.add_key_listener KeyListener.impl { |name, event|
case name
when :keyPressed
@world.player.jump
if event.key_char == 113 # q
@frame.visible = false
@frame.dispose
@run = false
elsif event.key_char == 110 # n
reset
end
when :keyReleased
end
}
@frame.visible = true
end
def on_exit
@frame.visible = false
@frame.dispose
super
end
end

3 changes: 3 additions & 0 deletions lib/roflbalt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
SCREEN_HEIGHT = 40

class Game
attr_accessor :run, :world
def initialize
reset
end
Expand Down Expand Up @@ -475,3 +476,5 @@ def char rx, ry, ticks
" " # Roflcopter crashes from time to time..
end
end


3 changes: 2 additions & 1 deletion roflbalt.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ Gem::Specification.new do |gem|
gem.description = %q{ASCII side-scrolling game, with ANSI color!}
gem.summary = %q{Canabalt-inspired ASCII side-scroller for your terminal, with ANSI color!}
gem.homepage = "https://github.com/pda/roflbalt"
gem.platform = 'jruby'

gem.require_paths = %w{ lib }
gem.executables = %w{ roflbalt }
gem.files = %w{ bin/roflbalt lib/roflbalt.rb README.md }
gem.files = %w{ bin/roflbalt lib/roflbalt.rb lib/jruby_game.rb README.md }
gem.name = "roflbalt"
gem.version = "0.0.2"
end