Skip to content

Instantly share code, notes, and snippets.

@ir-norn
Created September 25, 2015 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ir-norn/502e094fe08c6b9ece68 to your computer and use it in GitHub Desktop.
Save ir-norn/502e094fe08c6b9ece68 to your computer and use it in GitHub Desktop.
require "observer"
require "dxruby"
class Observer
include Observable
end
class O
attr_accessor :x , :y , :d , :func
def initialize x , y , d , func
@x = x
@y = y
@d = d
@func = func
end
def update *h
@func.call self
end
end
task = Observer.new
us_task = Observer.new
task.add_observer O.new 200 , 300 , Image.new(50,50,[200,220,170]) , ->o do
o.x += Input.x * 4
o.y += Input.y * 4
Window.draw o.x , o.y , o.d
if Input.keyPush? K_Z
us_task.add_observer O.new o.x , o.y , Image.new(10,5,[200,220,170]) , ->o do
o.y -= 3
if o.y < 0
us_task.delete_observer o
end
Window.draw o.x , o.y , o.d
end
end
end
font = Font.new 20
Window.loop do
exit if Input.keyPush? K_F9
task.changed
task.notify_observers
us_task.changed
us_task.notify_observers
Window.drawFont 50 , 50 , task.count_observers.to_s , font
Window.drawFont 50 , 80 , us_task.count_observers.to_s , font
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment