Hearthstone-like card hold mechanic?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
nikneym
Prole
Posts: 41
Joined: Sat Mar 09, 2013 1:22 pm
Contact:

Hearthstone-like card hold mechanic?

Post by nikneym » Mon Jan 21, 2019 2:17 am

Hey guys, its been awhile since i last asked a question, huh? so what are we waiting for! I'm working on a bakugan-like game and i'm trying to make card holding mechanic that similar to hearthstone. I made something like that:

Code: Select all

cards=0;
lp=love.graphics;

function love.keypressed(key)
	if key=="w" then
		cards=cards+1;
	elseif key=="s" then
		cards=cards-1;
	end
end

function love.draw()
	for i=1, cards do
		if i%2==0 then
			lp.setColor(255, 40, 40);
		else
			lp.setColor(30, 30, 30);
		end

		lp.push();
		lp.rotate(220+(i*220)-220);
		lp.rectangle("fill", 100+(i*100)-100, 100-(i*5)-5, 140, 205);
		lp.pop();
	end
end
Image

It almost works good but the display not the same as the one one the hearthstone.

Image

So the question here is, i guess, how can i reorganize the rotation of the cards whenever a new card added to our hand? or should i put limits like if cards==5 or cards==3 etc.

by the way, is there a solution about bad rendered rectangles?

monkyyy
Citizen
Posts: 52
Joined: Fri Mar 16, 2012 5:29 pm

Re: Hearthstone-like card hold mechanic?

Post by monkyyy » Mon Jan 21, 2019 3:59 am

>lp.rotate(220+(i*220)-220);

I would abstract it out; its a trail and error thing and the logic shouldn't be part of the for loop as the third card in the hand of three shouldn't be rotated the same as the third card in the hand of 10.

I would write two different functions, hand_draw_logic() that setups some global variables with the knowledge of how many cards there are, and a second draw_card(), the references those global variables but handles whatever card logic thing you need and simply takes its number position

monkyyy
Citizen
Posts: 52
Joined: Fri Mar 16, 2012 5:29 pm

Re: Hearthstone-like card hold mechanic?

Post by monkyyy » Mon Jan 21, 2019 5:36 am

my take

still needs some y angle hacking as well as a smarter rotation but have fun i always hated frame stacking logic

pay attention to the units of the lib your using, you made 2 bugs from ignoring the api.
Attachments
main.lua
(848 Bytes) Downloaded 36 times

grump
Party member
Posts: 572
Joined: Sat Jul 22, 2017 7:43 pm

Re: Hearthstone-like card hold mechanic?

Post by grump » Mon Jan 21, 2019 10:44 am

nikneym wrote:
Mon Jan 21, 2019 2:17 am

Code: Select all

		lp.rotate(220+(i*220)-220);
Rotation angles must be specified as radians, not degrees. Use math.rad to convert deg to rad.

Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests