반응형

Tweening을 적용해 보자.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import pygame
import pytweening
 
pygame.init()
pygame.display.set_caption("Super fun game development")
screen = pygame.display.set_mode((640480))
clock = pygame.time.Clock()
running = True
 
player = pygame.image.load("player.png").convert()
player.set_colorkey(player.get_at((00)))
player_size = (player.get_width()*1.5, player.get_height()*1.5)
player = pygame.transform.scale(player, player_size)
player_pos = player.get_rect()
player_pos.center = (screen.get_width()/2-200, screen.get_height()/2)
 
= 0
# pytweening 인수
 
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
        elif event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
            running = False
    
    n += 0.005
    if n > 1:
        n = 0
 
    dx = int(pytweening.easeInOutBounce(n) * 400)
    #dx = int(pytweening.easeInOutElastic(n) * 400)
    # 최종적으로 400 픽셀 이동. (0 <= n <= 1)
        
    screen.fill("black")
    screen.blit(player, (player_pos.left+dx, player_pos.top))
        
    pygame.display.flip()
    clock.tick(60)
 
pygame.quit()
 

 

 

easeInOutBounce

 

easeInOutElastic

 

반응형
Posted by J-sean
: