-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTiles.py
84 lines (72 loc) · 3.06 KB
/
Tiles.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
import pygame
import json
# from Debug import Debug
class Tiles:
def __init__(self, data, PathToImages, screenwidth, screenheight, Uo):
self.dat = data.read()
self.data = json.loads(self.dat)
self.screenwidth = screenwidth
self.screenheight = screenheight
self.Stone = pygame.transform.scale(pygame.image.load(
PathToImages + "Stone.png"), ((self.screenwidth/16, self.screenheight/16)))
self.Sand = pygame.transform.scale(pygame.image.load(
PathToImages + "Sand.png"), ((self.screenwidth/16, self.screenheight/16)))
self.middle = (screenwidth/2-Uo[0], screenheight/2-Uo[1])
self.sprites = [self.Stone] #, self.Sand
def Show(self, surface, Px, Py, Ux, Uy, Uo):
self.middleOffset = (self.middle[0] - self.Stone.get_size()
[0]/2, self.middle[1] - self.Stone.get_size()[1]/2)
X = -Px * Ux + self.middleOffset[0]
Y = Py * Uy + self.middleOffset[1]
for tile in self.data['Tiles']:
lx, ly = self.data['Tiles'][tile]['x']*Ux, -self.data['Tiles'][tile]['y']*Uy
surface.blit(
self.sprites[self.data['Tiles'][tile]['type']], (X+lx, Y+ly))
# surface.blit()
def UpdateData(self, data):
self.dat = data.read()
self.data = json.loads(self.dat)
def Corrected(self, Px, Py, PrevX, PrevY, DebugEnabled):
Grounded = False
wipx = Px
wipy = Py
for tile in self.data['Tiles']:
x = self.data['Tiles'][tile]['x']
y = self.data['Tiles'][tile]['y']
# print(str(x) + ", " + str(y))
a = x - 0.5 < wipx + 0.5
b = x + 0.5 > wipx - 0.5
c = y - 0.5 < wipy + 0.5
d = y + 0.5 > wipy - 0.5
a2 = x - 0.5 < PrevX + 0.5
b2 = x + 0.5 > PrevX - 0.5
c2 = y - 0.5 < PrevY + 0.5
d2 = y + 0.5 > PrevY - 0.5
if a & b & c & d:
if a & b:
if a and not a2:
wipx = x-1
#if DebugEnabled:
# print("PR hit TL")
else:
if b and not b2:
wipx = x+1
# if DebugEnabled:
# print("PL hit TR")
if c & d:
if c and not c2:
wipy = y-1
#if DebugEnabled:
# print("PT hit TB")
else:
if d and not d2:
wipy = y+1
Grounded = True
#if DebugEnabled:
# print("PB hit TT")
if DebugEnabled:
print(str(a), str(b), str(c), str(d), str(a2), str(b2), str(c2), str(d2))
if DebugEnabled:
print(str(wipx) + ", " + str(wipy))
mixed = [wipx,wipy,Grounded]
return(mixed)