2017-10-03 25 views
0

육각형 그리드 기반 게임을 만들려고합니다. 나는 기본적인 것들을 가지고있다. (라이브러리는 네이티브로 그것을 가지지 않았고 또한 그것을 만들어서 각각의 육각형을 다시 칠할 수 있기 때문에 육각형의 이웃을 얻는다.) 그러나 나는 한가지를 할 수 없다.주변 이웃 육각형을 "줄"채우기 모드로 변경

육각형 위로 마우스를 가져 가면 그 주변의 이웃이 행 채우기 모드 (picture example) (내 마우스가 왼쪽 상단 육각형 위에 있다고 가정)으로 변경되지만 '채우기'로 다시 변경하는 방법을 생각할 수 없습니다 '내가 그 위에 떠드는 것을 그만 두었을 때.

여기에 (내가 이웃과 육각형과 거래 유혹하고있어 경우에 체크 핸들) 관련 코드입니다 :

function love.update() 
    mx, my = love.mouse.getPosition() 
    if hexGrid:containingHex(mx, my)~=nil then --am I hovering over a hexagon? 
     local q,r=hexGrid:containingHex(mx, my).q,hexGrid:containingHex(mx, my).r -- get the position on the grid for the hexagon 
     local neighbors=hexGrid:neighbors(q,r) -- get neighbors of hexagon I'm hovering over 
     for dir, neighbor in pairs(neighbors) do -- loop through neighbor table 
      if neighbor ~=nil and hexes.getHexagon(hexGrid:getHex(neighbor.q,neighbor.r))["fill"]=="fill" then -- does neighbor exist and is their fill mode "fill"? 
       local neighborHexagon=hexGrid:getHex(neighbor.q,neighbor.r) -- get the hexagon from the grid 
       local neighborData=hexes.getHexagon(neighborHexagon) -- get it's data from a seperate dictionary (stores color data and fill mode data) 
       neighborData["fill"]="line" -- set fill mode to line 
      end 
     end 
    end 
end 

답변

0

이 당신이이 일에 대해 갈 수있는 몇 가지 방법이 있지만 가장 쉬운 방법 (IMO)는 모든 프레임의 끝에서 이전 타일의 상태를 재설정합니다.

업데이트 된 루프는 다음과 같이 보일 것입니다 : 당신이 내 문제를 잘못 이해하는 경우

-- Reference to the old tile position 
local oldhexagon 

function love.update() 
    mx, my = love.mouse.getPosition() 
    if hexGrid:containingHex(mx, my)~=nil then --am I hovering over a hexagon? 
     -- Check if you were previously over a tile 
     if oldhexagon then 
      -- Set old hexagon's fill mode to line 
     end 

     -- Get rid of the reference for next frame 
     oldhexagon = nil 

     -- etc. 

     oldhexagon = neighborData 
    end 
end 
+0

확실하지. 내가 위에 맴도는 사람은 절대로 바뀌지 않으며 (예 그림에 표시된 것처럼) 단지 이웃입니다. 나는 육각형의 ** 이웃들 **이 위에 떠있는 것을 멈추었을 때 되돌리기를 원합니다. – Ducktor

+0

@Ducktor 따라서, 마우스가 위에 있지 않으면 육각형이 채우기 모드를 갖기를 바란다. 줄이 있어야한다. – DavisDude