Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
31 changes: 31 additions & 0 deletions Scripts/traps/trap3-tracing_bullet.gd
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ var speed := 0.0
var tracing := true
var flying := false
var wall_counter := 0
var is_demo := false
var effect_reparented := false
@onready var feather_effect = $FeatherEffect
@onready var leave_wall_detector = $Area2D
@onready var wait_timer = $WaitTimer
@onready var animation = $AnimationPlayer
@onready var sprite = $AnimatedSprite2D


static func initialize(pos: Vector2, dir: Vector2, speed: float) -> Trap3TracingBullet:
Expand All @@ -32,6 +35,8 @@ static func initialize(pos: Vector2, dir: Vector2, speed: float) -> Trap3Tracing


func _ready() -> void:
if is_demo:
return
collision_layer = TRAP_COLLISION_LAYER
collision_mask = 0
leave_wall_detector.collision_mask = WALL_COLLISION_LAYER
Expand All @@ -45,6 +50,8 @@ func _ready() -> void:


func _destroy() -> void:
$CollisionShape2D.set_deferred("disabled", true)
await get_tree().create_timer(0.1).timeout
queue_free()


Expand Down Expand Up @@ -104,3 +111,27 @@ func _on_wall_exited(_body: Node2D) -> void:
wall_counter -= 1
if wall_counter <= 0:
collision_mask = PLAYER_COLLISION_LAYER | WALL_COLLISION_LAYER


#-------------------------


func serialize_state() -> Dictionary:
return {
"type": "trap3-tracing_bullet",
"position": global_position,
"rotation": rotation,
"scale": sprite.scale,
"feather_effect": feather_effect.emitting
}


func apply_demo_state(data: Dictionary) -> void:
global_position = data.get("position", Vector2.ZERO)
rotation = data.get("rotation", 0.0)
sprite.scale = data.get("scale", Vector2.ZERO)
feather_effect.emitting = data.get("feather_effect", false)
feather_effect.global_position = global_position
if !effect_reparented:
effect_reparented = true
feather_effect.reparent($"..")
21 changes: 21 additions & 0 deletions Scripts/traps/trap4-conveyor.gd
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ var speed = trap_data["trap4-conveyor"]["speed"]
var lifetime = trap_data["trap4-conveyor"]["lifetime"]
var area_scale = trap_data["trap4-conveyor"]["scale"]
var direction: Vector2
var is_demo: bool = false
var _is_disappearing: bool = false

@onready var wave_animation: AnimatedSprite2D = $AnimatedSprite2D
Expand All @@ -34,6 +35,8 @@ static func initialize(pos: Vector2, dir: Vector2) -> Trap4Conveyor:

func _ready() -> void:
# Trap should expire after the configured lifetime.
if is_demo:
return
scale = Vector2(area_scale, area_scale)
await get_tree().create_timer(lifetime).timeout
_destroy_trap()
Expand Down Expand Up @@ -64,3 +67,21 @@ func _on_body_entered(body: Node2D) -> void:
func _on_body_exited(body: Node2D) -> void:
if body == Global.game_manager.player and body is CharacterBody2D:
body.external_velocity -= speed * direction


#-----------------------------------------
func serialize_state() -> Dictionary:
return {
"type": "trap4-conveyor",
"position": global_position,
"rotation": rotation,
"scale": scale,
"shader_reveal": wave_animation.material.get_shader_parameter("reveal")
}


func apply_demo_state(data: Dictionary) -> void:
global_position = data.get("position", Vector2.ZERO)
rotation = data.get("rotation", 0.0)
wave_animation.material.set_shader_parameter("reveal", data.get("shader_reveal", 1.0))
scale = data.get("scale", Vector2.ZERO)
33 changes: 33 additions & 0 deletions Scripts/traps/trap6-scanline.gd
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ var velocity := Vector2(0, 0)
var speed := 5.0
var line_pos := Vector2(0, 0)
var time := 0.0
var is_demo := false
var hula_rotate := false

@onready var visual_line = $Hulas

Expand Down Expand Up @@ -44,6 +46,8 @@ func _clamp_to_four_directions(dir: Vector2) -> Vector2:

# Called when the node enters the scene tree for the first time.
func _ready() -> void:
if is_demo:
return
visible = true
visual_line.visible = true
body_entered.connect(_on_body_entered)
Expand All @@ -52,6 +56,7 @@ func _ready() -> void:
if abs(line_dir.x) > 0.1:
rotation = PI / 2
var hulas = visual_line.get_children()
hula_rotate = true
for hula in hulas:
hula.rotation = -PI / 2

Expand All @@ -70,3 +75,31 @@ func _physics_process(delta: float) -> void:

func _on_body_entered(_body: Node2D) -> void:
Global.player_hit.emit(damage)


#-----------------------------------------
func serialize_state() -> Dictionary:
return {
"type": "trap6-scanline",
"position": global_position,
"rotation": rotation,
"visual_line_modulate": visual_line.modulate,
"visual_line_position": visual_line.position,
"visual_line_scale": visual_line.scale,
"visual_line_rotation": visual_line.rotation,
"hula_rotate": hula_rotate
}


func apply_demo_state(data: Dictionary) -> void:
global_position = data.get("position", Vector2.ZERO)
rotation = data.get("rotation", 0.0)
visual_line.modulate = data.get("visual_line_modulate", Color.WHITE)
visual_line.position = data.get("visual_line_position", Vector2.ZERO)
visual_line.scale = data.get("visual_line_scale", Vector2.ONE)
visual_line.rotation = data.get("visual_line_rotation", 0.0)
if !hula_rotate and data.get("hula_rotate", false):
hula_rotate = true
var hulas = visual_line.get_children()
for hula in hulas:
hula.rotation = -PI / 2
Loading