Skip to content

Commit

Permalink
Gradually adds type hints (issue pythonarcade#1)
Browse files Browse the repository at this point in the history
Some type hints added while reading the code.
  • Loading branch information
filiplajszczak committed Feb 23, 2020
1 parent a332e0c commit 4cfc560
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
4 changes: 3 additions & 1 deletion source/map_to_sprites.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import List

import arcade

from constants import *
Expand All @@ -10,7 +12,7 @@
from entities.troll import Troll


def map_to_sprites(game_map):
def map_to_sprites(game_map: List[List[int]]) -> arcade.SpriteList[Entity]:

sprite_list = arcade.SpriteList(use_spatial_hash=True, spatial_hash_cell_size=16)

Expand Down
6 changes: 4 additions & 2 deletions source/procedural_generation/game_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@


# Some variables for the rooms in the map
from entities.entity import Entity

ROOM_MAX_SIZE = 10
ROOM_MIN_SIZE = 6
MAX_ROOMS = 35
Expand Down Expand Up @@ -67,7 +69,7 @@ def place_entities(room, entities, max_monsters_per_room, max_items_per_room):


class GameMap:
def __init__(self, width, height):
def __init__(self, width: int, height: int):
self.map_width = width
self.map_height = height
self.tiles = [
Expand All @@ -78,7 +80,7 @@ def __init__(self, width, height):
]

def make_map(
self, player,
self, player: Entity,
):
rooms = []
num_rooms = 0
Expand Down
4 changes: 3 additions & 1 deletion source/recalculate_fov.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
"""
Calculate Field Of Vision (FOV)
"""
from typing import List

import arcade
import math

from constants import *
from entities.entity import Entity
from util import char_to_pixel


def recalculate_fov(char_x, char_y, radius, sprite_lists):
def recalculate_fov(char_x: int, char_y: int, radius: int, sprite_lists: List[arcade.SpriteList[Entity]]):
for sprite_list in sprite_lists:
for sprite in sprite_list:
if sprite.is_visible:
Expand Down
4 changes: 2 additions & 2 deletions source/util.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
from constants import *


def char_to_pixel(char_x, char_y):
def char_to_pixel(char_x: int, char_y: int) -> (int, int):
px = char_x * SPRITE_WIDTH * SPRITE_SCALE + SPRITE_WIDTH / 2 * SPRITE_SCALE
py = (
char_y * SPRITE_HEIGHT * SPRITE_SCALE + SPRITE_HEIGHT / 2 * SPRITE_SCALE
) + STATUS_PANEL_HEIGHT
return px, py


def pixel_to_char(pixel_x, pixel_y):
def pixel_to_char(pixel_x: int, pixel_y: int) -> (int, int):
px = pixel_x - SPRITE_WIDTH / 2 * SPRITE_SCALE
px = round(px / (SPRITE_WIDTH * SPRITE_SCALE))

Expand Down

0 comments on commit 4cfc560

Please sign in to comment.