Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

# Set up the display

WIDTH, HEIGHT = 800, 600


screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Simple Minecraft")

# Colors
WHITE = (255, 255, 255)
BLUE = (0, 0, 255)
GREEN = (0, 255, 0)
GRAY = (128, 128, 128)
YELLOW = (255, 255, 0)

# Game settings
BLOCK_SIZE = 50
GRID_SIZE = 10

# Player position
player_x = 0
player_y = 0

# Respawn position
respawn_x = 0
respawn_y = 0

# Player speed
player_speed = 1 # Normal speed
sprinting = False

# Player velocity
player_vel_x = 0
player_vel_y = 0

# Gravity
gravity = 0.5
falling = True

# Grid data
grid = [[0] * GRID_SIZE for _ in range(GRID_SIZE)]

# Player inventory
inventory = {
"diamond": 0,
"iron": 0,
"gold": 0
}

# Game loop
running = True
clock = pygame.time.Clock()
while running:
screen.fill(WHITE)

for event in pygame.event.get():


if event.type == pygame.QUIT:
running = False
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_UP:
player_vel_y = -player_speed
elif event.key == pygame.K_DOWN:
player_vel_y = player_speed
elif event.key == pygame.K_LEFT:
player_vel_x = -player_speed
elif event.key == pygame.K_RIGHT:
player_vel_x = player_speed
elif event.key == pygame.K_LSHIFT:
# Enable sprint
player_speed = 2 # Double the speed
sprinting = True
elif event.key == pygame.K_r:
# Respawn the player
player_x = respawn_x
player_y = respawn_y
elif event.key == pygame.K_SPACE:
# Mine the block
block_x = player_x
block_y = player_y
if grid[block_y][block_x] == 1:
# Diamond ore
inventory["diamond"] += 1
grid[block_y][block_x] = 0
elif grid[block_y][block_x] == 2:
# Iron ore
inventory["iron"] += 1
grid[block_y][block_x] = 0
elif grid[block_y][block_x] == 3:
# Gold ore
inventory["gold"] += 1
grid[block_y][block_x] = 0
elif event.type == pygame.KEYUP:
if event.key == pygame.K_UP or event.key == pygame.K_DOWN:
player_vel_y = 0
elif event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT:
player_vel_x = 0
elif event.key == pygame.K_LSHIFT:
# Disable sprint
player_speed = 1 # Reset

You might also like