-
Notifications
You must be signed in to change notification settings - Fork 1
/
spritetest.py
executable file
·61 lines (48 loc) · 2.27 KB
/
spritetest.py
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/python
# Utility program to check the animations and functionality of the
# animatedSprite class
import pygame
from RPG.AnimatedSprite import AnimatedSprite
# code from http://www.gamedev.net/topic/444490-pygame-easy-as-py/
class Game:
def __init__(self):
pygame.init()
self.screen = pygame.display.set_mode((640,480))
pygame.display.set_caption("AnimatedSprite preview")
self.clock = pygame.time.Clock()
self.sprite = AnimatedSprite(self.clock, 'data/sprites/player/player_debug.png')
self.background = pygame.image.load('data/scenes/debug.png').convert()
def MainLoop(self):
keepGoing = True
direction = ''
while keepGoing:
self.clock.tick(30) #limit fps
for event in pygame.event.get():
if event.type == pygame.QUIT:
keepGoing = False
# may want to look at pygame.key.set_repeat
if event.type == pygame.KEYDOWN:
keyName = pygame.key.name(event.key)
self.sprite.speed = 10
if keyName == 'up':
self.sprite.direction = self.sprite.set_animation('up')
elif keyName == 'down':
self.sprite.direction = self.sprite.set_animation('down')
elif keyName == 'left':
self.sprite.direction = self.sprite.set_animation('left')
elif keyName == 'right':
self.sprite.direction = self.sprite.set_animation('right')
elif keyName == 'q':
self.sprite.direction = self.sprite.set_animation('spin')
elif event.type == pygame.KEYUP:
if pygame.key.name(event.key) in ('up','down','left','right','q'):
self.sprite.speed = 0
font = pygame.font.Font(None, 36)
info = "Animation: %s Frame: %s" % (self.sprite.animation, self.sprite.frame)
text = font.render(info, 1, (255, 255, 255))
self.screen.blit(self.background, (0,0))
self.screen.blit(text, (0,0))
self.screen.blit(self.sprite.get_frame(), (320,240))
pygame.display.flip()
g = Game()
g.MainLoop()