Skip to content

Instantly share code, notes, and snippets.

class World
attr_reader :grid, :width, :height
def initialize(window)
@width = 20
@height = 20
@grid = Array.new(width,[])
@grid = @grid.map {Array.new(height,0)}
@target_sprite = Gosu::Image.new(window, "target.bmp", true)
def backtrack_through_closed
final_path = []
next_position = @closed_list.select{|x| x[2] == @finish}[0][2]
final_path.unshift(next_position)
while next_position != @start
next_position = @closed_list.select{|x| x[2] == next_position}[0][3]
final_path.unshift(next_position)
end
end
def button_down(id)
case id
when Gosu::MsLeft
if (0 < mouse_x && mouse_x < 480 && 0 < mouse_y && mouse_y < 480)
@player.reposition(mouse_x, mouse_y)
end
end
def reposition(x, y)
@x = (x/24).floor
class World < Chingu::GameObject
attr_reader :grid, :width, :height, :walls
def initialize(options)
super
@width = 20
@height = 20
@grid = Array.new(width,[])
@grid = @grid.map {Array.new(height,0)}
require 'nokogiri'
#@url = "http://ws.spotify.com/lookup/1/?uri=spotify:track:6NmXV4o6bmp704aPGyTVVG"
@url = "http://www.google.com/"
@doc = Nokogiri::HTML(open(@url))
class Spotify
include Cinch::Plugin
listen_to :message
def listen(m)
url_regex = /(?<http>http\:\/\/)?open.spotify.com\/(?<tag>track|album|artist)\/(?<id>[a-zA-Z0-9]{22})/
match = url_regex.match(m.message)
if match
parse(match[:tag],match[:id],m)
end
<?xml version='1.0' encoding='UTF-8'?><entry xmlns='http://www.w3.org/2005/Atom' xmlns:media='http://search.yahoo.com/mrss/' xmlns:gd='http://schemas.google.com/g/2005' xmlns:yt='http://gdata.youtube.com/schemas/2007' gd:etag='W/&quot;AkcFR347eCp7I2A9WhVXFU8.&quot;'><id>tag:youtube.com,2008:video:QH2-TGUlwu4</id><published>2011-04-06T03:21:59.000Z</published><updated>2012-04-15T22:13:36.000Z</updated><category scheme='http://schemas.google.com/g/2005#kind' term='http://gdata.youtube.com/schemas/2007#video'/><category scheme='http://gdata.youtube.com/schemas/2007/categories.cat' term='Comedy' label='Comedy'/><category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='cat'/><category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='flying through space'/><category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='annoying'/><category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='amazing'/><category scheme='http://gdata.youtube.com/schemas/2007
<?xml version='1.0' encoding='UTF-8'?>
<entry xmlns='http://www.w3.org/2005/Atom' xmlns:media='http://search.yahoo.com/mrss/' xmlns:gd='http://schemas.google.com/g/2005' xmlns:yt='http://gdata.youtube.com/schemas/2007' gd:etag='W/&quot;AkcFR347eCp7I2A9WhVXFU8.&quot;'>
<id>tag:youtube.com,2008:video:QH2-TGUlwu4</id>
<published>2011-04-06T03:21:59.000Z</published>
<updated>2012-04-15T22:13:36.000Z</updated>
<category scheme='http://schemas.google.com/g/2005#kind' term='http://gdata.youtube.com/schemas/2007#video'/>
<category scheme='http://gdata.youtube.com/schemas/2007/categories.cat' term='Comedy' label='Comedy'/>
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='cat'/>
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='flying through space'/>
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='annoying'/>
class FSMBuild
state_machine :initial => :wait do
event :walk do
transition :wait => :walking
end
event :stop do
transition :walking => :wait
class FSMBuild
state_machine :initial => :searching_mat do
event :path_found do
transition :searching_mat => :walking_mat, :searching_buildspot => :walking_buildspot
end
event :path_not_found do
transition :searching_mat => same, :searching_buildspot => same