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
|
import pygame
import os
from AnimatedSprite import *
class Game():
def __init__(self):
pygame.display.init()
self.screen = pygame.display.set_mode((800,600))
self.clock = pygame.time.Clock()
# load images
images_main = self.load_sprite_group(50,50,"main.png")
# load levels
# setup objects
self.me = AnimatedSprite(images_main,30)
# start
print("initializing...")
def load_sprite_group(self, w, h, filename):
'''
Specs :
Master can be any height.
Sprites frames width must be the same width
Master width must be len(frames)*frame.width
Assuming you ressources directory is named "ressources"
'''
images = []
master_image = pygame.image.load(os.path.join('images', filename)).convert_alpha()
master_width, master_height = master_image.get_size()
for i in xrange(int(master_width/w)):
images.append(master_image.subsurface((i*w,0,w,h)))
return images
def start (self):
print("starting...")
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
return
if event.type == pygame.MOUSEBUTTONDOWN:
pass
self.screen.fill((0,0,0))
time_passed = self.clock.tick(30)
self.me.render(self.screen)
pygame.display.flip()
def main():
game = Game()
game.start()
if __name__ == "__main__":
main()
|