Many reasons for that.
Spears had many massive advantages over more elaborate weapons like swords or rapiers or crossbows or axes or whatever else you could think of.
1. They were extremely, stupidly easy to make. And cheap! We've been making them since the stone age and the design was more or less perfect then. Still perfect now. This might seem like a triviality for arming one guy, like say some super saiyan rpg adventurer hero, but when you're dealing with hundreds of thousands of soldiers or even millions.... then cost and time to make each weapon is the most important aspect of the game.
2. The second most important aspect of a weapon is how easy it is to actually use the weapon. A spear, though simple, is stupidly easy to use and train with. Especially considering most if not all the soldiers were peasant levies or drafted men or even prisoners and slaves. Of course, if you practiced for years, a soldier could be an expert spearmaster, but that's not what armies needed. They needed huge contingents of men who could march in formation and poke at things. So all a peasant had to learn how to do with a spear was follow his fellow soldiers in lines and poke at things. No slashing. No advanced guarding. Maybe a little bracing, but mostly just poking.
3. The spearwall, pikewall, pokey-stick wall, was the single most feared infantry formation for over 1,500 years. Not just to fight horses, like Total War would have you believe. It was primarily developed to smash through thick infantry lines while taking minimal losses. Invented by the Greeks, everyone from Romans to Celts to Egyptians to Germans and even the Chinese used it. A tight ball of pokey-death is extremely hard to face. It had many weaknesses of course, but hey... as I mentioned earlier, we kinda used it until guns could shoot more than 1 shot a minute.
So yeah. People used WAAAAAAAAAAAAAAAAY more spears than swords back in ye olde days. In fact, owning a sword was usually considered a sign of nobility. Had to be pretty rich to own one. Most of these fancy weapons we see in games today, a person back in the middle ages would have considered far beyond their status. Like a gold AK47 for us today. For them, it's all about spears, horses, and what new way we've discovered to throw things at the enemy.
Once again, sorry for the detour.