Skip to content

Instantly share code, notes, and snippets.

@devyn
Created May 22, 2009 03:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save devyn/115905 to your computer and use it in GitHub Desktop.
Save devyn/115905 to your computer and use it in GitHub Desktop.
class ARF
attr :coords
def initialize map, follow, size, app
@map, @follow, @size, @app, @coords = (map.is_a?(Array) ? map : [map]), follow, size, app, [follow.left,follow.top]
@vx, @vy = 0,0 # velocity
animate_loop
end
def [](x,y)
@coords[0] += x
@coords[1] += y
@follow.move *@coords
@coords
end
def animate_loop
map, follow, size = @map, @follow, @size
sc = method :[]
gc = method :coords
si = method :instance_variable_set
gi = method :instance_variable_get
@app.instance_eval do
animate 12 do
si['@vx',gi['@vx']-1] if gc[][0] > size[0]*0.7
si['@vx',gi['@vx']+1] if gc[][0] < size[0]*0.3
si['@vy',gi['@vy']-1] if gc[][1] > size[1]*0.7
si['@vy',gi['@vy']+1] if gc[][1] < size[1]*0.3
end
animate do
map.each {|o| o.move(o.left+gi['@vx'],o.top+gi['@vy']) }
sc[gi['@vx'],gi['@vy']]
end
animate 6 do
si['@vx',gi['@vx']-(gi['@vx']<=>0)]
si['@vy',gi['@vy']-(gi['@vy']<=>0)]
end
end
end
end
require 'camera'
Shoes.app(:width=>320,:height=>240) {
@co = ARF.new(image(1024,768){fill red..blue, :angle => 45; rect 0,0,1023,767},image(24,24){fill lime; rect 0,0,23,23},[320,240],self)
animate do
b,x,y = self.mouse
next unless b == 1
@co[-5,0] if x < 320*0.7
@co[+5,0] if x > 320*0.3
@co[0,-5] if y < 240*0.7
@co[0,+5] if y > 240*0.3
end
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment