Kaydet (Commit) e1cde7ff authored tarafından Batuhan Taşkaya's avatar Batuhan Taşkaya

Inital player, player registery, texture

üst 7ad67d8e
......@@ -9,8 +9,8 @@ from typing import Tuple
import pygame
from pygame.locals import QUIT
from lordlarkamarasi.textures import AVAILABLE_BLOCKS, BASE_PATH, TILE_SIZE, Blocks
from lordlarkamarasi.textures import AVAILABLE_BLOCKS, BASE_PATH, TILE_SIZE, Blocks, Entities
from lordlarkamarasi.players import PlayerRegistery
class Map(UserList):
def __init__(self, width, height, surface):
......@@ -57,6 +57,8 @@ class Game:
self.surface = pygame.display.set_mode(window)
self.map = Map.from_file('maps/base_map.ini')
self.playerreg = PlayerRegistery()
def process_event(self, event: pygame.event.EventType):
self.draw_map()
......@@ -71,6 +73,7 @@ class Game:
pygame.quit()
def start(self):
self.playerreg.join("BTaskaya")
self.event_handler()
def draw_map(self):
......@@ -79,6 +82,9 @@ class Game:
self.surface.blit(
block.value.texture, (cpos * TILE_SIZE, rpos * TILE_SIZE)
)
for player in self.playerreg.values():
self.surface.blit(Entities.PLAYER.value.texture, (player.coord.x * TILE_SIZE, player.coord.y * TILE_SIZE))
if __name__ == "__main__":
......
from dataclasses import dataclass, field
from collections import UserDict
@dataclass
class Coordinates:
x: int = 0
y: int = 0
@dataclass
class Player:
username: str
coord: Coordinates = field(default_factory=Coordinates)
class PlayerRegistery(UserDict):
def join(self, username):
self.data[username] = Player(username)
def quit(self, username):
del self.data[username]
......@@ -13,22 +13,24 @@ def relative_load(path: str) -> pygame.Surface:
return pygame.image.load(os.fspath(BASE_PATH / path))
@dataclass
class Block:
class Texture:
id: int
texture: pygame.Surface
must_connect: Optional[id] = None
class Blocks(Enum):
GRASS = Block(0, relative_load("textures/land/grass.png"))
STONE = Block(1, relative_load("textures/land/stone.png"))
WATER = Block(2, relative_load("textures/land/water.png"))
SAND = Block(3, relative_load("textures/land/sand.png"))
GRASS = Texture(0, relative_load("textures/land/grass.png"))
STONE = Texture(1, relative_load("textures/land/stone.png"))
WATER = Texture(2, relative_load("textures/land/water.png"))
SAND = Texture(3, relative_load("textures/land/sand.png"))
@classmethod
def get_by_id(cls, id):
block, = filter(lambda member: member.value.id == id, cls.__members__.values())
return cls(block)
class Entities(Enum):
PLAYER = Texture(0xF0, relative_load("textures/entities/player.png"))
ALL_BLOCKS = set(Blocks.__members__.values())
AVAILABLE_BLOCKS = set(filter(lambda block: not block.value.must_connect, ALL_BLOCKS))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment