Animation for position hints

This commit is contained in:
theo@manjaro 2022-03-09 17:20:25 +01:00
parent e2b4da9828
commit 18101c4f43

View File

@ -9,16 +9,22 @@ function gen:new(game,x,y,color,grid)
Circle.grid = grid Circle.grid = grid
Circle.color = color Circle.color = color
Circle.shadowsprite = game:newImage("circles/shadow.png") Circle.shadowsprite = game:newImage("circles/shadow.png")
Circle.shadowpos = {}
Circle.moves = {}
Circle.sprites = {game:newImage("circles/regular/"..color..".png"),game:newImage("circles/selected/"..color..".png")} Circle.sprites = {game:newImage("circles/regular/"..color..".png"),game:newImage("circles/selected/"..color..".png")}
Circle:register("Circle") Circle:register("Circle")
Circle:register(color) Circle:register(color) Circle.selected = false
Circle.selected = false
Circle.highlight = false Circle.highlight = false
Circle.highlightTimer = game:Timer(0.08) Circle.highlightTimer = game:Timer(0.08)
function Circle:step(dt) function Circle:step(dt)
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
local i = 1
for i=1,#self.moves do
self.shadowpos[i][1]= self.shadowpos[i][1] + (self.moves[i][1]-self.shadowpos[i][1])/10
self.shadowpos[i][2]= self.shadowpos[i][2] + (self.moves[i][2]-self.shadowpos[i][2])/10
end
if self.highlight then if self.highlight then
self.highlightTimer:tick(dt) self.highlightTimer:tick(dt)
@ -41,13 +47,14 @@ function gen:new(game,x,y,color,grid)
function Circle:draw() function Circle:draw()
local spriteindex = 1 local spriteindex = 1
if self.selected or self.highlight and self.highlightTimer.loops%2==0 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 if self.selected then
local i local i
for i=1,#self.moves do for i=1,#self.moves do
lg.draw(self.shadowsprite,self.moves[i][1]-self.game.camerax-self.spriteoffx,self.moves[i][2]-self.game.cameray-self.spriteoffy) --lg.draw(self.shadowsprite,self.moves[i][1]-self.game.camerax-self.spriteoffx,self.moves[i][2]-self.game.cameray-self.spriteoffy)
lg.draw(self.shadowsprite,self.shadowpos[i][1]-self.game.camerax-self.spriteoffx,self.shadowpos[i][2]-self.game.cameray-self.spriteoffy)
end end
end end
lg.draw(self.sprites[spriteindex],self.drawx-self.game.camerax-self.spriteoffx,self.drawy-self.game.cameray-self.spriteoffy)
end end
function Circle:MouseCallback(x,y,presses) function Circle:MouseCallback(x,y,presses)
@ -58,12 +65,21 @@ function gen:new(game,x,y,color,grid)
for i=1,#c do for i=1,#c do
if c[i]~=self then c[i].selected = false end if c[i]~=self then c[i].selected = false end
end end
local pastselected = self.selected
self.selected = not self.selected self.selected = not self.selected
self.depth = 1 self.depth = 1
if self.selected then if self.selected then
if not pastselected then
self.moves = self:findAvailableMoves() self.moves = self:findAvailableMoves()
self.shadowpos = {}
local i = 1
self.shadowpos = {}
for i=1,#self.moves do
table.insert(self.shadowpos,{self.rect.x,self.rect.y})
end
self.depth = 2 self.depth = 2
end end
end
else else
objs = self.game:findName(self:getTurn()) objs = self.game:findName(self:getTurn())
local i local i