forked from Coursaux/GameJam
/
building.py
158 lines (136 loc) · 5.64 KB
/
building.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import os
import pygame
from constants import *
from sprites import SpriteGroup
from general import load_image, get_relative, Coords
from scaled_rect import ScaledRect
from collectibles import Collectible
class Building:
"""
rect for collision, entrance
image for background
note that entrance is relative to position
"""
def __init__(self, entrance, background_png_name, name, collectibles, furniture):
png_name = os.path.join("inside_houses", background_png_name)
self.entrance = ScaledRect.from_rect(entrance)
self.background = load_image(png_name, return_rect=False)
self.name = name
self.collectibles = collectibles
self.furniture = {k: ScaledRect.from_rect(v) for k, v in furniture.items()}
exit_x = 59
exit_y = self.background.get_height()//SCALE - 25
exit_width = self.background.get_width()//SCALE - 59*2
exit_height = 15
self.exit_area = ScaledRect(exit_x, exit_y, exit_width, exit_height)
self.walls = ScaledRect(11, 63, 140, 175)
def enters(self, character, camera):
return character.get_rect_at_feet().colliderect(get_relative(self.entrance.rect, camera))
@property
def camera_entrance_coords(self):
"""
gets the camera into the middle of the entrance
"""
return Coords(*self.entrance.rect.center)
@property
def camera_exit_coords(self):
"""
gets the camera into the middle of the exit
"""
return Coords(*self.exit_area.rect.center)
def debug_draw_position(self, screen, camera):
relative_position = get_relative(self.entrance.rect, camera)
pygame.draw.rect(screen, pygame.Color("orange"), relative_position)
def debug_draw_inner(self, screen, camera):
relative_position = get_relative(self.walls.rect, camera)
pygame.draw.rect(screen, pygame.Color("red"), relative_position)
for furniture in self.furniture.values():
relative_position = get_relative(furniture.rect, camera)
pygame.draw.rect(screen, pygame.Color("green"), relative_position)
relative_position = get_relative(self.exit_area.rect, camera)
pygame.draw.rect(screen, pygame.Color("orange"), relative_position)
def create_buildings():
"""
"""
buildings_dict = {
"weaver_house": Building(
entrance=pygame.Rect(323, 324, 20, 7),
background_png_name="weaver_house.png",
name="the weaver's house",
collectibles=SpriteGroup({
"bandages": Collectible("bandages.png", 37, 198),
"scarf": Collectible("ugly_green_scarf.png", 44, 108),
}),
furniture={
"thread_thing1": pygame.Rect(70, 65, 18, 23),
"thread_thing2": pygame.Rect(98, 65, 21, 23),
"thread_thing3": pygame.Rect(122, 203, 20, 24),
"barrel": pygame.Rect(123, 56, 23, 30),
"table": pygame.Rect(17, 179, 37, 45),
"bed": pygame.Rect(14, 67, 44, 60),
}
),
"your_house": Building(
entrance=pygame.Rect(518, 347, 20, 8),
background_png_name="your_house.png",
name="your house",
collectibles=SpriteGroup({
"gold": Collectible("pileogold.png", 39, 180)
}),
furniture={
"bed": pygame.Rect(98, 65, 46, 66),
"table": pygame.Rect(16, 179, 40, 46),
"dresser": pygame.Rect(14, 58, 47, 27),
"bedside_table": pygame.Rect(72, 56, 20, 29),
}
),
"other_house": Building(
entrance=pygame.Rect(629, 500, 23, 8),
background_png_name="other_house.png",
name="the neighbour's house",
collectibles=SpriteGroup({
"sword": Collectible("sword.png", 37, 80),
"bow and arrow": Collectible("bow_arrow.png", 130, 200),
"daggers": Collectible("daggers.png", 100, 125),
}),
furniture={
"bed": pygame.Rect(98, 58, 48, 97),
"table": pygame.Rect(14, 62, 37, 45),
"barrel1": pygame.Rect(15, 173, 21, 26),
"barrel2": pygame.Rect(14, 204, 23, 28),
"barrel3": pygame.Rect(41, 205, 23, 27),
"barrel4": pygame.Rect(126, 203, 21, 29),
}
),
"baker_house": Building(
entrance=pygame.Rect(449, 546, 22, 8),
background_png_name="baker_house.png",
name="the baker's house",
collectibles=SpriteGroup({
"bread": Collectible("bread.png", 19, 118),
"cheese": Collectible("cheese.png", 37, 118),
}),
furniture={
"ovens": pygame.Rect(33, 45, 114, 33),
"dresser": pygame.Rect(16, 124, 98, 29),
"barrels": pygame.Rect(125, 205, 23, 26),
}
),
"butcher_house": Building(
entrance=pygame.Rect(307, 597, 20, 8),
background_png_name="butcher_house.png",
name="the butcher's house",
collectibles=SpriteGroup({
"water_skin": Collectible("water_skin.png", 38, 84),
"jerky": Collectible("jerky.png", 19, 203),
}),
furniture={
"table1": pygame.Rect(17, 68, 36, 44),
"table2": pygame.Rect(104, 68, 36, 41),
"dressers": pygame.Rect(17, 150, 96, 26),
"small_table": pygame.Rect(15, 203, 19, 28),
}
),
}
group = SpriteGroup(buildings_dict)
return group