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

builds not need be a sprite

parent 11db5f12
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import pygame
import math
SKY = (113, 197, 207)
GROUND = (221, 216, 148)
build = pygame.image.load('images/buildings.png')
def make_back(parent):
w = parent.game_w
h = parent.game_h
floor_y = parent.floor_y
back = pygame.surface.Surface((w, h), 0)
back.fill(SKY)
rect = pygame.rect.Rect(0, floor_y, w, h - floor_y)
back.fill(GROUND, rect)
if w > 684:
t = int(math.ceil(w / 684.0))
else:
t = 1
y = floor_y - 229
for i in range(t):
back.blit(build, (684 * i, y))
return back
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import pygame
import math
build = pygame.image.load('images/buildings.png')
class Build(pygame.sprite.Sprite):
def __init__(self, parent, x=0, y=0):
pygame.sprite.Sprite.__init__(self)
self.parent = parent
self.mPos = [x, y]
if self.parent.game_w > 684:
t = math.ceil(self.parent.game_w / 684.0)
t = int(t)
else:
t = 1
self.image = pygame.surface.Surface((684 * t, 229), 0)
self.image.fill((255, 255, 255))
for i in range(t):
self.image.blit(build, (684 * i, 0))
self.image.set_colorkey((255, 255, 255))
self.rect = self.image.get_rect()
self.rect.x = self.mPos[0]
self.rect.y = self.mPos[1]
......@@ -26,7 +26,7 @@ import pygame.sprite as sprite
from floor import Floor
from pipe import Pipe_I
from pipe import Pipe_S
from build import Build
from background import make_back
from bird import Bird
from scores import EndScore
from scores import Message
......@@ -34,8 +34,7 @@ from scores import CurrentScore
GAME_SIZE = (684, 600)
#GAME_SIZE = (1200, 700)
SKY = (113, 197, 207)
GROUND = (221, 216, 148)
MIN_HEIGHT = 82 * 2 + 160
DIST = 160
PIPE_W = 91
......@@ -71,23 +70,20 @@ class Flappy():
self.score = 0
self.sprites = pygame.sprite.LayeredUpdates()
self.tubes = pygame.sprite.LayeredUpdates()
self.background = pygame.surface.Surface(GAME_SIZE, 0)
self.background.fill(SKY)
rect = pygame.rect.Rect(0, self.floor_y, self.game_w, self.game_h - self.floor_y)
self.background.fill(GROUND, rect)
self.background = make_back(self)
self.screen.blit(self.background, (0, 0))
########################################################################
self.floor = Floor(0, self.floor_y, GAME_SIZE[0])
self.floor.mVel = 0
self.build = Build(self, 0, self.build_y)
self.bird = Bird(self, self.bird_x, self.bird_y)
self.bird.mAcc = 0
self.end_scores = EndScore(self.end_s_x, 200)
self.message = Message(self.mes_x, self.mes_y)
self.currentS = CurrentScore(self.sc_x, 100)
########################################################################
self.sprites.add(self.build, layer=0)
self.sprites.add(self.floor, layer=0)
self.sprites.add(self.bird, layer=2)
self.sprites.add(self.message, layer=3)
......
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