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:-))