Hi Guys,
I've been thinking on this for a while and I can't seem to crack it. I'm trying to illustrate a hand of cards. I know I can draw them in a for loop to the index of the player's hand. But how to position them properly in code is confusing me. What I want to do is have them in a typical overlapping style so you can only see the suit and number on the side. Does anyone have any ideas?
Illustrating a player's card hand
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Illustrating a player's card hand
What do you have so far? It's easier for us to help you if we know where you're coming from.
Help us help you: attach a .love.
- pakoskyfrog
- Citizen
- Posts: 62
- Joined: Mon Feb 04, 2013 12:54 pm
- Location: France
Re: Illustrating a player's card hand
You can try drawing filled rectangular polygons, each next overlapping the previous.
Not tested but it could be something like :
Not tested but it could be something like :
Code: Select all
local rect = {100, 150, 170, 250} -- 70x100
alpha = math.pi/7
for i = 1, #hand do
local angle = (i-1)*alpha
local frame = rotate_rect(rect, angle) -- make it with trigonometrics
love.graphics.setColor(0,0,0) -- Black
love.graphics.polygon('fill', frame) -- card background
love.graphics.setColor(255,255,255) -- white
love.graphics.polygon('line', frame) -- card
draw_card(hand[i], alpha) -- make it draw that you've got a queen of heart of whatever you've got
end
Re: Illustrating a player's card hand
If you want to have it like in hearts:
here is a simple solution, though not the most efficient one:
First draw all cards into an image and load them into löve. Then perform a for loop from left to right and draw one after the other, they will automatically overlap.
here is a simple solution, though not the most efficient one:
First draw all cards into an image and load them into löve. Then perform a for loop from left to right and draw one after the other, they will automatically overlap.
Check out my blog on gamedev
Re: Illustrating a player's card hand
Thanks for the reply, this is what I've pretty much been trying to do. I can't figure out how to position them, though. I know the Y position will be the same all the time but the x position is what I can't crack.micha wrote:If you want to have it like in hearts:
here is a simple solution, though not the most efficient one:
First draw all cards into an image and load them into löve. Then perform a for loop from left to right and draw one after the other, they will automatically overlap.
To be honest I'm not advanced enough of a coder to know how this is all working, particularly the maths. But thanks for the suggestion.pakoskyfrog wrote:You can try drawing filled rectangular polygons, each next overlapping the previous.
Not tested but it could be something like :Code: Select all
local rect = {100, 150, 170, 250} -- 70x100 alpha = math.pi/7 for i = 1, #hand do local angle = (i-1)*alpha local frame = rotate_rect(rect, angle) -- make it with trigonometrics love.graphics.setColor(0,0,0) -- Black love.graphics.polygon('fill', frame) -- card background love.graphics.setColor(255,255,255) -- white love.graphics.polygon('line', frame) -- card draw_card(hand[i], alpha) -- make it draw that you've got a queen of heart of whatever you've got end
Re: Illustrating a player's card hand
You need to know the position of the first card (let's call it xfirst) and the distance between the cards (xdist)tdc5013 wrote:Thanks for the reply, this is what I've pretty much been trying to do. I can't figure out how to position them, though. I know the Y position will be the same all the time but the x position is what I can't crack.
Code: Select all
for i=0,12 do
posx = xfirst + i*distx
posy = fixedNumber
love.graphics.draw(appropriateImage,posx,posy)
end
Check out my blog on gamedev
Re: Illustrating a player's card hand
That works perfectly! Thanks for the info, greatly appreciated.
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot], CharlesAceta and 1 guest