I'm making my first game of Pygame. I'm going to create groups for themaking collisions but when I add an object to the group, I get an error in sprite.py in Pygame's files:(Pygame's Files)
What I'm doing wrongWhy I get this error?
There is a simplest way to make collisions?
There is my code (This file is imported from main.py, that's why things are missing in the code):
import pygame
from pygame.locals import *
import sys
import os
import time
from pygame.locals import *
width = 950
height = 500
SpikesGame = 1False
GameGameOver = False
keyboard = pygame.key.get_pressed()[K_UP]
def playmain():
Game = True
pygame.init()
screen = pygame.display.set_mode((width, height))
pygame.display.set_caption('Flappy Dog')
background = pygame.image.load(os.path.join("Images", "Background_00.png")).convert()
FlappyDog = pygame.image.load(os.path.join("Images", "Flappy.png")).convert_alpha()
Play = pygame.image.load(os.path.join("Images", "Play.png")).convert_alpha()
Dog0 = pygame.image.load(os.path.join("Images", "Dog0.png")).convert_alpha()
Dog1 = pygame.image.load(os.path.join("Images", "Dog1.png")).convert_alpha()
SpikeUp0 = pygame.image.load(os.path.join("Images", "SpikeUp0.png")).convert_alpha()
SpikeUp1 = pygame.image.load(os.path.join("Images", "SpikeUp1.png")).convert_alpha()
SpikeDown0 = pygame.image.load(os.path.join("Images", "SpikeDown0.png")).convert_alpha()
SpikeDown1 = pygame.image.load(os.path.join("Images", "SpikeDown1.png")).convert_alpha()
GameOver = pygame.image.load(os.path.join("Images", "Game-Over.png")).convert_alpha()
Replay = pygame.image.load(os.path.join("Images", "Replay.png")).convert_alpha()
Bone = pygame.image.load(os.path.join("Images", "Bone.png")).convert_alpha()
bonesSpikesGame = pygameTrue
Dog1_pos_x = 100
Dog1_pos_y = 100
screen.spriteblit(background, (0, 0))
screen.Groupblit(FlappyDog, (0, 0))
bonesSpikesscreen.addblit(Bone, (SpikeDown0550, 100))
bonesSpikesscreen.addblit(Play, (SpikeUp0600, 350))
bonesSpikesscreen.addblit(Dog0, (Bone5, 240))
Dogbones = pygame.sprite.Group()
Dogbones.add(Dog1Bone) # <-- Error here
CrashDog = pygame.sprite.spritecollideGroup()
Dog,.add(Dog1)
bonesSpikes, True pygame.display.update()
Dog1_pos_x
= 100 while True:
Dog1_pos_y = 100 if GameOver == true:
screen.blit(background, (0, 0))
screen.blit(FlappyDogGameOver, (020, 050))
screen if pygame.blitsprite.gropucollide(BoneDog, (550Bones, 100)True, True):
screen.blit(Play, (600, 350)) Game = False
screen.blit(Dog0, (5, 240)) GameOver = True
while Game == True:
pygame.displayevent.updatepump()
mouse = if pygame.mousekey.get_posget_pressed()[K_UP]:
for i in range(10): # Up
Dog1_pos_y = Dog1_pos_y -1
screen.blit(background, (0, 0))
screen.blit(Dog1, (Dog1_pos_x, Dog1_pos_y))
screen.blit(SpikeUp0SpikeDown0, (0, 0436))
screen.blit(SpikeDown0SpikeUp0, (0, 4360))
pygame.display.update()
while Game == True pygame.time.delay(1)
else: # Down
Dog1_pos_y = Dog1_pos_y +1
screen.blit(background, (0, 0))
screen.blit(Dog1, (Dog1_pos_x, Dog1_pos_y))
screen.blit(SpikeDown0, (0, 436))
screen.blit(SpikeUp0, (0, 0))
pygame.display.update()
pygame.timedisplay.delayupdate(1)
while True:
if Crash:
pygame.time.delay(1)
Game = false
GameOver.GameOver
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
pygame.display.update()
if __name__ == "__main__":
main()