-
-
Save eljojo/046b0d0f20d9c2866723 to your computer and use it in GitHub Desktop.
first attempt to build a twitch-plays-pokemon. http://ajipirijou.com/talks/how-i-built-my-own-tpp-part-1/
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 requires JRuby and Sinatra | |
# For more information, visit http://ajipirijou.com/talks/how-i-built-my-own-tpp-part-1/ | |
# For a video of the system working, visit: https://www.youtube.com/watch?v=RHFCe3lwlqI | |
require 'sinatra' | |
set :bind, '0.0.0.0' | |
mappings = { | |
"a" => java.awt.event::KeyEvent::VK_Z, | |
"b" => java.awt.event::KeyEvent::VK_X, | |
"up" => java.awt.event::KeyEvent::VK_UP, | |
"down" => java.awt.event::KeyEvent::VK_DOWN, | |
"left" => java.awt.event::KeyEvent::VK_LEFT, | |
"right" => java.awt.event::KeyEvent::VK_RIGHT, | |
"start" => java.awt.event::KeyEvent::VK_ENTER, | |
"select" => java.awt.event::KeyEvent::VK_BACK_SPACE, | |
"l" => java.awt.event::KeyEvent::VK_A, | |
"r" => java.awt.event::KeyEvent::VK_S | |
} | |
robot = java.awt.Robot.new | |
get '/:key' do |key| | |
key_code = mappings[key.downcase] | |
if key_code | |
robot.keyPress(key_code) | |
robot.delay(100) | |
robot.keyRelease(key_code) | |
end | |
redirect '/' | |
end | |
get '/' do | |
res = [] | |
mappings.each do |key, _| | |
res << %Q{<a href="/#{key}">#{key.upcase}</a></br>} | |
end | |
<<-eos | |
<html> | |
<head> | |
<title>JPP</title> | |
<meta name = "viewport" content = "width = 320, | |
initial-scale = 1, user-scalable = no"> | |
<style>a { font-size: 30px; }</style> | |
</head> | |
<body> | |
#{res.join} | |
<h1>JRUBY-PLAYS-POKEMON</h1> | |
</body> | |
</html> | |
eos | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Osom!