Arts >> Arte y entretenimiento >  >> Teatro >> Comedia

Juego Python hecho por fans: Prototipo "El Veloz" de Bob Esponja

El código a continuación es un prototipo en Python/Pygame creado por fans inspirado en el episodio de Bob Esponja "El Veloz" (donde Bob Esponja gana supervelocidad). No es código oficial del juego.

import pygame
import sys
# Colores
NEGRO = (0, 0, 0)
BLANCO = (255, 255, 255)
VERDE = (0, 255, 0)
ROJO = (255, 0, 0)
# Pantalla
ANCHO_PANTALLA = 800
ALTO_PANTALLA = 600
screen = pygame.display.set_mode((ANCHO_PANTALLA, ALTO_PANTALLA))
# Jugador (Bob Esponja)
player = pygame.sprite.Sprite()
player.image = pygame.image.load("spongebob.png")
player.rect = player.image.get_rect()
# Muros
walls = pygame.sprite.Group()
for i in range(5):
    wall = pygame.sprite.Sprite()
    wall.image = pygame.Surface((100, 100))
    wall.image.fill(VERDE)
    wall.rect = wall.image.get_rect()
    wall.rect.x = i * 100
    wall.rect.y = i * 100
    walls.add(wall)
# Bucle principal
while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()
    keys = pygame.key.get_pressed()
    if keys[pygame.K_LEFT]:
        player.rect.x -= 5
    if keys[pygame.K_RIGHT]:
        player.rect.x += 5
    if keys[pygame.K_UP]:
        player.rect.y -= 5
    if keys[pygame.K_DOWN]:
        player.rect.y += 5
    if pygame.sprite.spritecollideany(player, walls):
        player.rect.x -= 5
        player.rect.y -= 5
    screen.fill(NEGRO)
    screen.blit(player.image, player.rect)
    walls.draw(screen)
    pygame.display.flip()

Esta demo simple muestra movimiento básico y colisión. Un juego real añadiría animación, niveles, enemigos y la mecánica de velocidad "Veloz".

Comedia

Related Categories