Compare commits
No commits in common. 'b76966421ea7e5aacb9e59849b7d8bc2dd09eed7' and '996c9f61c65af212e9d8838bf11c2e37728ea81f' have entirely different histories.
b76966421e
...
996c9f61c6
|
Before Width: | Height: | Size: 1.4 MiB After Width: | Height: | Size: 1.4 MiB |
|
Before Width: | Height: | Size: 1.4 MiB After Width: | Height: | Size: 1.4 MiB |
@ -1,49 +0,0 @@
|
|||||||
import pygame
|
|
||||||
import settings
|
|
||||||
|
|
||||||
class Player:
|
|
||||||
def __init__(self, x, y):
|
|
||||||
self.image_normal = pygame.transform.scale(
|
|
||||||
pygame.image.load(settings.player.fred.normal).convert_alpha(),
|
|
||||||
settings.player.size
|
|
||||||
)
|
|
||||||
self.image_jump = pygame.transform.scale(
|
|
||||||
pygame.image.load(settings.player.fred.olli).convert_alpha(),
|
|
||||||
settings.player.size
|
|
||||||
)
|
|
||||||
self.image = self.image_normal # Anfangszustand
|
|
||||||
self.rect = self.image.get_rect(topleft=(x, y))
|
|
||||||
self.velocity_y = 0
|
|
||||||
self.speed = 5
|
|
||||||
self.gravity = 1
|
|
||||||
self.jump_strength = -12
|
|
||||||
self.on_ground = False
|
|
||||||
|
|
||||||
def update(self, ground_y):
|
|
||||||
keys = pygame.key.get_pressed()
|
|
||||||
was_on_ground = self.on_ground
|
|
||||||
if keys[pygame.K_LEFT]:
|
|
||||||
self.rect.x -= self.speed
|
|
||||||
if keys[pygame.K_RIGHT]:
|
|
||||||
self.rect.x += self.speed
|
|
||||||
if keys[pygame.K_SPACE] and self.on_ground:
|
|
||||||
self.velocity_y = self.jump_strength
|
|
||||||
self.on_ground = False
|
|
||||||
if self.on_ground and self.image != self.image_normal:
|
|
||||||
self.image = self.image_normal
|
|
||||||
elif not self.on_ground and self.image != self.image_jump:
|
|
||||||
self.image = self.image_jump
|
|
||||||
if not self.on_ground and was_on_ground and settings.DEBUG:
|
|
||||||
print("Fred springt!")
|
|
||||||
|
|
||||||
self.velocity_y += self.gravity
|
|
||||||
self.rect.y += self.velocity_y
|
|
||||||
|
|
||||||
# Boden-Kollision
|
|
||||||
if self.rect.bottom >= ground_y:
|
|
||||||
self.rect.bottom = ground_y
|
|
||||||
self.velocity_y = 0
|
|
||||||
self.on_ground = True
|
|
||||||
|
|
||||||
def draw(self, screen):
|
|
||||||
screen.blit(self.image, self.rect)
|
|
||||||
Loading…
Reference in new issue