Class: Retrograph::Easy::App

Inherits:
Object
  • Object
show all
Defined in:
lib/retrograph/easy/app.rb,
lib/retrograph/easy/logo.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(display) ⇒ App

Returns a new instance of App.



40
41
42
43
44
45
46
47
48
# File 'lib/retrograph/easy/app.rb', line 40

def initialize(display)
  @_retrograph_held_event = nil
  @_retrograph_display = display
  @_retrograph_sprite_manager = SpriteManager.new(display)
  @_retrograph_controller_manager = ControllerManager.new
  @_retrograph_controllers =
    @_retrograph_controller_manager.controllers.freeze
  @_retrograph_periodic_manager = PeriodicManager.new
end

Instance Attribute Details

#_retrograph_controllersObject (readonly) Also known as: controllers

Returns the value of attribute _retrograph_controllers.



50
51
52
# File 'lib/retrograph/easy/app.rb', line 50

def _retrograph_controllers
  @_retrograph_controllers
end

Instance Method Details

#already?(label) ⇒ Boolean

Returns:

  • (Boolean)


77
78
79
# File 'lib/retrograph/easy/app.rb', line 77

def already?(label)
  @_retrograph_periodic_manager.already? label
end

#clear_spritesObject



81
82
83
84
# File 'lib/retrograph/easy/app.rb', line 81

def clear_sprites
  @_retrograph_sprite_manager.clear_sprites
  self
end

#each_frame(n_frames = nil) ⇒ Object



202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
# File 'lib/retrograph/easy/app.rb', line 202

def each_frame(n_frames=nil)
  count = 0
  @_retrograph_display.each_frame do
    break if n_frames == count
    while event = (@_retrograph_held_event || SDL::Event2.poll)
      @_retrograph_held_event = nil
      case event
      when SDL::Event2::Quit
        quit
      when SDL::Event2::Active
        if not event.gain and event.state == 2
          _suspend
          next
        end
      when SDL::Event2::KeyDown
        @_retrograph_controller_manager.key_pressed(event.sym)
        if (event.mod & SDL::Key::MOD_ALT).nonzero?
          case event.sym
          when SDL::Key::RETURN
            @_retrograph_display.toggle_fullscreen
          when SDL::Key::F4
            quit
          when SDL::Key::TAB
            if @_retrograph_display.managed and @_retrograph_display.fullscreen
              @_retrograph_display.minimize
            end
          end
        end
        case event.sym
        when SDL::Key::ESCAPE
          quit
        when SDL::Key::F11
          @_retrograph_display.toggle_fullscreen
        end
      when SDL::Event2::KeyUp
        @_retrograph_controller_manager.key_released(event.sym)
      end
    end
    yield
    @_retrograph_periodic_manager.tick()
    count += 1 if n_frames
  end
end

#each_of_n_frames(n_frames) ⇒ Object



198
199
200
# File 'lib/retrograph/easy/app.rb', line 198

def each_of_n_frames(n_frames)
  each_frame(n_frames) { yield }
end

#frame_for?(label) ⇒ Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/retrograph/easy/app.rb', line 69

def frame_for?(label)
  @_retrograph_periodic_manager.frame_for? label
end

#multi_sprite(x, y, pattern, width_tiles, height_tiles, flags) ⇒ Object



90
91
92
# File 'lib/retrograph/easy/app.rb', line 90

def multi_sprite(x, y, pattern, width_tiles, height_tiles, flags)
  @_retrograph_sprite_manager.add_multi_sprite(x, y, pattern, width_tiles, height_tiles, flags)
end

#palette_entry(index, entry) ⇒ Object



112
113
114
# File 'lib/retrograph/easy/app.rb', line 112

def palette_entry(index, entry)
  @_retrograph_display.write_vdu_byte(0x7f00+index, entry)
end

#palette_entry_rgb(index, r, g, b) ⇒ Object

Raises:

  • (RangeError)


100
101
102
103
104
105
106
107
108
109
110
# File 'lib/retrograph/easy/app.rb', line 100

def palette_entry_rgb(index, r, g, b)
  r = (r * 255).round if Float === r
  g = (g * 255).round if Float === g
  b = (b * 255).round if Float === b
  raise RangeError, "index out of range" if index < 0 or index > 31
  entry = ((r >> 2) & 0x30) |
          ((g >> 4) & 0x0c) |
          ((b >> 6) & 0x03)
  palette_entry(index, entry)
  self
end

#phase_of(label) ⇒ Object



73
74
75
# File 'lib/retrograph/easy/app.rb', line 73

def phase_of(label)
  @_retrograph_periodic_manager.phase_of label
end

#quitObject

Raises:



166
167
168
# File 'lib/retrograph/easy/app.rb', line 166

def quit
  raise Quit
end

#reset_vduObject



116
117
118
119
# File 'lib/retrograph/easy/app.rb', line 116

def reset_vdu
  write_vdu(0x0000, "\000" * 0x4000)
  self
end

#show_retrograph_logoObject



280
281
282
283
# File 'lib/retrograph/easy/logo.rb', line 280

def 
  Logo.new(self).show
  self
end

#sprite(x, y, pattern, flags) ⇒ Object



86
87
88
# File 'lib/retrograph/easy/app.rb', line 86

def sprite(x, y, pattern, flags)
  @_retrograph_sprite_manager.add_sprite(x, y, pattern, flags)
end

#sprite_group(x, y, width, height, flags) ⇒ Object



94
95
96
97
98
# File 'lib/retrograph/easy/app.rb', line 94

def sprite_group(x, y, width, height, flags)
  @_retrograph_sprite_manager.add_sprite_group(x, y, width, height, flags) do
    yield
  end
end

#sprite_pattern(base, index, data) ⇒ Object



156
157
158
159
# File 'lib/retrograph/easy/app.rb', line 156

def sprite_pattern(base, index, data)
  tile_pattern_4bit(base + 0x2000, index, data)
  self
end

#start(label, interval, phases = 1) ⇒ Object



59
60
61
62
# File 'lib/retrograph/easy/app.rb', line 59

def start(label, interval, phases=1)
  @_retrograph_periodic_manager.start label, interval, phases
  nil
end

#stop(label) ⇒ Object



64
65
66
67
# File 'lib/retrograph/easy/app.rb', line 64

def stop(label)
  @_retrograph_periodic_manager.stop label
  nil
end

#tile_pattern_1bit(base, index, data) ⇒ Object



141
142
143
144
# File 'lib/retrograph/easy/app.rb', line 141

def tile_pattern_1bit(base, index, data)
  @_retrograph_display.write_vdu(base + index * 8, data)
  self
end

#tile_pattern_2bit(base, index, data) ⇒ Object



146
147
148
149
# File 'lib/retrograph/easy/app.rb', line 146

def tile_pattern_2bit(base, index, data)
  @_retrograph_display.write_vdu(base + index * 16, data)
  self
end

#tile_pattern_4bit(base, index, data) ⇒ Object



151
152
153
154
# File 'lib/retrograph/easy/app.rb', line 151

def tile_pattern_4bit(base, index, data)
  @_retrograph_display.write_vdu(base + index * 32, data)
  self
end

#title(new_title) ⇒ Object



54
55
56
57
# File 'lib/retrograph/easy/app.rb', line 54

def title(new_title)
  @_retrograph_display.title = new_title
  self
end

#vdu_mode(mode) ⇒ Object



121
122
123
124
# File 'lib/retrograph/easy/app.rb', line 121

def vdu_mode(mode)
  write_vdu_byte(0x7ff8, mode)
  self
end

#wait_scanlines(count) ⇒ Object



161
162
163
164
# File 'lib/retrograph/easy/app.rb', line 161

def wait_scanlines(count)
  @_retrograph_display.wait_scanlines(count)
  self
end

#write_vdu(offset, data) ⇒ Object



126
127
128
129
# File 'lib/retrograph/easy/app.rb', line 126

def write_vdu(offset, data)
  @_retrograph_display.write_vdu(offset, data)
  self
end

#write_vdu_2d(offset, stride, data) ⇒ Object



136
137
138
139
# File 'lib/retrograph/easy/app.rb', line 136

def write_vdu_2d(offset, stride, data)
  @_retrograph_display.write_vdu_2d(offset, stride, data)
  self
end

#write_vdu_byte(offset, byte) ⇒ Object



131
132
133
134
# File 'lib/retrograph/easy/app.rb', line 131

def write_vdu_byte(offset, byte)
  @_retrograph_display.write_vdu_byte(offset, byte)
  self
end