init
This commit is contained in:
commit
70332388e8
17 changed files with 242 additions and 0 deletions
5
cave_survival/__about__.py
Normal file
5
cave_survival/__about__.py
Normal 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"
|
||||
3
cave_survival/__init__.py
Normal file
3
cave_survival/__init__.py
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
# SPDX-FileCopyrightText: 2023-present Waylon S. Walker <waylon@waylonwalker.com>
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
9
cave_survival/__main__.py
Normal file
9
cave_survival/__main__.py
Normal 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())
|
||||
BIN
cave_survival/__pycache__/__about__.cpython-310.pyc
Normal file
BIN
cave_survival/__pycache__/__about__.cpython-310.pyc
Normal file
Binary file not shown.
BIN
cave_survival/__pycache__/__init__.cpython-310.pyc
Normal file
BIN
cave_survival/__pycache__/__init__.cpython-310.pyc
Normal file
Binary file not shown.
BIN
cave_survival/__pycache__/console.cpython-310.pyc
Normal file
BIN
cave_survival/__pycache__/console.cpython-310.pyc
Normal file
Binary file not shown.
BIN
cave_survival/__pycache__/run.cpython-310.pyc
Normal file
BIN
cave_survival/__pycache__/run.cpython-310.pyc
Normal file
Binary file not shown.
BIN
cave_survival/assets/stev/1.png
Normal file
BIN
cave_survival/assets/stev/1.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.3 KiB |
BIN
cave_survival/assets/stev/2.png
Normal file
BIN
cave_survival/assets/stev/2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.3 KiB |
42
cave_survival/cli/__init__.py
Normal file
42
cave_survival/cli/__init__.py
Normal 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
|
||||
BIN
cave_survival/cli/__pycache__/__init__.cpython-310.pyc
Normal file
BIN
cave_survival/cli/__pycache__/__init__.cpython-310.pyc
Normal file
Binary file not shown.
3
cave_survival/console.py
Normal file
3
cave_survival/console.py
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
from rich.console import Console
|
||||
|
||||
console = Console()
|
||||
78
cave_survival/run.py
Normal file
78
cave_survival/run.py
Normal 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()
|
||||
Loading…
Add table
Add a link
Reference in a new issue