Forum » Programiranje » python flappy bird
python flappy bird
dejco_h ::
dober dan malo se igram in delam nekoč popularno igro flappy bird v pythonu.Ampak ker se naletel na težavo se obračam na vas napaka je zelo banalna ampak dejansko ne vidim napake v kodi.torej namesto da bi se mi pipes(cevi) pojavljale pred mano se z nekega čudnega razloga pojavljajo za mano. kaj mi lahko prosim samo kdo pove ali namigne kje je napaka?
Hvala vsem za odgovore že vnaprej
Hvala vsem za odgovore že vnaprej
import pygame import sys import random pygame.init() WIDTH,HEIGTH=551,720 win=pygame.display.set_mode((WIDTH,HEIGTH)) pygame.display.set_caption("FLAPY BIRDS") black=(0,0,0) clock=pygame.time.Clock() bird_images = [pygame.image.load("assets/bird_down.png"), pygame.image.load("assets/bird_mid.png"), pygame.image.load("assets/bird_up.png")] skyline_image = pygame.image.load("assets/background.png") ground_image = pygame.image.load("assets/ground.png") top_pipe_image = pygame.image.load("assets/pipe_top.png") bottom_pipe_image = pygame.image.load("assets/pipe_bottom.png") game_over_image = pygame.image.load("assets/game_over.png") start_image = pygame.image.load("assets/start.png") scrool_speed=1 bird_start_position=(100,250) class Pipes(pygame.sprite.Sprite): def __init__(self,x,y,image): pygame.sprite.Sprite.__init__(self) self.image=image self.rect=self.image.get_rect() self.x=x self.y=y def update(self): self.rect.x-=scrool_speed if self.rect.x<=- WIDTH: self.kill() class Bird(pygame.sprite.Sprite): def __init__(self): pygame.sprite.Sprite.__init__(self) self.image=bird_images[0] self.rect=self.image.get_rect() self.rect.center=bird_start_position self.image_index=0 self.vel=0 self.flap=False def update(self,user_input): self.image_index+=1 if self.image_index>=30: self.image_index=0 self.image=bird_images[self.image_index//10] self.vel+=0.5 if self.vel>7: self.vel=7 if self.rect.y<500: self.rect.y+=int(self.vel) if self.vel==0: self.flap=False self.image=pygame.transform.rotate(self.image,self.vel*-7) if user_input[pygame.K_SPACE] and not self.flap and self.rect.y>0: self.flap=True self.vel=-7 class Ground(pygame.sprite.Sprite): def __init__(self,x,y): pygame.sprite.Sprite.__init__(self) self.image=ground_image self.rect=self.image.get_rect() self.rect.x,self.rect.y=x,y def update(self): self.rect.x-=scrool_speed if self.rect.x<=-WIDTH: self.kill() def main(): bird=pygame.sprite.GroupSingle() bird.add(Bird()) pipe_timer=0 pipes=pygame.sprite.Group() x_pos_ground,y_pos_ground=0,520 ground=pygame.sprite.Group() ground.add(Ground(x_pos_ground,y_pos_ground)) run=True FPS=60 while run: for event in pygame.event.get(): if event.type==pygame.QUIT: pygame.quit() exit() win.blit(skyline_image,(0,0)) if len(ground)<=2: ground.add(Ground(WIDTH, y_pos_ground)) usr = pygame.key.get_pressed() pipes.draw(win) ground.draw(win) bird.draw(win) pipes.update() ground.update() bird.update(usr) if pipe_timer<=0: x_top,x_bottom=550,550 y_top=random.randint(-600, -480) y_bottom=y_top+random.randint(90,130)+bottom_pipe_image.get_height() pipes.add(Pipes(x_top,y_top,top_pipe_image)) pipes.add(Pipes(x_bottom,y_bottom,bottom_pipe_image)) pipe_timer=random.randint(180,250) pipe_timer-=1 clock.tick(FPS) pygame.display.update() if __name__ == '__main__': main()
Vredno ogleda ...
Tema | Ogledi | Zadnje sporočilo | |
---|---|---|---|
Tema | Ogledi | Zadnje sporočilo | |
» | Return ne deluje[python]Oddelek: Programiranje | 962 (826) | Jonatan |
» | [Python3] Izvajanje ukazov po določenem časuOddelek: Programiranje | 1442 (1052) | noraguta |
» | Predstavitev dvojiškega drevesa z seznamomOddelek: Programiranje | 1929 (1529) | ktka |
» | [Python]Naloga z razredi in dedovanjemOddelek: Programiranje | 1140 (892) | ktka |
» | python -slovarOddelek: Programiranje | 3117 (2096) | Valex86 |