Что вы могли бы сделать, чтобы «предупредить» pygame / ваш код, вы можете использовать операторы if
, если вы используете не-ООП, и все, что у вас есть, это список координат для вашего местоположения игрока, или если у вас есть объектдля вашего игрока вы можете pygame.sprite.Sprite
как супер класс.Вот решение, если вы используете список координат, а не большой класс.
loc = [x, y] # Don't run this because it won't understand what x and y are. This is just an example
safe_rect = ( x , y , w , h ) # Using tuple because I assume that the safe doesn't move
while True:
if loc[0] >= safe_rect[0] and # The newlines are for readability
loc[0] < safe_rect[0] + safe_rect[2] and
loc[1] >= safe_rect[1] and
loc[1] < safe_rect[1] + safe_rect[3]:
not_yet_existent_do_something_function() # Performs statements once inside the safe
Если вы хотите включить таймер, сделайте следующее:
import time
loc = [x, y]
safe_rect = ( x , y , w , h )
# Time variables
time = time.time()
time_wanted = time + 3 # 3 seconds after the time is assigned to time
while True:
if loc[0] >= safe_rect[0] and
loc[0] < safe_rect[0] + safe_rect[2] and
loc[1] >= safe_rect[1] and
loc[1] < safe_rect[1] + safe_rect[3]:
if time.time() > time_wanted:
not_yet_existent_do_something_function()
Я надеюсь, что это работает для васЕсли у вас есть вопрос о том, что я сделал, пожалуйста, спросите меня.