Arts >> Arte e intrattenimento >  >> Teatro >> Commedia

Gioco Python Fan-Made: Prototipo SpongeBob "The Quickster"

Il codice sotto è un prototipo fan-creato in Python/Pygame ispirato all'episodio SpongeBob SquarePants "The Quickster" (dove SpongeBob guadagna super-velocità). Non è codice gioco ufficiale.

import pygame
import sys
# Colori
NERO = (0, 0, 0)
BIANCO = (255, 255, 255)
VERDE = (0, 255, 0)
ROSSO = (255, 0, 0)
# Schermo
LARGHEZZA_SCHERMO = 800
ALTEZZA_SCHERMO = 600
screen = pygame.display.set_mode((LARGHEZZA_SCHERMO, ALTEZZA_SCHERMO))
# Giocatore (SpongeBob)
player = pygame.sprite.Sprite()
player.image = pygame.image.load("spongebob.png")
player.rect = player.image.get_rect()
# Muri
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)
# Loop Principale
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(NERO)
    screen.blit(player.image, player.rect)
    walls.draw(screen)
    pygame.display.flip()

Questa demo semplice mostra movimento base e collisione. Un vero gioco aggiungerebbe animazione, livelli, nemici, e la meccanica velocità "Quickster".

Commedia

Related Categories