Added stairs (can't climb yet).

This commit is contained in:
Segey Lapin
2020-04-13 18:18:07 +03:00
parent c9860ae759
commit 88e8359f64
9 changed files with 1836 additions and 52 deletions

View File

@@ -33,7 +33,7 @@ func _physics_process(delta):
velocity.z = h_velocity.z
velocity.y = h_velocity.y
if !get_meta("grabbed") && !in_smart_obj && !disable_gravity:
velocity.y += -9.8 * delta
velocity.y += -9.8
velocity = move_and_slide(velocity,Vector3(0,1,0))
orientation.origin = Vector3()
fixup.origin = Vector3()

View File

@@ -33,7 +33,7 @@ func _physics_process(delta):
velocity.z = h_velocity.z
velocity.y = h_velocity.y
if !get_meta("grabbed") && !in_smart_obj && !disable_gravity:
velocity.y += -9.8 * delta
velocity.y += -9.8
velocity = move_and_slide(velocity,Vector3(0,1,0))
orientation.origin = Vector3()
fixup.origin = Vector3()

View File

@@ -33,6 +33,7 @@ func start_ai():
$"meta-ai".start()
func spawn_player(spawner):
print("spawned player")
loading.queue_free()
var player_sc = load("res://scenes/characters/male.tscn")
var player = player_sc.instance()

View File

@@ -123,12 +123,16 @@ var state = 0
func _ready():
pass
# Called every frame. 'delta' is the elapsed time since the previous frame.
var furniture_nodes = []
var dungeon_ids = []
func _process(_delta):
match(state):
0:
global.load_game()
if global.save_data.has("dungeon"):
dungeon_save = global.save_data.dungeon
state = 1
1:
dungeon.resize(floors * size_x * size_y)
for k in range(floors):
for i in range(size_x):
@@ -140,16 +144,25 @@ func _process(_delta):
ri.translation.z = j * h - size_y / 2 * h
dungeon[k * size_x * size_y + j * size_x + i] = ri
if dungeon_save.empty():
state = 1
state = 20
else:
state = 2
1:
state = 30
20:
build_rooms()
state = 21
21:
build_special_rooms()
state = 22
22:
for r in dungeon:
r.create_rooms()
for k in get_tree().get_nodes_in_group("furniture"):
state = 23
23:
furniture_nodes = get_tree().get_nodes_in_group("furniture")
state = 24
24:
if furniture_nodes.size() > 0:
var k = furniture_nodes.pop_front()
if k.name.begins_with("fc"):
if randf() > 0.5 && !k.get_parent().has_meta("kitchen_room"):
var bed_i = bed.instance()
@@ -167,16 +180,22 @@ func _process(_delta):
closet_i.set_meta("save_path", "res://scenes/furniture/closet.tscn")
k.add_child(closet_i)
k.rotate_y(randf() * PI / 24.0)
save()
state = 3
2:
for k in range(dungeon.size()):
else:
save()
state = 40
30:
dungeon_ids = range(dungeon.size())
state = 31
31:
if dungeon_ids.size() > 0:
var k = dungeon_ids.pop_front()
dungeon[k].save_data = dungeon_save[str(k)]
dungeon[k].restore()
state = 3
3:
else:
state = 40
40:
print("loaded")
state = 4
state = 50
prepared = true
emit_signal("prepared")
_:

View File

@@ -14,6 +14,7 @@ var door = preload("res://scenes/maps/door.tscn")
var jail_door = preload("res://scenes/maps/jail-door.tscn")
var window = preload("res://scenes/maps/window.tscn")
var outside_door = preload("res://scenes/maps/window.tscn")
var stairs = preload("res://scenes/maps/stairs.tscn")
var outside_door_placed = false
var tw2d
var te2d
@@ -230,6 +231,11 @@ func create_rooms():
master_room()
elif has_meta("stairs"):
master_room()
var stairs_i = stairs.instance()
add_child(stairs_i)
for e in get_children():
if e.is_in_group("furniture"):
e.queue_free()
if get_meta("stairs") > 0:
$c_modular/floor.queue_free()
elif exits.size() == 1:

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,5 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://scenes/maps/stairs.escn" type="PackedScene" id=1]
[node name="stairs" instance=ExtResource( 1 )]

View File

@@ -2,7 +2,7 @@ extends Node
signal spawn_player(pos)
signal spawn_npc(xform)
enum states {STATE_PREINIT, STATE_INIT, STATE_EXECUTE, STATE_SLEEP}
enum states {STATE_PREINIT, STATE_INIT, STATE_INIT_ASTAR, STATE_EXECUTE, STATE_SLEEP}
var state = states.STATE_PREINIT
var astar = null
@@ -113,13 +113,20 @@ func spawn_characters():
print("npc")
emit_signal("spawn_npc", e)
var path_nodes = []
var endings = []
var connections = {}
func _physics_process(delta):
match state:
states.STATE_INIT:
print("starting AI")
var endings = []
var connections = {}
for e in get_tree().get_nodes_in_group("path"):
path_nodes = get_tree().get_nodes_in_group("path")
endings = []
connections = {}
state = states.STATE_INIT_ASTAR
states.STATE_INIT_ASTAR:
if path_nodes.size() > 0:
var e = path_nodes.pop_front()
print(e.name)
var new_points = Array(e.curve.get_baked_points())
var new_ids = []
@@ -145,39 +152,25 @@ func _physics_process(delta):
astar.connect_points(new_ids[s], new_ids[s + 1])
connections[new_ids[s]] = new_ids[s + 1]
connections[new_ids[s + 1]] = new_ids[s]
print("path nodes passed")
var space_state = get_parent().get_world().direct_space_state
for id1 in endings:
for id2 in endings:
if id1 == id2:
continue
if astar.are_points_connected(id1, id2):
continue
var p0 = astar.get_point_position(id1)
var p1 = astar.get_point_position(id2)
var front_result = space_state.intersect_ray(p0 + Vector3(0, 0.5, 0), p1 + Vector3(0, 0.5, 0), [], 0x1)
if !front_result.has("collider"):
astar.connect_points(id1, id2)
# for pk in connections.keys():
# var id1 = pk
# var id2 = connections[pk]
# if astar.are_points_connected(id1, id2):
# var p0 = astar.get_point_position(id1)
# var p1 = astar.get_point_position(id2)
# var front_result = space_state.intersect_ray(p0 + Vector3(0, 0.8, 0), p1 + Vector3(0, 0.8, 0), [], 0x1)
# if front_result.has("collider"):
# var collider = front_result.collider
# var ok = false
# if collider.is_in_group("furniture"):
# ok = true
# elif collider.is_in_group("door"):
# ok = true
# astar.disconnect_points(id1, id2)
print("astar complete")
spawn_characters()
print("characters spawned")
$blackboard.set("metaai", self)
state = states.STATE_EXECUTE
else:
print("path nodes passed")
var space_state = get_parent().get_world().direct_space_state
for id1 in endings:
for id2 in endings:
if id1 == id2:
continue
if astar.are_points_connected(id1, id2):
continue
var p0 = astar.get_point_position(id1)
var p1 = astar.get_point_position(id2)
var front_result = space_state.intersect_ray(p0 + Vector3(0, 0.5, 0), p1 + Vector3(0, 0.5, 0), [], 0x1)
if !front_result.has("collider"):
astar.connect_points(id1, id2)
print("astar complete")
spawn_characters()
print("characters spawned")
$blackboard.set("metaai", self)
state = states.STATE_EXECUTE
states.STATE_EXECUTE:
if randf() > 0.7:
calc_visible_lists()
@@ -227,7 +220,7 @@ func _physics_process(delta):
for r in npc_raycasts:
if r.has("radius"):
var shape : = SphereShape.new()
shape.radius
shape.radius = r.radius
var query = PhysicsShapeQueryParameters.new()
query.set_shape(query)
query.collision_mask = r.mask