import pygame
import sys
from time import sleep
class Doodlejump:
def __init__(self):
self.go = True
self.x = 275
self.y = 800
self.doodle = Doodle(self.x, self.y, "doodle_resized.png")
self.gravity = 7.5
self.jump_counter = 0
self.speed = 2
self.jump_timer = 0
def run(self):
pygame.init()
pygame.display.set_caption("Doodlejump")
clock = pygame.time.Clock()
screen = pygame.display.set_mode((600, 800))
while self.go:
if self.x < 0:
self.x = 0
elif self.x >= 600 - self.doodle.width:
self.x = 600 - self.doodle.width
if self.y < 0:
self.y = 0
elif self.y >= 800 - self.doodle.height:
self.y = 800 - self.doodle.height
if self.y >= 800 - self.doodle.height:
self.jump_counter = 0
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
pressed = pygame.key.get_pressed()
if pressed[pygame.K_LEFT]:
self.x -= self.speed
if pressed[pygame.K_RIGHT]:
self.x += self.speed
screen.fill((255, 255, 255))
is_jumping = False
if pressed[pygame.K_SPACE] and not is_jumping and self.jump_counter < 1 and self.jump_timer <= 0:
is_jumping = True
self.y -= self.speed
self.jump_counter += 1
self.jump_timer = 100
if self.jump_timer > 0:
self.jump_timer -= 1
jump_speed_factor = 250
if is_jumping:
self.y -= jump_speed_factor
jump_speed_factor *= 0.3
else:
self.y += self.gravity
self.jump_timer -= 15
platform = pygame.draw.rect(screen, (0, 0, 0), (100, 700, 150, 30))
if platform.colliderect(self.doodle):
print("Kollision!!!")
screen.blit(self.doodle.image, (self.x, self.y))
pygame.display.update()
clock.tick(60)
if __name__ == "__main__":
game = Doodlejump()
game.run()
我策划了一场与佩伊加梅交的Doodlejump游戏,但不幸的是,我的碰撞探测确实奏效。 当我试图把我的杜戈放在平台上时,它只是跳跃走。 原因何在? 我已经把发言从法典的顶点移到底部,但这种说法并没有改变。 采用col(col)法的“一”方法是错误的? 如果发生碰撞,就根本不进入路障。