This commit is contained in:
Harmony Honey 2021-09-04 00:35:15 -04:00
parent 6c6c434f44
commit fc37670deb
8 changed files with 153 additions and 9 deletions

View file

@ -87,7 +87,7 @@ _global_script_class_icons={
[application]
config/name="gdBox"
run/main_scene="res://src/map/05.tscn"
run/main_scene="res://src/map/A01.tscn"
config/icon="res://icon.png"
[autoload]
@ -100,7 +100,7 @@ Pause="*res://src/autoload/Pause.tscn"
[display]
window/size/width=228
window/size/width=224
window/size/height=128
window/size/test_width=1368
window/size/test_height=768

View file

@ -60,9 +60,9 @@ func _process(delta):
time_since_floor += 1
# if outside map
if position.y < -999 or position.y > 999:
dev.out(name + " fell out of world")
queue_free()
# if position.y < -999 or position.y > 999:
# dev.out(name + " fell out of world")
# queue_free()
# update() the _draw() when hitbox values are changed (in the editor)
func _set_hit_x(value):
@ -97,6 +97,9 @@ func _draw():
func aabb(x1 : int, y1 : int, w1 : int, h1 : int, x2 : int, y2 : int, w2 : int, h2 : int):
return x1 < x2 + w2 and x2 < x1 + w1 and y1 < y2 + h2 and y2 < y1 + h1
func aabb_other(x2 : int, y2 : int, w2 : int, h2 : int):
return position.x < x2 + w2 and x2 < position.x + hitbox_x and position.y < y2 + h2 and y2 < position.y + hitbox_y
func is_overlapping(a : Actor):
return aabb(position.x, position.y, hitbox_x, hitbox_y, a.position.x, a.position.y, a.hitbox_x, a.hitbox_y)

View file

@ -4,7 +4,6 @@
[ext_resource path="res://media/audio/sfx/hit10.wav" type="AudioStream" id=2]
[ext_resource path="res://src/actor/Box.gd" type="Script" id=3]
[sub_resource type="Animation" id=1]
resource_name = "hit"
length = 0.4

View file

@ -101,9 +101,9 @@ func _process(delta):
return
# fall out of stage
if position.y > 100:
death()
return
# if position.y > 100:
# death()
# return
# hit spike
if speed.y > -1:

81
src/map/A01.tscn Normal file

File diff suppressed because one or more lines are too long

15
src/map/Room.gd Normal file
View file

@ -0,0 +1,15 @@
tool
extends ColorRect
export var cam_pos := Vector2.ZERO setget _set_cam_pos
export var draw_color := Color(1, 1, 1, 0.5)
var cam_size := Vector2(228, 128)
func _set_cam_pos(arg):
cam_pos = arg
update()
func _draw():
draw_circle(cam_pos, 3, draw_color)
#draw_rect(Rect2(cam_pos - cam_size / 2, cam_size), draw_color)

45
src/map/RoomManager.gd Normal file
View file

@ -0,0 +1,45 @@
extends Node2D
var rooms = []
var player
var active
var cam
func _ready():
visible = false
cam = get_parent().get_node("GameCamera")
rooms = get_children()
for i in get_tree().get_nodes_in_group("player"):
player = i
break
find_room()
func _process(delta):
if !is_player_inside(active):
find_room()
func aabb(x1 : int, y1 : int, w1 : int, h1 : int, x2 : int, y2 : int, w2 : int, h2 : int) -> bool:
return x1 < x2 + w2 and x2 < x1 + w1 and y1 < y2 + h2 and y2 < y1 + h1
func is_player_inside(room) -> bool:
return aabb(player.center().x, player.center().y, 0, 0, room.rect_position.x, room.rect_position.y, room.rect_size.x, room.rect_size.y)
func set_active(arg):
active = arg
cam.limit_left = active.rect_position.x
cam.limit_top = active.rect_position.y
cam.limit_right = active.rect_position.x + active.rect_size.x
cam.limit_bottom = active.rect_position.y + active.rect_size.y
#cam.position = active.rect_position + active.rect_size / 2
print("active room: ", active.name, " left: ", cam.limit_left, " right: ", cam.limit_right, " top: ", cam.limit_top, " bottom: ", cam.limit_bottom)
func find_room():
for i in rooms:
if i != active and is_player_inside(i):
set_active(i)
break

View file

@ -34,6 +34,7 @@ func _process(delta):
pos_target = pos_start.linear_interpolate(node_target.position + pos_offset, target_influence)
else:
pos_target = node_target.position + pos_offset
# smoothing
lerp_pos = lerp_pos.linear_interpolate(pos_target, lerp_step)
position = lerp_pos.round()