Commit b941604c authored by Alan Aguiar's avatar Alan Aguiar
Browse files

basic check for collides

parent 42b75f77
......@@ -7,6 +7,8 @@ import random
bird_h = pygame.image.load('images/bird_h_alfa.png')
bird_u = pygame.image.load('images/bird_u_alfa.png')
bird_d1 = pygame.image.load('images/bird_d45_alfa.png')
bird_d2 = pygame.image.load('images/bird_d55_alfa.png')
class Bird(pygame.sprite.Sprite):
......
......@@ -22,6 +22,7 @@ class Flappy():
def __init__(self):
self.sprites = pygame.sprite.LayeredUpdates()
self.tubes = pygame.sprite.LayeredUpdates()
self.background = pygame.surface.Surface(GAME_SIZE, 0)
self.background.fill(SKY)
self.build_y = GAME_SIZE[1] - 229 - 50
......@@ -40,8 +41,10 @@ class Flappy():
self.sprites.add(self.build)
self.sprites.add(self.floor)
#self.sprites.add(pipe1)
#self.sprites.add(pipe2)
self.sprites.add(pipe1)
self.sprites.add(pipe2)
self.tubes.add(pipe1)
self.tubes.add(pipe2)
self.sprites.add(self.bird)
......@@ -64,6 +67,12 @@ class Flappy():
self.sprites.update()
self.sprites.draw(self.screen)
col = pygame.sprite.spritecollide(self.bird, self.tubes, False)
if not(col == []):
print 'Toco'
t = col[0]
pygame.display.flip()
self.clock.tick(30)
......
......@@ -39,6 +39,7 @@ class Pipe_I(pygame.sprite.Sprite):
self.rect.y = self.mPos[1]
if self.mPos[0] < -91:
self.parent.sprites.remove(self)
self.parent.tubes.remove(self)
elif self.mPos[0] < (self.parent.game_p):
if self.flag:
......@@ -47,10 +48,12 @@ class Pipe_I(pygame.sprite.Sprite):
p = Pipe_I(self.parent, self.parent.game_w, h)
self.parent.sprites.add(p)
self.parent.tubes.add(p)
s = p.mPos[1] + p.height + 160
s = self.parent.game_h - p.height - 160 - 50
p = Pipe_S(self.parent, self.parent.game_w, s)
self.parent.sprites.add(p)
self.parent.tubes.add(p)
class Pipe_S(pygame.sprite.Sprite):
......@@ -83,4 +86,5 @@ class Pipe_S(pygame.sprite.Sprite):
self.rect.y = self.mPos[1]
if self.mPos[0] < -91:
self.parent.sprites.remove(self)
self.parent.tubes.remove(self)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment