it works and before I go further, let's commit

This commit is contained in:
Paul Liverman
2015-12-05 23:08:57 -08:00
parent a5c7aae494
commit 1dc98d80d3
4 changed files with 462 additions and 33 deletions

View File

@@ -1,34 +1,42 @@
local set = setmetatable
local class = require "lib.middleclass"
local insert = table.insert
local remove = table.remove
local random = math.random
local floor = math.floor
local ceil = math.ceil
local lg = love.graphics
local Deck = {}
local Deck = class("Deck")
local inspect = require "lib.inspect" --NOTE DEBUG
Deck.static.width = 64*2
Deck.static.height = 89*2
function Deck.initialize(cards)
local self = {}
print(inspect(cards)) --NOTE DEBUG
function Deck:initialize(cards)
self.cards = cards or {}
self.x = 0
self.y = 0
self.r = 0
self.face = "down" --or "up"
set(self, {__index = Deck})
return self
end
function Deck:draw()
local thickness = floor(#self.cards / 3)
print(inspect(self.cards)) --NOTE DEBUG
self.cards[#self.cards]:draw(self.face, self.x, self.y, self.r)
function Deck:draw(face, x, y, r)
if not face then face = self.face end
if not x then x = self.x end
if not y then y = self.y end
if not r then r = self.r end
--TODO draw the extra lines
lg.push()
lg.translate(x, y)
lg.rotate(r)
lg.setColor(255, 255, 255, 255)
for i=ceil(#self.cards / 3), 1, -1 do --every 3 cards is 1 pixel of thickness to the deck, rounded up
lg.rectangle("line", i - Deck.static.width/2, i - Deck.static.height/2, Deck.static.width, Deck.static.height)
end
lg.pop()
self.cards[#self.cards]:draw(face, x, y, r)
end
function Deck:moveTo(x, y, r)
@@ -37,6 +45,14 @@ function Deck:moveTo(x, y, r)
self.r = r or self.r
end
function Deck:flip()
if self.face == "down" then
self.face = "up"
else
self.face = "down"
end
end
function Deck:shuffleCards()
local new = {}
@@ -47,6 +63,10 @@ function Deck:shuffleCards()
self.cards = new
end
function Deck:shuffleIn(card) --TODO make capable of handling multiple cards
--
end
function Deck:drawCards(count)
if count and (count > 1) then
local new = {}
@@ -83,5 +103,4 @@ function Deck:placeCardsUnder(cards)
end
end
set(Deck, {__call = Deck.initialize})
return Deck