That's a little tiny question, but ... so is "why are rainbows?". The answer to that one is horribly complicated, far far too much for a little text box like this - and so is the answer to yours!
As Rishard has said, writing a game engine is a lot of work - it's normally a project for a large team of experienced developers, not for a single coder, and to be honest I wouldn't even attempt it myself (and I've been in this game for decades!)
If you really think you want to write your own, then start here: how to write a game engine - Google Search
] and follow a couple of links. They will at least give you a sense of the scale you are looking at, and the subjects you are going to need to learn to get started.
If you decide to continue, you have an interesting project here - but it's going to take you a long time to get "usable results" so try not to get disheartened.