NeutronLoved/objects/circle.lua

38 lines
1011 B
Lua
Raw Normal View History

2022-03-03 20:24:10 +01:00
local gen= {}
function gen:new(game,x,y,color,grid)
local Circle = game.objects.base:new(game,x,y,grid.cellsize,grid.cellsize)
Circle.cellsize = grid.cellsize
Circle.grid = grid
2022-03-04 10:39:02 +01:00
Circle.color = color
2022-03-03 20:24:10 +01:00
Circle.shadowsprite = game:newImage("circles/shadow.png")
Circle.sprites = {game:newImage("circles/regular/"..color..".png"),game:newImage("circles/selected/"..color..".png")}
Circle:register("Circle")
Circle:register(color)
Circle.selected = false
function Circle:step(dt) end
function Circle:draw()
local spriteindex = 1
if self.selected then spriteindex = 2 end
lg.draw(self.sprites[spriteindex],self.rect[1]-self.game.camerax-self.spriteoffx,self.rect[2]-self.game.cameray-self.spriteoffy)
end
2022-03-04 10:39:02 +01:00
function Circle:MouseCallback(x,y,presses)
if self.rect:collidepoint(x,y) then
local c = self.game:findName(self.color)
local i
for i=1,#c do
if c[i]~=self then c[i].selected = false end
end
self.selected = not self.selected
end
end
2022-03-03 20:24:10 +01:00
return Circle
end
return gen