浏览代码

Fixing instancing of the GlowDot color. Created a 'pusher' that will push the player in a defined direction.

master
Bryan Miller 4 年前
父节点
当前提交
a22155e6b8
共有 8 个文件被更改,包括 192 次插入28 次删除
  1. +1
    -1
      Data/Objects/BladeSaw.tscn
  2. +27
    -2
      Data/Objects/Glowdot.tscn
  3. +3
    -0
      Data/Objects/HalfDoor.tscn
  4. +5
    -10
      Data/Objects/PulseArrow.tscn
  5. +67
    -0
      Data/Objects/Pusher.tscn
  6. +18
    -10
      Data/Scenes/World.tscn
  7. +9
    -5
      Data/Scripts/PulseArrow.gd
  8. +62
    -0
      Data/Scripts/Pusher.gd

+ 1
- 1
Data/Objects/BladeSaw.tscn 查看文件

@@ -11,7 +11,7 @@ degrees_per_second = 270.0

[node name="audio" type="AudioStreamPlayer2D" parent="."]
stream = ExtResource( 3 )
max_distance = 512.0
max_distance = 1024.0

[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="."]
position = Vector2( 0.291977, -0.407814 )

+ 27
- 2
Data/Objects/Glowdot.tscn 查看文件

@@ -2,10 +2,35 @@

[ext_resource path="res://Data/Graphics/placeholder.png" type="Texture" id=1]
[ext_resource path="res://Data/Scripts/Glowdot.gd" type="Script" id=2]
[ext_resource path="res://Data/Shaders/Glowdot.shader" type="Shader" id=3]

[sub_resource type="Shader" id=2]
code = "shader_type canvas_item;

uniform vec4 primary_color:hint_color = vec4(1.0, 0.8, 0.0, 1.0);
uniform float fade_offset:hint_range(0.0, 0.5) = 0.1;

float ramp(float v, float f_min, float f_max){
float res = (v - f_min) / (f_max - f_min);
return max(0.0, min(res, 1.0));
}

void fragment(){
float mask = length(vec2(0.5, 0.5) - (UV.xy));
float fade = 1.0 - ramp(mask, fade_offset, 0.5);
if (mask > 0.5){
mask = 0.0;
} else {mask = 1.0;}
if (mask == 1.0){
COLOR = vec4(primary_color.rgb, fade);
} else {
COLOR = vec4(primary_color.rgb, mask);
}
}"

[sub_resource type="ShaderMaterial" id=1]
shader = ExtResource( 3 )
resource_local_to_scene = true
shader = SubResource( 2 )
shader_param/primary_color = Color( 1, 0.8, 0, 1 )
shader_param/fade_offset = 0.15


+ 3
- 0
Data/Objects/HalfDoor.tscn 查看文件

@@ -6,6 +6,7 @@
[ext_resource path="res://Data/Graphics/Tileset.png" type="Texture" id=6]

[sub_resource type="ShaderMaterial" id=1]
resource_local_to_scene = true
shader = ExtResource( 3 )
shader_param/primary_color = Color( 1, 0.8, 0, 1 )
shader_param/fade_offset = 0.15
@@ -72,3 +73,5 @@ region_rect = Rect2( 0, 512, 32, 16 )
polygon = PoolVector2Array( -47.9044, -15.9911, -30.1666, -15.9101, -18.8273, -9.9975, -19.0703, -8.86357, -21.0952, -7.08169, -27.0888, -5.13782, -29.9236, -1.97902, -29.8426, 1.74673, -27.0888, 5.06752, -21.0952, 7.09238, -18.9893, 9.03626, -18.9893, 10.0892, -30.0855, 15.8398, -47.9854, 15.9208 )

[node name="Tween" type="Tween" parent="."]

[editable path="Doorway/Glow"]

+ 5
- 10
Data/Objects/PulseArrow.tscn 查看文件

@@ -29,26 +29,31 @@ void fragment(){
}"

[sub_resource type="ShaderMaterial" id=2]
resource_local_to_scene = true
shader = SubResource( 1 )
shader_param/primary_color = Color( 1, 0.8, 0, 1 )
shader_param/fade_offset = 0.15

[sub_resource type="ShaderMaterial" id=3]
resource_local_to_scene = true
shader = SubResource( 1 )
shader_param/primary_color = Color( 1, 0.8, 0, 1 )
shader_param/fade_offset = 0.15

[sub_resource type="ShaderMaterial" id=4]
resource_local_to_scene = true
shader = SubResource( 1 )
shader_param/primary_color = Color( 1, 0.8, 0, 1 )
shader_param/fade_offset = 0.15

[sub_resource type="ShaderMaterial" id=5]
resource_local_to_scene = true
shader = SubResource( 1 )
shader_param/primary_color = Color( 1, 0.8, 0, 1 )
shader_param/fade_offset = 0.15

[sub_resource type="ShaderMaterial" id=6]
resource_local_to_scene = true
shader = SubResource( 1 )
shader_param/primary_color = Color( 1, 0.8, 0, 1 )
shader_param/fade_offset = 0.15
@@ -59,38 +64,28 @@ script = ExtResource( 1 )
[node name="Dot" parent="." instance=ExtResource( 3 )]
material = SubResource( 2 )
position = Vector2( 0, -0.698334 )
pulse_in_time = 0.5
pulse_out_time = 0.5
pulse_out = 0.75

[node name="Dot21" parent="." instance=ExtResource( 3 )]
material = SubResource( 3 )
position = Vector2( -53.772, 35.6152 )
pulse_in_time = 0.5
pulse_out_time = 0.5
pulse_out = 0.75
pulse_offset = 0.35

[node name="Dot31" parent="." instance=ExtResource( 3 )]
material = SubResource( 4 )
position = Vector2( -110.337, 66.3421 )
pulse_in_time = 0.5
pulse_out_time = 0.5
pulse_out = 0.75
pulse_offset = 0.6

[node name="Dot22" parent="." instance=ExtResource( 3 )]
material = SubResource( 5 )
position = Vector2( 52.3753, 35.6152 )
pulse_in_time = 0.5
pulse_out_time = 0.5
pulse_out = 0.75
pulse_offset = 0.35

[node name="Dot32" parent="." instance=ExtResource( 3 )]
material = SubResource( 6 )
position = Vector2( 106.147, 66.3421 )
pulse_in_time = 0.5
pulse_out_time = 0.5
pulse_out = 0.75
pulse_offset = 0.6

+ 67
- 0
Data/Objects/Pusher.tscn 查看文件

@@ -0,0 +1,67 @@
[gd_scene load_steps=5 format=2]

[ext_resource path="res://Data/Scripts/Pusher.gd" type="Script" id=1]
[ext_resource path="res://Data/Objects/PulseArrow.tscn" type="PackedScene" id=2]

[sub_resource type="ParticlesMaterial" id=1]
emission_shape = 2
emission_box_extents = Vector3( 40, 1, 1 )
flag_disable_z = true
direction = Vector3( 0, -1, 0 )
spread = 0.0
gravity = Vector3( 0, 0, 0 )
initial_velocity = 80.0
orbit_velocity = 0.0
orbit_velocity_random = 0.0
angle = 45.0
angle_random = 0.25
scale = 1.5
scale_random = 0.5

[sub_resource type="RectangleShape2D" id=2]
extents = Vector2( 40, 40 )

[node name="Pusher" type="Node2D"]
script = ExtResource( 1 )

[node name="PulseArrow1" parent="." instance=ExtResource( 2 )]
position = Vector2( -18, -18.0497 )
scale = Vector2( 0.1, 0.1 )
pulse_color = Color( 0.356863, 0.960784, 0.211765, 1 )

[node name="PulseArrow2" parent="." instance=ExtResource( 2 )]
position = Vector2( -18, -4.04972 )
scale = Vector2( 0.1, 0.1 )
pulse_color = Color( 0.356863, 0.960784, 0.211765, 1 )

[node name="PulseArrow3" parent="." instance=ExtResource( 2 )]
position = Vector2( -18, 9.95028 )
scale = Vector2( 0.1, 0.1 )
pulse_color = Color( 0.356863, 0.960784, 0.211765, 1 )

[node name="PulseArrow6" parent="." instance=ExtResource( 2 )]
position = Vector2( 18, -18.0497 )
scale = Vector2( 0.1, 0.1 )
pulse_color = Color( 0.356863, 0.960784, 0.211765, 1 )

[node name="PulseArrow5" parent="." instance=ExtResource( 2 )]
position = Vector2( 18, -4.04972 )
scale = Vector2( 0.1, 0.1 )
pulse_color = Color( 0.356863, 0.960784, 0.211765, 1 )

[node name="PulseArrow4" parent="." instance=ExtResource( 2 )]
position = Vector2( 18, 9.95028 )
scale = Vector2( 0.1, 0.1 )
pulse_color = Color( 0.356863, 0.960784, 0.211765, 1 )

[node name="Particles2D" type="Particles2D" parent="."]
position = Vector2( 0, 40.5267 )
amount = 20
process_material = SubResource( 1 )

[node name="Area2D" type="Area2D" parent="."]

[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
shape = SubResource( 2 )
[connection signal="body_entered" from="Area2D" to="." method="_on_Area2D_body_entered"]
[connection signal="body_exited" from="Area2D" to="." method="_on_Area2D_body_exited"]

+ 18
- 10
Data/Scenes/World.tscn 查看文件

@@ -1,6 +1,6 @@
[gd_scene load_steps=10 format=2]

[ext_resource path="res://Data/Objects/PulseArrow.tscn" type="PackedScene" id=1]
[ext_resource path="res://Data/Objects/Pusher.tscn" type="PackedScene" id=1]
[ext_resource path="res://Data/Objects/Player.tscn" type="PackedScene" id=2]
[ext_resource path="res://Data/Objects/Liquid.tscn" type="PackedScene" id=3]
[ext_resource path="res://Data/Shaders/Liquid.shader" type="Shader" id=4]
@@ -52,19 +52,27 @@ liquid_surface_color = Color( 0.576471, 0.760784, 0.996078, 1 )
position = Vector2( 94.9786, 581.025 )
color = Color( 0.0470588, 0.0156863, 0.980392, 1 )

[node name="Doorway2" parent="." instance=ExtResource( 6 )]
position = Vector2( -306.381, 286.254 )
rotation = 1.57079
color = Color( 0.0235294, 0.980392, 0.0156863, 1 )

[node name="BladeSaw" parent="." instance=ExtResource( 5 )]
position = Vector2( -389.595, -64.0996 )

[node name="BladeSaw2" parent="." instance=ExtResource( 5 )]
position = Vector2( -298.686, -133.59 )
degrees_per_second = -270.0

[node name="Pusher" parent="." instance=ExtResource( 1 )]
position = Vector2( 108.94, -32.8218 )
pulse_color = Color( 0.0941176, 0.156863, 0.815686, 1 )

[node name="TileMap" type="TileMap" parent="."]
tile_set = ExtResource( 7 )
collision_layer = 2
format = 1
tile_data = PoolIntArray( -262145, 1, 262146, -327678, 1, 196611, -327677, 1, 327684, -327676, 1, 327684, -327675, 1, 327684, -327674, 1, 327684, -327673, 1, 196612, -327672, 1, 196612, -327671, 1, 327684, -327670, 1, 196613, -196609, 1, 262147, -262143, 0, 0, -262142, 1, 458753, -262134, 1, 262149, -131081, 1, 0, -131080, 1, 1, -131079, 1, 65537, -131078, 1, 327684, -131077, 1, 327684, -131076, 1, 327684, -131075, 1, 327684, -131074, 1, 196612, -131073, 1, 327685, -196607, 0, 0, -196598, 1, 262149, -65545, 1, 65536, -65544, 1, 65537, -65543, 1, 65539, -131070, 0, 0, -131063, 1, 0, -131062, 1, 65537, -9, 1, 65541, -8, 1, 65537, -7, 1, 65539, -65534, 0, 0, -65529, 1, 262146, -65527, 1, 65536, -65526, 1, 65538, 65527, 1, 131072, 65528, 1, 65537, 65529, 1, 131074, 65532, 1, 262146, 65535, 1, 262146, 2, 0, 0, 7, 1, 327683, 8, 1, 327684, 9, 1, 196609, 10, 1, 65539, 131064, 1, 262147, 131068, 1, 262149, 131071, 1, 262147, 65538, 0, 0, 65545, 1, 65536, 65546, 1, 65538, 196600, 1, 262149, 196602, 1, 0, 196603, 1, 1, 196604, 1, 65537, 196605, 1, 131076, 196606, 1, 131076, 196607, 1, 65537, 131074, 0, 0, 131081, 1, 131072, 131082, 1, 65537, 262136, 1, 262147, 262138, 1, 131072, 262139, 1, 4, 262140, 1, 65537, 262141, 1, 4, 262142, 1, 4, 262143, 1, 131074, 196610, 0, 0, 196618, 1, 262147, 327672, 1, 262147, 327676, 1, 262147, 262154, 1, 262149, 393208, 1, 327683, 393209, 1, 196612, 393210, 1, 196612, 393211, 1, 196612, 393212, 1, 393218, 393213, 1, 327684, 393214, 1, 196612, 393215, 1, 327684, 327680, 1, 196613, 327683, 1, 196611, 327684, 1, 327684, 327685, 1, 196612, 327686, 1, 327684, 327687, 1, 196612, 327688, 1, 196612, 327689, 1, 196612, 327690, 1, 327685, 393216, 1, 262149, 393219, 1, 262149, 458752, 1, 262149, 458754, 1, 196611, 458755, 1, 327685, 524288, 1, 262147, 524290, 1, 262149, 589824, 1, 458753, 589826, 1, 458753 )
tile_data = PoolIntArray( -393207, 1, 0, -393206, 1, 1, -393205, 1, 2, -262145, 1, 262146, -327678, 1, 196611, -327677, 1, 327684, -327676, 1, 327684, -327675, 1, 327684, -327674, 1, 327684, -327673, 1, 196612, -327672, 1, 327684, -327671, 1, 65537, -327670, 1, 5, -327669, 1, 65539, -196609, 1, 262147, -262143, 0, 0, -262142, 1, 458753, -262134, 1, 65537, -262133, 1, 131074, -131081, 1, 0, -131080, 1, 1, -131079, 1, 65537, -131078, 1, 327684, -131077, 1, 327684, -131076, 1, 327684, -131075, 1, 327684, -131074, 1, 196612, -131073, 1, 327685, -196607, 0, 0, -196598, 1, 262147, -65545, 1, 65536, -65544, 1, 65537, -65543, 1, 65539, -131070, 0, 0, -131063, 1, 0, -131062, 1, 65537, -9, 1, 65541, -8, 1, 65537, -7, 1, 65539, -65534, 0, 0, -65529, 1, 262146, -65527, 1, 65536, -65526, 1, 65538, 65527, 1, 131072, 65528, 1, 65537, 65529, 1, 131074, 65532, 1, 262146, 65535, 1, 262146, 2, 0, 0, 7, 1, 327683, 8, 1, 327684, 9, 1, 196609, 10, 1, 65539, 131064, 1, 262147, 131068, 1, 262149, 131071, 1, 262147, 65538, 0, 0, 65545, 1, 65536, 65546, 1, 65538, 196600, 1, 262149, 196602, 1, 0, 196603, 1, 65537, 196604, 1, 393218, 196605, 1, 65537, 196606, 1, 131076, 196607, 1, 65537, 131074, 0, 0, 131081, 1, 131072, 131082, 1, 65537, 262136, 1, 262147, 262138, 1, 131072, 262139, 1, 131074, 262141, 1, 131072, 262142, 1, 4, 262143, 1, 131074, 196610, 0, 0, 196618, 1, 262147, 327672, 1, 262147, 262154, 1, 262149, 393208, 1, 327683, 393209, 1, 196612, 393210, 1, 327684, 393211, 1, 65537, 393212, 1, 1, 393213, 1, 65537, 393214, 1, 327684, 393215, 1, 327684, 327680, 1, 196613, 327683, 1, 196611, 327684, 1, 327684, 327685, 1, 196612, 327686, 1, 327684, 327687, 1, 196612, 327688, 1, 196612, 327689, 1, 196612, 327690, 1, 327685, 458747, 1, 131072, 458748, 1, 4, 458749, 1, 131074, 393216, 1, 262149, 393219, 1, 262149, 458752, 1, 262149, 458754, 1, 196611, 458755, 1, 327685, 524288, 1, 262147, 524290, 1, 262149, 589824, 1, 458753, 589826, 1, 458753 )

[node name="Player" parent="." instance=ExtResource( 2 )]
position = Vector2( -32.4329, -11.6956 )

[node name="PulseArrow" parent="." instance=ExtResource( 1 )]
position = Vector2( 250.511, 119.095 )
scale = Vector2( 0.1, 0.1 )
pulse_color = Color( 0.356863, 0.960784, 0.211765, 1 )

[node name="BladeSaw" parent="." instance=ExtResource( 5 )]
position = Vector2( 271.339, 28.5271 )

+ 9
- 5
Data/Scripts/PulseArrow.gd 查看文件

@@ -4,14 +4,18 @@ export var pulse_color:Color = Color(1.0, 0.8, 0.0, 1.0)


func _ready():
$Dot.pulse_color = pulse_color
set_color(pulse_color)
$Dot.start()
$Dot21.pulse_color = pulse_color
$Dot21.start()
$Dot22.pulse_color = pulse_color
$Dot22.start()
$Dot31.pulse_color = pulse_color
$Dot31.start()
$Dot32.pulse_color = pulse_color
$Dot32.start()

func set_color(c):
pulse_color = c
$Dot.pulse_color = c
$Dot21.pulse_color = c
$Dot22.pulse_color = c
$Dot31.pulse_color = c
$Dot32.pulse_color = c


+ 62
- 0
Data/Scripts/Pusher.gd 查看文件

@@ -0,0 +1,62 @@
extends Node2D

const PUSH_VEC_DEFAULT = Vector2(0.0, -1.0)

export var pulse_color:Color = Color(1.0, 1.0, 1.0, 1.0)
export(float, 0, 400) var push_force = 128
export(float, 0, 1.0) var push_frequency = 0.2
export(float, -180.0, 180) var push_angle = 0

var _bodies = []
var _delay = 1.1

func _dominant_color():
if pulse_color.r > pulse_color.g and pulse_color.r > pulse_color.b:
return "r"
elif pulse_color.g > pulse_color.r and pulse_color.g > pulse_color.b:
return "g"
elif pulse_color.b > pulse_color.r and pulse_color.b > pulse_color.g:
return "b"
return "n"

func _ready():
set_process(true)
for i in range(6):
get_node("PulseArrow" + String(i + 1)).set_color(pulse_color)


func _mood_match(body):
if body.has_method("get_mood"):
var mood = body.get_mood()
var dc = _dominant_color()
if (dc == "r" and mood.is_aggressive()) or \
(dc == "g" and mood.is_needie()) or \
(dc == "b" and mood.is_content()):
return true
return false

func _process(delta):
if _bodies.size() > 0 and _delay >= push_frequency:
_delay = 0.0
var v = PUSH_VEC_DEFAULT.rotated(deg2rad(push_angle))
for i in range(_bodies.size()):
if _mood_match(_bodies[i]):
_bodies[i].apply_central_impulse(v * push_force)
else:
_delay = min(1.1, _delay + delta)

func _has_body(body):
for i in range(_bodies.size()):
if _bodies[i] == body:
return i
return -1

func _on_Area2D_body_entered(body):
if body.is_in_group("Player") and _has_body(body) < 0:
_bodies.append(body)


func _on_Area2D_body_exited(body):
var id = _has_body(body)
if (id >= 0):
_bodies.remove(id)

正在加载...
取消
保存