Added blinking when clicking wrong circles
This commit is contained in:
parent
d1d9fb006a
commit
50d489b598
@ -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,7 +51,8 @@ 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
|
||||||
|
if self:isMyTurn() then
|
||||||
local c = self.game:findName("Circle")
|
local c = self.game:findName("Circle")
|
||||||
local i
|
local i
|
||||||
for i=1,#c do
|
for i=1,#c do
|
||||||
@ -54,6 +64,13 @@ function gen:new(game,x,y,color,grid)
|
|||||||
self.moves = self:findAvailableMoves()
|
self.moves = self:findAvailableMoves()
|
||||||
self.depth = 2
|
self.depth = 2
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
objs = self.game:findName(self:getTurn())
|
||||||
|
local i
|
||||||
|
for i=1,#objs do
|
||||||
|
objs[i].highlight = true
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
if self.selected then
|
if self.selected then
|
||||||
local i
|
local i
|
||||||
|
Loading…
Reference in New Issue
Block a user