I'm making a simple parody of the game Chippy. In general, the monster(alien) must shoot and we must dodge and shoot back. I made it so that the picture of the ball is added to the array with all the other balls and removed when leaving the screen, but for some reason only one ball is drawn, and the rest are added to the array but do not appear on the screen. I am using module tkinter to get screen dimensions:
P.S. the ball is the bullets that the monster(alien) shoots, it's just that the bullets are already taken
# === ball ===
import pygame
from tkinter import *
root = Tk()
class Ball():
def __init__(self, screen, alien):
self.screen = screen
self.ball_image = pygame.image.load('images/pixil-frame-0 (1).png')
self.rect = self.ball_image.get_rect()
self.rect.centerx = alien.x
self.rect.centery = alien.y
self.all_ball = []
self.test = True
self.timer = 0
def draw_ball(self, alien):
self.screen.blit(self.ball_image, (self.rect.centerx, self.rect.centery))
def move(self):
self.rect.centery += 15
def create_ball(self, screen, alien):
for ball in self.all_ball.copy():
if ball.rect.top <= 0 or ball.rect.left <= 0 or ball.rect.right >= root.winfo_screenwidth() or ball.rect.bottom >= root.winfo_screenheight():
self.all_ball.remove(ball)
if self.test == True:
self.all_ball.append(Ball(screen, alien))
For now, I want to get the monster(alien) to shoot these balls in different directions.