This is based on the same principle as how toy spud guns work, but they use something more engineered to compress the air. Air guns also work in a similar way; pulling the trigger releases a large spring which pushes a piston down a cylinder. This compresses the air behind the bullet until it overcomes the friction holding it there, and then it fires down the barrel.