From 5cc46154952f19b1753e920382a55a52a6de7643 Mon Sep 17 00:00:00 2001 From: Martin Thoma Date: Sun, 26 Nov 2023 08:20:44 +0100 Subject: [PATCH] Initial commit: Project setup, main game loop, CI --- .github/dependabot.yml | 9 +++ .github/workflows/github-ci.yaml | 89 ++++++++++++++++++++++++++ .gitignore | 12 ++++ .pre-commit-config.yaml | 52 +++++++++++++++ LICENSE | 21 ++++++ Makefile | 13 ++++ README.md | 51 +++++++++++++++ docs/main-action.png | Bin 0 -> 8728 bytes jump_and_run_game/__init__.py | 106 +++++++++++++++++++++++++++++++ jump_and_run_game/_version.py | 1 + pyproject.toml | 42 ++++++++++++ requirements/ci.in | 4 ++ requirements/ci.txt | 34 ++++++++++ requirements/dev.in | 3 + requirements/dev.txt | 58 +++++++++++++++++ tests/test_main.py | 31 +++++++++ 16 files changed, 526 insertions(+) create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/github-ci.yaml create mode 100644 .gitignore create mode 100644 .pre-commit-config.yaml create mode 100644 LICENSE create mode 100644 Makefile create mode 100644 README.md create mode 100644 docs/main-action.png create mode 100644 jump_and_run_game/__init__.py create mode 100644 jump_and_run_game/_version.py create mode 100644 pyproject.toml create mode 100644 requirements/ci.in create mode 100644 requirements/ci.txt create mode 100644 requirements/dev.in create mode 100644 requirements/dev.txt create mode 100644 tests/test_main.py diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..c1d0738 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,9 @@ +# Set update schedule for GitHub Actions + +version: 2 +updates: + + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "daily" diff --git a/.github/workflows/github-ci.yaml b/.github/workflows/github-ci.yaml new file mode 100644 index 0000000..c23c2b8 --- /dev/null +++ b/.github/workflows/github-ci.yaml @@ -0,0 +1,89 @@ +name: CI + +on: + push: + branches: [ main ] + paths-ignore: + - '**/*.md' + - '**/*.rst' + pull_request: + branches: [ main ] + paths-ignore: + - '**/*.md' + - '**/*.rst' + workflow_dispatch: + +jobs: + tests: + name: pytest on ${{ matrix.python-version }} + runs-on: ubuntu-20.04 + strategy: + matrix: + python-version: ["3.8", "3.9", "3.10", "3.11"] + + steps: + - name: Checkout Code + uses: actions/checkout@v4 + with: + submodules: 'recursive' + - name: Setup Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + + - name: Upgrade pip + run: python -m pip install --upgrade pip + - name: Install requirements (Python 3) + run: pip install -r requirements/ci.txt -r requirements/dev.txt + - name: Install jump_and_run_game + run: pip install . + + - name: Run tests + run: pytest -vv + + codestyle: + name: Check code style issues + runs-on: ubuntu-20.04 + steps: + - name: Checkout Code + uses: actions/checkout@v4 + with: + submodules: 'recursive' + + - name: Upgrade pip + run: python -m pip install --upgrade pip + - name: Install requirements + run: pip install -r requirements/ci.txt + - name: Install jump_and_run_game + run: pip install . + + - name: Lint with black + run: black --check . + - name: Lint with mypy + run: mypy . --ignore-missing-imports --exclude build + - name: Test with ruff + run: | + echo `ruff --version` + ruff jump_and_run_game/ + + package: + name: Build & verify package + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v4 + with: + python-version: ${{env.PYTHON_LATEST}} + + - run: python -m pip install flit check-wheel-contents + - run: flit build + - run: ls -l dist + - run: check-wheel-contents dist/*.whl + + - name: Test installing package + run: python -m pip install . + + - name: Test running installed package + working-directory: /tmp + run: python -c "import jump_and_run_game;print(jump_and_run_game.__version__)" diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a312527 --- /dev/null +++ b/.gitignore @@ -0,0 +1,12 @@ +# Python cache files +*.pyc +__pycache__/ + +# pyenv: Used to define which version of Python is used locally +.python-version + +# direnv +.envrc + +# temporary files created by flit +dist diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..fcb8c4a --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,52 @@ +# pre-commit run --all-files +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.5.0 + hooks: + - id: check-ast + - id: check-byte-order-marker + - id: check-case-conflict + - id: check-docstring-first + - id: check-yaml + - id: debug-statements + - id: end-of-file-fixer + exclude: "resources/.*|docs/make.bat" + - id: trailing-whitespace + - id: mixed-line-ending + args: ['--fix=lf'] + exclude: "docs/make.bat" + - id: check-added-large-files + args: ['--maxkb=1000'] +- repo: https://github.com/psf/black + rev: 23.11.0 + hooks: + - id: black + args: [--target-version, py36] +- repo: https://github.com/asottile/blacken-docs + rev: 1.16.0 + hooks: + - id: blacken-docs + additional_dependencies: [black==22.1.0] + exclude: "docs/user/robustness.md" +- repo: https://github.com/charliermarsh/ruff-pre-commit + rev: v0.1.6 + hooks: + - id: ruff + args: ['--fix'] +- repo: https://github.com/asottile/pyupgrade + rev: v3.15.0 + hooks: + - id: pyupgrade + args: [--py38-plus] +- repo: https://github.com/pycqa/flake8 + rev: 6.1.0 + hooks: + - id: flake8 + args: ["--ignore", "E,W,F"] + +- repo: https://github.com/pre-commit/mirrors-mypy + rev: 'v1.7.1' + hooks: + - id: mypy + additional_dependencies: [types-Pillow==10.0.0.2] + files: ^jump_and_run_game/.* diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..1100d74 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 Martin Thoma + +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. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..b601612 --- /dev/null +++ b/Makefile @@ -0,0 +1,13 @@ +maint: + pre-commit autoupdate + pip-compile -U requirements/ci.in + pip-compile -U requirements/dev.in + +upload: + flit publish + +install: + pip install -e . + +start: + jump_and_run_game diff --git a/README.md b/README.md new file mode 100644 index 0000000..3993175 --- /dev/null +++ b/README.md @@ -0,0 +1,51 @@ +# Your Jump-and-Run Game + +Welcome to `jump_and_run_game` – a fun and exciting jump-and-run game developed +in Python! + +## Overview + +It's really just a simple Jump- and Run game: 2D, jumping ... and walking. +Let's be honest, it's not running so far. + +## Table of Contents + +- [Installation](#installation) +- [Usage](#usage) +- [Controls](#controls) +- [Contributing](#contributing) + +## Installation + +1. Ensure you have Python 3.8 or later installed. + +2. Install dependencies: + + ```bash + pip install jump_and_run_game + ``` + +## Usage + +To play the game, run the following command: + +```bash +jump_and_run_game +``` + +This is how it looks like at the moment: + +![](docs/main-action.png) + +## Controls + +* Left Arrow: Move the player left. +* Right Arrow: Move the player right. +* Space: Make the player jump. + +## Contributing + +If you'd like to contribute to the project, feel free to open issues or add PRs. + +It's typically wise to open an issue first and wait for feedback, before adding +tons of code that might get rejected. diff --git a/docs/main-action.png b/docs/main-action.png new file mode 100644 index 0000000000000000000000000000000000000000..d2ccdb803cc6d9b11fcdaf818c4b5a78f3e705c1 GIT binary patch literal 8728 zcmeHNXN`)DM%#g_{R9Y>h zN+1XrVo4(sAV3(x6au15VGtPtge1&?3LU?E-H@5UbmF}Vu`d}V^5iXwC#HSzpFwq|}UZhC8O(L)&eX%FE1 zSJ77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4^#sL)}0-#)QoiyBKy0ZS#5U!X+m4s^vB}cmCk7A2 z_I)<}=5elPvqQ&lOmYM3sXREHQ7GRFm>224PgMM56S}j@fn5)d9^DVopX~syxO;t1 Jxp?#E{|4XJKg<9C literal 0 HcmV?d00001 diff --git a/jump_and_run_game/__init__.py b/jump_and_run_game/__init__.py new file mode 100644 index 0000000..5e89fba --- /dev/null +++ b/jump_and_run_game/__init__.py @@ -0,0 +1,106 @@ +from ._version import __version__ +from os import environ +import sys + +environ["PYGAME_HIDE_SUPPORT_PROMPT"] = "1" + +__all__ = [ + "__version__", +] + +import pygame # noqa: E402 + + +# Constants +WIDTH, HEIGHT = 800, 600 +FPS = 60 + +# Colors +WHITE = (255, 255, 255) +BLACK = (0, 0, 0) + + +class Player: + JUMP_HEIGHT = 10 + + def __init__(self, x, y): + self.x = x + self.y = y + self.speed = 5 + self.jump_count = Player.JUMP_HEIGHT + self.is_jumping = False + self.width = 50 + self.height = 50 + + def move_left(self) -> None: + self.x -= self.speed + + def move_right(self) -> None: + self.x += self.speed + + def jump(self) -> None: + if not self.is_jumping: + self.is_jumping = True + + def update(self) -> None: + if self.is_jumping: + if self.jump_count >= -Player.JUMP_HEIGHT: + neg = 1 + if self.jump_count < 0: + neg = -1 + self.y -= (self.jump_count**2) * 0.5 * neg + self.jump_count -= 1 + else: + self.is_jumping = False + self.jump_count = Player.JUMP_HEIGHT + + def render(self, screen: pygame.surface.Surface) -> None: + pygame.draw.rect(screen, BLACK, (self.x, self.y, self.width, self.height)) + + +def core_game_loop( + screen: pygame.surface.Surface, clock: pygame.time.Clock, player: Player +) -> None: + # Handle events + for event in pygame.event.get(): + if event.type == pygame.QUIT: + pygame.quit() + sys.exit() + + # Handle user input + keys = pygame.key.get_pressed() + if keys[pygame.K_LEFT] and player.x > 0: + player.move_left() + if keys[pygame.K_RIGHT] and player.x < WIDTH - 50: + player.move_right() + if keys[pygame.K_SPACE]: + player.jump() + + # Update game state + player.update() + + # Render graphics + screen.fill(WHITE) + player.render(screen) + + pygame.display.flip() + clock.tick(FPS) + + +def main(): + pygame.init() + + # Setup the window + screen = pygame.display.set_mode((WIDTH, HEIGHT)) + pygame.display.set_caption("Jump and Run Game") + + # Create core objects + clock = pygame.time.Clock() + player = Player(50, HEIGHT - 100) + + while True: + core_game_loop(screen, clock, player) + + +if __name__ == "__main__": + main() diff --git a/jump_and_run_game/_version.py b/jump_and_run_game/_version.py new file mode 100644 index 0000000..f102a9c --- /dev/null +++ b/jump_and_run_game/_version.py @@ -0,0 +1 @@ +__version__ = "0.0.1" diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..81a173d --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,42 @@ +[project] +name = "jump_and_run_game" +description = "A simple jump-and-run game in Python" +authors = [{name = "Martin Thoma", email="info@martin-thoma.de"}] +readme = "README.md" +dynamic = ["version"] +license = { file = "LICENSE" } +classifiers = [ + "Development Status :: 1 - Planning", + "Environment :: Other Environment", + "Intended Audience :: End Users/Desktop", + "License :: OSI Approved :: MIT License", + "Natural Language :: English", + "Operating System :: OS Independent", + "Programming Language :: Python :: 3 :: Only", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3", + "Topic :: Games/Entertainment :: Side-Scrolling/Arcade Games", + "Topic :: Games/Entertainment", + "Topic :: Software Development :: Libraries :: pygame", +] + +dependencies = [ + "pygame", +] +requires-python = ">=3.8" + +[project.scripts] +jump_and_run_game = "jump_and_run_game:main" + +[project.urls] +Source = "https://github.com/MartinThoma/jump_and_run_game" + +[build-system] +requires = ["flit_core >=3.2,<4"] +build-backend = "flit_core.buildapi" + +[tool.flit.sdist] +exclude = ["requirements", ".github/*", ".envrc", "Makefile", ".pre-commit-config.yaml"] diff --git a/requirements/ci.in b/requirements/ci.in new file mode 100644 index 0000000..fe90326 --- /dev/null +++ b/requirements/ci.in @@ -0,0 +1,4 @@ +black +mypy +pytest +ruff diff --git a/requirements/ci.txt b/requirements/ci.txt new file mode 100644 index 0000000..43d59f0 --- /dev/null +++ b/requirements/ci.txt @@ -0,0 +1,34 @@ +# +# This file is autogenerated by pip-compile with Python 3.11 +# by the following command: +# +# pip-compile --config=pyproject.toml requirements/ci.in +# +black==23.11.0 + # via -r requirements/ci.in +click==8.1.7 + # via black +iniconfig==2.0.0 + # via pytest +mypy==1.7.1 + # via -r requirements/ci.in +mypy-extensions==1.0.0 + # via + # black + # mypy +packaging==23.2 + # via + # black + # pytest +pathspec==0.11.2 + # via black +platformdirs==4.0.0 + # via black +pluggy==1.3.0 + # via pytest +pytest==7.4.3 + # via -r requirements/ci.in +ruff==0.1.6 + # via -r requirements/ci.in +typing-extensions==4.8.0 + # via mypy diff --git a/requirements/dev.in b/requirements/dev.in new file mode 100644 index 0000000..f99ae91 --- /dev/null +++ b/requirements/dev.in @@ -0,0 +1,3 @@ +flit +pre-commit +pip-tools diff --git a/requirements/dev.txt b/requirements/dev.txt new file mode 100644 index 0000000..bc302b5 --- /dev/null +++ b/requirements/dev.txt @@ -0,0 +1,58 @@ +# +# This file is autogenerated by pip-compile with Python 3.11 +# by the following command: +# +# pip-compile --config=pyproject.toml requirements/dev.in +# +build==1.0.3 + # via pip-tools +certifi==2023.11.17 + # via requests +cfgv==3.4.0 + # via pre-commit +charset-normalizer==3.3.2 + # via requests +click==8.1.7 + # via pip-tools +distlib==0.3.7 + # via virtualenv +docutils==0.20.1 + # via flit +filelock==3.13.1 + # via virtualenv +flit==3.9.0 + # via -r requirements/dev.in +flit-core==3.9.0 + # via flit +identify==2.5.32 + # via pre-commit +idna==3.6 + # via requests +nodeenv==1.8.0 + # via pre-commit +packaging==23.2 + # via build +pip-tools==7.3.0 + # via -r requirements/dev.in +platformdirs==4.0.0 + # via virtualenv +pre-commit==3.5.0 + # via -r requirements/dev.in +pyproject-hooks==1.0.0 + # via build +pyyaml==6.0.1 + # via pre-commit +requests==2.31.0 + # via flit +tomli-w==1.0.0 + # via flit +urllib3==2.1.0 + # via requests +virtualenv==20.24.7 + # via pre-commit +wheel==0.41.3 + # via pip-tools + +# The following packages are considered to be unsafe in a requirements file: +# pip +# setuptools diff --git a/tests/test_main.py b/tests/test_main.py new file mode 100644 index 0000000..d930a9a --- /dev/null +++ b/tests/test_main.py @@ -0,0 +1,31 @@ +from jump_and_run_game import Player + + +def test_player_movements(): + # Arrange + player = Player(0, 0) + + # Act + player.move_left() + player.move_right() + + # Assert + assert player.x == 0 + assert player.y == 0 + + +def test_player_jump(): + # Arrange + player = Player(0, 0) + assert player.is_jumping is False + + # Act + player.jump() + + # Assert + assert player.is_jumping is True + + +def test_player_update(): + player = Player(0, 0) + player.update()