Class: Ronela::Personaje

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(nombre, color) ⇒ Personaje

Returns a new instance of Personaje.



335
336
337
338
339
340
341
342
343
344
345
346
347
348
# File 'lib/ronela.rb', line 335

def initialize(nombre, color)
  @nombre = nombre
  
  if color.nil? or color.empty?
    @color = Color::html_a_sdl("f00")
  else
    @color = Color::html_a_sdl(color)
  end
  
  
  @fuente_msg = SDL::TTF.open("default.ttf", $config[:FUENTE_TAMANO_MSG], 0)
  @fuente_nombre = SDL::TTF.open("default.ttf", $config[:FUENTE_TAMANO_NOMBRE], 0)
  #lo que se escribio
end

Instance Attribute Details

#fondoObject

Returns the value of attribute fondo.



333
334
335
# File 'lib/ronela.rb', line 333

def fondo
  @fondo
end

Instance Method Details

#cargar_variables(variables) ⇒ Object

cargar desde RonelaLenguaje



426
427
# File 'lib/ronela.rb', line 426

def cargar_variables(variables)
end

#dice(en, que, limpiar_con = nil) ⇒ Object

personaje dice que en donde



401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
# File 'lib/ronela.rb', line 401

def dice en, que, limpiar_con=nil
  lancho, lalto = @fuente_nombre.text_size(".")
  x = $config[:DESPLAZA_X_PERSONAJE]
  
  y = ($config[:PANTALLA_ALTO] / 2) + $config[:DESPLAZA_Y_PERSONAJE] #100 a ojo
  yn = ($config[:PANTALLA_ALTO] / 2) + $config[:DESPLAZA_Y_PERSONAJE] - lalto
  ancho = $config[:PANTALLA_ANCHO] - x
  alto = $config[:PANTALLA_ALTO] - y

  lr = [0, yn, $config[:PANTALLA_ANCHO], $config[:PANTALLA_ALTO] / 2]
  limpiar_con.dibujar $pantalla, lr ,lr unless limpiar_con.nil?
  #limpiar_con.dibujar $pantalla unless limpiar_con.nil?


   en, x, yn      
  txt en, @nombre, [x, yn], @fuente_nombre
  txt en, que, [x,y],  @fuente_msg
  
  #actualize cuadro donde se escribio
  $pantalla.updateRect(0, yn , $config[:PANTALLA_ANCHO], $config[:PANTALLA_ALTO]  - yn )

end

#gui_dialogo(en, x, y) ⇒ Object

pinta donde dice el personaje le pone bonito



386
387
388
389
390
391
392
393
394
395
396
397
398
# File 'lib/ronela.rb', line 386

def (en, x, y)
  ancho =  $config[:PANTALLA_ANCHO] - x
  alto = $config[:PANTALLA_ALTO] - y 

  gui = SDL::Surface.new(SDL::HWSURFACE, ancho, alto, $pantalla.format)

  gui.fillRect(5, 5, ancho-5, alto-5, gui.mapRGB(*@color))
  gui.setAlpha(SDL::RLEACCEL|SDL::SRCALPHA, 15)

  SDL::Surface.blit(gui,0,0, ancho, alto, en, x, y)
  gui.destroy
   
end

#txt(en, que, pos, fuente) ⇒ Object

escribe mensaje y cambia de linea cuando llena al extremo de la ventana



352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
# File 'lib/ronela.rb', line 352

def txt en, que, pos, fuente
  r,g,b = @color
  x, y = pos
  xi, yi = x, y
  ancho_letra, alto_letra = fuente.text_size(" ")
  ancho_total = 0
  alto_total = 0
  ultimo_ancho = 0
  que_parte = que.split
  
  for palabra in que_parte
    ancho, alto = fuente.text_size(palabra)
    
    ancho_total += ancho + ancho_letra
    
    if ancho_total >= $config[:PANTALLA_ANCHO] - ancho
      ultimo_ancho = $config[:PANTALLA_ANCHO]
      ancho_total = 0

      #@todo posible bicho, cuando se crezca orizontal
      y += alto_letra if y+alto_letra < $config[:PANTALLA_ALTO]
      alto_total = y
      x = xi
      fuente.drawSolidUTF8(en, palabra, x, y, r, g, b)
    else
      fuente.drawSolidUTF8(en, palabra, x, y, r, g, b)
    end
    x += ancho + ancho_letra
  end
  
end