I would say comedy can be boiled down to:
1. Twisting expectations. This is like the character dodging an attack by falling down, either the example above or the classic slapstick stuff like slipping on a banana peel (if you need more examples, look for old episodes of a show called "Get Smart!"- he had a lot of escapes that way, though some of them were directly borrowed from Marx Brothers or Three Stooges routines) but there are other ways as well (another bit from that show is an entire episode built around a gun with one trigger and two barrels, dubbed a "stereophonic pistol" - when the bad guy actually gets one, holds it to the hero's head. and pulls the trigger ... it plays music because the guys who put it together took the name literally).
2. Just flat-out being SILLY. Using nonsense words (Twas Brilig and the Slithy Toves...), misusing words (not just puns, but they can be the best examples, as can using dialect - though that can cause problems as it can easily become offensive or just go over the heads of readers not familiar with the dialect being mimicked; the "authentic frontier gibberish" scene from Blazing Saddles or the "I speak jive" moment in Airplane are examples of how this can work or fail).
3. Sowing chaos - this can be through misunderstandings, just having random things happen, or just having too many things happen at once (the TV series I Love Lucy had some great takes on this, the most (in)famous being the one at the chocolate factory and the machine going faster and faster), or turning the mundane into the absurd (There is a play called Rhinocéros about a disease that turns people into rhinoceroses. Can't get much more absurd than THAT).
4. Exaggeration - especially exaggerating things like drunkenness (I Love Lucy again has a great example with her endorsing a food supplement that turns out to be 10% alcohol...) or character quirks.