The Possibilities Are Innumerable
The shapes a weapon (or "gun") can take are limited, but too numerous to give a big list. It depends on a lot of factors which sci-fi regularly tinkers with. Let's take a look at these limits.
Limits on Weapons
Weapon design is limited by several factors, including but not limited to:
- biology of wielder
- biology/structure of the target
- energy sources (frequently chemical for most guns but potentially electrical and mechanical sources)
- environment (modern metal guns don't work well in space or on Venus by virtue of the environment)
- manufacturing technologies
And these can vary wildly throughout sci-fi! A 3-d printed gun looks different than a traditionally manufactured gun, and both (I bet) would look different from a gun grown from bacteria.
As an example, let's say your gun is held by a tentacled creature and produces damage against robots by directing some strong EM fields. In place of a long barrel, you may have an antenna, which can take various shapes, including a flat plate! Additionally, said tentacle creature may find a smooth ball with orthogonal rods sticking out of it more comfortable. So the creature presents a flat plate to the target while holding a spikey ball with their tentacle. This is not a traditional gun at all!
The Universe Favors Certain Designs
Sometimes, physics just favors certain designs for certain tasks. The universe has rules and some things take better advantage of them. Ultimately, a gun needs to work, so humans here and aliens there may independently create very similar guns. (A parallel to this exists in biology: convergent evolution)
For example, barrels exist in IRL guns to stabilize and direct the bullet. The walls redirect the errant forces to the exit of the barrel. Likewise, the barrel constricts expanding gasses at to push the bullet forwards. Any gun which depends on expanding gasses to accelerate a projectile will, by virtue of physics, gravitate to a barrel.