Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@ _global_script_classes=[ {
"language": "GDScript",
"path": "res://src/class/savedict.gd"
}, {
"base": "Resource",
"class": "StagePreview",
"language": "GDScript",
"path": "res://src/stage/preview.gd"
}, {
"base": "Actor",
"class": "Switch",
"language": "GDScript",
Expand All @@ -79,7 +74,6 @@ _global_script_class_icons={
"Passthrough": "",
"Player": "",
"SaveDict": "",
"StagePreview": "",
"Switch": "",
"SwitchBlock": ""
}
Expand Down Expand Up @@ -115,8 +109,8 @@ KeyMenu="*res://src/menu/options/KeyMenu.tscn"

window/size/width=228
window/size/height=128
window/size/test_width=1280
window/size/test_height=720
window/size/test_width=1140
window/size/test_height=640
window/dpi/allow_hidpi=true
window/stretch/mode="viewport"
window/stretch/aspect="keep_height"
Expand Down
4 changes: 4 additions & 0 deletions src/actor/BoxSpawner.gd
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ export var color := "red"
var box = preload("res://src/actor/Box.tscn")

func _ready():
if Shared.is_level_select:
node_anim.advance(0.5)
return

for i in get_tree().get_nodes_in_group("switch_" + color):
i.connect("press", self, "release")

Expand Down
1 change: 1 addition & 0 deletions src/actor/BoxSpawner.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ vframes = 8
frame = 15

[node name="Sprite2" type="Sprite" parent="."]
visible = false
position = Vector2( 4, 4 )
z_index = 50
z_as_relative = false
Expand Down
1 change: 1 addition & 0 deletions src/actor/Note.gd
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export var palette : PoolColorArray
func _ready():
if Shared.is_level_select:
visible = false
queue_free()
return

if Engine.editor_hint: return
Expand Down
2 changes: 1 addition & 1 deletion src/actor/Player.gd
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func _ready():
btnx_array.append(0)

# assign camera target
if !is_attract_mode and Shared.cam:
if !is_attract_mode:
Shared.cam.node_target = self
Shared.cam.pos_target_offset = Vector2(4, 4)

Expand Down
4 changes: 2 additions & 2 deletions src/actor/Switch.gd
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ signal press
signal release

func _enter_tree():
if Engine.editor_hint: return
if Engine.editor_hint or Shared.is_level_select: return
add_to_group("switch_" + color)

func _physics_process(delta):
if Engine.editor_hint: return
if Engine.editor_hint or Shared.is_level_select: return

is_last = is_on
is_on = is_area_solid_actor(position.x, position.y)
Expand Down
1 change: 1 addition & 0 deletions src/autoload/Pause.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ font_data = ExtResource( 6 )

[node name="Pause" type="CanvasLayer"]
pause_mode = 2
layer = 20
script = ExtResource( 3 )
__meta__ = {
"_edit_horizontal_guides_": [ -19.0 ]
Expand Down
159 changes: 41 additions & 118 deletions src/autoload/Shared.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ extends Node

onready var node_ghost := $Ghost
onready var node_ghosts := $Ghosts
onready var cam := $Cam

var ghosts := []
var ghost_count := 10

var cam : Camera2D
var map_solid : TileMap
var map_obscure : TileMap

Expand Down Expand Up @@ -34,19 +35,19 @@ var save_path := "user://save/"
var save_filename := "box.save"
var keys_path := "keys.tres"
var options_path := "options.tres"
var scene_dict := {}
var replays := [{}, {}, {}, {}, {}, {}, {}]
var is_save := false
var last_menu := "main"
var last_cursor := 0

var window_scale := 1
var view_size := Vector2(228, 128)
var bus_volume = [10, 10, 10]

var actors := []
var player

var map_dict : Dictionary = load("res://src/stage/sheet.tres").dict

var map_select := 0
var maps := []
var map_name := ""
Expand Down Expand Up @@ -78,6 +79,7 @@ var last_palette = -1
var time_elapsed := 0
var auto_save_clock := 0
var auto_save_time := 1800
var window_option := 0 setget set_window_option

func _ready():
print("Shared._ready(): ")
Expand All @@ -89,11 +91,6 @@ func _ready():
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))
set_window_scale()

# lower volume
for i in [1, 2]:
set_bus_volume(i, 7)
Expand All @@ -102,26 +99,15 @@ func _ready():
var dir = Directory.new()
if !dir.open(save_path) == OK:
dir.make_dir(save_path)
for i in range(save_limit) + ["map"]:

for i in save_limit:
var s = save_path + str(i)
if !dir.open(s) == OK:
dir.make_dir(s)


# get all maps
for i in dir_list(map_dir):
var lm = load(map_dir + i)
var map_short = str(i.split(".")[0])

scene_dict[map_dir + i] = lm
maps.append(map_short)

var inst = lm.instance()
make_preview(inst, map_short)

#print("maps: ", maps, " ", maps.size(), " ", scene_dict)


maps.append(i.split(".")[0])


load_options()
Expand All @@ -131,78 +117,6 @@ func _ready():

Wipe.connect("finish", self, "wipe_finish")

func make_preview(inst : Node, map_short):
# make preview
var sp = StagePreview.new()
sp.palette = inst.palette

for c in inst.get_children():
var cname = c.name.to_lower()

var cells = []
if "map" in cname:
cells = c.get_used_cells()

if "spike" in cname:
for p in cells:
sp.spike += vec_string(p) + " "

elif "solid" in cname:
for p in cells:
make_key(p, c, sp.solid, 1)

elif "detail" in cname:
for p in cells:
make_key(p, c, sp.detail)

elif "obscure" in cname:
for p in cells:
make_key(p, c, sp.obscure, 0)

elif "camera" in cname:
var p = c.position
sp.camera = vec_string(p)

elif "actors" in cname:
for a in c.get_children():
var aname = a.name.to_lower()

var p = Vector2.ZERO
if a is Node2D:
p = a.position

if "player" in aname:
sp.player = vec_string(p)

elif "exit" in aname:
sp.exit = vec_string(p)

elif "box" in aname:
sp.box += vec_string(p) + " "



ResourceSaver.save(save_path + "map/" + map_short + ".tres", sp)

func vec_string(p : Vector2):
return str(int(p.x)) + "," + str(int(p.y))

func make_key(p : Vector2, c : TileMap, dict : Dictionary, skip_id := -1):
var id = c.get_cellv(p)
if id == skip_id:
return
var coord = c.get_cell_autotile_coord(p.x, p.y)

var t = c.is_cell_transposed(p.x, p.y)
var x = c.is_cell_x_flipped(p.x, p.y)
var y = c.is_cell_y_flipped(p.x, p.y)
var key = str(id) + " " + str(int(coord.x)) + " " + str(int(t)) + str(int(x)) + str(int(y))

if !dict.has(key):
dict[key] = ""

dict[key] += vec_string(p) + " "

func _input(event):
var joy = event is InputEventJoypadButton or event is InputEventJoypadMotion
if is_gamepad != joy:
Expand Down Expand Up @@ -275,9 +189,7 @@ func change_map():
if is_win:
save_replays()

if !scene_dict.has(scene_path):
scene_dict[scene_path] = load(scene_path)
get_tree().change_scene_to(scene_dict[scene_path])
get_tree().change_scene_to(load(scene_path))

is_win = false
is_save = false
Expand Down Expand Up @@ -399,11 +311,25 @@ func load_keys(path := keys_path):
for e in r.dict[a]:
InputMap.action_add_event(a, e)

func set_window_option(arg := window_option):
window_option = clamp(arg, 0, 4)
OS.window_borderless = window_option == 1 or window_option == 2
OS.window_fullscreen = window_option == 3
if window_option == 2:
OS.window_size = OS.get_screen_size()

OS.set_window_position(Vector2.ZERO if window_option == 2 else (OS.get_screen_size() * 0.5 - OS.get_window_size() * 0.5))
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE if window_option < 3 else Input.MOUSE_MODE_HIDDEN

func save_options(path := options_path):
var data = {}
data["sfx"] = bus_volume[1]
data["music"] = bus_volume[2]
data["fullscreen"] = int(OS.window_fullscreen)
data["ost"] = bus_volume[2]
data["touch"] = int(TouchScreen.is_stay)
data["full"] = int(OS.window_fullscreen)
data["view"] = int(window_option)
var ws = OS.window_size
data["size"] = str(ws.x) + "," + str(ws.y)
data["time"] = time_elapsed

print("save_options, path: ", path, " time: ", time_elapsed)
Expand All @@ -419,12 +345,21 @@ func load_options(path := options_path):
var v = int(dict["sfx"])
bus_volume[1] = v
set_bus_volume(1, v)
if dict.has("music"):
var v = int(dict["music"])
if dict.has("ost"):
var v = int(dict["ost"])
bus_volume[2] = v
set_bus_volume(2, v)
if dict.has("fullscreen"):
set_fullscreen(bool(dict["fullscreen"]))
if dict.has("full"):
set_fullscreen(bool(dict["full"]))
if dict.has("touch"):
TouchScreen.is_stay = bool(dict["touch"])
if dict.has("view"):
self.window_option = int(dict["view"])
if dict.has("size"):
var ws = str(dict["size"]).split_floats(",", false)
if ws.size() == 2:
OS.window_size = Vector2(float(ws[0]), float(ws[1]))
set_window_option()
if dict.has("time"):
time_elapsed = abs(int(dict["time"]))

Expand All @@ -437,13 +372,13 @@ func delete_slot(_slot := save_slot):
dir.remove(fname)
fname = dir.get_next()

replays[_slot] = {}
replays[_slot] = {}
load_save(_slot)

func save_replays(arg := replay_map, _slot := save_slot):
save_file(save_path + str(_slot) + "/" + arg + ".save", JSON.print(replays[save_slot][arg], "\t"))

func load_save(_slot = save_slot, is_reload := false):
func load_save(_slot = save_slot):
save_slot = clamp(_slot, 0, save_limit - 1)
var save_string = save_path + str(save_slot) + "/" + save_filename

Expand All @@ -456,14 +391,13 @@ func load_save(_slot = save_slot, is_reload := false):
save_clock = 0.0

var dict := {}
if is_reload: dict = save_data[_slot]

if dict.empty():
var l = load_file(save_string)
if l: dict = JSON.parse(l).result
else: print(save_string + " not found")

print(_slot, " / ", dict)
print(save_slot, " / ", dict)
if !dict.empty():
if dict.has("clock"):
save_clock = dict["clock"]
Expand Down Expand Up @@ -512,9 +446,6 @@ func generate_username():
var _name = pf[0] + middle[0] + sf[0] + end[0] + str(randi() % 100)
return _name

func delete_save():
print("delete save")

func unlock():
print("unlock")

Expand Down Expand Up @@ -621,14 +552,6 @@ func set_bus_volume(_bus := 1, _vol := 5):
bus_volume[_bus] = clamp(_vol, 0, 10)
AudioServer.set_bus_volume_db(_bus, linear2db(bus_volume[_bus] / 10.0))

func set_window_scale(arg := window_scale):
window_scale = max(1, arg if arg else window_scale)
if OS.get_name() != "HTML5":
OS.window_size = Vector2(view_size.x * window_scale, view_size.y * window_scale)
# center window
OS.set_window_position(OS.get_screen_size() * 0.5 - OS.get_window_size() * 0.5)
return "window_scale: " + str(window_scale) + " - resolution: " + str(OS.get_window_size())

func get_all_children(n, a := []):
if is_instance_valid(n):
a.append(n)
Expand Down
7 changes: 6 additions & 1 deletion src/autoload/Shared.tscn
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
[gd_scene load_steps=5 format=2]
[gd_scene load_steps=6 format=2]

[ext_resource path="res://src/autoload/Shared.gd" type="Script" id=1]
[ext_resource path="res://media/image/player_swap.png" type="Texture" id=2]
[ext_resource path="res://src/shader/player_palette_swap.gdshader" type="Shader" id=3]
[ext_resource path="res://src/stage/Cam.gd" type="Script" id=4]

[sub_resource type="ShaderMaterial" id=1]
shader = ExtResource( 3 )
Expand Down Expand Up @@ -32,3 +33,7 @@ vframes = 2
region_rect = Rect2( 0, 0, 8, 24 )

[node name="Ghosts" type="Node2D" parent="."]

[node name="Cam" type="Camera2D" parent="." groups=["game_camera"]]
current = true
script = ExtResource( 4 )
Loading