People used to believe that what you ate and how soon you ate it before you slept gave you/determined your dreams. Were you ever confused as to why Scrooge said "There's more gravy than of grave about you!" in a Muppet Christmas Carol? Now you know why. Nowadays, I'm pretty sure they don't think they affect your dreams nearly as much as they used to, but yeah, foods and meds that can affect your brain chemistry could affect your dreams, depending on the particular item ingested.
I wake up when I die. Like I got riddled with bullets, everything dimmed out and I woke up immediately afterward.