Class: Ronela::Imagen

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

Direct Known Subclasses

ImagenColor

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(archivo, tipo = :imagen) ⇒ Imagen

attr_accessor :mostrando #se esta mostrano?



203
204
205
206
207
208
209
210
211
# File 'lib/ronela.rb', line 203

def initialize(archivo, tipo=:imagen)
  @imagen = SDL::Surface.load(archivo)
  @fondo = nil
  @posicion = nil
  @x = 0
  @y = 0
  @mostrando = false
  @tipo = tipo
end

Instance Attribute Details

#fondoObject

Returns the value of attribute fondo.



197
198
199
# File 'lib/ronela.rb', line 197

def fondo
  @fondo
end

#imagenObject (readonly)

Returns the value of attribute imagen.



200
201
202
# File 'lib/ronela.rb', line 200

def imagen
  @imagen
end

#mostrandoObject (readonly)

Returns the value of attribute mostrando.



200
201
202
# File 'lib/ronela.rb', line 200

def mostrando
  @mostrando
end

#posicion=(value) ⇒ Object (writeonly)

Sets the attribute posicion

Parameters:

  • value

    the value to set the attribute posicion to.



199
200
201
# File 'lib/ronela.rb', line 199

def posicion=(value)
  @posicion = value
end

#tipoObject (readonly)

Returns the value of attribute tipo.



200
201
202
# File 'lib/ronela.rb', line 200

def tipo
  @tipo
end

#xObject

Returns the value of attribute x.



198
199
200
# File 'lib/ronela.rb', line 198

def x
  @x
end

#yObject

Returns the value of attribute y.



198
199
200
# File 'lib/ronela.rb', line 198

def y
  @y
end

Instance Method Details

#cargar_variables(variables) ⇒ Object

Lee variables desde RonelaLenguaje Variables para imagen

  • posicion centro|izquierda|derecha|arriba|abajo

  • opacidad 0..255



292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
# File 'lib/ronela.rb', line 292

def cargar_variables(variables)
  
  if variables.has_key? "posicion"
    @posicion = variables["posicion"] 
  else
    @posicion = "centro"
  end
  
  #@todo no funciona el alpha
  if variables.has_key? "opacidad"
    opacidad = variables["opacidad"].to_i
    Kernel.puts "Opacidad #{opacidad}"
    @imagen.setAlpha(SDL::SRCALPHA,  opacidad)
  end
end

#dibujar(en, rect = nil, srect = nil) ⇒ Object

dibuja la imagen en



241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
# File 'lib/ronela.rb', line 241

def dibujar en, rect=nil, srect=nil
  #si se vuelve a mostrar se borra donde estaba
  #esto permite que solo exista una sola imagen presentada en pantalla referencida por Imagen
  if @mostrando and @tipo != :escena
    limpiar_de_antes en
  end

  @mostrando = true  
  @x,@y = posicion_a_xy
  x,y = @x,@y
  xs, ys = 0,0
  xs, ys = srect unless srect.nil?

  unless rect.nil?
    SDL::Surface.blit(@imagen, xs,ys, rect[2], rect[3], en, rect[0], rect[1])
    $pantalla.updateRect(rect[0], rect[1], rect[2], rect[3])
  else      

    SDL::Surface.blit(@imagen, xs, ys, @imagen.w, @imagen.h, en, x, y)
    $pantalla.updateRect(x, y, @imagen.w, @imagen.h)
  end

end

#es_escenaObject



213
214
215
# File 'lib/ronela.rb', line 213

def es_escena
  @tipo = :escena
end

#es_imagenObject



217
218
219
# File 'lib/ronela.rb', line 217

def es_imagen
  @tipo = :imagen
end

#limpiar(en) ⇒ Object



230
231
232
233
234
235
236
237
# File 'lib/ronela.rb', line 230

def limpiar en
  x,y = posicion_a_xy
  unless @fondo.nil?
    @fondo.dibujar en, [x, y, @imagen.w, @imagen.h], [x, y, @imagen.w, @imagen.h]
    $pantalla.updateRect(x, y, @imagen.w, @imagen.h)
  end
  @mostrando = false
end

#limpiar_de_antes(en) ⇒ Object

borra en la posicion actual



222
223
224
225
226
227
# File 'lib/ronela.rb', line 222

def limpiar_de_antes en
  unless @fondo.nil?
    SDL::Surface.blit(@fondo.imagen, @x, @y, @imagen.w, @imagen.h, en, @x, @y)
    $pantalla.updateRect(x, y, @imagen.w, @imagen.h)
  end
end

#posicion_a_xyObject

convierte posicion palabra a arreglo



267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
# File 'lib/ronela.rb', line 267

def posicion_a_xy
  if @posicion.nil?
    return [0,0]
  end
  
  case @posicion
  when 'abajo'
    [$config[:PANTALLA_ANCHO] / 2 - @imagen.h / 2, $config[:PANTALLA_ALTO] - @imagen.h]      
  when 'arriba'
    [$config[:PANTALLA_ANCHO] / 2 - @imagen.h / 2, 0]
  when 'derecha'
    [$config[:PANTALLA_ANCHO] - @imagen.h, $config[:PANTALLA_ALTO] / 2 - @imagen.h / 2]
  when 'izquierda'
    [0, $config[:PANTALLA_ALTO] / 2 - @imagen.h / 2]
  when 'centro'
    [$config[:PANTALLA_ANCHO] / 2 - @imagen.w / 2, $config[:PANTALLA_ALTO] / 2 - @imagen.h  / 2]
  else
    [$config[:PANTALLA_ANCHO] / 2 - @imagen.w / 2, $config[:PANTALLA_ALTO] / 2 - @imagen.h  / 2]
  end
end