local
Code: Select all
love = require("love")
function Card()
return {
length = 100,
width = 60,
x = 200,
y = 880,
title = "",
selected = false,
move = function(self, player_x, player_y, ismouse_down)
if self.x <= player_x and player_x <= self.x + 60 and self.y <= player_y and player_y <= self.y + 100 then
if ismouse_down then
self.selected = true
end
end
if not ismouse_down then
self.selected = false
end
if self.selected then
self.x = player_x - 30
self.y = player_y - 50
end
end,
draw = function (self)
love.graphics.setColor(1, 1, 1)
love.graphics.rectangle("fill", self.x, self.y, self.width, self.length)
love.graphics.setColor(1,1,1)
end
}
end
return Card
Code: Select all
_G.love = require("love")
local card = require("Card")
local game = {
state = {
menu = false,
paused = false,
running = true,
ended = false,
}
}
local player = {
x = 30,
y = 30
}
local cards = {}
local dealButton = {
length = 70,
width = 120,
x = 1740,
y = 500,
draw = function (self)
love.graphics.setColor(1, 1, 1)
love.graphics.rectangle("fill", self.x, self.y, self.width, self.length)
love.graphics.setColor(1, 1, 1)
end
}
function love.mousepressed(x, y)
if dealButton.x <= x and x <= dealButton.x + 120 and dealButton.y <= y and y <= dealButton.y + 70 then
table.insert(cards, #cards + 1, card())
for i = 2, #cards do
cards[i].x = i * 80
end
end
end
function love.load()
love.graphics.setBackgroundColor(0.5,0.5,0.3)
love.mouse.setVisible(true)
end
function love.update(dt)
player.x, player.y = love.mouse.getPosition()
local mouseDown = love.mouse.isDown(1)
for i = 1, #cards do
cards[i]:move(player.x, player.y, mouseDown)
end
end
function love.draw()
love.graphics.printf("FPS: " .. love.timer.getFPS(), love.graphics.newFont(12), 10, 20, love.graphics.getWidth())
love.graphics.printf("Number of Cards: ".. #cards, love.graphics.newFont(12), 10, 50, love.graphics.getWidth())
if game.state["running"] then
dealButton:draw()
for i = 1, #cards do
cards[i]:draw()
end
end
end
Thanks for any help in advance and apologies for such a simple issue.