diff --git a/objects/circle.lua b/objects/circle.lua index 68ca672..5ef2405 100644 --- a/objects/circle.lua +++ b/objects/circle.lua @@ -13,25 +13,34 @@ function gen:new(game,x,y,color,grid) Circle:register("Circle") Circle:register(color) Circle.selected = false + Circle.highlight = false + Circle.highlightTimer = game:Timer(0.08) function Circle:step(dt) - if self.color=="neutron" and self:isMyTurn()then - if not self.selected then - self.moves = self:findAvailableMoves() - self.selected = true - end - end self.drawx = self.drawx + (self.rect.x-self.drawx)/10 self.drawy = self.drawy + (self.rect.y-self.drawy)/10 + + if self.highlight then + self.highlightTimer:tick(dt) + if self.highlightTimer.loops > 3 then + self.highlight = false + self.highlightTimer.loops = 0 + end + end end function Circle:isMyTurn() - return self.color=="pink" and self.grid.turn==1 or self.color=="blue" and self.grid.turn==3 or self.color=="neutron" and self.grid.turn%2==0 + return self:getTurn()==self.color + end + + function Circle:getTurn() + local turns = {"neutron","pink","neutron","blue"} + return turns[self.grid.turn+1] end function Circle:draw() local spriteindex = 1 - if self.selected then spriteindex = 2 end + if self.selected or self.highlight and self.highlightTimer.loops%2==0 then spriteindex = 2 end lg.draw(self.sprites[spriteindex],self.drawx-self.game.camerax-self.spriteoffx,self.drawy-self.game.cameray-self.spriteoffy) if self.selected then local i @@ -42,17 +51,25 @@ function gen:new(game,x,y,color,grid) end function Circle:MouseCallback(x,y,presses) - if self.rect:collidepoint(x,y) and self:isMyTurn() then - local c = self.game:findName("Circle") - local i - for i=1,#c do - if c[i]~=self then c[i].selected = false end - end - self.selected = not self.selected - self.depth = 1 - if self.selected then - self.moves = self:findAvailableMoves() - self.depth = 2 + if self.rect:collidepoint(x,y) then + if self:isMyTurn() then + local c = self.game:findName("Circle") + local i + for i=1,#c do + if c[i]~=self then c[i].selected = false end + end + self.selected = not self.selected + self.depth = 1 + if self.selected then + self.moves = self:findAvailableMoves() + self.depth = 2 + end + else + objs = self.game:findName(self:getTurn()) + local i + for i=1,#objs do + objs[i].highlight = true + end end end if self.selected then @@ -112,4 +129,4 @@ function gen:new(game,x,y,color,grid) return Circle end -return gen +return gen