This commit is contained in:
Waylon Walker 2023-01-28 10:46:05 -06:00
commit 70332388e8
No known key found for this signature in database
GPG key ID: 66E2BF2B4190EFE4
17 changed files with 242 additions and 0 deletions

View file

@ -0,0 +1,5 @@
# SPDX-FileCopyrightText: 2023-present Waylon S. Walker <waylon@waylonwalker.com>
#
# SPDX-License-Identifier: MIT
__version__ = "0.0.1"
name = "Cave Survival"

View file

@ -0,0 +1,3 @@
# SPDX-FileCopyrightText: 2023-present Waylon S. Walker <waylon@waylonwalker.com>
#
# SPDX-License-Identifier: MIT

View file

@ -0,0 +1,9 @@
# SPDX-FileCopyrightText: 2023-present Waylon S. Walker <waylon@waylonwalker.com>
#
# SPDX-License-Identifier: MIT
import sys
if __name__ == '__main__':
from .cli import cave_survival
sys.exit(cave_survival())

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

View file

@ -0,0 +1,42 @@
# SPDX-FileCopyrightText: 2023-present Waylon S. Walker <waylon@waylonwalker.com>
#
# SPDX-License-Identifier: MIT
import debugpy
import typer
from cave_survival.console import console
from cave_survival.run import run
from ..__about__ import __version__, name
def version_callback(value: bool) -> None:
if value:
console.print(f"{__version__}")
raise typer.Exit()
app = typer.Typer(
name=name,
help="A cave survival game",
)
@app.callback(invoke_without_command=True)
def main(
version: bool = typer.Option(
False,
"--version",
callback=version_callback, # is_eager=True
),
debug: bool = typer.Option(None, "--debug", help="start with debug mode running"),
) -> None:
if debug:
print("debugging")
debugpy.listen(("localhost", 5678))
print("waiting...")
debugpy.wait_for_client()
run()
# Do other global stuff, handle other global options here
return

Binary file not shown.

3
cave_survival/console.py Normal file
View file

@ -0,0 +1,3 @@
from rich.console import Console
console = Console()

78
cave_survival/run.py Normal file
View file

@ -0,0 +1,78 @@
import pygame
def run():
# Initialize Pygame
pygame.init()
# Set the window size and caption
size = (700, 500)
caption = "Pygame Image Movement"
screen = pygame.display.set_mode(size)
pygame.display.set_caption(caption)
# Load an image and get its rectangle
image1 = pygame.image.load("cave_survival/assets/stev/1.png")
image2 = pygame.image.load("cave_survival/assets/stev/2.png")
image_rect = image1.get_rect()
# Set the initial position of the image
image_rect.x = 0
image_rect.y = 0
movement_speed = 0.5
# Set the animation speed
animation_speed = 0.005
# Set the animation frame
animation_frame = 0
# Set the movement speed
movement_speed = 0.5
# Main game loop
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
# Get the current key presses
pressed = pygame.key.get_pressed()
# Move the image based on the key presses
if pressed[pygame.K_w]:
image_rect.y -= movement_speed
if pressed[pygame.K_a]:
image_rect.x -= movement_speed
if pressed[pygame.K_s]:
image_rect.y += movement_speed
if pressed[pygame.K_d]:
image_rect.x += movement_speed
# Animate the image if the player is moving
if (
pressed[pygame.K_w] or
pressed[pygame.K_a] or
pressed[pygame.K_s] or
pressed[pygame.K_d]
):
animation_frame += animation_speed
if animation_frame >= 2:
animation_frame = 0
image_rect.x += movement_speed + 1
# Draw the image on the screen
screen.fill((0, 0, 0))
if animation_frame < 1:
screen.blit(image1, image_rect)
else:
screen.blit(image2, image_rect)
else:
screen.fill((0, 0, 0))
screen.blit(image1, image_rect)
pygame.display.flip()
# Clean up
pygame.quit()