/
ap1k
/
PyGame_Practice
Обзор
Документация
Войти
/
ap1k
/
PyGame_Practice
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/entities/bullet.py
51 строка
1 KB
Roman
The all game
27 май 2025, 15:26
27 май 2025, 15:26
4ea7de9
Код
Авторство
О чём код?
""" Bullet class - represents a bullet entity in the game """ import pygame from src.entities.entity import Entity from src.utils.resource_loader import ResourceLoader class Bullet(Entity): """ Bullet entity class Implements the Entity interface """ def __init__(self, x, y, bullet_type, damage): """Initialize the bullet entity""" # Different bullet types have different sizes if bullet_type == "power": width, height = 10, 20 else: width, height = 5, 10 super().__init__(x, y, width, height) # Load the bullet image self.image = ResourceLoader().get_image(f"bullet_{bullet_type}") # Bullet properties self.speed = 10 self.damage = damage self.bullet_type = bullet_type # Adjust speed based on bullet type if bullet_type == "rapid": self.speed = 12 elif bullet_type == "power": self.speed = 8 def update(self): """Update the bullet state""" # Move the bullet upward self.y -= self.speed # Update the bullet's rectangle position self.update_rect() # Deactivate the bullet if it goes off the screen if self.y < -self.height: self.active = False def render(self, screen): """Render the bullet to the screen""" screen.blit(self.image, self.rect)