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

9
LICENSE.txt Normal file
View file

@ -0,0 +1,9 @@
MIT License
Copyright (c) 2023-present Waylon S. Walker <waylon@waylonwalker.com>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

21
README.md Normal file
View file

@ -0,0 +1,21 @@
# Cave Survival
[![PyPI - Version](https://img.shields.io/pypi/v/cave-survival.svg)](https://pypi.org/project/cave-survival)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/cave-survival.svg)](https://pypi.org/project/cave-survival)
-----
**Table of Contents**
- [Installation](#installation)
- [License](#license)
## Installation
```console
pip install cave-survival
```
## License
`cave-survival` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.

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()

69
pyproject.toml Normal file
View file

@ -0,0 +1,69 @@
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
[project]
name = "cave-survival"
description = 'survive in a cave game'
readme = "README.md"
requires-python = ">=3.7"
license = "MIT"
keywords = []
authors = [
{ name = "Waylon S. Walker", email = "waylon@waylonwalker.com" },
]
classifiers = [
"Development Status :: 4 - Beta",
"Programming Language :: Python",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
]
dependencies = [
"debugpy",
"pygame",
"typer",
"rich",
]
dynamic = ["version"]
[project.urls]
Documentation = "https://github.com/unknown/cave-survival#readme"
Issues = "https://github.com/unknown/cave-survival/issues"
Source = "https://github.com/unknown/cave-survival"
[project.scripts]
cave-survival = "cave_survival.cli:app"
[tool.hatch.version]
path = "cave_survival/__about__.py"
[tool.hatch.envs.default]
dependencies = [
"pytest",
"pytest-cov",
]
[tool.hatch.envs.default.scripts]
cov = "pytest --cov-report=term-missing --cov-config=pyproject.toml --cov=cave_survival --cov=tests {args}"
no-cov = "cov --no-cov {args}"
[[tool.hatch.envs.test.matrix]]
python = ["37", "38", "39", "310", "311"]
[tool.coverage.run]
branch = true
parallel = true
omit = [
"cave_survival/__about__.py",
]
[tool.coverage.report]
exclude_lines = [
"no cov",
"if __name__ == .__main__.:",
"if TYPE_CHECKING:",
]

3
tests/__init__.py Normal file
View file

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