Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame, random, sys
- from pygame.locals import *
- vec = pygame.math.Vector2
- # game settings
- WIDTH = 480
- HEIGHT = 640
- FPS = 60
- TITLE = 'Flappy Bird Clone'
- FONT = pygame.font.match_font('arial')
- # player properties
- PLAYER_HEIGHT = 40
- PLAYER_WIDTH = 57
- # collumn properties
- COLLUMN_GAP = PLAYER_HEIGHT * 5
- COLLUMN_WIDTH = PLAYER_WIDTH * 2
- # player gravity
- PLAYER_ACC = 0.5
- PLAYER_FRICTION = -0.12
- PLAYER_GRAV = 1
- # R G B
- BLACK = ( 0, 0, 0)
- WHITE = (255,255,255)
- RED = (255, 0, 0)
- GREEN = ( 0,255, 0)
- BLUE = ( 0, 0,255)
- YELLOW = (255,255, 0)
- OLIVE = (128,128, 0)
- LBLUE = ( 0, 0, 64)
- # set up game
- pygame.init()
- pygame.mixer.init()
- window_surface = pygame.display.set_mode((WIDTH, HEIGHT))
- window_surface.fill(LBLUE)
- pygame.display.set_caption(TITLE)
- main_clock = pygame.time.Clock()
- def terminate():
- pygame.quit()
- sys.exit()
- def draw_text(surf, text, size, x, y):
- font = pygame.font.Font(FONT, size)
- text_surface = font.render(text, True, WHITE)
- text_rect = text_surface.get_rect()
- text_rect.midtop = (x, y)
- surf.blit(text_surface, text_rect)
- class Player(pygame.sprite.Sprite):
- def __init__(self):
- pygame.sprite.Sprite.__init__(self)
- self.image = pygame.Surface((PLAYER_WIDTH, PLAYER_HEIGHT))
- self.rect = self.image.get_rect()
- self.image.fill(BLUE)
- def update(self):
- pass
- def jump(self):
- pass
- class Collumn(pygame.sprite.Sprite):
- def __init__(self, x, y, w, h):
- pygame.sprite.Sprite.__init__(self)
- self.image = pygame.Surface((w, h))
- self.rect = self.image.get_rect()
- self.image.fill(GREEN)
- all_sprites = pygame.sprite.Group()
- collumns = pygame.sprite.Group()
- player = Player()
- all_sprites.add(player)
- score = 0
- top_score = 0
- # game loop
- running = True
- while running:
- # keep speed at FPS
- main_clock.tick(FPS)
- # events
- for event in pygame.event.get():
- if event.type == QUIT:
- terminate()
- # update
- all_sprites.update()
- # draw
- window_surface.fill(LBLUE)
- all_sprites.draw(window_surface)
- # flip the display
- pygame.display.flip
- terminate()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement