Anonymní profil Pararam – Programujte.com
 x   TIP: Přetáhni ikonu na hlavní panel pro připnutí webu

Anonymní profil Pararam – Programujte.comAnonymní profil Pararam – Programujte.com

 

Příspěvky odeslané z IP adresy 78.98.31.–

Tinux
Python › Pygame -obrazok bez pozadia
21. 7. 2015   #203768
Tinux
Python › Pygame -obrazok bez pozadia
21. 7. 2015   #203759

Dokoncil som to nejak ,poslem ti to na mail:-))

Tinux
Python › Pygame -obrazok bez pozadia
20. 7. 2015   #203740

Jasné pohode :))

Tinux
Python › Pygame -obrazok bez pozadia
20. 7. 2015   #203738

Mas to tam ak ti to nepojde poslem ti to kazde zvlášť:))

Tinux
Python › Pygame -obrazok bez pozadia
20. 7. 2015   #203737

Aha no jasné :-)))

Tinux
Python › Pygame -obrazok bez pozadia
20. 7. 2015   #203735

Teraz ale neviem ze co konkretne chces:-))

Tinux
Python › Pygame -obrazok bez pozadia
20. 7. 2015   #203733

A kam ti to mam poslat?:-))

Tinux
Python › Pygame -obrazok bez pozadia
20. 7. 2015   #203731

Ono zalezi samozrejme aj na aku stranu dopadne ak na tu z kade prichadza lopta tak ju vrati na tu istu ale ak z druhej strany tak naopak ak chapes :-))

Tinux
Python › Pygame -obrazok bez pozadia
20. 7. 2015   #203730

   

Ako original :-)

Tinux
Python › Pygame -obrazok bez pozadia
20. 7. 2015   #203729

No "funguje" ale nie tak ako by som chcel ,ja by som to chcel proste tak ze pod akym uhlom dopadne pod takým sa odrazí na opačnú stranu :P

Tinux
Python › Pygame -obrazok bez pozadia
20. 7. 2015   #203727

To asi nepojde ,neviem preco :P aj ked som sa prihlasil ,ok dam ti ho sem,keby cokolvek pytaj sa,trochu som to spravil kedze chlapik mi poradil na stacku ze proste len zmenim os ak narazim zboku co ale nie je optimalne riesenie podla mna :P

import pygame
import sys
scr_w=640
scr_h=480
scr=pygame.display.set_mode((scr_w,scr_h))
sprites_group=pygame.sprite.Group()
blocks_group=pygame.sprite.Group()
main_block_group=pygame.sprite.Group()
 
class blockToDestroy(pygame.sprite.Sprite):

    def __init__(self):
        super().__init__()
        self.blockToDestroy_w=35
        self.blockToDestroy_h=15
        self.img=pygame.image.load("C:\Python34\locktodes.png").convert()
        self.image=pygame.Surface([self.blockToDestroy_w,self.blockToDestroy_h])

        self.rect=self.image.get_rect()
        self.image.blit(self.img,(0,0))
                
                
                
                

        
class Block(pygame.sprite.Sprite):
    def __init__(self):
        super().__init__()
        self.block_w=80
        self.block_h=20
        
        self.img=pygame.image.load("C:\Python34\ock.png").convert()
        self.image=pygame.Surface([self.block_w,self.block_h])
        
        self.rect=self.image.get_rect()
        self.image.blit(self.img,(0,0))
        
        self.rect.y=400
        self.rect.x=scr_w/2
        
        self.speed_block_x=1
 
    
        
 
class Ball(pygame.sprite.Sprite):
    def __init__(self):
        block=Block()
        super().__init__()
        self.ball_w=30
        self.speed_ball_y=0
        self.speed_ball_x=0
        
        self.img=pygame.image.load("C:\Python34\kocka.png").convert()
        
        self.image=pygame.Surface([self.ball_w,self.ball_w])
       
 
        self.rect=self.image.get_rect()
        self.image.blit(self.img,(0,0))
        
        self.rect.x=350
        self.rect.y=block.rect.y-self.ball_w
 
class Game():
    def __init__(self):
        self.jump=-10
        self.background=pygame.image.load("C:\Python34\images.png").convert()
        self.running=True
        self.block=Block()
        self.lopta=Ball()
        
        sprites_group.add(self.block)
        main_block_group.add(self.block)
        sprites_group.add(self.lopta)
        self.onGround=True
 
    def checkBounds(self):
        if self.block.rect.x<0:
            self.block.rect.x=0
 
        if self.block.rect.x>scr_w-self.block.block_w:
            self.block.rect.x=scr_w-self.block.block_w
        if self.lopta.rect.x<0:
            self.lopta.speed_ball_x*=-1
        if self.lopta.rect.x+self.lopta.ball_w>scr_w:
            self.lopta.speed_ball_x*=-1

        

    
    def spriteCollision(self):
        if pygame.sprite.spritecollide(self.lopta,blocks_group,True):
            self.lopta.speed_ball_y*=-1
            

    def checkMainBlock(self):
        if pygame.sprite.spritecollide(self.lopta,main_block_group,False):
            self.lopta.speed_ball_y*=-1
    def gameOver(self):
        if self.lopta.rect.y>400:
            sys.exit()
            pygame.quit()
            quit()
    def event(self):
        
        self.keys=pygame.key.get_pressed()
        for e in pygame.event.get():
            if e.type==pygame.QUIT:
                self.running=False
        if self.keys[pygame.K_RIGHT]:
            self.block.rect.x+=self.block.speed_block_x
        elif self.keys[pygame.K_LEFT]:
            self.block.rect.x-=self.block.speed_block_x
        elif self.keys[pygame.K_UP] and self.onGround:
            self.lopta.speed_ball_y=-1
            self.lopta.speed_ball_x=-1
        self.lopta.rect.y+=self.lopta.speed_ball_y
        self.lopta.rect.x+=self.lopta.speed_ball_x
        if self.lopta.rect.y<0:
            self.lopta.speed_ball_y=1
        self.checkBounds()
        if self.lopta.rect.y==370:
            self.onGround=True
        else:
            self.onGround=False
        
        

    def makeBlocks(self):
        for i in range(0,120,20):
            for j in range(0,640,40):
                self.btd=blockToDestroy()
                self.btd.rect.x=j
                self.btd.rect.y=i
                blocks_group.add(self.btd)
                sprites_group.add(self.btd)
        
    
        
 
 
    def main(self):
        self.makeBlocks()
                
    
                
		
        while self.running:
            
            self.event()
            scr.blit(self.background,(0,0))
            self.spriteCollision()
            self.checkMainBlock()
            self.gameOver()
            sprites_group.draw(scr)
            pygame.display.flip()

           

newGame=Game()
newGame.main()
pygame.quit()
quit()


nie je to bohvieako upravené,mozu tam byt nejake drobnosti :-))

Tinux
Python › Pygame -obrazok bez pozadia
20. 7. 2015   #203725

Robim tu hru kde mas dole ten obdlznik s ktorym hybes a gulickou nicis tie hore,po grafickej stranke to mam,jedine co mi chyba je uhol odrazu :P Ak chces kod tak ti ho poslem do spravy...lebo som uz aj videl ako vyratat uhol medzi 2 bodmi ale neviem to zakomponovat do mojho kodu

Tinux
Python › Pygame -obrazok bez pozadia
20. 7. 2015   #203723

Niekde som to uz videl ale nevedel som naco to je :-)) alebo v skicari to prefarbim(pozadie)na nejaku farbu a kod opisem:-)) btw nevedel by si mi pomoct este s uhlami? :-))

Tinux
Python › Pygame -obrazok bez pozadia
20. 7. 2015   #203720

Zdravím,potrebujem pomoc,ako do PyGame importujem obrázok,nar. loptu,no potrebujem ju bez pozadia,cisto loptu,lebo ten obrazok je stvorec takze mam biely stvorec na modrom pozadi s loptou vo vnutri :-) Diky

Pararam
Python › PyGame - pohyb hada
20. 7. 2015   #203719

Jo aha diky:-)) mohol by si mi pomoct este s jednou vecou v pygame?:)

Pararam
Python › PyGame Skakanie aj do x aj d…
18. 7. 2015   #203673

Zdravim ,mam mensi problem v PyGame ,teda skor otazku
 

import pygame
class App():
    def __init__(self):
        pygame.init()
        self.clock=pygame.time.Clock()
        
        self.window_height=480
        self.window_width=640
        self._y=400
        self._x=100
        self.ground_height=40
        self.ground_width=1000
        self.isOnGround=True
        pygame.key.set_repeat(50,50)
        self.rect_width=40
        self.rect_height=40
        self.running=True
        self.speed=-10
        self.screen=pygame.display.set_mode((self.window_width,self.window_height))
    def checkBound(self,x,y):
        if x<0:
            self._x=0
        if y<0:
            self._y=0
        if x>self.window_width-self.rect_width:
            self._x=self.window_width-self.rect_width
        if y>self.window_height-self.rect_height-self.ground_height:
            self._y=self.window_height-self.rect_height-self.ground_height
    def jump(self):
        
        self.isOnGround=False
        while self.isOnGround==False:
            
            self._y+=self.speed
            self.speed+=1
            
            
            print(self._y,self.window_height-self.ground_height-self.rect_height)
            if self._y>=self.window_height-self.ground_height-self.rect_height:
                
                
                self._y=self.window_height-self.ground_height-self.rect_height
                self.speed=-10
                self.isOnGround=True

            self.update()
            

            
            
        
        
        
    def event(self):
        for e in pygame.event.get():
            if e.type==pygame.QUIT:
                self.running=False
            if e.type==pygame.KEYDOWN:
                if e.key==pygame.K_UP:
                    self._y-=10
                if e.key==pygame.K_DOWN:
                    self._y+=10
                if e.key==pygame.K_RIGHT:
                    self._x+=10
                if e.key==pygame.K_LEFT:
                    self._x-=10
                if e.key==pygame.K_SPACE and self.isOnGround:
                    self.jump()
                    
                
    def update(self):
        self.screen.fill((255,255,255))
        self.checkBound(self._x,self._y)
        pygame.draw.rect(self.screen,(0,0,255),(0,self.window_height-self.ground_height,self.ground_width,self.ground_height))
        pygame.draw.rect(self.screen,(255,0,0),(self._x,self._y,self.rect_width,self.rect_height))
        pygame.display.update()
    def main(self):
        while self.running:
            self.clock.tick(30)
            self.event()
            self.update()
    
            
myApp=App()
myApp.main()
pygame.quit()
quit()

Otazka znie asi takto,ked sa hybem doprava ci dolava a skocim tak sa zastavim a skocim,no a ako iste viete moja otazka znie ako zariadim aby ked skocim sa posuval aj na osi x ..Dakujem velmi pekne:-))
 

 

 

Hostujeme u Českého hostingu       ISSN 1801-1586       ⇡ Nahoru Webtea.cz logo © 20032024 Programujte.com
Zasadilo a pěstuje Webtea.cz, šéfredaktor Lukáš Churý