-
Notifications
You must be signed in to change notification settings - Fork 0
/
graphics.py
91 lines (65 loc) · 2.78 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import pygame
from bitmapfont import *
from globalconst import *
tiles = {}
font = None
rotatedSprites = {}
masks = {}
rotatedMasks = {}
debugTiles = []
def loadGraphics():
global font
font = BitmapFont('gfx/heimatfont.png', scr_w=SCR_W, scr_h=SCR_H, colors=[(255,255,255), (240,0,240)])
global tiles
tiles = {'#': pygame.image.load('gfx/wall-solid.png'),
'1': pygame.image.load('gfx/wall-ramp-lowerright.png'),
'2': pygame.image.load('gfx/wall-ramp-lowerleft.png'),
'3': pygame.image.load('gfx/wall-ramp-upperright.png'),
'4': pygame.image.load('gfx/wall-ramp-upperleft.png'),
'_': pygame.image.load('gfx/floor-center.png'),
'F': pygame.image.load('gfx/floor-border-left.png'),
'T': pygame.image.load('gfx/floor-border-right.png'),
'player0': pygame.image.load('gfx/player0.png'),
'player1': pygame.image.load('gfx/player1.png'),
'player2': pygame.image.load('gfx/player2.png'),
'player3': pygame.image.load('gfx/player3.png'),
'player4': pygame.image.load('gfx/player4.png'),
'player5': pygame.image.load('gfx/player5.png'),
'debug': pygame.image.load('gfx/debugtile.png'),
}
global masks
for tileId in tiles.keys():
masks[tileId] = pygame.mask.from_surface(tiles[tileId])
def getFont():
return font
def rotateSprite(obj):
tileId = obj.getSprite()
if not tileId in tiles:
return (None, None)
tile = tiles[tileId]
# no filtering
#rotated_sprite = pygame.transform.rotate(tile, obj.rotation)
#rotated_sprite = pygame.transform.scale(rotated_sprite, (round(rotated_sprite.get_size()[0] / 16), round(rotated_sprite.get_size()[1] / 16)))
# instant filtering
#rotated_sprite = pygame.transform.rotozoom(tile, obj.rotation, 1.0/16.0)
# multi-step filtering
rotated_sprite = pygame.transform.rotozoom(tile, obj.rotation, 0.5)
rotated_sprite = pygame.transform.rotozoom(rotated_sprite, 0, 0.5)
rotated_sprite = pygame.transform.rotozoom(rotated_sprite, 0, 0.5)
rotated_sprite = pygame.transform.rotozoom(rotated_sprite, 0, 0.5)
rotated_rect = rotated_sprite.get_rect(center=(obj.x, obj.y))
rotatedSprites[obj] = (rotated_sprite, rotated_rect)
rotatedMasks[obj] = pygame.mask.from_surface(rotated_sprite)
return rotated_sprite, rotated_rect
def getTiles():
return tiles
def getFont():
return font
def getRotatedSprites():
return rotatedSprites
def checkPixelTileCollision(obj, tileId, tilex, tiley):
mask = masks[tileId]
playermask = rotatedMasks[obj]
objx = rotatedSprites[obj][1].x
objy = rotatedSprites[obj][1].y
return mask.overlap(playermask, (int(objx - tilex * TILE_W), int(objy - tiley * TILE_H)))