|
After Width: | Height: | Size: 308 B |
|
After Width: | Height: | Size: 317 B |
|
After Width: | Height: | Size: 312 B |
|
After Width: | Height: | Size: 345 B |
|
After Width: | Height: | Size: 334 B |
|
After Width: | Height: | Size: 334 B |
|
After Width: | Height: | Size: 342 B |
|
After Width: | Height: | Size: 337 B |
|
After Width: | Height: | Size: 351 B |
|
After Width: | Height: | Size: 342 B |
|
After Width: | Height: | Size: 337 B |
|
After Width: | Height: | Size: 340 B |
|
After Width: | Height: | Size: 341 B |
|
After Width: | Height: | Size: 342 B |
|
After Width: | Height: | Size: 337 B |
|
After Width: | Height: | Size: 334 B |
|
After Width: | Height: | Size: 351 B |
|
After Width: | Height: | Size: 342 B |
|
After Width: | Height: | Size: 337 B |
|
After Width: | Height: | Size: 334 B |
|
After Width: | Height: | Size: 345 B |
|
After Width: | Height: | Size: 341 B |
|
After Width: | Height: | Size: 312 B |
|
After Width: | Height: | Size: 317 B |
|
After Width: | Height: | Size: 334 B |
|
After Width: | Height: | Size: 345 B |
|
After Width: | Height: | Size: 332 B |
|
After Width: | Height: | Size: 292 B |
|
After Width: | Height: | Size: 332 B |
|
After Width: | Height: | Size: 345 B |
|
After Width: | Height: | Size: 332 B |
|
After Width: | Height: | Size: 333 B |
|
After Width: | Height: | Size: 309 B |
|
After Width: | Height: | Size: 337 B |
|
After Width: | Height: | Size: 340 B |
|
After Width: | Height: | Size: 342 B |
50
main.py
|
|
@ -58,17 +58,34 @@ class Player:
|
|||
self.anim_counter = 0
|
||||
self.ANIM_SPEED = 8
|
||||
|
||||
|
||||
self.stand = pygame.image.load(sprites["stand"]).convert_alpha()
|
||||
self.walk_left = pygame.image.load(sprites["walk_left"]).convert_alpha()
|
||||
self.walk_right = pygame.image.load(sprites["walk_right"]).convert_alpha()
|
||||
self.jump_img = pygame.image.load(sprites["jump"]).convert_alpha()
|
||||
|
||||
|
||||
# support three-stage jump:
|
||||
# - sprites["jump"] can be a list/tuple of 3 paths [start, mid, end]
|
||||
# - or provide explicit keys "jump_start", "jump_mid", "jump_end"
|
||||
# - otherwise fallback to a single jump image (same for all stages)
|
||||
jump_entry = sprites.get("jump")
|
||||
if isinstance(jump_entry, (list, tuple)) and len(jump_entry) == 3:
|
||||
self.jump_start = pygame.image.load(jump_entry[0]).convert_alpha()
|
||||
self.jump_mid = pygame.image.load(jump_entry[1]).convert_alpha()
|
||||
self.jump_end = pygame.image.load(jump_entry[2]).convert_alpha()
|
||||
elif all(k in sprites for k in ("jump_start", "jump_mid", "jump_end")):
|
||||
self.jump_start = pygame.image.load(sprites["jump_start"]).convert_alpha()
|
||||
self.jump_mid = pygame.image.load(sprites["jump_mid"]).convert_alpha()
|
||||
self.jump_end = pygame.image.load(sprites["jump_end"]).convert_alpha()
|
||||
else:
|
||||
single_path = jump_entry if isinstance(jump_entry, str) else sprites.get("jump", sprites["stand"])
|
||||
single = pygame.image.load(single_path).convert_alpha()
|
||||
self.jump_start = self.jump_mid = self.jump_end = single
|
||||
|
||||
self.stand = pygame.transform.scale(self.stand, (int(self.stand.get_width() * scale), int(self.stand.get_height() * scale)))
|
||||
self.walk_left = pygame.transform.scale(self.walk_left, (int(self.walk_left.get_width() * scale), int(self.walk_left.get_height() * scale)))
|
||||
self.walk_right = pygame.transform.scale(self.walk_right, (int(self.walk_right.get_width() * scale), int(self.walk_right.get_height() * scale)))
|
||||
self.jump_img = pygame.transform.scale(self.jump_img, (int(self.jump_img.get_width() * scale), int(self.jump_img.get_height() * scale)))
|
||||
self.jump_start = pygame.transform.scale(self.jump_start, (int(self.jump_start.get_width() * scale), int(self.jump_start.get_height() * scale)))
|
||||
self.jump_mid = pygame.transform.scale(self.jump_mid, (int(self.jump_mid.get_width() * scale), int(self.jump_mid.get_height() * scale)))
|
||||
self.jump_end = pygame.transform.scale(self.jump_end, (int(self.jump_end.get_width() * scale), int(self.jump_end.get_height() * scale)))
|
||||
|
||||
self.surface = self.stand
|
||||
self.rect = self.surface.get_rect(midbottom=(self.x, self.y))
|
||||
|
|
@ -121,7 +138,18 @@ class Player:
|
|||
|
||||
def update_animation(self):
|
||||
if self.jumping:
|
||||
self.surface = self.jump_img
|
||||
# choose jump stage by vertical velocity:
|
||||
# - strong negative: start (ascending)
|
||||
# - near zero: mid (apex)
|
||||
# - positive: end (descending)
|
||||
up_thresh = -self.jump_power * 0.4
|
||||
down_thresh = self.jump_power * 0.4
|
||||
if self.y_velocity < up_thresh:
|
||||
self.surface = self.jump_start
|
||||
elif self.y_velocity > down_thresh:
|
||||
self.surface = self.jump_end
|
||||
else:
|
||||
self.surface = self.jump_mid
|
||||
elif self.moving:
|
||||
self.anim_counter += 1
|
||||
frame = (self.anim_counter // self.ANIM_SPEED) % 2
|
||||
|
|
@ -160,10 +188,14 @@ goblin = Player(
|
|||
knight = Player(
|
||||
500, GROUND_Y,
|
||||
{
|
||||
"stand": "images/sprites/knight.png",
|
||||
"walk_left": "images/sprites/knight.png",
|
||||
"walk_right": "images/sprites/knight.png",
|
||||
"jump": "images/sprites/knight.png"
|
||||
"stand": "images/knight-named/stand.png",
|
||||
"walk_left": "images/knight-named/walkleft.png",
|
||||
"walk_right": "images/knight-named/walkright.png",
|
||||
"jump": [
|
||||
"images/knight-named/roll1.png",
|
||||
"images/knight-named/roll2.png",
|
||||
"images/knight-named/roll3.png"
|
||||
]
|
||||
},
|
||||
3,
|
||||
{
|
||||
|
|
|
|||