Can select circles
This commit is contained in:
parent
0be510ea83
commit
8f7b5fff0a
8
game.lua
8
game.lua
@ -216,6 +216,13 @@ function Game:draw(screen)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Game:MouseCallback(x,y,presses)
|
||||||
|
local i
|
||||||
|
for i=1,#self.gameloop do
|
||||||
|
self.gameloop[i]:MouseCallback(x,y,presses)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function Game:bint(bool) -- Convert Boolean to Integer
|
function Game:bint(bool) -- Convert Boolean to Integer
|
||||||
local result = 0
|
local result = 0
|
||||||
if bool then result = 1 end
|
if bool then result = 1 end
|
||||||
@ -251,6 +258,7 @@ function Game:Timer(time)
|
|||||||
end
|
end
|
||||||
|
|
||||||
return Timer
|
return Timer
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
Game:reinit()
|
Game:reinit()
|
||||||
|
9
main.lua
9
main.lua
@ -70,3 +70,12 @@ end
|
|||||||
function love.resize(w, h)
|
function love.resize(w, h)
|
||||||
if game.OSTYPE~="3DS" then push:resize(w, h) end
|
if game.OSTYPE~="3DS" then push:resize(w, h) end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function love.mousepressed(x,y,button,istouch,presses)
|
||||||
|
-- Format positions according to screen
|
||||||
|
|
||||||
|
if game.OS ~= "Horizon" then
|
||||||
|
x,y = push:toGame(x,y)
|
||||||
|
end
|
||||||
|
game:MouseCallback(x,y,presses)
|
||||||
|
end
|
||||||
|
@ -13,6 +13,8 @@ function basegen:new(game,x,y,w,h)
|
|||||||
|
|
||||||
function Base:step(dt) end
|
function Base:step(dt) end
|
||||||
|
|
||||||
|
function Base:MouseCallback(x,y,presses) end
|
||||||
|
|
||||||
function Base:register(name)
|
function Base:register(name)
|
||||||
table.insert(self.classes,name)
|
table.insert(self.classes,name)
|
||||||
end
|
end
|
||||||
|
@ -5,6 +5,7 @@ function gen:new(game,x,y,color,grid)
|
|||||||
local Circle = game.objects.base:new(game,x,y,grid.cellsize,grid.cellsize)
|
local Circle = game.objects.base:new(game,x,y,grid.cellsize,grid.cellsize)
|
||||||
Circle.cellsize = grid.cellsize
|
Circle.cellsize = grid.cellsize
|
||||||
Circle.grid = grid
|
Circle.grid = grid
|
||||||
|
Circle.color = color
|
||||||
Circle.shadowsprite = game:newImage("circles/shadow.png")
|
Circle.shadowsprite = game:newImage("circles/shadow.png")
|
||||||
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")
|
||||||
@ -19,6 +20,17 @@ function gen:new(game,x,y,color,grid)
|
|||||||
lg.draw(self.sprites[spriteindex],self.rect[1]-self.game.camerax-self.spriteoffx,self.rect[2]-self.game.cameray-self.spriteoffy)
|
lg.draw(self.sprites[spriteindex],self.rect[1]-self.game.camerax-self.spriteoffx,self.rect[2]-self.game.cameray-self.spriteoffy)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
return Circle
|
return Circle
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ function gridgen:new(game,x,y,cellsize)
|
|||||||
local i
|
local i
|
||||||
for i=1,5 do
|
for i=1,5 do
|
||||||
local xspawn = x+(i-1)*cellsize
|
local xspawn = x+(i-1)*cellsize
|
||||||
local pink = game.objects.circle:new(game,xspawn,y,"pink",self)
|
local pink = game.objects.circle:new(game,xspawn,y,"pink",Grid)
|
||||||
local blue = game.objects.circle:new(game,xspawn,y+4*cellsize,"blue",Grid)
|
local blue = game.objects.circle:new(game,xspawn,y+4*cellsize,"blue",Grid)
|
||||||
game:summon(pink)
|
game:summon(pink)
|
||||||
game:summon(blue)
|
game:summon(blue)
|
||||||
|
29
ù
Normal file
29
ù
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
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
|
||||||
|
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
|
||||||
|
|
||||||
|
function Circle:MouseCallback(x,y,presses)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
return Circle
|
||||||
|
end
|
||||||
|
|
||||||
|
return gen
|
Loading…
Reference in New Issue
Block a user