Added blinking when clicking wrong circles

This commit is contained in:
theo@manjaro 2022-03-08 09:40:15 +01:00
parent d1d9fb006a
commit 50d489b598
1 changed files with 37 additions and 20 deletions

View File

@ -13,25 +13,34 @@ function gen:new(game,x,y,color,grid)
Circle:register("Circle") Circle:register("Circle")
Circle:register(color) Circle:register(color)
Circle.selected = false Circle.selected = false
Circle.highlight = false
Circle.highlightTimer = game:Timer(0.08)
function Circle:step(dt) 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.drawx = self.drawx + (self.rect.x-self.drawx)/10
self.drawy = self.drawy + (self.rect.y-self.drawy)/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 end
function Circle:isMyTurn() 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 end
function Circle:draw() function Circle:draw()
local spriteindex = 1 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) lg.draw(self.sprites[spriteindex],self.drawx-self.game.camerax-self.spriteoffx,self.drawy-self.game.cameray-self.spriteoffy)
if self.selected then if self.selected then
local i local i
@ -42,17 +51,25 @@ function gen:new(game,x,y,color,grid)
end end
function Circle:MouseCallback(x,y,presses) function Circle:MouseCallback(x,y,presses)
if self.rect:collidepoint(x,y) and self:isMyTurn() then if self.rect:collidepoint(x,y) then
local c = self.game:findName("Circle") if self:isMyTurn() then
local i local c = self.game:findName("Circle")
for i=1,#c do local i
if c[i]~=self then c[i].selected = false end for i=1,#c do
end if c[i]~=self then c[i].selected = false end
self.selected = not self.selected end
self.depth = 1 self.selected = not self.selected
if self.selected then self.depth = 1
self.moves = self:findAvailableMoves() if self.selected then
self.depth = 2 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
end end
if self.selected then if self.selected then
@ -112,4 +129,4 @@ function gen:new(game,x,y,color,grid)
return Circle return Circle
end end
return gen return gen