Skip to content

Commit

Permalink
Use color modulation instead of alternate meshes for highlighting squ…
Browse files Browse the repository at this point in the history
…are (Just like disc).
chrisl8 committed Mar 11, 2024

Verified

This commit was signed with the committer’s verified signature.
chrisl8 Christen Lofland
1 parent b167d39 commit aed7849
Showing 4 changed files with 12 additions and 50 deletions.
19 changes: 11 additions & 8 deletions items/square/square.gd
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
extends RigidBody2D

var item_type: String = "Entity"

@export var spawn_position: Vector2


@@ -29,9 +31,9 @@ func _physics_process(_delta: float) -> void:

func nearby(is_nearby: bool, _body: Node2D) -> void:
if is_nearby:
$HighlightMesh.visible = true
$NormalMesh.modulate = Color(1.0, 216 / 255.0, 0.0, 1.0)
else:
$HighlightMesh.visible = false
$NormalMesh.modulate = Color(1.0, 1.0, 1.0, 1.0)


#func _process(delta: float) -> void:
@@ -50,16 +52,15 @@ func grab() -> void:
"saddlebrown"
)
# Delete myself if someone grabbed me
print(global_position)
queue_free()
print(global_position)
# Once that is done, tell the player node that grabbed me to spawn a "held" version
var player: Node = get_node_or_null(
str("/root/Main/Players/", multiplayer.get_remote_sender_id(), "/Interaction Controller")
)
if player and player.has_method("spawn_player_controlled_thing"):
print(global_position)
player.spawn_player_controlled_thing.rpc(global_position,global_rotation,name)
player.spawn_player_controlled_thing.rpc(global_position, global_rotation, name)


var WaitingToSetLocation = false
var ForceSetPosition
@@ -72,12 +73,14 @@ var ForceSetRotation
#This is hard baked enough into Godot's methodology that I assume it is intended behavior, and consequently this will need to be broken out into it's own script
#to allow this behaviour to be easilly addded to objects, as it is critical for physics control.

func SetSpawnLocation(Position:Vector2,Rotation:float) -> void:

func SetSpawnLocation(Position: Vector2, Rotation: float) -> void:
ForceSetPosition = Position
ForceSetRotation = Rotation
WaitingToSetLocation = true


func _integrate_forces(state: PhysicsDirectBodyState2D) -> void:
if WaitingToSetLocation:
state.transform = Transform2D(ForceSetRotation,ForceSetPosition)
WaitingToSetLocation = false
state.transform = Transform2D(ForceSetRotation, ForceSetPosition)
WaitingToSetLocation = false
9 changes: 1 addition & 8 deletions items/square/square.tscn
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
[gd_scene load_steps=8 format=3 uid="uid://bbgco05vj36s"]
[gd_scene load_steps=7 format=3 uid="uid://bbgco05vj36s"]

[ext_resource type="Script" path="res://items/square/square.gd" id="1_mi7bp"]
[ext_resource type="Texture2D" uid="uid://dysoemuojkdlh" path="res://items/square/square.png" id="2_d5e2h"]
[ext_resource type="Texture2D" uid="uid://dtemsdwv1hhhx" path="res://items/square/square_highlight.png" id="3_swh2x"]
[ext_resource type="Script" path="res://items/multiplayer_synchronizer.gd" id="4_rkra7"]

[sub_resource type="RectangleShape2D" id="RectangleShape2D_0i0wv"]
@@ -29,12 +28,6 @@ scale = Vector2(20, 20)
mesh = SubResource("QuadMesh_v6qtj")
texture = ExtResource("2_d5e2h")

[node name="HighlightMesh" type="MeshInstance2D" parent="."]
visible = false
scale = Vector2(20, 20)
mesh = SubResource("QuadMesh_v6qtj")
texture = ExtResource("3_swh2x")

[node name="MultiplayerSynchronizer" type="MultiplayerSynchronizer" parent="."]
replication_config = SubResource("SceneReplicationConfig_wd4wg")
script = ExtResource("4_rkra7")
Binary file removed items/square/square_highlight.png
Binary file not shown.
34 changes: 0 additions & 34 deletions items/square/square_highlight.png.import

This file was deleted.

0 comments on commit aed7849

Please sign in to comment.