-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraphics.py
65 lines (53 loc) · 2.06 KB
/
graphics.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""graphics.py"""
"""
This file is part of The Last Caturai.
The Last Caturai is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
The Last Caturai is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Foobar. If not, see <http://www.gnu.org/licenses/>.
"""
"""It handles graphics."""
import pygame
import config
# Function which loads an image into the Window
def load_image(path, transparent):
try: image = pygame.image.load(path)
# Manages error if image cannot be loaded
except (pygame.error) as message:
raise(message)
# Converting to inner pygame format (more efficient)
image = image.convert()
if transparent:
color = image.get_at((0, 0))
image.set_colorkey(color, pygame.RLEACCEL)
return image
# Function to manage texts
def text(text, posx, posy, color, size):
font = pygame.font.Font(config.fonts+"ShrimpFriedRiceNo1.ttf", size)
output = pygame.font.Font.render(font, text, 1, color) # Transforms font into a Sprite
output_rect = output.get_rect()
output_rect.centerx = posx
output_rect.centery = posy
return output, output_rect
# Function that selects a tileset and stores it inside an array
def select_tileset(path, size):
image = load_image(path, True)
rect = image.get_rect()
col = rect.width / size[0]
fil = rect.height / size[1]
sprite = [None]
for f in range(fil):
for c in range(col):
sprite.append(image.subsurface((rect.left, rect.top, width, height)))
rect.left += width
rect.top += height
rect.left = 0
return sprite