People have what we call psychological boundaries which are relationship expectations, limits, beliefs, values, etc. It's how we regulate ourselves and our emotional distance from other people. Ideally, we have healthy emotional boundaries separating ourselves from others. However, sometimes, our emotional boundaries are fuzzy, unhealthy, and need clarifying. Other people may step in and try to manipulate our feelings or ideas through flattery or other methods. They attempt to impose their own values, beliefs, needs, etc. because it gives them what they want. (In this case, I think ultimately it's sex he wants from you, but he'll settle for sexy flirtation right now.) Unhealthy boundaries -- this is your situation.
Having a crush on someone who is inaccessible -- a teacher, coach, boss, person who is married, a celebrity, or in this case, a friend's father -- this sometimes happens, especially to teens who are new to raging hormones. People can't always help who they find attractive BUT they don't have to act on it or tell that person. You may not have actually told him, but your behavior might have telegraphed it. I'm not giving you a free pass, but honestly, he was the adult in this situation and it was incumbent upon him to respond appropriately even if you behaved in a flirty manner. (I am guessing you're an older teen?)
You already know there's something deeply inappropriate -- I would add DISTURBING -- about this relationship for several reasons:
1) he's married and yet flirting with you
2) he's your friend's dad (What is her reaction to all of this?)
3) most importantly, he's SIGNIFICANTLY older than you. If you're under age, he may be flirting with serious legal jeopardy should he actually make a move on a minor (i.e., a CHILD under the law). Just flirting with you like this isn't appropriate but doing more than flirting could end him up in jail and on a predator's list for life.
4) he's seemingly jealous of your boyfriend and jokes about his ability to inflict violence. This "caveman" type comment both confused you and at least made you think twice. I suspect that you couldn't share the conversations you have with your friend's father with others, such as his wife, your parents, your boyfriend, etc. Secrets are trouble.
5) he's teasing about drinking and if you are under age, then that's contributing to the delinquency of a minor. Alcohol reduces social inhibitions. Do not under ANY circumstances drink with him.
My short answer is no, this is NOT all in your head. Find a way not to have these one-on-one conversations with him or be around him at all preferably. It would be ideal if you could be honest with your friend about her creepy dad and agree to go elsewhere. I wouldn't be shocked if your friend's parents had ongoing marital troubles and her dad had a longstanding alcohol problem. Don't underestimate the level of potential danger this man could pose to you in the wrong situation. Men who like young girls are bad news. Draw those boundaries.