/
ap1k
/
PyGame_Practice
Обзор
Документация
Войти
/
ap1k
/
PyGame_Practice
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/entities/entity.py
43 строки
1 KB
Roman
The all game
27 май 2025, 15:26
27 май 2025, 15:26
4ea7de9
Код
Авторство
О чём код?
""" Entity base class - abstract base class for all game entities """ import pygame from abc import ABC, abstractmethod class Entity(ABC): """ Abstract base class for all game entities Follows the Liskov Substitution Principle by defining a common interface """ def __init__(self, x, y, width, height): """Initialize the entity with position and dimensions""" self.x = x self.y = y self.width = width self.height = height self.rect = pygame.Rect(x, y, width, height) self.image = None self.active = True def update_rect(self): """Update the entity's rectangle position""" self.rect.x = self.x self.rect.y = self.y @abstractmethod def update(self): """Update the entity state""" pass @abstractmethod def render(self, screen): """Render the entity to the screen""" pass def is_colliding(self, other): """Check if this entity is colliding with another entity""" return self.rect.colliderect(other.rect) def deactivate(self): """Deactivate the entity (remove it from the game)""" self.active = False