Skip to content

Commit

Permalink
reflect player actions in mirror
Browse files Browse the repository at this point in the history
  • Loading branch information
myin142 committed Nov 17, 2023
1 parent ceb4b6b commit 16b0892
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 2 deletions.
Binary file modified godot/assets/Screen_Start.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion godot/src/base-system/RelativeRemoteTransform2D.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ extends Node2D

@export var remote_node: Node2D
@export var relative_to_origin := 1.1
@export var center := Vector2.ZERO

func _process(delta):
remote_node.global_position = global_position * relative_to_origin
if remote_node:
var dir = global_position - center
remote_node.global_position = dir * relative_to_origin
7 changes: 7 additions & 0 deletions godot/src/character/PlayerMirrorSprite2D.gd
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class_name PlayerMirrorSprite2D
extends MirrorSprite2D

@export var clone := false
@export var player: Player
@export var normal_trident_texture: Texture2D
@export var mirror_trident_texture: Texture2D
Expand All @@ -15,3 +16,9 @@ func update():
super.update()
else:
texture = mirror_trident_texture if GameManager.mirror else normal_trident_texture

func _process(_d):
if not clone: return

frame = player.get_frame()
scale.x = player.get_body_scale().y
2 changes: 2 additions & 0 deletions godot/src/character/player_reflection.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@

[node name="PlayerMirrorSprite2D" type="Sprite2D"]
texture = ExtResource("5_h6dwk")
offset = Vector2(3, -2)
hframes = 4
script = ExtResource("4_j7uc5")
clone = true
normal_trident_texture = ExtResource("1_awrgi")
mirror_trident_texture = ExtResource("3_4mtbe")
mirror_texture = ExtResource("1_m2o5t")
3 changes: 3 additions & 0 deletions godot/src/game.gd
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const ROOM = preload("res://src/props/room.tscn")
@onready var player = $Player
@onready var music_player = $MusicPlayer
@onready var mirror_viewport = $MirrorViewport
@onready var relative_remote_transform_2d = $Player/RelativeRemoteTransform2D

@export var enemy_value := 5.0
@export var enemy_kills := 5.0
Expand Down Expand Up @@ -54,6 +55,8 @@ func _create_room() -> Room:
_logger.debug("Player entered in direction %s" % dir)
var new_room = room.rooms[dir]
cam.global_position = new_room.global_position
relative_remote_transform_2d.center = cam.global_position

player.velocity = Vector2.ZERO
player.global_position = new_room.get_door(-dir).global_position + dir * 10
player.immediate_return_trident()
Expand Down
3 changes: 2 additions & 1 deletion godot/src/game.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,10 @@ position_smoothing_enabled = true
z_index = 10

[node name="RelativeRemoteTransform2D" type="Node2D" parent="Player" node_paths=PackedStringArray("remote_node")]
position = Vector2(0, -2)
script = ExtResource("3_vvprc")
remote_node = NodePath("../../MirrorViewport/PlayerReflection")
relative_to_origin = 1.05
relative_to_origin = 1.06

[node name="BGM" type="AudioStreamPlayer" parent="."]
process_mode = 3
Expand Down
5 changes: 5 additions & 0 deletions godot/src/player.gd
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,8 @@ func immediate_return_trident():
trident = null
_update_throw()

func get_frame():
return sprite.frame

func get_body_scale():
return body.scale
1 change: 1 addition & 0 deletions godot/src/start.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ stretch_mode = 5
[node name="ScreenBubbles" parent="MarginContainer2" instance=ExtResource("3_8tvo4")]

[node name="Background2" type="TextureRect" parent="MarginContainer2"]
modulate = Color(1, 1, 1, 0.721569)
layout_mode = 2
texture = ExtResource("5_ao30t")
expand_mode = 5
Expand Down

0 comments on commit 16b0892

Please sign in to comment.