Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Some boolean logic
- player.buttons = 000011001000 (2**3 + 2**6 + 2**7 = 200)
- PlayerButtons.DUCK = 000010000000 (2**7 = 128)
- PlayerButtons.JUMP = 000001000000 (2**6 = 64)
- PlayerButtons.USE = 000000001000 (2**3 = 8)
- PlayerButtons.SCORE = 010000000000 (2**10 = 1024)
- That means that the player is holding DUCK, JUMP and USE.
- To add to that list SCORE, you should use a | operator:
- player.buttons |= 010000000000
- Now player.buttons equals to:
- 010011001000 (2**3 + 2**6 + 2**7 + 2**10 = 1224)
- To remove DUCK from the list, you can first negate DUCK using ~ operator:
- 111101111111
- Now if you apply it with &=, all bits will stay the same, except one. One bit will be nulled:
- player.buttons &= 111101111111
- Now player.buttons equals to:
- 010001001000
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement