So I'm starting with classes, groups and sprites. Everything seems to be right in my code but it just does not run. I have tried detecting that what runs by using print("hello")
command but haven't gotten anything back.
class Spaceship(pygame.sprite.Sprite): ###thigs that fly arround when GUI == 4
def __init__(self, ships, GUIstatus):
# ships is a Group for all ships
pygame.sprite.Sprite.__init__(self, ships)
self.shipUp = pygame.image.load("icons/shipUP.png")
self.shipRight = pygame.image.load("icons/shipRIGHT.png")
self.shipLeft = pygame.image.load("icons/shipLEFT.png")
self.shipDown = pygame.image.load("icons/shipDOWN.png")
# the image has to be in self.image
self.image = self.shipLeft
# no need for shipnpc_x and shipnpc_y, since we store
# our position in self.rect
self.rect = self.image.get_rect()
self.GUIstatus = GUIstatus
self.shipType = random.randrange(0,5)
# this has to be called update instead of update
# to work with groups
def update(self):
# to change the position, we just alter self.rect
if self.exists == 0 and self.GUIstatus == 4:
if dirrection == LEFT:
#self.rect.move_ip(-self.speed, 0)
self.shipImage = self.shipLeft
print("Hello i'm a spacecraft")
if dirrection == RIGHT:
#self.rect.move_ip(self.speed, 0)
self.shipImage = self.shipRight
if dirrection == UP:
#self.rect.move_ip(0, -self.speed)
self.shipImage = self.shipUp
if dirrection == DOWN:
#self.rect.move_ip(0, self.speed)
self.shipImage = self.shipDown
Then I'm using this:
ships = pygame.sprite.Group()
for _ in range(30):
Spaceship(ships, GUIstatus)
and then for drawing and updating:
ships.update()
ships.draw(screen)
But nothing is running it seems? Why?