Переглянути джерело

Added a 'liquid' from which the player will get 'mood' changes and 'access' keys. Added 'moods' to the player. Dropping the idea of a tether all together. NOTE: Name of game will probably change soon, lol

master
Bryan Miller 4 роки тому
джерело
коміт
9a1b1d4e37
12 змінених файлів з 275 додано та 32 видалено
  1. +3
    -0
      .import/placeholder.png-60c11fd3c8ec00ed7c1bd361096f92dc.md5
  2. BIN
      .import/placeholder.png-60c11fd3c8ec00ed7c1bd361096f92dc.stex
  3. BIN
      Data/Graphics/placeholder.png
  4. +34
    -0
      Data/Graphics/placeholder.png.import
  5. +32
    -0
      Data/Objects/Liquid.tscn
  6. +5
    -4
      Data/Objects/Player.tscn
  7. +7
    -3
      Data/Scenes/World.tscn
  8. +98
    -23
      Data/Scripts/Controller.gd
  9. +17
    -0
      Data/Scripts/Liquid.gd
  10. +75
    -0
      Data/Shaders/Liquid.shader
  11. +3
    -2
      Data/Shaders/WaveFish.shader
  12. +1
    -0
      project.godot

+ 3
- 0
.import/placeholder.png-60c11fd3c8ec00ed7c1bd361096f92dc.md5 Переглянути файл

@@ -0,0 +1,3 @@
source_md5="01869c3604b99aea38eb6b597f15f8d7"
dest_md5="b07fcc1de681e1e4fc0cc651a43f6d23"


BIN
.import/placeholder.png-60c11fd3c8ec00ed7c1bd361096f92dc.stex Переглянути файл


BIN
Data/Graphics/placeholder.png Переглянути файл

Before After
Width: 64  |  Height: 64  |  Size: 536B

+ 34
- 0
Data/Graphics/placeholder.png.import Переглянути файл

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

importer="texture"
type="StreamTexture"
path="res://.import/placeholder.png-60c11fd3c8ec00ed7c1bd361096f92dc.stex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://Data/Graphics/placeholder.png"
dest_files=[ "res://.import/placeholder.png-60c11fd3c8ec00ed7c1bd361096f92dc.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=true
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=true
svg/scale=1.0

+ 32
- 0
Data/Objects/Liquid.tscn Переглянути файл

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

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

[sub_resource type="ShaderMaterial" id=1]
shader = ExtResource( 3 )
shader_param/sprite_scale = Vector2( 1, 1 )
shader_param/distortion = 16.265
shader_param/liquid_color_main = Color( 0, 0.0862745, 0.603922, 1 )
shader_param/liquid_color_surface = Color( 0.517647, 0.572549, 1, 1 )
shader_param/liquid_surface_thickness = 0.12
shader_param/wave_amp = 0.25
shader_param/wave_freq = 1.0
shader_param/wave_scale = 1.0

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

[node name="Liquid" type="Sprite"]
material = SubResource( 1 )
texture = ExtResource( 2 )
script = ExtResource( 1 )

[node name="Trigger" type="Area2D" parent="."]
collision_layer = 8

[node name="CollisionShape2D" type="CollisionShape2D" parent="Trigger"]
visible = false
shape = SubResource( 2 )
[connection signal="body_entered" from="Trigger" to="." method="_on_Trigger_body_entered"]

+ 5
- 4
Data/Objects/Player.tscn Переглянути файл

@@ -1,7 +1,7 @@
[gd_scene load_steps=9 format=2]

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

[sub_resource type="CircleShape2D" id=1]
@@ -33,9 +33,10 @@ color = Color( 0.737255, 0.737255, 0.737255, 1 )

[sub_resource type="ShaderMaterial" id=8]
shader = ExtResource( 5 )
shader_param/cell_color = Color( 0, 0, 0, 1 )
shader_param/cell_energy = 3.0
shader_param/rimWidth = 2.425
shader_param/rim_color = Color( 0.870588, 0.870588, 0.870588, 1 )
shader_param/cell_color = Color( 0.4, 0.690196, 0.109804, 1 )
shader_param/rim_color = Color( 1, 1, 1, 1 )
shader_param/fisheye_power = 3.0
shader_param/wave_amp = 0.1
shader_param/wave_freq = 0.075
@@ -68,6 +69,6 @@ process_material = SubResource( 6 )
[node name="Sprite" type="Sprite" parent="."]
material = SubResource( 8 )
scale = Vector2( 0.5, 0.5 )
texture = ExtResource( 3 )
texture = ExtResource( 2 )
[connection signal="body_entered" from="." to="." method="_on_Player_body_entered"]
[connection signal="body_exited" from="." to="." method="_on_Player_body_exited"]

+ 7
- 3
Data/Scenes/World.tscn Переглянути файл

@@ -1,13 +1,17 @@
[gd_scene load_steps=4 format=2]
[gd_scene load_steps=5 format=2]

[ext_resource path="res://icon.png" type="Texture" 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]

[sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 32, 32 )

[node name="World" type="Node2D"]

[node name="Player" parent="." instance=ExtResource( 2 )]
position = Vector2( 83.8801, 47.7922 )

[node name="Ground" type="Node2D" parent="."]

[node name="StaticBody2D" type="StaticBody2D" parent="Ground"]
@@ -72,5 +76,5 @@ shape = SubResource( 1 )
self_modulate = Color( 0, 0, 0, 1 )
texture = ExtResource( 1 )

[node name="Player" parent="." instance=ExtResource( 2 )]
position = Vector2( 83.8801, 47.7922 )
[node name="Liquid" parent="." instance=ExtResource( 3 )]
position = Vector2( 109.92, 207.685 )

+ 98
- 23
Data/Scripts/Controller.gd Переглянути файл

@@ -1,32 +1,103 @@
extends RigidBody2D

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 = 8
export var collision_major_speed_threshold = 32
export var collision_timedt_threshold = 0.1
const COLLISION_MINOR_SPEED_THRESHOLD = 8
const COLLISION_MAJOR_SPEED_THRESHOLD = 32
const COLLISION_TIMEDT_THRESHOLD = 0.1

# The maximum distance from the player in which the mouse will adjust the push force.
# at max_mouse_distance the full base_push_force <+ modifiers> will be applied.
export var max_mouse_distance = 256 setget _set_max_mouse_distance

# The maximum the mouse can be from the player before player becomes "uncomfortable"
# (adjusted by mood)
export var max_comfort_distance = 10 setget _set_max_comfort_distance

# The base tangential acceleration that will be applied to the particles to give the
# player the illusion it's trying to move on it's own. This is just effects things visually (ATM)
export var base_tangential_accel = 32 setget _set_base_tangential_accel

# The base force applied when being pushed.
export var base_push_force = 128 setget _set_base_push_force


# Mood = r: <aggression>, g: <neediness>, b: <contentment>
# <aggression> Affects how strong a players push is and how strong the player's collision with the world will be.
# <neediness> Affects how quickly and strongly the player will follow the mouse
# <contentment> Affects how slowly mood color is shifted back to neutral and widens comfort distance
var mood = Color.black

var neutral_rim = Color(0.9, 0.9, 0.9, 1.0)

var body_radius = 0
var mouse_position = Vector2.ZERO
var mouse_down = false
var push = false
var traveling = 0;

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


func set_colors(prime, alt):
if alt.r != alt.g or alt.r != alt.b:
# only change the rim if there's a single dominant color.
$Sprite.material.set_shader_param("rim_color", alt);
$Particles.process_material.color = alt
if prime.r != prime.g or prime.r != prime.b: # Only adjust mood if not all values are the same.
# Even if not all the same, there must be a single dominant color for mood to be adjusted.
if prime.r > prime.g and prime.r > prime.b:
adjust_mood(Vector3(0.25, 0.0, 0.0))
if prime.g > prime.r and prime.g > prime.b:
adjust_mood(Vector3(0.0, 0.25, 0.0))
if prime.b > prime.r and prime.b > prime.g:
adjust_mood(Vector3(0.0, 0.0, 0.25));

func get_colors():
return {
"prime": $Sprite.material.get_shader_param("cell_color"),
"alt": $Sprite.material.get_shader_param("rim_color")
};

func adjust_mood(mv):
mood.x = clamp(mood.x + mv.x, 0.0, 1.0)
mood.y = clamp(mood.y + mv.y, 0.0, 1.0)
mood.z = clamp(mood.z + mv.z, 0.0, 1.0)
var color = Color(mood.x, mood.y, mood.z, 1.0)
$Sprite.material.set_shader_param("cell_color", color);

func get_tangential_acceleration():
return base_tangential_accel

func get_push_force():
return base_push_force

func get_discomfort():
pass

func get_body_radius():
return $CollisionShape2D.shape.radius

func _set_max_mouse_distance(v):
var br = $CollisionShape2D.shape.radius
max_mouse_distance = max(br * 2, v)

func _set_max_comfort_distance(v):
var br = $CollisionShape2D.shape.radius
max_comfort_distance = max(br, v)

func _set_base_tangential_accel(v):
base_tangential_accel = max(1.0, v)

func _set_base_push_force(v):
base_push_force = max(1.0, v)

# Called when the node enters the scene tree for the first time.
func _ready():
set_process(true)
set_physics_process(true)
set_process_input(true)
body_radius = $CollisionShape2D.shape.radius
$Particles.process_material.color = $Sprite.material.get_shader_param("rim_color");
$Sprite.material.set_shader_param("rim_color", neutral_rim);
$Particles.process_material.color = neutral_rim


func _input(event):
@@ -39,23 +110,28 @@ func _input(event):
push = true


func _shift_mood(delta):
# This should shift the mood color back to black.
# called py the _physics_process method (I could use the _process method, but I don't
# want to possibly mix timings)
pass

func _physics_process(delta):
if mouse_down:
return # We don't follow the mouse or move the squiq when mouse is down.
if push:
push = false
traveling = max_travel_time
var v_direction = (position - mouse_position).normalized()
apply_central_impulse(v_direction * abs(v_direction.length()) * push_force)
apply_central_impulse(v_direction * abs(v_direction.length()) * get_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 distance = clamp(mouse_position.x - position.x, -max_mouse_distance, max_mouse_distance)
var dpercent = distance / max_mouse_distance
if abs(distance) > get_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;
$Particles.process_material.tangential_accel = dpercent * get_tangential_acceleration();
apply_central_impulse(v_horizontal * distance * delta)
else:
$Particles.process_material.tangential_accel = 0
@@ -70,9 +146,9 @@ func _process(delta):

func _draw():
if mouse_down:
var distance = min(position.distance_to(mouse_position), max_distance)
var distance = min(position.distance_to(mouse_position), max_mouse_distance)
var v_direction = (position - mouse_position).normalized().rotated(-rotation)
var v_start = v_direction * body_radius
var v_start = v_direction * get_body_radius()
var v_end = v_direction * distance
var v_tipA = v_end - (v_direction.rotated(deg2rad(30)) * min(distance, 16))
var v_tipB = v_end - (v_direction.rotated(-deg2rad(30)) * min(distance, 16))
@@ -86,15 +162,14 @@ func _draw():
func _on_Player_body_entered(body):
in_air = false
#print(linear_velocity)
if air_time > collision_timedt_threshold:
if air_time > COLLISION_TIMEDT_THRESHOLD:
var lvlen = linear_velocity.length()
if lvlen >= collision_minor_speed_threshold and lvlen < collision_major_speed_threshold:
if lvlen >= COLLISION_MINOR_SPEED_THRESHOLD and lvlen < COLLISION_MAJOR_SPEED_THRESHOLD:
print("ooOF")
elif lvlen >= collision_major_speed_threshold:
elif lvlen >= COLLISION_MAJOR_SPEED_THRESHOLD:
print("Oooooch!")
air_time = 0


func _on_Player_body_exited(body):
in_air = true
print("I'm flying!")

+ 17
- 0
Data/Scripts/Liquid.gd Переглянути файл

@@ -0,0 +1,17 @@
extends Sprite

func _ready():
material.set_shader_param("sprite_scale", scale)
set_process(true)


func _process(delta):
pass


func _on_Trigger_body_entered(body):
if (body.has_method("set_colors")):
body.set_colors(
material.get_shader_param("liquid_color_main"),
material.get_shader_param("liquid_color_surface")
)

+ 75
- 0
Data/Shaders/Liquid.shader Переглянути файл

@@ -0,0 +1,75 @@
shader_type canvas_item;

uniform vec2 sprite_scale = vec2(1.0, 1.0);
uniform float distortion : hint_range(0.1, 100.0) = 8.0;

uniform vec4 liquid_color_main : hint_color = vec4(0.1, 0.2, 0.8, 0.25);
uniform vec4 liquid_color_surface : hint_color = vec4(0.1, 0.2, 1.0, 0.5);
uniform float liquid_surface_thickness : hint_range(0.0, 1.0) = 0.2;

uniform float wave_amp : hint_range(-1.0, 1.0) = 0.25;
uniform float wave_freq : hint_range(0.0, 1.0) = 1.0;
uniform float wave_scale :hint_range(0.0, 10.0) = 1.0;


float rand(vec2 p){
return fract(sin(dot(p, vec2(12.9898, 78.233))) * 43758.5453123);
}

float noise(vec2 p){
vec2 i = floor(p);
vec2 f = fract(p);
float a = rand(i);
float b = rand(i + vec2(1.0, 0.0));
float c = rand(i + vec2(0.0, 1.0));
float d = rand(i + vec2(1.0, 1.0));
vec2 cubic = f * f * (3.0 - (2.0 * f));
return mix(a, b, cubic.x) + (c - a) * cubic.y * (1.0 - cubic.x) + (d - b) * cubic.x * cubic.y;
}

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

vec2 wavey_y(vec2 p, float time) {
float dy = wave_amp * sin(wave_freq * (p.x * liquid_surface_thickness) * time);
//return vec2(dx, dy);
return vec2(p.x, p.y + dy);
}


void fragment(){
vec2 noise1 = UV * sprite_scale * distortion;
vec2 noise2 = UV * (sprite_scale * distortion) + 4.0;
vec2 motion1 = vec2(TIME * 0.3, TIME * -0.4);
vec2 motion2 = vec2(TIME * 0.1, TIME * 0.5);
vec2 distort1 = vec2(noise(noise1 + motion1), noise(noise2 + motion1)) - vec2(0.5);
vec2 distort2 = vec2(noise(noise1 + motion2), noise(noise2 + motion2)) - vec2(0.5);
vec2 dsum = (distort1 + distort2) / 60.0;
vec4 color = texture(SCREEN_TEXTURE, SCREEN_UV + dsum);
color = mix(color, liquid_color_main, 0.3);
color.rgb = mix(vec3(0.5), color.rgb, 1.4);
float near_top = 1.0 - clamp((UV.y + dsum.y) / (liquid_surface_thickness / sprite_scale.y), 0.0, 1.0);
color = mix(color, liquid_color_surface, near_top);
float tedge_lower = 0.6;
float tedge_upper = tedge_lower + 0.1;
if (near_top > tedge_lower){
color.a = 0.0;
if (near_top < tedge_upper){
color.a = (tedge_upper - near_top) / (tedge_upper - tedge_lower);
}
}
COLOR = color;
}

+ 3
- 2
Data/Shaders/WaveFish.shader Переглянути файл

@@ -1,8 +1,9 @@
shader_type canvas_item;

uniform vec4 cell_color : hint_color;
uniform float cell_energy : hint_range(1.0, 20.0) = 1.0;
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;
uniform float wave_amp : hint_range(-1.0, 1.0) = 0.25;
uniform float wave_freq : hint_range(0.0, 1.0) = 0.25;
@@ -81,7 +82,7 @@ vec2 wavey(vec2 p, float time) {


void fragment(){
float n = ramp(CellularNoise(wavey(fisheye(UV.xy), TIME), 5.0, TIME), 0.2, 0.9);
float n = ramp(CellularNoise(wavey(fisheye(UV.xy), TIME), 5.0, TIME * cell_energy), 0.2, 0.9);
float rim = length(vec2(0.5, 0.5) - (UV.xy));
float mask = 1.0;
if (rim > 0.5){

+ 1
- 0
project.godot Переглянути файл

@@ -45,6 +45,7 @@ ButtonB={
2d_physics/layer_1="Anchors"
2d_physics/layer_2="Ground"
2d_physics/layer_3="Tether"
2d_physics/layer_4="Liquids"

[rendering]


Завантаження…
Відмінити
Зберегти