瀏覽代碼

Adjustments to resolution handling. Fixed bug when attempting to shoot in the verticle. Worked on shader for player body. Attempted to add texture to particle effect.

master
Bryan Miller 4 年之前
父節點
當前提交
cef96c5204
共有 7 個文件被更改,包括 176 次插入21 次删除
  1. +3
    -0
      .import/droplet_a.png-8f6c379deb142771389574f34129dfa4.md5
  2. 二進制
      .import/droplet_a.png-8f6c379deb142771389574f34129dfa4.stex
  3. 二進制
      Data/Graphics/droplet_a.png
  4. +34
    -0
      Data/Graphics/droplet_a.png.import
  5. +128
    -14
      Data/Objects/Player.tscn
  6. +10
    -6
      Data/Scripts/Controller.gd
  7. +1
    -1
      project.godot

+ 3
- 0
.import/droplet_a.png-8f6c379deb142771389574f34129dfa4.md5 查看文件

@@ -0,0 +1,3 @@
source_md5="647815dcbdbd31e343dd6b5c378def1a"
dest_md5="c90de94acc25789d5e4176113897a468"


二進制
.import/droplet_a.png-8f6c379deb142771389574f34129dfa4.stex 查看文件


二進制
Data/Graphics/droplet_a.png 查看文件

Before After
Width: 16  |  Height: 16  |  Size: 1.3KB

+ 34
- 0
Data/Graphics/droplet_a.png.import 查看文件

@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="StreamTexture"
path="res://.import/droplet_a.png-8f6c379deb142771389574f34129dfa4.stex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://Data/Graphics/droplet_a.png"
dest_files=[ "res://.import/droplet_a.png-8f6c379deb142771389574f34129dfa4.stex" ]

[params]

compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=false
svg/scale=1.0

+ 128
- 14
Data/Objects/Player.tscn 查看文件

@@ -1,34 +1,138 @@
[gd_scene load_steps=7 format=2]
[gd_scene load_steps=11 format=2]

[ext_resource path="res://Data/Scripts/Controller.gd" type="Script" id=1]
[ext_resource path="res://Data/Colors/GooGradient.tres" type="Texture" id=2]
[ext_resource path="res://icon.png" type="Texture" id=3]
[ext_resource path="res://Data/Graphics/droplet_a.png" type="Texture" id=4]

[sub_resource type="CircleShape2D" id=1]
radius = 16.0

[sub_resource type="Curve" id=4]
_data = [ Vector2( 0, 1 ), 0.0, 0.219234, 0, 0, Vector2( 1, 0.559091 ), -0.228985, 0.0, 0, 0 ]
_data = [ Vector2( 0, 1 ), 0.0, 0.219234, 0, 0, Vector2( 1, 0.434091 ), -0.228985, 0.0, 0, 0 ]

[sub_resource type="CurveTexture" id=5]
curve = SubResource( 4 )

[sub_resource type="ParticlesMaterial" id=6]
lifetime_randomness = 0.28
lifetime_randomness = 0.52
emission_shape = 1
emission_sphere_radius = 10.0
emission_sphere_radius = 16.0
flag_disable_z = true
gravity = Vector3( 0, 0, 0 )
initial_velocity = 0.25
initial_velocity_random = 1.0
direction = Vector3( 0, 0, 0 )
spread = 0.0
gravity = Vector3( 0, 8, 0 )
orbit_velocity = 0.0
orbit_velocity_random = 0.0
radial_accel = -10.0
radial_accel_random = 0.54
linear_accel = 10.0
damping = 12.0
damping_random = 0.41
scale = 4.0
angle = 45.0
angle_random = 0.85
scale = 0.75
scale_curve = SubResource( 5 )
color_ramp = ExtResource( 2 )

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

uniform float rimWidth : hint_range(1.0, 3.0) = 2.0;
uniform vec4 rim_color : hint_color;
uniform vec4 cell_color : hint_color;
uniform float fisheye_power = 2.0;

vec2 random2(vec2 p){
return fract(sin(vec2(dot(p, vec2(127.1, 311.7)), dot(p, vec2(269.5, 183.3)))) * 43758.5453);
}

float ramp(float v, float f_min, float f_max){
if (v <= f_min){return 0.0;}
if (v >= f_max){return 1.0;}
return (v - f_min) / f_max;
}

float CellularNoise(vec2 vUV, float scale, float time){
// Code modified from...
// https://thebookofshaders.com/12/
vec2 st = vUV * scale;
//st.x = vres.x/vres.y;
vec2 i_st = floor(st);
vec2 f_st = fract(st);
float min_dist = 1.0;
for (int y = -1; y <= 1; y++){
for (int x = -1; x <= 1; x++){
vec2 neighbor = vec2(float(x), float(y));
vec2 point = random2(i_st + neighbor);
point = 0.5 + (0.5 * sin(time + (6.2831 * point)));
float dist = length((neighbor + point) - f_st);
min_dist = min(min_dist, dist);
}
}
return min_dist;
}


vec2 distort(vec2 p) {
// Function borrowed and slightly modified from...
// https://gist.github.com/henriquelalves/989fdd72e10c90091188
p *= 2.0;
p -= vec2(1.0, 1.0);
if (length(p) >= 1.5){return p;}
//return p;
if(p.x > 0.0){
float angle = p.y / p.x;
float theta = atan(angle);
float radius = length(p);
radius = pow(radius, fisheye_power);
p.x = radius * cos(theta);
p.y = radius * sin(theta);
} else {
float angle = p.y / p.x;
float theta = atan(angle);
float radius = length(p);
radius = pow(radius, fisheye_power);
p.y = radius * sin(-theta);
p.x = radius * cos(theta);
p.x = - p.x;
}
return 0.5 * (p + vec2(1.0,1.0));
}


void fragment(){
float n = ramp(CellularNoise(distort(UV.xy), 5.0, TIME), 0.2, 0.9);
float rim = length(vec2(0.5, 0.5) - (UV.xy));
if (rim > 0.5){
rim = 0.0;
}
rim = ramp(pow(rim, rimWidth), 0.0, 0.5);
vec4 color = texture(SCREEN_TEXTURE, SCREEN_UV);
if (rim > 0.0){
color = vec4(cell_color.rgb * n, n);
color = color + vec4(rim_color.rgb * rim, rim);
} else {
color = vec4(color.rgb, 0.0);
}
COLOR = color;
}"

[sub_resource type="ShaderMaterial" id=8]
shader = SubResource( 7 )
shader_param/rimWidth = 1.81
shader_param/rim_color = Color( 0.705882, 0.976471, 0.027451, 1 )
shader_param/cell_color = Color( 0.690196, 0.435294, 0.109804, 1 )
shader_param/fisheye_power = 3.0

[node name="Player" type="RigidBody2D"]
collision_mask = 3
contacts_reported = 1
@@ -36,12 +140,9 @@ contact_monitor = true
script = ExtResource( 1 )

[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
visible = false
shape = SubResource( 1 )

[node name="Particles" type="Particles2D" parent="."]
amount = 100
process_material = SubResource( 6 )

[node name="Joint" type="PinJoint2D" parent="."]
bias = 0.9
softness = 0.1
@@ -49,5 +150,18 @@ softness = 0.1
[node name="Camera" type="Camera2D" parent="."]
current = true
smoothing_enabled = true

[node name="Particles" type="Particles2D" parent="."]
visible = false
amount = 50
lifetime = 8.0
local_coords = false
process_material = SubResource( 6 )
texture = ExtResource( 4 )

[node name="Sprite" type="Sprite" parent="."]
material = SubResource( 8 )
scale = Vector2( 0.5, 0.5 )
texture = ExtResource( 3 )
[connection signal="body_entered" from="." to="." method="_on_Player_body_entered"]
[connection signal="body_exited" from="." to="." method="_on_Player_body_exited"]

+ 10
- 6
Data/Scripts/Controller.gd 查看文件

@@ -4,8 +4,8 @@ export var max_distance = 64
export var max_tangential_accel = 32
export var max_travel_time = 2.0
export var push_force = 128
export var collision_minor_speed_threshold = 16
export var collision_major_speed_threshold = 56
export var collision_minor_speed_threshold = 8
export var collision_major_speed_threshold = 32
export var collision_timedt_threshold = 0.1


@@ -17,6 +17,7 @@ var traveling = 0;

var in_air = true
var air_time = 0
var last_speed = 0


# Called when the node enters the scene tree for the first time.
@@ -41,16 +42,16 @@ func _physics_process(delta):
if mouse_down:
return # We don't follow the mouse or move the squiq when mouse is down.
var distance = clamp(mouse_position.x - position.x, -max_distance, max_distance)
var dpercent = distance / max_distance
if push:
push = false
traveling = max_travel_time
var v_direction = (position - mouse_position).normalized()
apply_central_impulse(v_direction * abs(dpercent) * push_force)
apply_central_impulse(v_direction * abs(v_direction.length()) * push_force)
elif in_air:
air_time += delta
else:
var distance = clamp(mouse_position.x - position.x, -max_distance, max_distance)
var dpercent = distance / max_distance
if abs(distance) > body_radius:
var v_horizontal = Physics2DServer.area_get_param(get_world_2d().get_space(), Physics2DServer.AREA_PARAM_GRAVITY_VECTOR).rotated(deg2rad(-90))
$Particles.process_material.tangential_accel = dpercent * max_tangential_accel;
@@ -58,6 +59,9 @@ func _physics_process(delta):
else:
$Particles.process_material.tangential_accel = 0
last_speed = linear_velocity.length()
#print(last_speed)


func _process(delta):
@@ -80,7 +84,7 @@ func _draw():

func _on_Player_body_entered(body):
in_air = false
print(linear_velocity)
#print(linear_velocity)
if air_time > collision_timedt_threshold:
var lvlen = linear_velocity.length()
if lvlen >= collision_minor_speed_threshold and lvlen < collision_major_speed_threshold:

+ 1
- 1
project.godot 查看文件

@@ -22,7 +22,7 @@ config/icon="res://icon.png"
[display]

window/size/width=800
window/stretch/mode="viewport"
window/stretch/mode="2d"
window/stretch/aspect="keep"

[input]

Loading…
取消
儲存