-
Notifications
You must be signed in to change notification settings - Fork 0
/
7cell_brief4.py
79 lines (69 loc) · 2.5 KB
/
7cell_brief4.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import pygame, sys, re
from time import sleep
from pygame.locals import *
from random import shuffle
clock = pygame.time.Clock()
FPS = 30
playtime = 0.0
counter = 0
pygame.font.init()
font = pygame.font.Font(None, 30)
batch_size = 7
tiles = {}
sprites = {}
pygame.init()
sizex=1920
sizey=1080
xdivision = 16
ydivision = 9
xshuf = [i for i in range(xdivision*ydivision)]
unitx = sizex/xdivision
unity = sizey/ydivision
import os
for file in os.listdir("data/sprites"):
if file.endswith(".png"):
m = re.search('^(\w+)_(\d+)_(\d+).png',file)
(spritename, spritex, spritey) = (m.group(1), int(m.group(2)), int(m.group(3)))
print file
print ("%s %i %i" % (spritename, spritex, spritey))
spriteboxx = int(spritex%xdivision)
spriteboxy = int(spritey%ydivision)
spriteboxnumber = int((spriteboxy*xdivision)+spriteboxx)
# sprite = pygame.image.load(os.path.join('data/sprites', file)).convert_alpha
# size=sprite.Surface.get_size()
# print size
# (spritesizex,spritesizey) = sprite.get_rect()
# print ("x=%s y=%s" % (spritesizex, spritesizey))
tiles[spriteboxnumber] = ( spritename, spritex, spritey)
for key in tiles.keys():
(spritename, spritex, spritey)=tiles[key]
print ("%i %s %i %i" % (key, spritename, spritex, spritey))
screen = pygame.display.set_mode((sizex, sizey))
#background = pygame.image.load('data/all_on_one_no_bg.png')
background = pygame.image.load('data/plastic_reality_bg.png')
im2= pygame.Surface(screen.get_size())
#im2.fill((0, 0, 0))
#im2 = pygame.image.load('data/plastic_reality_bg.png')
im2 = pygame.image.load('data/all_on_one_no_bg.png')
screen.blit(im2,(0,0))
pygame.display.flip()
while True:
milliseconds = clock.tick(FPS)
playtime += milliseconds / 1000.0
shuffle(xshuf)
for i in range(0,7):
random_value = xshuf[i]
try:
# print random_value
(sprite_to_print,spx,spy)=tiles[random_value]
print (sprite_to_print, spx, spy)
print (pygame.Rect(spx,spy,120,120))
screen.blit(im2, (spx, spy), pygame.Rect(spx, spy, 120, 120))
text_surface = font.render("FPS: %f Playtime: %f " % (clock.get_fps(),playtime), True, (255,255,255))
screen.blit(text_surface, (10, 10))
# pygame.display.flip()
time.sleep(1)
screen.blit(background, (spx, spy), pygame.Rect(spx, spy, sizex, sizey))
# pygame.display.flip()
except:
sprite_to_print="False"