Untitled
unknown
plain_text
a year ago
829 B
6
Indexable
import time
class Game:
def __init__(self):
self.last_bullet_time = 0 # Track the time the last bullet was created
def create_bullet(self):
current_time = time.time() # Get the current time
if current_time - self.last_bullet_time >= 1: # Check if 1 second has passed
self.last_bullet_time = current_time
self._create_bullet_logic() # Call the function to create the bullet
else:
print("Cannot create bullet yet. Please wait.")
def _create_bullet_logic(self):
# Logic to create and send a bullet
print("Bullet created!")
# Example usage:
game = Game()
game.create_bullet() # Should create a bullet
time.sleep(0.5)
game.create_bullet() # Should not create a bullet
time.sleep(1)
game.create_bullet() # Should create a bulletEditor is loading...
Leave a Comment