python - Sprite jumping way too high -


earlier, fixed lag of code , before, game made sprite lag. fixed that, time keeps making sprite fly way high , out of screen not coming down... can sprite(poppy) not jump high?

import pygame, sys pygame.locals import * pygame.init()  class poppy(pygame.sprite.sprite):    def __init__(self): #making player        pygame.sprite.sprite.__init__(self)        self.image = pygame.image.load('poppy.png')        self.rect = self.image.get_rect()        self.grav = .5        self.y_vel = 5        self.jumping = false     def jump_update(self): #checking jumps        if self.jumping:            self.y_vel += self.grav            self.rect.y += self.y_vel     def jump(self): #the jump initializer        if not self.jumping:            self.y_vel = -50            self.jumping = true     def keys(self): #the keys        key = pygame.key.get_pressed()        dist = 5        if key[pygame.k_right]: # right key            self.rect.x += dist # move right        elif key[pygame.k_left]: # left key            self.rect.x -= dist     def collide_check(self, platform_list): #check if hit ground or platforms        blocks in platform_list:            if pygame.sprite.collide_rect(self, blocks) == true:                self.rect.y = blocks.top         if self.rect.y >= 600-self.rect.height:              # ball hits top , bottom            self.y_vel = 0            self.rect.y = 600 - self.rect.height            self.jumping = false     def move(self):        self.rect.y += self.y_vel     def draw(self, surface):        surface.blit(self.image, (self.rect.x, self.rect.y))  class platform(pygame.sprite.sprite):    def __init__(self):        pygame.sprite.sprite.__init__(self)        self.image = pygame.image.load('levoneplatform.png')        self.rect = self.image.get_rect()  class enemy(pygame.sprite.sprite):   def __init__(self):      pygame.sprite.sprite.__init__(self)      self.image = pygame.image.load('enemy.png')      self.rect = self.image.get_rect()   class menu():    def __init__(self):        self.background_image = pygame.image.load('menu.png').convert_alpha()     def update(self):        screen.blit(self.background_image, [0,0])   class levone():    def __init__(self):         self.background_image = pygame.image.load('night.png').convert_alpha()          platforms_one = [ (200,300),                        (50,500),                        (550,650),                        (300,200),                        (120,100)                   ]        k,v in platforms_one:            platform = platform()            enemy = enemy()            platform.rect.x = k            enemy.rect.x = k            platform.rect.y = v            enemy.rect.y = v - 44            platform_list.add(platform)            enemy_list.add(enemy)     def update(self):         screen.blit(self.background_image, [0, 0])  class levtwo():    def __init__(self):         self.background_image = pygame.image.load('night.png').convert_alpha()         platforms_two = platforms_two = [ (300,400),                        (500,500),                        (100,300),                        (300,100),                   ]         k,v in platforms_two:            platform = platform()            enemy = enemy()            platform.rect.x = k            enemy.rect.x = k            platform.rect.y = v            enemy.rect.y = v - 44            platform_list.add(platform)            enemy_list.add(enemy)     def update(self):        screen.blit(self.background_image, [0,0])   screen = pygame.display.set_mode((800,600)) enemy_list = pygame.sprite.group() platform_list = pygame.sprite.group() poppy = poppy() menu = menu() levone = levone()   clock = pygame.time.clock() level = 1  while true:   clock.tick(60)    event in pygame.event.get():       if event.type == quit:           pygame.quit()           sys.exit()       elif event.type == keydown:           if event.key == k_space:               poppy.jump()    menu.update()   if event.type == mousebuttondown:        x,y = pygame.mouse.get_pos()        if x >= 544.86 , x <= 700.86 , y <= 385.02 , y >= 340.03:            level = 1    if level == 1:         poppy.keys()       poppy.move()        levone.update()         poppy.draw(screen)       platform_list.draw(screen)       enemy_list.draw(screen)        pygame.display.update()    if level == 2:        second_lives = 3        levtwo.update()       poppy.keys()       poppy.move()        platform_list.draw(screen)       enemy_list.draw(screen)       poppy.draw(screen)    pygame.display.update() 

you've set gravity @ 0.5 units/second^2, jump @ velocity of -50 units/second; take 2 minutes character start falling again!

either increase gravity, or decrease velocity of jump -3.

edit:

call function somewhere in move() or update() function:

def jump_update(self): #checking jumps    if self.jumping:        self.y_vel += self.grav        self.rect.y += self.y_vel 

right it's not being used.


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -