Me calling Daniel. I want that, after time, the object appeared and disappeared through time, but I can’t do it. I tried to remove the group, but still it does not work, please help.)
# game shmup - 3 part
# Solutions and shooting
Import pygame
Import Random
Width = 1600.
Height = 800.
FPS = 60.
# Set colors
White = (255, 255, 255)
Black = (0, 0, 0)
RED = (255, 0, 0)
Green = (0, 255, 0)
Blue = (0, 0, 255)
Yellow = (255, 255, 0)
# Variables
Timer_Games = 0.
#Other
pygame.time.set_timer (pygame.userevent, 1000) # timer watching instructions
LLL = 60.
# Create a game and window
pygame.init ()
pygame.mixer.init ()
screen = pygame.display.set_mode ((Width, Height))
pygame.display.set_caption ("Shmup!")
Clock = pygame.time.clock ()
Class MOB3 (pygame.sprite.sprite):
Def __init __ (Self):
Pygame.Sprite.Sprite .__ INIT __ (SELF)
self.image = pygame.surface ((60, 900))
self.image.fill (Yellow)
self.image.set_alpha (150)
self.Rect = Self.Image.get_rect ()
Self.Rect.centerX = LLL
Self.Rect.centery = Height / 2
# Self.Rect.y = Random.randrange (-100, -40)
Self.Speedy = 4.
All_sprites = pygame.sprite.group ()
mobs1 = pygame.sprite.group ()
# Cycle games
Running = True.
While Running:
Clock.tick (FPS)
For e in pygame.event.get (): Runs timer, every second he considers
If e.Type == Pygame.useRevent: # Only the timer works in his borders
Timer_Games + = 1
If Timer_Games == 3:
For i in Range (8):
q = mob3 ()
All_sprites.add (q)
mobs1.add (q)
LLL + = 200
If e.type == pygame.quit:
Running = False
ELIF E.TYPE == Pygame.Keydown:
if e.key == pygame.k_space:
Player.Shoot ()
# Update
All_sprites.update ()
# Find all sprites that face between two groups.
# Rendering
Screen.fill (Black)
All_sprites.DRAW (Screen)
# After drawing everything, turn the screen
pygame.display.flip ()
pygame.quit ()
Answer 1, Authority 100%
I’m not sure that I understood you right, but try this:
import pygame
Import Random
Width = 1200.
Height = 400.
FPS = 60.
# Set colors
White = (255, 255, 255)
Black = (0, 0, 0)
RED = (255, 0, 0)
Green = (0, 255, 0)
Blue = (0, 0, 255)
Yellow = (255, 255, 0)
# Variables
Timer_Games = 0.
#Other
pygame.time.set_timer (pygame.userevent, 1000) # timer watching instructions
LLL = 60.
# Create a game and window
pygame.init ()
pygame.mixer.init ()
screen = pygame.display.set_mode ((Width, Height))
pygame.display.set_caption ("Shmup!")
Clock = pygame.time.clock ()
Class MOB3 (pygame.sprite.sprite):
Def __init __ (Self, LLL): # +++ LLL
Super () .__ init __ () # +++
Pygame.Sprite.Sprite .__ INIT __ (SELF)
self.image = pygame.surface ((60, 900))
# Self.Image.fill (Yellow)
c = random.sample ([Yellow, Blue, Green, Red, White], 1) [0] # +
self.image.fill (C) # +
self.image.set_alpha (150)
self.Rect = Self.Image.get_rect ()
Self.Rect.centerX = LLL
Self.Rect.centery = Height / 2
# Self.Rect.y = Random.randrange (-100, -40)
Self.Speedy = 4.
All_sprites = pygame.sprite.group ()
mobs1 = pygame.sprite.group ()
Running = True.
While Running:
Clock.tick (FPS)
For e in pygame.event.get (): Runs timer, every second he considers
If e.Type == Pygame.useRevent: # Only the timer works in his borders
Timer_Games + = 1
All_sprites = pygame.sprite.group () # +++
LLL = 60 # +++
# If Timer_Games == 3: # ---
IF Timer_Games% 3 == 0: # +++
For i in Range (8):
Q = Mob3 (LLL) # +++ LLL
All_sprites.add (q)
mobs1.add (q)
LLL + = 150 # 200
If e.type == pygame.quit:
Running = False.
ELIF E.TYPE == Pygame.Keydown:
if e.key == pygame.k_space:
Player.Shoot ()
# Update
All_sprites.update ()
# Find all sprites that face between two groups.
# Rendering
Screen.fill (Black)
All_sprites.DRAW (Screen)
# After drawing everything, turn the screen
pygame.display.flip ()
pygame.quit ()