Advertisement
xerpi

Untitled

Apr 10th, 2011
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.31 KB | None | 0 0
  1. -------------------------------------- LIB RINGMENU v1 by CHIMECHO (c) -------------------------------------
  2. -- Copylefts bla bla bla
  3. -- Rollazo del autor
  4. -- y.. prohibidio usarlo en el psp génesis! ¬¬'
  5.  
  6. function order(tbl)
  7.     local ordr = {} -- zm, pos, esto va a ordernar segun el zoom, las mas chicas primero, las mas grandes despues...
  8.     for i=1,#tbl do
  9.         table.insert(ordr,{zm=tbl[i].zoom,pos=i})
  10.     end
  11.     table.sort(ordr,function (a,b) return a.zm < b.zm end)
  12.     return ordr
  13. end
  14.  
  15. function rotate(opt, des) -- opciones, desfase de la primera imagen
  16.     local ang_act = des
  17.     for i=1,#opt do
  18.         opt[i].ang = ang_act
  19.         opt[i].x = math.cos(math.rad(opt[i].ang)) * opt.w/2
  20.         opt[i].y = math.sin(math.rad(opt[i].ang)) * opt.h/2 -- los mas chiquitos, arriba
  21.         opt[i].zoom = (1 + math.sin(math.rad(opt[i].ang)) * 0.2)
  22.         opt[i].w = screen.textwidth(opciones[i].text,opciones[i].size) * opt[i].zoom
  23.         opt[i].h = 15 * opt[i].zoom
  24.         ang_act = ang_act - opt.ang
  25.     end
  26.     opt.orden = order(opt)
  27. end
  28.  
  29. ringmenu = {}
  30.  
  31. function ringmenu.blit(obj,desfx,desfy)
  32.     if not desfx then desfx = 0 end
  33.     if not desfy then desfy = 0 end
  34.     if controls.press("right") then obj.dir = "right" end
  35.     if controls.press("left") then obj.dir = "left" end
  36.     if controls.up() then obj.desy=math.max(obj.desy-0.1,-1) end
  37.     if controls.down() then obj.desy=math.min(obj.desy+0.1,1) end
  38.    
  39.     if obj.dir=="right" then
  40.         obj.angulo = obj.angulo + (obj.ang/10) -- que la anim siempre dure 10 frames
  41.         obj.anganillo = obj.anganillo + (obj.ang/10)
  42.         rotate(obj, obj.anganillo)
  43.         if obj.angulo>=obj.ang then -- solo hasta el siguiente elemento
  44.             obj.dir="stop"
  45.             obj.angulo = 0
  46.         end
  47.     elseif obj.dir=="left" then
  48.         obj.angulo = obj.angulo - (obj.ang/10)
  49.         obj.anganillo = obj.anganillo - (obj.ang/10)
  50.         rotate(obj, obj.anganillo)
  51.         if obj.angulo<=-obj.ang then
  52.             obj.dir="stop"
  53.             obj.angulo = 0
  54.         end
  55.     end
  56.    
  57.     for j=1,#obj do
  58.         i=obj.orden[j].pos
  59.         screen.print(desfx + 240 + obj[i].x - (obj[i].w/2), desfy + 136 + (obj[i].y * obj.desy) - (obj[i].h/2),opciones[i].text,opciones[i].size*(obj[i].zoom)*1.2,opciones[i].color,opciones[i].colorfondo) -- centrado y con zoom
  60.     end
  61. end
  62.  
  63. function ringmenu.create(w,h,imgs_tbl) -- ancho del anillo, alto del anillo, imagenes
  64.     local cant_op = #imgs_tbl
  65.     local ang = 180 - (((cant_op - 2)/cant_op)*180) -- angulo entre cada vertice del poligono, fuente: wikipedia
  66.     local ring = {orden = {}, w = w, h = h, ang = ang, anganillo = 90, angulo = 0, dir = "stop", desy = 1, blit = ringmenu.blit}
  67.     for i=1,cant_op do
  68.         ring[i] = {imagen = imgs_tbl[i]}
  69.     end
  70.     rotate(ring, ring.anganillo)
  71.     return ring
  72. end
  73.  
  74. -------------------------------------- HASTA AKI LA LIB -------------------------------------
  75.  
  76.  
  77. --blanco = color.new(255,255,255)
  78. --colores = {color.new(255,0,0),color.new(0,255,0),color.new(0,0,255),color.new(0,255,255),color.new(255,0,255),color.new(255,255,255)}
  79.  
  80. opciones = {
  81. {text = "Jugar",color=color.new(255,0,0),colorfondo=0x0,size=0.85},
  82. {text = "Scores",color=color.new(0,255,0),colorfondo=0x0,size=0.85},
  83. {text = "Créditos",color=color.new(0,0,255),colorfondo=0x0,size=0.85},
  84. {text = "Salir",color=color.new(155,155,0),colorfondo=0x0,size=0.85}
  85. }
  86.  
  87.  
  88. menu = ringmenu.create(320,60,opciones)
  89.  
  90. while true do
  91.     controls.read()
  92.    
  93.     menu:blit()
  94.    
  95.     if controls.press("cross") then Chimecho() end
  96.     screen.flip()
  97. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement