Ir para conteúdo
Entre para seguir isso  
Capaverde

rotateAreaToRight(area)

Recommended Posts

Capaverde    1
Capaverde

Funções para girar a área

 

rotateAreaToRight:

function rotateAreaToRight(area)
local width,height = getAreaWidthAndHeight(area)
local newarea = {}
local f = 0
repeat
table.insert(newarea,{})
f = f+1
until f >= height
for tx=1,width do
   for ty=1,height do
   local cx,cy = getAreaCenter(area)
   local delta = {x=tx-cx,y=ty-cy}
   local value = area[ty][tx]
   delta = rotateDelta90graus(delta)
       newarea[delta.y+cy][delta.x+cx] = value
   end
end
return newarea
end

Funções secundárias:

function rotateDelta90graus(delta)
local x = -delta.y
local y = delta.x
return {x=x,y=y}
end

function getAreaWidthAndHeight(area) return table.getn(area[1]),#area end

function rotateAreaToRight(cid, area)
local width,height = getAreaWidthAndHeight(area)
local newarea = {}
local f = 0
repeat
table.insert(newarea,{})
f = f+1
until f >= height
for tx=1,width do
   for ty=1,height do
   local cx,cy = getAreaCenter(area)
   local delta = {x=tx-cx,y=ty-cy}
   local value = area[ty][tx]
   delta = rotateDelta90graus(delta)
       newarea[delta.y+cy][delta.x+cx] = value
   end
end
return newarea
end

function getAreaCenter(area)
local x,y = getAreaWidthAndHeight(area)
for tx=1,x do
   for ty=1,y do
       if area[ty][tx] == 2 or area[ty][tx] == 3 then
       return tx,ty
       end
   end
end
end

function changepos(pos,deltax,deltay,deltaz)
pos.x = pos.x+deltax
pos.y = pos.y+deltay
pos.z = pos.z+deltaz
return pos
end

function changeposbydir(pos, dir, sqms)
local delta = direc[dir+1]
return {x=pos.x+delta[1]*sqms,y=pos.y+delta[2]*sqms,z=pos.z}
end

vc também precisa dessa table

direc = {{0,-1},{1,0},{0,1},{-1,0},{-1,1},{1,1},{-1,-1},{1,-1}}

tenha em mente que, apesar da imensa probabilidade de haverem bugs com a utilização incorreta dessas funções, eu não botei nenhuma debug message pq eu nao quis

Editado por Capaverde
otimização do código

Compartilhar este post


Link para o post
[ B a l i l l o ]    0
[ B a l i l l o ]

Como assim girar a area? o.0

 

E poem ela num script para ter idéia de como usa-la :P

Compartilhar este post


Link para o post
[ B a l i l l o ]    0
[ B a l i l l o ]

Nossa, ja deu para intender intão, essa função então é bem legal :)

 

Bom, nada que não seja facil de corrigir, mas la no teu topic do Hurricane vc precisa por os parametros para ir no spell.xml e talkactions.xml, tem mt noob ainda que não sabe disso :P

 

E poem um link la e um aki para as respectivas seções, se não eles catam a spell e não iram saber de como fazer a função rotate funfar :P

 

Isso acima foi uma sugestão :)

Compartilhar este post


Link para o post
Visitante
Este tópico está impedido de receber novos posts.
Entre para seguir isso  
  • Quem Está Navegando   0 membros estão online

    Nenhum usuário registrado visualizando esta página.

×