Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

typing #59

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ 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@v4
Expand Down
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
7 changes: 3 additions & 4 deletions apps/demo/demo-stitched.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from __future__ import annotations

from pathlib import Path
from typing import List

import pygame
from pygame.locals import (
Expand Down Expand Up @@ -57,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 Expand Up @@ -174,7 +173,7 @@ def update(self, dt: float):
"""
self.group.update(dt)

def run(self):
def run(self) -> None:
clock = pygame.time.Clock()
self.running = True

Expand Down
35 changes: 19 additions & 16 deletions apps/demo/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,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 @@ -50,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,9 +91,8 @@ def draw_text(self, surface):
surface.blit(text, (0, y))
y += text.get_height()

def handle_input(self):
""" Simply handle pygame input events
"""
def handle_input(self) -> None:
"""Simply handle pygame input events"""
for event in pygame.event.get():
if event.type == QUIT:
self.running = False
Expand Down Expand Up @@ -129,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 @@ -164,21 +167,21 @@ def update(self, td):
# in a game, you would set center to a playable character
self.map_layer.center(self.center)

def run(self):
def run(self) -> None:
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 @@ -197,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
3 changes: 1 addition & 2 deletions apps/demo/translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@


class Dummy:

def run(self):
def run(self) -> None:
surface = None

for spr in self.sprites():
Expand Down
9 changes: 5 additions & 4 deletions apps/tutorial/quest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from __future__ import annotations

from pathlib import Path
from typing import List

import pygame
from pygame.locals import (
Expand Down Expand Up @@ -70,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 @@ -80,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 @@ -113,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 Expand Up @@ -220,7 +221,7 @@ def update(self, dt: float):
if sprite.feet.collidelist(self.walls) > -1:
sprite.move_back(dt)

def run(self):
def run(self) -> None:
"""
Run the game loop

Expand Down
Loading