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

View File

@ -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,7 +51,8 @@ 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
if self.rect:collidepoint(x,y) then
if self:isMyTurn() then
local c = self.game:findName("Circle")
local i
for i=1,#c do
@ -54,6 +64,13 @@ function gen:new(game,x,y,color,grid)
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
local i