Skip to content

Commit

Permalink
typing
Browse files Browse the repository at this point in the history
  • Loading branch information
JaskRendix committed Jan 14, 2024
1 parent 7ce82e4 commit fda29d5
Show file tree
Hide file tree
Showing 20 changed files with 1,025 additions and 453 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ '3.7', '3.8', '3.9' ]
python-version: ['3.9', '3.10', '3.11', '3.12']
name: Python ${{ matrix.python-version }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
architecture: x64
Expand Down
675 changes: 675 additions & 0 deletions LICENSE.txt

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
prune .github
exclude .gitignore
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pyscroll
========

For Python 3.7+ and pygame 2.0+
For Python 3.9+ and pygame 2.0+

__pygame-ce is supported__

Expand Down
17 changes: 9 additions & 8 deletions apps/demo/demo-stitched.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,21 @@
from __future__ import annotations

from pathlib import Path
from typing import List

import pygame
from pygame.locals import (
K_UP,
K_DOWN,
K_LEFT,
K_RIGHT,
K_MINUS,
K_EQUALS,
K_ESCAPE,
K_LEFT,
K_MINUS,
K_RIGHT,
K_UP,
KEYDOWN,
QUIT,
VIDEORESIZE,
K_r,
)
from pygame.locals import KEYDOWN, VIDEORESIZE, QUIT
from pytmx.util_pygame import load_pygame

import pyscroll
Expand Down Expand Up @@ -55,11 +56,11 @@ def __init__(self) -> None:
self.feet = pygame.Rect(0, 0, self.rect.width * 0.5, 8)

@property
def position(self) -> List[float]:
def position(self) -> list[float]:
return list(self._position)

@position.setter
def position(self, value: List[float]) -> None:
def position(self, value: list[float]) -> None:
self._position = list(value)

def update(self, dt: float) -> None:
Expand Down
40 changes: 22 additions & 18 deletions apps/demo/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
See the "Quest" tutorial for a more simple use with
pygame sprites and groups.
"""
from pytmx.util_pygame import load_pygame
import pygame
import pyscroll
import pyscroll.data
import collections
import logging

import pygame
from pygame.locals import *
from pytmx.util_pygame import load_pygame

import pyscroll
import pyscroll.data
import pyscroll.orthographic

logger = logging.getLogger(__name__)
Expand All @@ -35,11 +36,12 @@ def init_screen(width, height):


class ScrollTest:
""" Test and demo of pyscroll
"""Test and demo of pyscroll
For normal use, please see the quest demo, not this.
"""

def __init__(self, filename):

# load data from pytmx
Expand All @@ -49,19 +51,22 @@ def __init__(self, filename):
map_data = pyscroll.data.TiledMapData(tmx_data)

# create new renderer
self.map_layer = pyscroll.orthographic.BufferedRenderer(map_data, screen.get_size())
self.map_layer = pyscroll.orthographic.BufferedRenderer(
map_data, screen.get_size()
)

# create a font and pre-render some text to be displayed over the map
f = pygame.font.Font(pygame.font.get_default_font(), 20)
t = ["scroll demo. press escape to quit",
"arrow keys move"]
t = ["scroll demo. press escape to quit", "arrow keys move"]

# save the rendered text
self.text_overlay = [f.render(i, 1, (180, 180, 0)) for i in t]

# set our initial viewpoint in the center of the map
self.center = [self.map_layer.map_rect.width / 2,
self.map_layer.map_rect.height / 2]
self.center = [
self.map_layer.map_rect.width / 2,
self.map_layer.map_rect.height / 2,
]

# the camera vector is used to handle camera movement
self.camera_acc = [0, 0, 0]
Expand All @@ -87,8 +92,7 @@ def draw_text(self, surface):
y += text.get_height()

def handle_input(self):
""" Simply handle pygame input events
"""
"""Simply handle pygame input events"""
for event in pygame.event.get():
if event.type == QUIT:
self.running = False
Expand Down Expand Up @@ -128,7 +132,7 @@ def handle_input(self):
def update(self, td):
self.last_update_time = td

friction = pow(.0001, self.last_update_time)
friction = pow(0.0001, self.last_update_time)

# update the camera vector
self.camera_vel[0] += self.camera_acc[0] * td
Expand Down Expand Up @@ -166,18 +170,18 @@ def update(self, td):
def run(self):
clock = pygame.time.Clock()
self.running = True
fps = 60.
fps = 60.0
fps_log = collections.deque(maxlen=20)

try:
while self.running:
# somewhat smoother way to get fps and limit the framerate
clock.tick(fps*2)
clock.tick(fps * 2)

try:
fps_log.append(clock.get_fps())
fps = sum(fps_log)/len(fps_log)
dt = 1/fps
fps = sum(fps_log) / len(fps_log)
dt = 1 / fps
except ZeroDivisionError:
continue

Expand All @@ -196,7 +200,7 @@ def run(self):
pygame.init()
pygame.font.init()
screen = init_screen(800, 600)
pygame.display.set_caption('pyscroll Test')
pygame.display.set_caption("pyscroll Test")

try:
filename = sys.argv[1]
Expand Down
1 change: 0 additions & 1 deletion apps/demo/translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@


class Dummy:

def run(self):
surface = None

Expand Down
22 changes: 17 additions & 5 deletions apps/tutorial/quest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,21 @@
from __future__ import annotations

from pathlib import Path
from typing import List

import pygame
from pygame.locals import K_UP, K_DOWN, K_LEFT, K_RIGHT, K_MINUS, K_EQUALS, K_ESCAPE, K_r
from pygame.locals import KEYDOWN, VIDEORESIZE, QUIT
from pygame.locals import (
K_DOWN,
K_EQUALS,
K_ESCAPE,
K_LEFT,
K_MINUS,
K_RIGHT,
K_UP,
KEYDOWN,
QUIT,
VIDEORESIZE,
K_r,
)
from pytmx.util_pygame import load_pygame

import pyscroll
Expand Down Expand Up @@ -59,6 +69,7 @@ class Hero(pygame.sprite.Sprite):
it collides with level walls.
"""

def __init__(self) -> None:
super().__init__()
self.image = load_image("hero.png").convert_alpha()
Expand All @@ -69,11 +80,11 @@ def __init__(self) -> None:
self.feet = pygame.Rect(0, 0, self.rect.width * 0.5, 8)

@property
def position(self) -> List[float]:
def position(self) -> list[float]:
return list(self._position)

@position.setter
def position(self, value: List[float]) -> None:
def position(self, value: list[float]) -> None:
self._position = list(value)

def update(self, dt: float) -> None:
Expand Down Expand Up @@ -102,6 +113,7 @@ class QuestGame:
Finally, it uses a pyscroll group to render the map and Hero.
"""

map_path = RESOURCES_DIR / "grasslands.tmx"

def __init__(self, screen: pygame.Surface) -> None:
Expand Down
Loading

0 comments on commit fda29d5

Please sign in to comment.