From b9573deb7585c6ffceb88c7c89701c0c1b56b3a9 Mon Sep 17 00:00:00 2001 From: "Waylon S. Walker" Date: Sun, 23 Nov 2025 11:30:10 -0600 Subject: [PATCH] wip --- game.py | 93 ++++++++++++++++++++++++++++++++++++++++++++++++ map.py | 24 +++++++++++++ pyproject.toml | 1 + requirements.txt | 28 +++++++++++++++ voxels.py | 52 +++++++++++++++++++++++++++ 5 files changed, 198 insertions(+) create mode 100644 game.py create mode 100644 map.py create mode 100644 requirements.txt create mode 100644 voxels.py diff --git a/game.py b/game.py new file mode 100644 index 0000000..bb566fd --- /dev/null +++ b/game.py @@ -0,0 +1,93 @@ +import sys + +import pygame + +from map import generate_map + +pygame.init() + +screen_width = 800 +screen_height = 600 +screen = pygame.display.set_mode((screen_width, screen_height)) +clock = pygame.time.Clock() + +player_skin = pygame.image.load("player.png") +# load the player image +player_image = pygame.image.load("player.png").convert_alpha() + +# set the size of the hitbox +hitbox_width = 16 +hitbox_height = 32 + +# create a surface to draw the hitbox on +hitbox_surface = pygame.Surface((hitbox_width, hitbox_height), pygame.SRCALPHA) + +# draw the hitbox outline +outline_color = (255, 0, 0) # red outline color +outline_width = 5 # outline width in pixels +pygame.draw.rect( + hitbox_surface, outline_color, hitbox_surface.get_rect(), outline_width +) + +# scale the player image to the size of the hitbox +player_skin = pygame.transform.scale(player_image, (hitbox_width, hitbox_height)) +player_x = 0 +player_y = 0 +player_speed = 5 +player_direction = "right" + +map_data = generate_map(screen_width * 5, screen_height) + +while True: + for event in pygame.event.get(): + if event.type == pygame.QUIT: + pygame.quit() + sys.exit() + + keys = pygame.key.get_pressed() + + if keys[pygame.K_LEFT]: + player_x -= player_speed + + if keys[pygame.K_RIGHT]: + player_x += player_speed + + if keys[pygame.K_DOWN]: + # Handle crouching + ... + + if keys[pygame.K_SPACE]: + # Handle jumping + ... + + if keys[pygame.K_LSHIFT]: + # Handle running + ... + + # Handle aiming and firing the grapple hook using Pygame's mouse functions + + screen.fill((255, 255, 255)) + + # Draw the map using the map_data generated with perlin noise + tile_size = 16 + for y, row in enumerate(map_data): + for x, noise_value in enumerate(row): + if noise_value > 0.3: + pygame.draw.rect( + screen, + (0, 0, 0), + (x * tile_size, y * tile_size, tile_size, tile_size), + ) + + # Draw the player's skin and hitbox on the screen + screen.blit(player_skin, (player_x, player_y)) + # pygame.draw.rect( + # screen, (255, 0, 0, 128), (player_x, player_y, hitbox_width, hitbox_height) + # ) + + # blit the hitbox surface onto the player surface + player_surface = pygame.Surface((hitbox_width, hitbox_height), pygame.SRCALPHA) + player_surface.blit(hitbox_surface, (0, 0)) + + pygame.display.update() + clock.tick(60) diff --git a/map.py b/map.py new file mode 100644 index 0000000..8c3282e --- /dev/null +++ b/map.py @@ -0,0 +1,24 @@ +import noise + + +def generate_map(width, height): + scale = 20.0 + octaves = 3 + persistence = 0.5 + lacunarity = 2.0 + map_data = [] + for i in range(width): + column = [] + for j in range(height): + noise_value = 0 + frequency = 1.0 + amplitude = 1.0 + for k in range(octaves): + noise_value += amplitude * noise.snoise2( + i / scale * frequency, j / scale * frequency + ) + frequency *= lacunarity + amplitude *= persistence + column.append(noise_value) + map_data.append(column) + return map_data diff --git a/pyproject.toml b/pyproject.toml index 581d051..7568c3d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -26,6 +26,7 @@ classifiers = [ dependencies = [ "debugpy", "pygame", + "pyopengl", "typer", "rich", "pydantic", diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..923ae06 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,28 @@ +# +# This file is autogenerated by pip-compile with Python 3.10 +# by the following command: +# +# pip-compile pyproject.toml +# +click==8.1.3 + # via typer +debugpy==1.6.6 + # via cave-survival (pyproject.toml) +markdown-it-py==2.2.0 + # via rich +mdurl==0.1.2 + # via markdown-it-py +noise==1.2.2 + # via cave-survival (pyproject.toml) +pydantic==1.10.6 + # via cave-survival (pyproject.toml) +pygame==2.3.0 + # via cave-survival (pyproject.toml) +pygments==2.14.0 + # via rich +rich==13.3.2 + # via cave-survival (pyproject.toml) +typer==0.7.0 + # via cave-survival (pyproject.toml) +typing-extensions==4.5.0 + # via pydantic diff --git a/voxels.py b/voxels.py new file mode 100644 index 0000000..403917e --- /dev/null +++ b/voxels.py @@ -0,0 +1,52 @@ +import pygame +from pygame.locals import * +from OpenGL.GL import * +from OpenGL.GLU import * + +# Set up the dimensions of the window +window_width, window_height = 800, 600 + +# Initialize Pygame +pygame.init() +pygame.display.set_mode((window_width, window_height), DOUBLEBUF | OPENGL) + +# Set up the perspective view +gluPerspective(45, (window_width / window_height), 0.1, 50.0) + +# Move the camera backward to view the scene +glTranslatef(0.0, 0.0, -5) + +# Main game loop +while True: + for event in pygame.event.get(): + if event.type == pygame.QUIT: + pygame.quit() + quit() + + # Keyboard input + keys = pygame.key.get_pressed() + if keys[pygame.K_s]: + glRotatef(1, 0, 1, 0) + if keys[pygame.K_d]: + glRotatef(-1, 0, 1, 0) + if keys[pygame.K_w]: + glRotatef(1, 1, 0, 0) + if keys[pygame.K_d]: + glRotatef(-1, 1, 0, 0) + + # Clear the screen and draw the cubes + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) + + # Draw your 3D voxel grid here + glBegin(GL_QUADS) + # Example: Draw a simple 1x1x1 cube at (0, 0, 0) + glColor3f(1, 0, 0) + glVertex3f(-0.5, -0.5, -0.5) + glVertex3f(0.5, -0.5, -0.5) + glVertex3f(0.5, 0.5, -0.5) + glVertex3f(-0.5, 0.5, -0.5) + glEnd() + + # Update the display + pygame.display.flip() + pygame.time.wait(10)