-
Notifications
You must be signed in to change notification settings - Fork 0
/
coins.py
74 lines (57 loc) · 2.36 KB
/
coins.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
import pygame, sys
from pygame.locals import *
import random
from PIL import Image
def create_coins(map_image, dictionary, block_size, width):
"""Function that, given a pixeled image of a map, a dictionary with various color for the relative blocks, their image and other information, the size of the block and the width of the monitor return a map the dimension of the map_image moltiplied by the block_size
"""
coinmap_image = Image.open(map_image)
coinmap_raw = list(coinmap_image.getdata()) #getting data(color) from the image
map = []
small_coin = []
big_coin = []
x = 0
y = 0
for element in coinmap_raw: #the image of the block
if element == (255, 255, 0) or element == (255, 0, 0):
if element == (255, 255, 0):
surface_sprite = pygame.transform.scale(
pygame.image.load(dictionary[element][0]),
(block_size, block_size))
coin = Coin(surface_sprite, x, y, dictionary[element][1])
elif element == (255, 0, 0):
surface_sprite = pygame.transform.scale(
pygame.image.load(dictionary[element][0]),
(block_size, block_size))
coin = Bigcoin(surface_sprite, x, y, dictionary[element][1])
map.append(coin)
x += block_size
if x == width:
x = 0
y += block_size
return map
def place_coins(coinmap_group, window):
for coin in coinmap_group:
coin.draw(window, coin.rect.x, coin.rect.y)
class Coin(pygame.sprite.Sprite):
"""The class of the various 'coins'"""
def __init__(self, image, x, y, type):
pygame.sprite.Sprite.__init__(self)
self.image = image
self.rect = self.image.get_rect()
self.rect.x = x
self.rect.y = y
self.type = type
def draw(self, screen, x, y):
screen.blit(self.image, (x, y))
class Bigcoin(pygame.sprite.Sprite):
"""The class of the big 'coins'"""
def __init__(self, image, x, y, type):
pygame.sprite.Sprite.__init__(self)
self.image = image
self.rect = self.image.get_rect()
self.rect.x = x
self.rect.y = y
self.type = type
def draw(self, screen, x, y):
screen.blit(self.image, (x, y))