0% found this document useful (0 votes)
7 views3 pages

Last Landfall

last landfall

Uploaded by

kushalkhattar28
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views3 pages

Last Landfall

last landfall

Uploaded by

kushalkhattar28
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

import pygame

import random
import time

# Initialize Pygame
pygame.init()

# Screen dimensions
WIDTH, HEIGHT = 800, 600
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Last Landfall")

# Colors
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
RED = (255, 0, 0)
BROWN = (139, 69, 19)

# Clock for controlling frame rate


clock = pygame.time.Clock()
FPS = 60

# Fonts
font = pygame.font.Font(None, 36)

# Player settings
player = {
"x": WIDTH // 2,
"y": HEIGHT // 2,
"width": 40,
"height": 40,
"color": GREEN,
"health": 100,
"hydration": 100,
"hunger": 100,
"speed": 5,
"resources": 0
}

# Resource and hazard settings


resources = []
hazards = []

for _ in range(10):
resources.append({
"x": random.randint(0, WIDTH - 20),
"y": random.randint(0, HEIGHT - 20),
"width": 20,
"height": 20,
"color": BLUE
})

for _ in range(5):
hazards.append({
"x": random.randint(0, WIDTH - 30),
"y": random.randint(0, HEIGHT - 30),
"width": 30,
"height": 30,
"color": RED
})

# Game loop
running = True
while running:
screen.fill(WHITE)

for event in pygame.event.get():


if event.type == pygame.QUIT:
running = False

# Player movement
keys = pygame.key.get_pressed()
if keys[pygame.K_UP]:
player["y"] -= player["speed"]
if keys[pygame.K_DOWN]:
player["y"] += player["speed"]
if keys[pygame.K_LEFT]:
player["x"] -= player["speed"]
if keys[pygame.K_RIGHT]:
player["x"] += player["speed"]

# Constrain player to screen boundaries


player["x"] = max(0, min(WIDTH - player["width"], player["x"]))
player["y"] = max(0, min(HEIGHT - player["height"], player["y"]))

# Draw player
pygame.draw.rect(screen, player["color"], (player["x"], player["y"],
player["width"], player["height"]))

# Draw resources and check for collection


for resource in resources[:]:
pygame.draw.rect(screen, resource["color"], (resource["x"], resource["y"],
resource["width"], resource["height"]))
if pygame.Rect(player["x"], player["y"], player["width"],
player["height"]).colliderect(
pygame.Rect(resource["x"], resource["y"], resource["width"],
resource["height"])):
resources.remove(resource)
player["resources"] += 1

# Draw hazards and check for collision


for hazard in hazards:
pygame.draw.rect(screen, hazard["color"], (hazard["x"], hazard["y"],
hazard["width"], hazard["height"]))
if pygame.Rect(player["x"], player["y"], player["width"],
player["height"]).colliderect(
pygame.Rect(hazard["x"], hazard["y"], hazard["width"],
hazard["height"])):
player["health"] -= 1

# Update survival stats


player["hydration"] -= 0.05
player["hunger"] -= 0.03

if player["health"] <= 0 or player["hydration"] <= 0 or player["hunger"] <= 0:


running = False
# Display stats
health_text = font.render(f"Health: {int(player['health'])}", True, BLACK)
hydration_text = font.render(f"Hydration: {int(player['hydration'])}", True,
BLACK)
hunger_text = font.render(f"Hunger: {int(player['hunger'])}", True, BLACK)
resources_text = font.render(f"Resources: {player['resources']}", True, BLACK)

screen.blit(health_text, (10, 10))


screen.blit(hydration_text, (10, 40))
screen.blit(hunger_text, (10, 70))
screen.blit(resources_text, (10, 100))

# Update the display


pygame.display.flip()

# Control frame rate


clock.tick(FPS)

pygame.quit()

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy