Multiple Ghosts! currently ghost_count = 3 ! (;

This commit is contained in:
Harmony Honey 2023-11-30 20:13:58 -05:00
parent c7de6059db
commit 9033ec61fb
3 changed files with 46 additions and 21 deletions

View file

@ -1,6 +1,9 @@
extends Node
onready var node_ghost := $Ghost
onready var node_ghosts := $Ghosts
var ghosts := []
var ghost_count := 3
var node_map_solid : TileMap
var node_camera_game : Camera2D
@ -37,7 +40,7 @@ var map_times := {}
var deaths := {}
var replays := {}
var replay := {"frames" : 0, "x" : [], "y": [], "sprite" : []}
var replaying := {}
var replaying := []
var is_win := false
@ -50,6 +53,13 @@ var notes := []
func _ready():
print("Shared._ready(): ")
# ghosts
for i in ghost_count:
var g = node_ghost.duplicate()
node_ghosts.add_child(g)
ghosts.append(g)
node_ghost.visible = false
# scale window
window_scale = floor(OS.get_screen_size().x / get_viewport().size.x)
window_scale = max(1, floor(window_scale * 0.9))
@ -68,6 +78,7 @@ func _ready():
Wipe.connect("finish", self, "wipe_finish")
# silent wolf
var api_key = load("silent_wolf_api_key.gd").source_code.strip_edges().replace('"', "")
SilentWolf.configure({
@ -94,17 +105,20 @@ func _physics_process(delta):
if !Pause.is_paused:
map_frame += 1
if replaying.has_all(["frames", "x", "y", "sprite"]) and map_frame < replaying["frames"]:
var px = node_ghost.position.x
node_ghost.position.x = replaying["x"][map_frame]
node_ghost.position.y = replaying["y"][map_frame]
var nx = node_ghost.position.x
node_ghost.frame = replaying["sprite"][map_frame]
if px != nx:
node_ghost.flip_h = nx < px
else:
node_ghost.visible = false
for i in ghosts.size():
var g = ghosts[i]
if i < replaying.size():
var r = replaying[i]
if r.has_all(["frames", "x", "y", "sprite"]) and map_frame < r["frames"]:
var px = g.position.x
var new_pos = Vector2(r["x"][map_frame], r["y"][map_frame])
g.position = new_pos
g.frame = r["sprite"][map_frame]
if px != new_pos.x:
g.flip_h = new_pos.x < px
else:
g.visible = false
if is_instance_valid(player) and !is_win:
replay["frames"] += 1
@ -153,8 +167,9 @@ func change_map():
is_win = false
map_frame = 0
replay = {"frames" : 0, "x" : [], "y" : [], "sprite" : []}
replaying = {}
node_ghost.visible = false
replaying = []
for i in ghosts:
i.visible = false
Pause.set_process_input(true)
is_note = false
@ -165,13 +180,15 @@ func change_map():
if is_in_game:
TouchScreen.turn_arrows(false)
TouchScreen.show_keys(true, true, true, true, true)
if replays.has(map_name):
var r = {"frames" : INF}
for i in replays[map_name]:
if i.has("frames") and i["frames"] < r["frames"]:
r = i.duplicate()
replaying = r
node_ghost.visible = true
replays[map_name].sort_custom(self, "sort_replays")
for i in min(3, replays[map_name].size()):
var r = replays[map_name][i].duplicate()
if r.has_all(["frames", "x", "y", "sprite"]):
replaying.append(r)
ghosts[i].visible = true
elif is_level_select:
UI.keys()

View file

@ -17,3 +17,5 @@ texture = ExtResource( 2 )
offset = Vector2( 4, -4 )
hframes = 14
region_rect = Rect2( 0, 0, 8, 24 )
[node name="Ghosts" type="Node2D" parent="."]

View file

@ -11,6 +11,8 @@ var screen_dist = 105
var columns = 4
var is_input := true
var input_count := 0
var input_wait := 3
onready var node_audio_scroll : AudioStreamPlayer = $AudioScroll
onready var node_audio_select : AudioStreamPlayer = $AudioSelect
@ -63,11 +65,15 @@ func _input(event):
else:
var btnx = btn.p("right") - btn.p("left")
var btny = btn.p("down") - btn.p("up")
if btnx or btny:
if input_count == 0 and (btnx or btny):
input_count = input_wait
scroll(btnx + (btny * columns))
node_audio_scroll.pitch_scale = 1 + rand_range(-0.1, 0.5)
node_audio_scroll.play()
func _physics_process(delta):
input_count = max(0, input_count - 1)
# view a scene inside the viewport by path
func view_scene(port, path):
for i in port.get_children():