Untitled

 avatar
unknown
plain_text
2 years ago
1.7 kB
3
Indexable
import pygame
import random

# initialize pygame
pygame.init()

# set display dimensions
display_width = 800
display_height = 600

# create the game window
gameDisplay = pygame.display.set_mode((display_width, display_height))

# set the title of the game window
pygame.display.set_caption("Tiger Escape")

# set the clock for controlling the game's frame rate
clock = pygame.time.Clock()

# set the tiger's starting position
tiger_x = 50
tiger_y = 300

# set the zookeeper's starting position
zookeeper_x = display_width
zookeeper_y = random.randint(0, display_height - 64)

# set the velocity of the tiger and zookeeper
tiger_speed = 5
zookeeper_speed = 5

# load the tiger and zookeeper images
tigerImg = pygame.image.load("tiger.png")
zookeeperImg = pygame.image.load("zookeeper.png")

# resize the images to a smaller size
tigerImg = pygame.transform.scale(tigerImg, (64, 64))
zookeeperImg = pygame.transform.scale(zookeeperImg, (64, 64))

def tiger(x, y):
    gameDisplay.blit(tigerImg, (x, y))

def zookeeper(x, y):
    gameDisplay.blit(zookeeperImg, (x, y))

# run the game loop
running = True
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

    # update the tiger's position
    tiger_x += tiger_speed

    # update the zookeeper's position
    zookeeper_x -= zookeeper_speed

    # redraw the background
    gameDisplay.fill((255, 255, 255))

    # draw the tiger and zookeeper
    tiger(tiger_x, tiger_y)
    zookeeper(zookeeper_x, zookeeper_y)

    # update the display
    pygame.display.update()

    # control the frame rate
    clock.tick(60)

# quit pygame
pygame.quit()
quit()
Editor is loading...