-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRoom1.gd
More file actions
209 lines (169 loc) · 5.2 KB
/
Room1.gd
File metadata and controls
209 lines (169 loc) · 5.2 KB
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
extends Area2D
#turn into packed scene or a class?, load spec from file
signal room_entered
#room one learn about basic movement
var mobs = []
var map: Array = []
var size_x = 0
var size_y = 0
var empty_tile = Tile.new()
var room_type = Tile.ROOM_TYPES.NORMAL
var exit_pos : Vector2i
var exit_direction : String
var entrance_pos : Vector2i
var entrance_direction : String
var room_name = "room1"
var room_origin = Vector2i(0,0)
var movement_cost = 5
@onready var fow: ColorRect = $FOW
#for now rooms should be either 7x7, 7x12, 12x7, or 12x12 (actually 5 or 10, but room for boundary and entrance/exit)
func _ready() -> void:
#func _init(room_size_x: int, room_size_y: int) -> void:
size_x = 7
size_y = 7
build_room()
#takes position in global tile space
func can_land(position: Vector2i) -> bool:
print("current global tile position: " + str(position))
var local_tile_pos = position-room_origin
print("current room tile position: " + str(local_tile_pos))
var tile = get_tile(local_tile_pos.x, local_tile_pos.y)
return tile.can_walk()
#takes position in global tile space
func can_walk(position: Vector2i, direction: String) -> bool:
print("current global tile position: " + str(position))
var local_tile_pos = position-room_origin
print("current room tile position: " + str(local_tile_pos))
print("direction: " + direction)
if local_tile_pos == entrance_pos:
print("entrance tile")
if direction == entrance_direction:
return true
else:
return false
if local_tile_pos == exit_pos:
print("exit tile")
if direction == exit_direction:
return true
else:
return false
var nextTile = get_adjacent_tile(local_tile_pos, direction)
print("next tile type: " + nextTile.txt())
return nextTile.can_walk()
#TODO do same with can_jump
func get_adjacent_tile(position: Vector2i, direction: String) -> Tile:
#do I need to convert from map xy to room xy? how? hardcode where start tile is? hardcode where top left corner is
print("get_adjacent_tile position: " + str(position) )
if direction == "up": #TODO need to enum this
position.y += -1
if direction == "down":
position.y += +1
if direction == "left":
position.x += -1
if direction == "right":
position.x += +1
print("getting tile at position: " + str(position))
return get_tile(position.x,position.y) #TODO change to vector
func debug_print_room() -> void:
for y in size_y :
var row = "[ "
for x in size_x :
row += get_tile(x,y).txt()
row += " ]"
print(row)
func set_tile(tile: Tile, x: int, y: int) -> void :
map[y*size_y+x] = tile
#assumes room local coords
func get_tile(x: int, y: int) -> Tile : #TODO convert to vector
return map[y*size_y+x]
func get_mob_at(global_pos: Vector2i) -> Object:
var target_tile = get_tile_global(global_pos)
if target_tile == null :
return null
return target_tile.mob
func kill_mob_at(global_pos: Vector2i):
var target_tile = get_tile_global(global_pos)
target_tile.mob = null
#TODO emit killed event, catch somewhere and show an animation
#global tile map coords
func get_tile_global(global_pos: Vector2i) -> Tile:
var local_pos = global_pos - room_origin
if !is_inside_room(local_pos) :
return null
return get_tile(local_pos.x, local_pos.y)
func is_inside_room(local_pos: Vector2i) -> bool :
print("is local_pos: " + str(local_pos) + " inside:(" + str(size_x) + ", " + str(size_y) + ")")
if local_pos.x < 0 || local_pos.x >= size_x :
return false
if local_pos.y < 0 || local_pos.y >= size_y :
return false
return true
func hide_fow() -> void:
fow.color.a = 0
func show_fow() -> void:
fow.color.a = 65
func build_room() -> void:
var wall_tile = Tile.new_wall_tile()
var floor_tile = Tile.new_floor_tile()
var entrance_tile = Tile.new_entrance_tile()
var exit_tile = Tile.new_exit_tile()
var event_tile = Tile.new_floor_tile()
event_tile.event = "tutorial_spread"
#row by row, need to refactor this, pull from resource?
map.append(wall_tile)
map.append(wall_tile)
map.append(wall_tile)
map.append(wall_tile)
map.append(wall_tile)
map.append(wall_tile)
map.append(wall_tile)
map.append(wall_tile)
map.append(floor_tile)
map.append(wall_tile)
map.append(wall_tile)
map.append(wall_tile)
map.append(floor_tile)
map.append(wall_tile)
map.append(entrance_tile)
map.append(floor_tile)
map.append(wall_tile)
map.append(wall_tile)
map.append(wall_tile)
map.append(floor_tile)
map.append(exit_tile)
entrance_direction = "right"
entrance_pos = Vector2(0,2)
exit_direction = "right"
exit_pos = Vector2(6,2)
map.append(wall_tile)
map.append(floor_tile)
map.append(wall_tile)
map.append(wall_tile)
map.append(floor_tile)
map.append(floor_tile)
map.append(wall_tile)
map.append(wall_tile)
map.append(floor_tile)
map.append(floor_tile)
map.append(wall_tile)
map.append(floor_tile)
map.append(wall_tile)
map.append(wall_tile)
map.append(wall_tile)
map.append(wall_tile)
map.append(floor_tile)
map.append(event_tile)
map.append(floor_tile)
map.append(wall_tile)
map.append(wall_tile)
map.append(wall_tile)
map.append(wall_tile)
map.append(wall_tile)
map.append(wall_tile)
map.append(wall_tile)
map.append(wall_tile)
map.append(wall_tile)
debug_print_room()
func _on_body_entered(body: Node2D) -> void:
print("body entered room 1")
room_entered.emit(room_name)