-
Notifications
You must be signed in to change notification settings - Fork 3
/
buildworld.py
210 lines (169 loc) · 4.37 KB
/
buildworld.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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
"""
Game world for "mh"
this will create a pickle that can be read by the library
"""
import pygame
pygame.mixer.init()
from lib2d.env import Environment, Area
from lib2d.avatar import Avatar, Animation, StaticAnimation
from lib2d.objects import AvatarObject
from lib2d import res, tmxloader
from lib.rpg import Hero, NPC
from collections import defaultdict
# build the initial environment
uni = Environment()
uni.name = 'MH'
uni.setGUID(0)
# build our avatars and heros
avatar = Avatar()
ani = Animation("warrior-male-stand.png", "stand", 1, 4)
avatar.add(ani)
ani = Animation("warrior-male-walk.png", "walk", [0,1,2,1], 4)
avatar.add(ani)
ani = Animation("warrior-male-attack.png", "attack", 4, 4, 60)
avatar.add(ani)
avatar.play("walk")
npc = Hero()
npc.setName("Rat")
npc.setAvatar(avatar)
npc.setGUID(1)
uni.add(npc)
avatar = Avatar()
ani = Animation("townfolk-male-walk.png", "walk", [0,1,2,1], 4)
avatar.add(ani)
npc = NPC()
npc.setName("Mayor")
npc.setAvatar(avatar)
npc.setGUID(2)
uni.add(npc)
avatar = Avatar()
ani = Animation("ranger-male-walk.png", "walk", [0,1,2,1], 4)
avatar.add(ani)
npc = NPC()
npc.setName("Bolt")
npc.setAvatar(avatar)
npc.setGUID(3)
uni.add(npc)
avatar = Avatar()
ani = Animation("healer-male-walk.png", "walk", [0,1,2,1], 4)
avatar.add(ani)
npc = NPC()
npc.setName("Ax")
npc.setAvatar(avatar)
npc.setGUID(4)
uni.add(npc)
avatar = Avatar()
ani = Animation("healer-female-walk.png", "walk", [0,1,2,1], 4)
avatar.add(ani)
npc = NPC()
npc.setName("Tooth")
npc.setAvatar(avatar)
npc.setGUID(5)
uni.add(npc)
avatar = Avatar()
ani = Animation("magician-male-walk.png", "walk", [0,1,2,1], 4)
avatar.add(ani)
npc = NPC()
npc.setName("Nail")
npc.setAvatar(avatar)
npc.setGUID(6)
uni.add(npc)
avatar = Avatar()
ani = StaticAnimation("16x16-forest-town.png", "barrel", (9,1), (16,16))
avatar.add(ani)
item = AvatarObject()
item.pushable = True
item.setName("Barrel")
item.setAvatar(avatar)
item.setGUID(513)
uni.add(item)
avatar = Avatar()
ani = StaticAnimation("16x16-forest-town.png", "sign", (11,1), (16,16))
avatar.add(ani)
item = AvatarObject()
item.pushable = False
item.setName("Sign")
item.setAvatar(avatar)
item.setGUID(514)
uni.add(item)
avatar = Avatar()
ani = StaticAnimation("16x16-forest-town.png", "rock", (8,9), (16,16))
avatar.add(ani)
item = AvatarObject()
item.pushable = True
item.setName("Rock")
item.setAvatar(avatar)
item.setGUID(515)
uni.add(item)
avatar = Avatar()
ani = StaticAnimation("16x16-forest-town.png", "stump", (8,7), (16,16))
avatar.add(ani)
item = AvatarObject()
item.pushable = False
item.setName("Stump")
item.setAvatar(avatar)
item.setGUID(516)
uni.add(item)
avatar = Avatar()
ani = StaticAnimation("16x16-forest-town.png", "stump", (8,7), (16,16))
avatar.add(ani)
item = AvatarObject()
item.pushable = False
item.setName("Stump")
item.setAvatar(avatar)
item.setGUID(517)
uni.add(item)
avatar = Avatar()
ani = StaticAnimation("16x16-forest-town.png", "stump", (8,7), (16,16))
avatar.add(ani)
item = AvatarObject()
item.pushable = False
item.setName("Stump")
item.setAvatar(avatar)
item.setGUID(518)
uni.add(item)
avatar = Avatar()
ani = StaticAnimation("16x16-forest-town.png", "stump", (8,7), (16,16))
avatar.add(ani)
item = AvatarObject()
item.pushable = False
item.setName("Stump")
item.setAvatar(avatar)
item.setGUID(519)
uni.add(item)
avatar = Avatar()
ani = StaticAnimation("16x16-forest-town.png", "stump", (8,7), (16,16))
avatar.add(ani)
item = AvatarObject()
item.pushable = False
item.setName("Stump")
item.setAvatar(avatar)
item.setGUID(520)
uni.add(item)
# build the areas to explore
village = Area()
uni.add(village)
village.setMap("village.tmx")
village.setName("Village")
village.setGUID(1001)
home = Area()
uni.add(home)
home.setMap("building0.tmx")
home.setName("Building0")
home.setGUID(1002)
# finialize exits by adding the needed references
allAreas = [ i for i in uni.getChildren() if isinstance(i, Area) ]
allExits = defaultdict(list)
# make table of all exits
for area in allAreas:
for guid in area.exits.keys():
allExits[guid].append(area)
print guid, area
# set the exits properly
for guid, areaList in allExits.items():
if len(areaList) == 2:
areaList[0].exits[guid] = (areaList[0].exits[guid][0], areaList[1].guid)
areaList[1].exits[guid] = (areaList[1].exits[guid][0], areaList[0].guid)
print areaList[0], areaList[0].exits
print areaList[1], areaList[1].exits
uni.save("mh")