.
This commit is contained in:
+175
@@ -0,0 +1,175 @@
|
|||||||
|
# ---> Python
|
||||||
|
# Byte-compiled / optimized / DLL files
|
||||||
|
__pycache__/
|
||||||
|
*.py[cod]
|
||||||
|
*$py.class
|
||||||
|
|
||||||
|
# C extensions
|
||||||
|
*.so
|
||||||
|
|
||||||
|
# Distribution / packaging
|
||||||
|
.Python
|
||||||
|
build/
|
||||||
|
develop-eggs/
|
||||||
|
dist/
|
||||||
|
downloads/
|
||||||
|
eggs/
|
||||||
|
.eggs/
|
||||||
|
lib/
|
||||||
|
lib64/
|
||||||
|
parts/
|
||||||
|
sdist/
|
||||||
|
var/
|
||||||
|
wheels/
|
||||||
|
share/python-wheels/
|
||||||
|
*.egg-info/
|
||||||
|
.installed.cfg
|
||||||
|
*.egg
|
||||||
|
MANIFEST
|
||||||
|
|
||||||
|
# PyInstaller
|
||||||
|
# Usually these files are written by a python script from a template
|
||||||
|
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
||||||
|
*.manifest
|
||||||
|
*.spec
|
||||||
|
|
||||||
|
# Installer logs
|
||||||
|
pip-log.txt
|
||||||
|
pip-delete-this-directory.txt
|
||||||
|
|
||||||
|
# Unit test / coverage reports
|
||||||
|
htmlcov/
|
||||||
|
.tox/
|
||||||
|
.nox/
|
||||||
|
.coverage
|
||||||
|
.coverage.*
|
||||||
|
.cache
|
||||||
|
nosetests.xml
|
||||||
|
coverage.xml
|
||||||
|
*.cover
|
||||||
|
*.py,cover
|
||||||
|
.hypothesis/
|
||||||
|
.pytest_cache/
|
||||||
|
cover/
|
||||||
|
|
||||||
|
# Translations
|
||||||
|
*.mo
|
||||||
|
*.pot
|
||||||
|
|
||||||
|
# Django stuff:
|
||||||
|
*.log
|
||||||
|
local_settings.py
|
||||||
|
db.sqlite3
|
||||||
|
db.sqlite3-journal
|
||||||
|
|
||||||
|
# Flask stuff:
|
||||||
|
instance/
|
||||||
|
.webassets-cache
|
||||||
|
|
||||||
|
# Scrapy stuff:
|
||||||
|
.scrapy
|
||||||
|
|
||||||
|
# Sphinx documentation
|
||||||
|
docs/_build/
|
||||||
|
|
||||||
|
# PyBuilder
|
||||||
|
.pybuilder/
|
||||||
|
target/
|
||||||
|
|
||||||
|
# Jupyter Notebook
|
||||||
|
.ipynb_checkpoints
|
||||||
|
|
||||||
|
# IPython
|
||||||
|
profile_default/
|
||||||
|
ipython_config.py
|
||||||
|
|
||||||
|
# pyenv
|
||||||
|
# For a library or package, you might want to ignore these files since the code is
|
||||||
|
# intended to run in multiple environments; otherwise, check them in:
|
||||||
|
# .python-version
|
||||||
|
|
||||||
|
# pipenv
|
||||||
|
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
||||||
|
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
||||||
|
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
||||||
|
# install all needed dependencies.
|
||||||
|
#Pipfile.lock
|
||||||
|
|
||||||
|
# UV
|
||||||
|
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
||||||
|
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
||||||
|
# commonly ignored for libraries.
|
||||||
|
#uv.lock
|
||||||
|
|
||||||
|
# poetry
|
||||||
|
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
||||||
|
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
||||||
|
# commonly ignored for libraries.
|
||||||
|
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
||||||
|
#poetry.lock
|
||||||
|
|
||||||
|
# pdm
|
||||||
|
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
||||||
|
#pdm.lock
|
||||||
|
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
||||||
|
# in version control.
|
||||||
|
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
|
||||||
|
.pdm.toml
|
||||||
|
.pdm-python
|
||||||
|
.pdm-build/
|
||||||
|
|
||||||
|
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
||||||
|
__pypackages__/
|
||||||
|
|
||||||
|
# Celery stuff
|
||||||
|
celerybeat-schedule
|
||||||
|
celerybeat.pid
|
||||||
|
|
||||||
|
# SageMath parsed files
|
||||||
|
*.sage.py
|
||||||
|
|
||||||
|
# Environments
|
||||||
|
.env
|
||||||
|
.venv
|
||||||
|
env/
|
||||||
|
venv/
|
||||||
|
ENV/
|
||||||
|
env.bak/
|
||||||
|
venv.bak/
|
||||||
|
|
||||||
|
# Spyder project settings
|
||||||
|
.spyderproject
|
||||||
|
.spyproject
|
||||||
|
|
||||||
|
# Rope project settings
|
||||||
|
.ropeproject
|
||||||
|
|
||||||
|
# mkdocs documentation
|
||||||
|
/site
|
||||||
|
|
||||||
|
# mypy
|
||||||
|
.mypy_cache/
|
||||||
|
.dmypy.json
|
||||||
|
dmypy.json
|
||||||
|
|
||||||
|
# Pyre type checker
|
||||||
|
.pyre/
|
||||||
|
|
||||||
|
# pytype static type analyzer
|
||||||
|
.pytype/
|
||||||
|
|
||||||
|
# Cython debug symbols
|
||||||
|
cython_debug/
|
||||||
|
|
||||||
|
# PyCharm
|
||||||
|
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
||||||
|
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
||||||
|
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
||||||
|
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||||
|
#.idea/
|
||||||
|
|
||||||
|
# Ruff stuff:
|
||||||
|
.ruff_cache/
|
||||||
|
|
||||||
|
# PyPI configuration file
|
||||||
|
.pypirc
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2026 henri.vielhaben
|
||||||
|
|
||||||
|
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.
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
```mermaid
|
||||||
|
classDiagram
|
||||||
|
Item
|
||||||
|
Item : count: int
|
||||||
|
Item : type: int
|
||||||
|
Item : inc(self, amount)
|
||||||
|
|
||||||
|
Kart
|
||||||
|
Kart : int speed_max
|
||||||
|
Kart : Vector2 vel
|
||||||
|
Kart : Vector2 pos
|
||||||
|
Kart : string color
|
||||||
|
Kart : ram(self, Kart other)
|
||||||
|
Kart : consume_item(self, Item item)
|
||||||
|
```
|
||||||
|
|
||||||
|
Die Methode `inc(amount)` in `Item` ändert `.count` um `amount`.
|
||||||
|
Die Methode `ram(other)` in `Kart` tauscht die beiden Geschwindigkeiten.
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
classDiagram
|
||||||
|
Item
|
||||||
|
Item : int count
|
||||||
|
Item : int type
|
||||||
|
Item : inc(self, amount)
|
||||||
|
|
||||||
|
Kart
|
||||||
|
Kart : int speed_max
|
||||||
|
Kart : string color
|
||||||
|
Kart : ram(self, Kart other)
|
||||||
|
Kart : consume_item(self, Item item)
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
import pygame
|
||||||
|
|
||||||
|
class Input:
|
||||||
|
def __init__(self):
|
||||||
|
self.left: bool = False
|
||||||
|
self.right: bool = True
|
||||||
|
self.down: bool = False
|
||||||
|
self.up: bool = False
|
||||||
|
self.close: bool = False
|
||||||
|
|
||||||
|
def poll(self) -> None:
|
||||||
|
events = pygame.event.get()
|
||||||
|
for event in events:
|
||||||
|
if event.type == pygame.QUIT:
|
||||||
|
self.close = True
|
||||||
|
if event.type == pygame.KEYDOWN:
|
||||||
|
if event.key == pygame.K_LEFT:
|
||||||
|
self.left = True
|
||||||
|
if event.key == pygame.K_RIGHT:
|
||||||
|
self.right = True
|
||||||
|
if event.key == pygame.K_UP:
|
||||||
|
self.up = True
|
||||||
|
if event.key == pygame.K_DOWN:
|
||||||
|
self.down = True
|
||||||
|
if event.type == pygame.KEYUP:
|
||||||
|
if event.key == pygame.K_LEFT:
|
||||||
|
self.left = True
|
||||||
|
if event.key == pygame.K_RIGHT:
|
||||||
|
self.right = True
|
||||||
|
if event.key == pygame.K_UP:
|
||||||
|
self.up = True
|
||||||
|
if event.key == pygame.K_DOWN:
|
||||||
|
self.down = True
|
||||||
|
|
||||||
|
def horizontal(self) -> float:
|
||||||
|
return self.right - self.left
|
||||||
|
|
||||||
|
def vertical(self) -> float:
|
||||||
|
return self.down - self.up
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
ITEM_MUSHROOM = 0
|
||||||
|
ITEM_BANANA = 1
|
||||||
|
|
||||||
|
|
||||||
|
class Item:
|
||||||
|
def __init__(self):
|
||||||
|
self.kind = 0
|
||||||
|
self.count = 0
|
||||||
|
|
||||||
|
def inc(self, value):
|
||||||
|
self.count += value
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
from typing import Self, override
|
||||||
|
|
||||||
|
import items
|
||||||
|
import pygame
|
||||||
|
from input import Input
|
||||||
|
from items import Item
|
||||||
|
from pygame.math import clamp
|
||||||
|
|
||||||
|
Vec2 = pygame.Vector2
|
||||||
|
|
||||||
|
class Kart:
|
||||||
|
def __init__(self, name: str, pos: Vec2, vel: Vec2, dir: float, speed_max: float):
|
||||||
|
self.name: str = name
|
||||||
|
self.pos: Vec2 = pos
|
||||||
|
self.vel: Vec2 = vel
|
||||||
|
self.dir: float = dir
|
||||||
|
self.speed_max: float = speed_max
|
||||||
|
|
||||||
|
@override
|
||||||
|
def __str__(self) -> str:
|
||||||
|
return f"Kart {{ name: {self.name}, pos: {self.pos}, vel: {self.vel}, dir: {self.dir}, speed_max: {self.speed_max}}}"
|
||||||
|
|
||||||
|
def tick(self, input: Input):
|
||||||
|
input_x = input.horizontal()
|
||||||
|
input_y = input.vertical()
|
||||||
|
assert abs(input_x) < 1
|
||||||
|
assert abs(input_y) < 1
|
||||||
|
|
||||||
|
acc_amount = input_y * 2
|
||||||
|
self.vel += Vec2(acc_amount, 0).rotate(self.dir)
|
||||||
|
steer = input_x * 2
|
||||||
|
self.dir += steer
|
||||||
|
|
||||||
|
self.vel.clamp_magnitude_ip(self.speed_max)
|
||||||
|
self.pos += self.vel
|
||||||
|
|
||||||
|
def ram(self, other: Self):
|
||||||
|
"""
|
||||||
|
swap the two kart's velocities (not physically accurate)
|
||||||
|
"""
|
||||||
|
temp = self.vel
|
||||||
|
self.vel = other.vel
|
||||||
|
other.vel = temp
|
||||||
|
|
||||||
|
def consume_item(self, item: Item):
|
||||||
|
if item.kind == items.ITEM_BANANA:
|
||||||
|
self.speed_max += 1
|
||||||
|
elif item.kind == items.ITEM_BANANA:
|
||||||
|
self.speed_max -= 1
|
||||||
|
|
||||||
|
self.speed_max = clamp(self.speed_max, 0, 100)
|
||||||
Reference in New Issue
Block a user