quote text-sharp-sharp-sharp title description
I want to create a spaceship that can fire bullets. According to the book, it always shows
AttributeError: "Group" object has no attribute" control bullets"
Please have a look and beg on your knees
sources of topics and their own ideas
related codes
import pygame
from pygame.sprite import Sprite
class Bullet(Sprite):
def __init__(self,a,,):
super().__init__()
self. =
self. = pygame.Rect(0,0,a.,a.)
self..centeyx = ..centerx
self..top = ..top
self.y =(self..y)
self.= a.
self. = a.
def (self):
self.y -= self.
self..y = self.y
def (self):
pygeme.draw.rect(self.a,self.,self.)
```
----------
```
import sys
import pygame
from import Bullet
def (,,):
-sharp
.fill(a.)
.()
-sharp
pygame.display.flip()
def (,,,a):
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
elif event.type == pygame.KEYDOWN:
(event,,,,a)
elif event.type == pygame.KEYUP:
(event,)
def (event,,,,a):
if event.key == pygame.K_RIGHT:
.a = True
elif event.key == pygame.K_LEFT:
.b = True
elif event.key == pygame.K_SPACE:
= Bullet(a,,)
.add()
def (event,):
if event.key == pygame.K_RIGHT:
.a = False
elif event.key == pygame.K_LEFT:
.b = False
----------
----------
import sys
import pygame
from import
from import Ship
import as l
from pygame.sprite import Group
def ():
-sharp
a=()
-sharp
= pygame.display.set_mode((a.,a.))
-sharp
pygame.display.set_caption("")
= Group()
= Ship(,a)
while True:
l.(,a,,)
.()
.()
l.(,,a,)
()
what result do you expect? What is the error message actually seen?
I don"t know much English, so I change everything that can be replaced by Chinese to Chinese. Not all the code is posted, because there are no changes left, and errors should appear in these three pieces of code.
Traceback (most recent call last):
File "C: war Aliens Game .py", line 23, in < module >
()
File "C: war Aliens Game. Py", line 19, in start the game
.()
AttributeError: "Group" object has no attribute" control bullet
this is the wrong prompt, kneel and beg for kindness.
I can"t find the error after looking for it all afternoon