Issues (13)

src/app.py (11 issues)

1
from typing import Set
0 ignored issues
show
Missing module docstring
Loading history...
2
3
import pygame
4
5
from . import FPS_LIMIT, TITLE, screen, viewport, SCREEN_SIZE
6
from .classes.camera import camera
7
from .classes.tiles import Tiles
8
9
10
class App:
0 ignored issues
show
Missing class docstring
Loading history...
11
12
    def __init__(self) -> None:
13
        self.clock: pygame.time.Clock = pygame.time.Clock()
14
        self.is_running: bool = True
15
16
        self.debug = False
17
        self.fps_limit = FPS_LIMIT
18
19
        self.pressed: Set[int] = set()
20
        self.tiles = Tiles(16, 13)
21
22
    def handle_event(self, event: pygame.event.Event) -> None:
0 ignored issues
show
Missing function or method docstring
Loading history...
23
        if event.type == pygame.QUIT:
0 ignored issues
show
The Module pygame does not seem to have a member named QUIT.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
24
            self.is_running = False
25
26
        elif event.type == pygame.KEYDOWN:
0 ignored issues
show
The Module pygame does not seem to have a member named KEYDOWN.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
27
            self.pressed.add(event.key)
28
29
            if event.key == pygame.K_f:
0 ignored issues
show
The Module pygame does not seem to have a member named K_f.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
30
                self.toggle_debug_mode()
31
32
        elif event.type == pygame.KEYUP:
0 ignored issues
show
The Module pygame does not seem to have a member named KEYUP.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
33
            self.pressed.remove(event.key)
34
35
    def toggle_debug_mode(self):
0 ignored issues
show
Missing function or method docstring
Loading history...
36
        if self.debug:
37
            self.debug = False
38
            self.fps_limit = FPS_LIMIT
39
            pygame.display.set_caption(TITLE)
40
41
        else:
42
            self.debug = True
43
            # The more fps, the more cpu usage
44
            self.fps_limit = 1000
45
46
    def update(self):
0 ignored issues
show
Missing function or method docstring
Loading history...
47
        # Temporary white bg to simulate scratch background.
48
        viewport.fill((255, 255, 255))
49
50
        camera.update(self.pressed)
51
        self.tiles.draw(viewport, camera)
52
53
        screen.blit(pygame.transform.scale(viewport, SCREEN_SIZE), (0, 0))
54
        pygame.display.update()
55
56
        for event in pygame.event.get():
57
            self.handle_event(event)
58
59
    def run(self) -> None:
0 ignored issues
show
Missing function or method docstring
Loading history...
60
        while self.is_running:
61
            self.update()
62
63
            if self.debug:
64
                fps = self.clock.get_fps()
65
66
                pygame.display.set_caption(
67
                    f"{TITLE} - {fps:.0f} fps - {(1 / fps) * 1000:.1f} µs"
68
                )
69
70
            self.clock.tick(self.fps_limit)
71
72
    def __del__(self) -> None:
73
        pygame.display.quit()
74
        pygame.quit()
0 ignored issues
show
The Module pygame does not seem to have a member named quit.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
75