Would is used in conditional sentences.
When we imagine or think of something which is not real, we use would + infinitive.
When we regret about something in the past, we wanted things to go otherwise, but we can't change that anymore, we use would + have + past participle.
Examples
I would go to the cinema tonight, but I don't have a company. (but I still can go if I find a company)
I would have gone to the cinema yesterday, but I didn't have a company. (I regret it but I can't change it)
John would come to the party tomorrow, but he won't have time. (but he still can come if he has time)
John would have come to the party last week, but he didn't have time. (he regrets it but he can't change the past)
Diane would buy a new car, but she doesn't have enough money. (she still can buy it if she has money)
Diane would have bought a new car last month, but she had to spend all her money on home renovation. (that happened last month so she can't change that)