Untitled
unknown
plain_text
14 days ago
2.9 kB
1
Indexable
#pgzero WIDTH = 600 # Ancho de la ventana HEIGHT = 300 # Altura de la ventana TITLE = "Corredor de Alienígenas" # Título para la ventana de juego FPS = 30 # Número de fotogramas por segundo # Objetos alien = Actor('alien', (50, 240)) background = Actor("background") box = Actor('box', (550, 265)) new_image = 'alien' #Seguimiento de la imagen actual bee = Actor('bee', (850, 175)) # Abeja go = Actor("GO") game_over = 0 # NO HEMOS PERDIDO puntaje = 0 def draw(): background.draw() alien.draw() box.draw() bee.draw() screen.draw.text('Puntaje: ' + str(puntaje), pos=(10, 10), color="white", fontsize = 24) if game_over == 1: go.draw() screen.draw.text('Enter para reiniciar', center=(300, 200), color="white", fontsize = 24) screen.draw.text('Has chocado con una caja 📦', center=(300, 250), color="white", fontsize = 24) elif game_over == 2: go.draw() screen.draw.text('Enter para reiniciar', center=(300, 200), color="white", fontsize = 24) screen.draw.text('Has chocado con una abeja 🐝', center=(300, 250), color="white", fontsize = 24) def update(dt): global new_image, game_over, puntaje # Movimiento de la abeja if bee.x > -20: bee.x = bee.x - 5 else: bee.x = WIDTH + 20 puntaje += 1 # Movimiento de la caja if box.x > -20: box.x = box.x - 5 box.angle = box.angle + 5 else: box.x = WIDTH + 20 puntaje += 1 # Controles if keyboard.left or keyboard.a and alien.x > 20: alien.x = alien.x - 5 if new_image != 'left': alien.image = 'left' new_image = 'left' elif keyboard.right or keyboard.d and alien.x < 580: alien.x = alien.x + 5 if new_image != 'right': alien.image = 'right' new_image = 'right' elif keyboard.down or keyboard.s: if new_image != 'duck': alien.image = 'duck' new_image = 'duck' alien.y = 250 else: alien.image = 'alien' new_image = 'alien' if alien.y > 240 and new_image == 'duck': alien.y = 240 # Colisión if alien.colliderect(box): game_over = 1 box.x += 5 bee.x += 5 elif alien.colliderect(bee): game_over = 2 bee.x += 5 box.x += 5 # REINICIO DE JUEGO if (game_over == 1 or game_over == 2) and keyboard.enter: game_over = 0 alien.pos = (50, 240) box.pos = (550, 265) bee.pos = (850, 175) puntaje = 0 def on_key_down(key): # Salto if keyboard.space or keyboard.up or keyboard.w: alien.y = 100 animate(alien, tween='bounce_end', duration=2, y=240)
Editor is loading...
Leave a Comment