Log In  


import pygame
import sys

Initialize Pygame

pygame.init()

Constants

SCREEN_WIDTH = 640
SCREEN_HEIGHT = 480
TILE_SIZE = 32
FPS = 60

Colors

BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
RED = (200, 0, 0)
BLUE = (0, 0, 255)
GREEN = (0, 255, 0)
YELLOW = (255, 255, 0)

Screen Setup

screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.display.set_caption("Othello: The Moor of Venice - Act 1")
clock = pygame.time.Clock()

Font

font = pygame.font.SysFont(None, 24)

Player Class

class Player(pygame.sprite.Sprite):
def init(self, x, y):
super().init()
self.image = pygame.Surface((TILE_SIZE, TILE_SIZE))
self.image.fill(BLUE)
self.rect = self.image.get_rect()
self.rect.topleft = (x, y)
self.speed = 4

def handle_movement(self):
    keys = pygame.key.get_pressed()
    if keys[pygame.K_LEFT]:
        self.rect.x -= self.speed
    if keys[pygame.K_RIGHT]:
        self.rect.x += self.speed
    if keys[pygame.K_UP]:
        self.rect.y -= self.speed
    if keys[pygame.K_DOWN]:
        self.rect.y += self.speed

NPC Class

class NPC(pygame.sprite.Sprite):
def init(self, x, y, name, dialogue, color=RED):
super().init()
self.image = pygame.Surface((TILE_SIZE, TILE_SIZE))
self.image.fill(color)
self.rect = self.image.get_rect()
self.rect.topleft = (x, y)
self.name = name
self.dialogue = dialogue
self.interacted = False

def talk(self):
    dialogue_box = font.render(f"{self.name}: {self.dialogue}", True, WHITE)
    screen.blit(dialogue_box, (50, SCREEN_HEIGHT - 50))

World setup

player = Player(50, 400)

npcs = pygame.sprite.Group()

Characters

desdemona = NPC(150, 100, "Desdemona", "My love, I choose you!", GREEN)
brabantio = NPC(300, 100, "Brabantio", "You have stolen my daughter!", RED)
duke = NPC(500, 50, "Duke", "Defend your love, brave Othello.", YELLOW)
iago = NPC(100, 300, "Iago", "Trust me, my lord!", RED)
cassio = NPC(400, 300, "Cassio", "Your loyal officer, my general!", GREEN)
roderigo = NPC(250, 250, "Roderigo", "Desdemona should be mine!", RED)

npcs.add(desdemona, brabantio, duke, iago, cassio, roderigo)

all_sprites = pygame.sprite.Group()
all_sprites.add(player)
all_sprites.add(npcs)

Game variables

act1_progress = 0 # 0 = start, 1 = met Desdemona, 2 = faced Brabantio, 3 = talked to Duke
show_text = ""
text_timer = 0

Game loop

def game_loop():
global act1_progress, show_text, text_timer
running = True

while running:
    clock.tick(FPS)

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()

    player.handle_movement()

    # Reset interaction
    active_npc = None

    for npc in npcs:
        if player.rect.colliderect(npc.rect):
            active_npc = npc
            break

    keys = pygame.key.get_pressed()
    if active_npc and keys[pygame.K_SPACE]:
        if not active_npc.interacted:
            active_npc.interacted = True
            show_text = f"{active_npc.name}: {active_npc.dialogue}"
            text_timer = 120  # show text for 2 seconds

            # Progress based on interaction
            if active_npc.name == "Desdemona" and act1_progress == 0:
                act1_progress = 1
            elif active_npc.name == "Brabantio" and act1_progress == 1:
                act1_progress = 2
            elif active_npc.name == "Duke" and act1_progress == 2:
                act1_progress = 3
                show_text = "The Duke believes you! You are sent to Cyprus. (Act 1 Complete!)"

    if text_timer > 0:
        text_timer -= 1
        if text_timer == 0:
            show_text = ""

    # Drawing
    screen.fill(BLACK)
    all_sprites.draw(screen)

    # Show instructions
    instructions = font.render("Move: Arrow Keys | Talk: Space Bar", True, WHITE)
    screen.blit(instructions, (10, 10))

    # Show story progress
    if act1_progress == 0:
        stage = "Find Desdemona"
    elif act1_progress == 1:
        stage = "Confront Brabantio"
    elif act1_progress == 2:
        stage = "Speak to the Duke"
    elif act1_progress == 3:
        stage = "Act 1 Complete!"
    stage_text = font.render(f"Objective: {stage}", True, WHITE)
    screen.blit(stage_text, (10, 40))

    # Show dialogue
    if show_text:
        dialogue_text = font.render(show_text, True, WHITE)
        screen.blit(dialogue_text, (50, SCREEN_HEIGHT - 50))

    pygame.display.flip()

game_loop()

1




[Please log in to post a comment]