oil_tanker: add new GooParticle emitter

This commit is contained in:
Alice Gaudon 2020-08-19 16:57:52 +02:00
parent 45019768d5
commit 0ddfa9d866
15 changed files with 252 additions and 9 deletions

View File

@ -1,3 +1,11 @@
[gd_resource type="AnimatedTexture" format=2]
[gd_resource type="Resource" load_steps=2 format=2]
[ext_resource path="res://scripts/GooParticle.gd" type="Script" id=1]
[resource]
script = ExtResource( 1 )
name = "BigGoo1"
columns = 10
rows = 11
skip_x_last_frames = 9
framerate = 5

11
images/goo/BigGoo2.tres Normal file
View File

@ -0,0 +1,11 @@
[gd_resource type="Resource" load_steps=2 format=2]
[ext_resource path="res://scripts/GooParticle.gd" type="Script" id=1]
[resource]
script = ExtResource( 1 )
name = "BigGoo2"
columns = 8
rows = 1
skip_x_last_frames = 0
framerate = 5

View File

@ -3,17 +3,22 @@ render_mode blend_mix;
uniform int particles_anim_h_frames;
uniform int particles_anim_v_frames;
uniform bool particles_anim_loop;
uniform int frame;
void vertex() {
float h_frames = float(particles_anim_h_frames);
float v_frames = float(particles_anim_v_frames);
VERTEX.xy /= vec2(h_frames, v_frames);
float particle_total_frames = float(particles_anim_h_frames * particles_anim_v_frames);
float particle_frame = floor(INSTANCE_CUSTOM.z * float(particle_total_frames));
if (!particles_anim_loop) {
particle_frame = clamp(particle_frame, 0.0, particle_total_frames - 1.0);
} else {
particle_frame = mod(particle_frame, particle_total_frames);
} UV /= vec2(h_frames, v_frames);
// float particle_frame = floor(INSTANCE_CUSTOM.z * float(particle_total_frames));
// if (!particles_anim_loop) {
// particle_frame = clamp(particle_frame, 0.0, particle_total_frames - 1.0);
// } else {
// particle_frame = mod(particle_frame, particle_total_frames);
// }
float particle_frame = float(frame);
UV /= vec2(h_frames, v_frames);
UV += vec2(mod(particle_frame, h_frames) / h_frames, floor(particle_frame / h_frames) / v_frames);
}

11
images/goo/goo1.tres Normal file
View File

@ -0,0 +1,11 @@
[gd_resource type="Resource" load_steps=2 format=2]
[ext_resource path="res://scripts/GooParticle.gd" type="Script" id=1]
[resource]
script = ExtResource( 1 )
name = "goo1"
columns = 4
rows = 1
skip_x_last_frames = 0
framerate = 4

11
images/goo/goo2.tres Normal file
View File

@ -0,0 +1,11 @@
[gd_resource type="Resource" load_steps=2 format=2]
[ext_resource path="res://scripts/GooParticle.gd" type="Script" id=1]
[resource]
script = ExtResource( 1 )
name = "goo2"
columns = 4
rows = 1
skip_x_last_frames = 0
framerate = 4

11
images/goo/goo3.tres Normal file
View File

@ -0,0 +1,11 @@
[gd_resource type="Resource" load_steps=2 format=2]
[ext_resource path="res://scripts/GooParticle.gd" type="Script" id=1]
[resource]
script = ExtResource( 1 )
name = "goo3"
columns = 4
rows = 1
skip_x_last_frames = 0
framerate = 4

11
images/goo/goo4.tres Normal file
View File

@ -0,0 +1,11 @@
[gd_resource type="Resource" load_steps=2 format=2]
[ext_resource path="res://scripts/GooParticle.gd" type="Script" id=1]
[resource]
script = ExtResource( 1 )
name = "goo4"
columns = 1
rows = 1
skip_x_last_frames = 0
framerate = 1

11
images/goo/goo5.tres Normal file
View File

@ -0,0 +1,11 @@
[gd_resource type="Resource" load_steps=2 format=2]
[ext_resource path="res://scripts/GooParticle.gd" type="Script" id=1]
[resource]
script = ExtResource( 1 )
name = "goo5"
columns = 1
rows = 1
skip_x_last_frames = 0
framerate = 1

11
images/goo/goo6.tres Normal file
View File

@ -0,0 +1,11 @@
[gd_resource type="Resource" load_steps=2 format=2]
[ext_resource path="res://scripts/GooParticle.gd" type="Script" id=1]
[resource]
script = ExtResource( 1 )
name = "goo6"
columns = 1
rows = 1
skip_x_last_frames = 0
framerate = 1

11
images/goo/goo7.tres Normal file
View File

@ -0,0 +1,11 @@
[gd_resource type="Resource" load_steps=2 format=2]
[ext_resource path="res://scripts/GooParticle.gd" type="Script" id=1]
[resource]
script = ExtResource( 1 )
name = "goo7"
columns = 1
rows = 1
skip_x_last_frames = 0
framerate = 1

11
images/goo/goo8.tres Normal file
View File

@ -0,0 +1,11 @@
[gd_resource type="Resource" load_steps=2 format=2]
[ext_resource path="res://scripts/GooParticle.gd" type="Script" id=1]
[resource]
script = ExtResource( 1 )
name = "goo8"
columns = 1
rows = 1
skip_x_last_frames = 0
framerate = 1

View File

@ -24,6 +24,11 @@ _global_script_classes=[ {
"language": "GDScript",
"path": "res://scripts/game1/Flatfish.gd"
}, {
"base": "Resource",
"class": "GooParticle",
"language": "GDScript",
"path": "res://scripts/GooParticle.gd"
}, {
"base": "Node",
"class": "IntroScript",
"language": "GDScript",
@ -38,6 +43,7 @@ _global_script_class_icons={
"DialogueAction": "",
"DialogueBox": "",
"Flatfish": "",
"GooParticle": "",
"IntroScript": "",
"LogEntity": ""
}

View File

@ -1,10 +1,24 @@
[gd_scene load_steps=13 format=2]
[gd_scene load_steps=28 format=2]
[ext_resource path="res://scripts/oil_tanker.gd" type="Script" id=1]
[ext_resource path="res://images/oil_tanker/OilTanker.tres" type="SpriteFrames" id=2]
[ext_resource path="res://images/oil_tanker/oilTankerInside_Background.png" type="Texture" id=3]
[ext_resource path="res://scenes/SidePlayer.tscn" type="PackedScene" id=4]
[ext_resource path="res://images/oil_tanker/oilTankerInside_Foreground.png" type="Texture" id=5]
[ext_resource path="res://scripts/GooEmitter.gd" type="Script" id=6]
[ext_resource path="res://images/goo/goo.shader" type="Shader" id=7]
[ext_resource path="res://images/goo/BigGoo1.tres" type="Resource" id=8]
[ext_resource path="res://images/goo/BigGoo1.png" type="Texture" id=9]
[ext_resource path="res://images/goo/BigGoo1_Outlines.png" type="Texture" id=10]
[ext_resource path="res://images/goo/BigGoo2.tres" type="Resource" id=11]
[ext_resource path="res://images/goo/goo5.tres" type="Resource" id=12]
[ext_resource path="res://images/goo/goo8.tres" type="Resource" id=13]
[ext_resource path="res://images/goo/goo4.tres" type="Resource" id=14]
[ext_resource path="res://images/goo/goo2.tres" type="Resource" id=15]
[ext_resource path="res://images/goo/goo7.tres" type="Resource" id=16]
[ext_resource path="res://images/goo/goo6.tres" type="Resource" id=17]
[ext_resource path="res://images/goo/goo1.tres" type="Resource" id=18]
[ext_resource path="res://images/goo/goo3.tres" type="Resource" id=19]
[sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 10, 27.9493 )
@ -27,6 +41,13 @@ b = Vector2( -129.208, -5.53812 )
[sub_resource type="SegmentShape2D" id=7]
b = Vector2( -87.4343, 42.6051 )
[sub_resource type="ShaderMaterial" id=10]
shader = ExtResource( 7 )
shader_param/particles_anim_h_frames = 10
shader_param/particles_anim_v_frames = 11
shader_param/particles_anim_loop = true
shader_param/frame = null
[node name="Node2D" type="Node2D"]
script = ExtResource( 1 )
@ -37,6 +58,13 @@ centered = false
[node name="Player" parent="InsideOilTanker" instance=ExtResource( 4 )]
position = Vector2( 192, 64.4552 )
[node name="GooEmitter" type="Node2D" parent="InsideOilTanker"]
position = Vector2( -43.5548, 47.7155 )
script = ExtResource( 6 )
goo_particles = [ ExtResource( 8 ), ExtResource( 11 ), ExtResource( 18 ), ExtResource( 15 ), ExtResource( 19 ), ExtResource( 14 ), ExtResource( 12 ), ExtResource( 17 ), ExtResource( 16 ), ExtResource( 13 ) ]
direction = Vector2( 1, 0 )
spawn_rate = 2
[node name="Foreground" type="Sprite" parent="InsideOilTanker"]
texture = ExtResource( 5 )
centered = false
@ -86,6 +114,12 @@ position = Vector2( 204.978, 72.7017 )
shape = SubResource( 7 )
[node name="OilTanker" type="AnimatedSprite" parent="."]
visible = false
frames = ExtResource( 2 )
centered = false
[node name="GooExample" type="Sprite" parent="."]
visible = false
material = SubResource( 10 )
texture = ExtResource( 9 )
normal_map = ExtResource( 10 )
centered = false

70
scripts/GooEmitter.gd Normal file
View File

@ -0,0 +1,70 @@
extends Node2D
export(Array, Resource) var goo_particles = []
export(Vector2) var direction
export(int) var spawn_radius = 32
export(int) var spawn_rate = 1
export(int) var despawn_radius = 250
export(float) var movement_speed = 10
var goo_shader = preload('res://images/goo/goo.shader')
var delta_sum = 0
var time = 0
func _ready():
for particle in goo_particles:
particle.load_textures()
func emit():
var particle = goo_particles[rand_range(0, goo_particles.size())] as GooParticle
print(particle.name)
var instance = Particle.new()
instance.particle = particle
instance.material = ShaderMaterial.new()
instance.material.shader = goo_shader
instance.material.set_shader_param('particles_anim_h_frames', particle.columns)
instance.material.set_shader_param('particles_anim_v_frames', particle.rows)
instance.material.set_shader_param('particles_anim_loop', true)
instance.material.set_shader_param('frame', 0)
instance.texture = particle.texture
instance.normal_map = particle.normal_map
instance.shader_frame = 0
instance.position = Vector2(rand_range(0, spawn_radius), rand_range(0, spawn_radius))
instance.initial_y = instance.position.y
instance.initial_time = time
add_child(instance)
func _process(delta):
delta_sum += delta
time += delta
for child in get_children():
child.delta_sum += delta
while child.delta_sum >= 1.0 / child.particle.framerate:
child.delta_sum -= 1.0 / child.particle.framerate
child.shader_frame += 1
if child.shader_frame >= child.particle.frame_count:
child.shader_frame = 0
child.material.set_shader_param('frame', child.shader_frame)
child.position += direction * delta * movement_speed
child.position.y = child.initial_y + sin(time - child.initial_time) * 3
while delta_sum >= spawn_rate:
delta_sum -= spawn_rate
emit()
for child in get_children():
if child.position.length() > despawn_radius:
child.queue_free()
class Particle:
extends Sprite
var shader_frame = 0
var particle : GooParticle
var delta_sum : float = 0
var initial_y : int
var initial_time : float

21
scripts/GooParticle.gd Normal file
View File

@ -0,0 +1,21 @@
extends Resource
class_name GooParticle
export var name : String
export var columns : int = 1
export var rows : int = 1
export var skip_x_last_frames : int = 0
export var framerate = 5
var texture : Texture
var normal_map : Texture
var frame_count : int
var loaded = false
func load_textures():
if !loaded:
loaded = true
texture = load('res://images/goo/' + name + '.png')
normal_map = load('res://images/goo/' + name + '_Outlines.png')
frame_count = columns * rows - skip_x_last_frames