Spaces:
Sleeping
Sleeping
humanda5
commited on
Commit
Β·
573bc98
1
Parent(s):
082f464
random village set test
Browse files
npc_social_network/maps/town_hall.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import pygame
|
2 |
import sys
|
|
|
3 |
|
4 |
# μ΄κΈ° μ€μ
|
5 |
pygame.init()
|
@@ -11,13 +12,22 @@ pygame.display.set_caption("town_hall")
|
|
11 |
# μμ μ μ
|
12 |
COLORS = {
|
13 |
"empty": (230, 230, 230),
|
14 |
-
|
15 |
-
"
|
16 |
-
"
|
17 |
-
"
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
19 |
}
|
20 |
|
|
|
|
|
|
|
|
|
21 |
# λ§μ ꡬ쑰 μ μ
|
22 |
village_map = {
|
23 |
"buildings": [
|
@@ -27,10 +37,39 @@ village_map = {
|
|
27 |
{"type": "farm", "location": [10,3]},
|
28 |
{"type": "temple", "location": [8,8]},
|
29 |
],
|
30 |
-
"
|
31 |
{"name": "Elin", "job": "farmer", "location": [2,3]},
|
32 |
{"name": "Borg", "job": "blacksmith", "location": [6,6]}
|
33 |
]
|
34 |
}
|
35 |
|
36 |
-
# νλ©΄ λ λλ§ ν¨μ
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import pygame
|
2 |
import sys
|
3 |
+
import random
|
4 |
|
5 |
# μ΄κΈ° μ€μ
|
6 |
pygame.init()
|
|
|
12 |
# μμ μ μ
|
13 |
COLORS = {
|
14 |
"empty": (230, 230, 230),
|
15 |
+
|
16 |
+
"grass": (144, 238, 144), # μ°λ
Ήμ
|
17 |
+
"dirt": (210, 180, 140), # νμ
|
18 |
+
"stone": (169, 169, 169), # νμ
|
19 |
+
|
20 |
+
"house": (150, 75, 0), # κ°μ
|
21 |
+
"market": (255, 215, 0), # κΈμ
|
22 |
+
"farm": (34, 139, 34), # μ§μ λ
Ήμ
|
23 |
+
"temple": (128, 0, 128), # 보λΌμ
|
24 |
+
"npc": (0,0,255) # νλμ
|
25 |
}
|
26 |
|
27 |
+
# λλ€ λ°°κ²½ νμΌ μμ±
|
28 |
+
terrain_types = ["grass", "dirt", "stone"]
|
29 |
+
terrain_map = [[random.choice(terrain_types) for _ in range(grid_width)] for _ in range(grid_height)]
|
30 |
+
|
31 |
# λ§μ ꡬ쑰 μ μ
|
32 |
village_map = {
|
33 |
"buildings": [
|
|
|
37 |
{"type": "farm", "location": [10,3]},
|
38 |
{"type": "temple", "location": [8,8]},
|
39 |
],
|
40 |
+
"npcs":[
|
41 |
{"name": "Elin", "job": "farmer", "location": [2,3]},
|
42 |
{"name": "Borg", "job": "blacksmith", "location": [6,6]}
|
43 |
]
|
44 |
}
|
45 |
|
46 |
+
# νλ©΄ λ λλ§ ν¨μ
|
47 |
+
def draw_map():
|
48 |
+
screen.fill(COLORS['empty'])
|
49 |
+
for y in range(grid_height):
|
50 |
+
for x in range(grid_width):
|
51 |
+
terrain = terrain_map[y][x]
|
52 |
+
color = COLORS.get(terrain, (200, 200, 200))
|
53 |
+
pygame.draw.rect(screen, color, (x * tile_size, y * tile_size, tile_size, tile_size))
|
54 |
+
|
55 |
+
for building in village_map["buildings"]:
|
56 |
+
x, y = building["location"]
|
57 |
+
color = COLORS.get(building["type"], (100, 100, 100))
|
58 |
+
pygame.draw.rect(screen, color, (x * tile_size, y * tile_size, tile_size, tile_size))
|
59 |
+
|
60 |
+
for npc in village_map["npcs"]:
|
61 |
+
x, y = npc["location"]
|
62 |
+
pygame.draw.circle(screen, COLORS["npc"], (x * tile_size + tile_size // 2, y * tile_size + tile_size // 2), 8)
|
63 |
+
|
64 |
+
# pygame 루ν
|
65 |
+
runnig = True
|
66 |
+
while runnig:
|
67 |
+
draw_map()
|
68 |
+
pygame.display.update()
|
69 |
+
|
70 |
+
for event in pygame.event.get():
|
71 |
+
if event.type == pygame.QUIT:
|
72 |
+
runnig = False
|
73 |
+
|
74 |
+
pygame.quit()
|
75 |
+
sys.exit()
|