map #3
Loading…
Reference in New Issue
There is no content yet.
Delete Branch "%!s(<nil>)"
Deleting a branch is permanent. Although the deleted branch may exist for a short time before cleaning up, in most cases it CANNOT be undone. Continue?
import pygame
import json
import csv
Initialize Pygame
pygame.init()
Load JSON data
with open('data.json') as json_file:
level_data = json.load(json_file)
Load Collisions
collisions = []
with open('Collisions.csv', 'r') as csv_file:
csv_reader = csv.reader(csv_file)
for row in csv_reader:
row_data = []
for value in row:
if value: # Check if the value is not empty
row_data.append(int(value))
else:
row_data.append(0) # Assuming non-numeric or empty values represent empty spaces
collisions.append(row_data)
Set up the display
screen_width = 1920
screen_height = 1015
screen = pygame.display.set_mode((screen_width, screen_height))
pygame.display.set_caption('Your Game Name')
Load images for layers
layers = {}
for layer in level_data["layers"]:
layers[layer] = pygame.image.load(layer).convert_alpha()
layers[layer] = pygame.transform.scale(layers[layer], (screen_width, screen_height))
Create a new surface for collisions with color black
collision_layer = pygame.Surface((screen_width, screen_height), pygame.SRCALPHA)
collision_layer.fill((0, 0, 0, 0)) # Fill the surface with transparent color
Draw rectangles for collision areas
for y, row in enumerate(collisions):
for x, value in enumerate(row):
if value == 1:
rect = pygame.Rect(x * 64, y * 80, 64, 80) # Adjust the rect dimensions based on your collision cell size
pygame.draw.rect(collision_layer, (0, 0, 0), rect)
Load image for player
player_image = pygame.image.load("Player.png").convert_alpha()
player_image = pygame.transform.scale(player_image, (32, 32)) # Adjust player size to fit the new scale
Player properties
player_rect = player_image.get_rect(topleft=(100, 100)) # Starting position of the player
Main game loop
running = True
while running:
# Handle events
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
Quit Pygame
pygame.quit()