Class: R2D::Window

Inherits:
Object
  • Object
show all
Defined in:
lib/r2d/window.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Window

Returns a new instance of Window.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/r2d/window.rb', line 9

def initialize(options = {})
  options = options.merge({w: 640, h: 480, title: "R2D", bg: nil, cursor: true, fs: false})
  @w, @h, @title, @bg, @cursor, @fs, =
    options[:w], options[:h], options[:title], options[:bg], options[:cursor], options[:fs]
  
  @objects = []
  @on_keys = {}
  @keys_down = {}
  @update_proc = Proc.new {}
  
  Adapters.create(self, :gosu)
  
  @@current = self
end

Instance Attribute Details

#bgObject

Returns the value of attribute bg.



6
7
8
# File 'lib/r2d/window.rb', line 6

def bg
  @bg
end

#cursorObject

Returns the value of attribute cursor.



6
7
8
# File 'lib/r2d/window.rb', line 6

def cursor
  @cursor
end

#fsObject

Returns the value of attribute fs.



6
7
8
# File 'lib/r2d/window.rb', line 6

def fs
  @fs
end

#hObject

Returns the value of attribute h.



6
7
8
# File 'lib/r2d/window.rb', line 6

def h
  @h
end

#keys_downObject (readonly)

Returns the value of attribute keys_down.



7
8
9
# File 'lib/r2d/window.rb', line 7

def keys_down
  @keys_down
end

#objectsObject (readonly)

Returns the value of attribute objects.



7
8
9
# File 'lib/r2d/window.rb', line 7

def objects
  @objects
end

#on_keysObject (readonly)

Returns the value of attribute on_keys.



7
8
9
# File 'lib/r2d/window.rb', line 7

def on_keys
  @on_keys
end

#titleObject

Returns the value of attribute title.



6
7
8
# File 'lib/r2d/window.rb', line 6

def title
  @title
end

#update_procObject (readonly)

Returns the value of attribute update_proc.



7
8
9
# File 'lib/r2d/window.rb', line 7

def update_proc
  @update_proc
end

#wObject

Returns the value of attribute w.



6
7
8
# File 'lib/r2d/window.rb', line 6

def w
  @w
end

Class Method Details

.add(o) ⇒ Object



24
25
26
# File 'lib/r2d/window.rb', line 24

def self.add(o)
  @@current.add(o)
end

.remove(o) ⇒ Object



28
29
30
# File 'lib/r2d/window.rb', line 28

def self.remove(o)
  @@current.remove(o)
end

Instance Method Details

#add(o) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/r2d/window.rb', line 32

def add(o)
  if !@objects.include?(o)
    @objects.push(o)
    true
  else
    false
  end
end

#add_key_down(key, proc) ⇒ Object



64
65
66
67
# File 'lib/r2d/window.rb', line 64

def add_key_down(key, proc)
  @keys_down[Adapters.key_lookup(key)] = proc
  true
end

#add_on_key(key, proc) ⇒ Object



54
55
56
57
# File 'lib/r2d/window.rb', line 54

def add_on_key(key, proc)
  @on_keys[Adapters.key_lookup(key)] = proc
  true
end

#clearObject



50
51
52
# File 'lib/r2d/window.rb', line 50

def clear
  @objects.clear
end

#key_down?(key) ⇒ Boolean

Returns:

  • (Boolean)


59
60
61
62
# File 'lib/r2d/window.rb', line 59

def key_down?(key)
  button_down?(Adapters.key_lookup(key))
  true
end

#mouse_xObject



79
80
81
# File 'lib/r2d/window.rb', line 79

def mouse_x
  Adapters.mouse_x
end

#mouse_yObject



83
84
85
# File 'lib/r2d/window.rb', line 83

def mouse_y
  Adapters.mouse_y
end

#on_key(key, block) ⇒ Object



74
75
76
77
# File 'lib/r2d/window.rb', line 74

def on_key(key, block)
  add_on_key(key, block)
  true
end

#remove(o) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/r2d/window.rb', line 41

def remove(o)
  if i = @objects.index(o)
    @objects.slice!(i)
    true
  else
    false
  end
end

#showObject



87
88
89
# File 'lib/r2d/window.rb', line 87

def show
  Adapters.show
end

#update(block) ⇒ Object



69
70
71
72
# File 'lib/r2d/window.rb', line 69

def update(block)
  @update_proc = block
  true
end