├── LICENSE ├── README.md ├── Thumbs.db ├── addons └── DYNAMIC_WATER │ ├── demo_droplets_particles_materials │ └── water_droplets.tres │ ├── dynamic_water.gd │ ├── dynamic_water_plugin.gd │ ├── icon.png │ ├── icon.png.import │ └── plugin.cfg ├── icon.png ├── instructions.txt ├── preview_1.png ├── preview_2.png ├── preview_3.png └── tests ├── .import ├── icon.png-487276ed1e3a0c39cad0279d744ee560.stex └── icon.png-7c1e58275ae1e3cfa6ce13114b746973.stex ├── CollisionPolygon2D.gd ├── addons └── DYNAMIC_WATER │ ├── demo_droplets_particles_materials │ └── water_droplets.tres │ ├── dynamic_water.gd │ ├── dynamic_water_plugin.gd │ ├── icon.png │ ├── icon.png.import │ └── plugin.cfg ├── default_env.tres ├── icon.png ├── icon.png.import ├── project.godot ├── scenes ├── Player.tscn └── world.tscn └── scripts └── Player.gd /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 gdgamedev 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # dynamic_water_plugin 2 | 3 | ![ScreenShot](/preview_1.png) 4 | ![ScreenShot](/preview_2.png) 5 | ![ScreenShot](/preview_3.png) 6 | 7 | 8 | ### --PT-BR-- 9 | Há algum tempo, você vem criando um jogo no estilo plataforma, ele é incrível, fases criativas, mas... Falta algo naquele rio um poça de água... Não se preocupe!! Com este plugin, poderá criar água dinâmica polygonal de forma simples e rápida e customizável!! 10 | 11 | Por que usar água dinâmica poligonal?\ 12 | -Pois necessita de menos processamento, tudo que está sendo exeucutado são cálculos físicos de oscilação harmonica amortecida e dispersão da energia. 13 | 14 | Serve apenas como água?\ 15 | -Não!! Você pode customizar a cor e a forma como se comporta para parecer com lava, por exemplo. 16 | 17 | Eu acho que já vi isso am algum lugar...\ 18 | -Realmente, a ideia não é 100% meu, apenas modifiquei alguns itens do tutorial do **The Step Event** para a engine Game Maker Studio 1.4 e 2, aqui está o link caso tenha interesse: https://www.youtube.com/watch?v=LG3wocqjC-0 19 | 20 | Como usar?\ 21 | -Aqui vai um pequeno tutorial de como usar: 22 | 23 | Após inserir a pasta addons no seu projeto, e ativar o plugin pelas opções do projeto poderá, em qualquer cena, adicionar um novo node chamado "dynamic water", que deriva-se do node2D; 24 | 25 | Quando for inserido o node, mude as propriedades "HEIGHT" (altura) e "WIDTH" (largura) para mudar a área da água; 26 | 27 | Mudando a propriedade "RESOLUTION" (resolução), você pode mudar a quantidade de vetores na superfície da água, aumentando a qualidade das ondas; 28 | 29 | A propriedade "COLOR" (cor) permite mudar a cor da água; 30 | 31 | Agora, algumas propriedades físicas, que brincando um pouco pode entender mais: 32 | 33 | -"TENSION" (tensão) muda a propriedade "elastica" da água, fazendo com que os vetores tendem voltar à posição original mais rapidamente;\ 34 | -"DAMPING" (amortecimento) faz com que a energia perca mais rapidamente;\ 35 | -"PASSES" Número de vetores que será dispersado a energia;\ 36 | -"DISPERSION" (dispersão) A quantidade de energia dispersado pelos vetores 37 | 38 | Tá, mas agora como faço a água se mexer?\ 39 | -Por enquanto até a versão 1.0 do plugin, a única maneira é de usar um objeto da classe RigidBody2D, pois as variáveis calculadas de energia aplicada precisa de variáveis do RigidBody2D (que é a velocidade linear, exclusivo da classe). Tenho planos de aprimorar o plugin para calcular a velocidade de qualquer corpo a patir de mudança de posição. 40 | 41 | Eu tenho algumas ideias para seu plugin, posso ajudá-lo?\ 42 | -Claro, caso queira auxiliar nesse e nos outros projetos, mande um e-mail para: ghsoares99795@gmail.com 43 | 44 | Enfim, muito obrigado pela sua atenção e espero que goste do plugin!! 45 | 46 | 47 | 48 | ### --EN-US-- 49 | For some time, you've been creating a platform-style game, with awesome and creative levels. But... something's missing in that river or puddle of water... Don't worry! With this plugin, you will be able to create dynamic and customizable polygonal water the fast and simple way! 50 | 51 | Why use dynamic polygonal water?\ 52 | -Because it needs less processing, everything that is being processed are physical calculations of damped harmonic oscillation and energy dispersion. 53 | 54 | I can only use this for water?\ 55 | -Nope! You can customize the color and the way that the fluid acts to be more like, lava, for example. 56 | 57 | I think I saw this somewhere else...\ 58 | -Yes, the idea is not 100% mine. I just modified some items from the tutorial from the **The Step Event** of the game engine Game Maker Studio 1.4 and 2, here is the link if it interests you.: https://www.youtube.com/watch?v=LG3wocqjC-0 59 | 60 | How do I use this?\ 61 | -Here is a little tutorial to help you.: 62 | 63 | 64 | After inserting the folder addons in your project, and activate the plugin in the project options you can, in any scene, add a new node called `dynamic water` that derives from `Node2D`. 65 | 66 | When the node is inserted, change the properties `HEIGHT` and `WIDTH` to change the water area. 67 | 68 | By changing the property `RESOLUTION`, you change the ammount of vectors in the water surface, increasing the quality of the waves. 69 | 70 | The property `COLOR` changes the color of the water (duh?). 71 | 72 | Now for the physics properties. Playing with them a little can help to understand them more: 73 | 74 | -`TENSION`: Changes the "springiness" of the water waves, meaning the vectors return to their original positions faster. 75 | 76 | -`DAMPING`: Water waves die down faster. 77 | 78 | -`PASSES`: Number of vectors that the waves' energy is dispersed into. 79 | 80 | -`DISPERSION`: The amount of energy dispersed into the wave vectors; 81 | 82 | OK, but how do I make the water move?\ 83 | -Until version 1.0 of the plugin, the only way is to use an object of the `RigidBody2D` class, because the calculated variables of energy need some variables from a `RigidBody2D` (linear velocity, exclusive of the class). I have plans of improving the plugin to calculate the velocity of any body from the position change. 84 | 85 | I have some ideas for your plugin. Can I help?\ 86 | -Of course, if you want to help in that and other projects, send an e-mail to: ghsoares99795@gmail.com 87 | 88 | So, thank you for your attention and I hope that you enjoy this plugin!! 89 | 90 | ~~SRY FOR THE BAD ENGLISH BTW XD~~ 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | -------------------------------------------------------------------------------- /Thumbs.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghsoares/dynamic_water_plugin/24d27a5901f33d6717555e181369b32c91a0870c/Thumbs.db -------------------------------------------------------------------------------- /addons/DYNAMIC_WATER/demo_droplets_particles_materials/water_droplets.tres: -------------------------------------------------------------------------------- 1 | [gd_resource type="ParticlesMaterial" load_steps=3 format=2] 2 | 3 | [sub_resource type="Gradient" id=1] 4 | 5 | offsets = PoolRealArray( 0, 1 ) 6 | colors = PoolColorArray( 0, 0.859375, 1, 1, 0, 0.929688, 1, 0 ) 7 | 8 | [sub_resource type="GradientTexture" id=2] 9 | 10 | flags = 4 11 | gradient = SubResource( 1 ) 12 | width = 2048 13 | 14 | [resource] 15 | 16 | render_priority = 0 17 | trail_divisor = 1 18 | emission_shape = 0 19 | flag_align_y = false 20 | flag_rotate_y = false 21 | flag_disable_z = true 22 | spread = 20.0 23 | flatness = 0.0 24 | gravity = Vector3( 0, 300, 0 ) 25 | initial_velocity = 400.0 26 | initial_velocity_random = 1.0 27 | angular_velocity = 0.0 28 | angular_velocity_random = 0.0 29 | orbit_velocity = 0.0 30 | orbit_velocity_random = 0.0 31 | linear_accel = 0.0 32 | linear_accel_random = 0.0 33 | radial_accel = 0.0 34 | radial_accel_random = 0.0 35 | tangential_accel = 0.0 36 | tangential_accel_random = 0.0 37 | damping = 0.0 38 | damping_random = 0.0 39 | angle = 0.0 40 | angle_random = 0.0 41 | scale = 3.0 42 | scale_random = 1.0 43 | color_ramp = SubResource( 2 ) 44 | hue_variation = 0.0 45 | hue_variation_random = 0.0 46 | anim_speed = 0.0 47 | anim_speed_random = 0.0 48 | anim_offset = 0.0 49 | anim_offset_random = 0.0 50 | anim_loop = false 51 | _sections_unfolded = [ "Color", "Initial Velocity" ] 52 | 53 | -------------------------------------------------------------------------------- /addons/DYNAMIC_WATER/dynamic_water.gd: -------------------------------------------------------------------------------- 1 | tool 2 | extends Node2D 3 | 4 | #variáveis modificáveis pelo editor 5 | export (float) var ALTURA = 0 6 | export (float) var LARGURA = 0 7 | export (float) var RESOLUCAO = 1 8 | export (Color) var COR = Color(1.0, 1.0, 1.0, 1.0) 9 | export (ParticlesMaterial) var droplets_material_path 10 | 11 | export (float) var TENSAO = 0.025 12 | export (float) var AMORTECIMENTO = 0.001 13 | export (int) var PASSES = 1 14 | export (float) var DISPERSAO = 0.01 15 | 16 | #variáveis não modificáveis 17 | var vecs_positions = [] 18 | var vecs_velocity = [] 19 | var left_vec = [] 20 | var right_vec = [] 21 | 22 | var water 23 | var area 24 | var _col 25 | 26 | 27 | func _ready(): #função chamado na execução do node 28 | if Engine.is_editor_hint() == false: 29 | create_water_block() 30 | set_process(true) 31 | self.z_index = 999 32 | 33 | func _process(delta): #função chamada todo frame 34 | if Engine.is_editor_hint() == false: 35 | _dynamic_physics() 36 | else: 37 | update() 38 | 39 | func _dynamic_physics(): #função responsável pela física dinâmica da água 40 | for i in vecs_positions.size() - 2: 41 | var target_y = -ALTURA - vecs_positions[i].y 42 | vecs_velocity[i] += (TENSAO * target_y) - (AMORTECIMENTO * vecs_velocity[i]) 43 | vecs_positions[i].y += vecs_velocity[i] 44 | 45 | water.polygon[i] = vecs_positions[i] 46 | 47 | #dispersão 48 | for i in vecs_positions.size() - 2: 49 | left_vec[i] = 0 50 | right_vec[i] = 0 51 | 52 | for j in PASSES: 53 | for i in vecs_positions.size() - 2: 54 | if i > 0: 55 | left_vec[i] = DISPERSAO * (vecs_positions[i].y - vecs_positions[i - 1].y) 56 | vecs_velocity[i - 1] += left_vec[i] 57 | if i < vecs_positions.size() - 3: 58 | right_vec[i] = DISPERSAO * (vecs_positions[i].y - vecs_positions[i + 1].y) 59 | vecs_velocity[i + 1] += right_vec[i] 60 | for i in vecs_positions.size() - 2: 61 | if i > 0: 62 | vecs_positions[i - 1].y += left_vec[i] 63 | if i < vecs_positions.size() - 3: 64 | vecs_positions[i + 1].y += right_vec[i] 65 | 66 | func create_water_block(): #criação da água 67 | #criação de variáveis de custom nodes 68 | var water_block = Polygon2D.new() 69 | var area = Area2D.new() 70 | var col = CollisionPolygon2D.new() 71 | 72 | #criação de variáveis de valores 73 | var distance_beetween_vecs = LARGURA / RESOLUCAO 74 | var vecs = PoolVector2Array([]) 75 | 76 | vecs.insert(0, Vector2(0, -ALTURA)) 77 | 78 | for i in RESOLUCAO: 79 | vecs.insert(i+1, Vector2(distance_beetween_vecs * (i + 1),-ALTURA)) 80 | 81 | vecs.insert(RESOLUCAO + 1, Vector2(LARGURA, 0)) 82 | vecs.insert(RESOLUCAO + 2, Vector2(0, 0)) 83 | 84 | #designação de variáveis aos custom nodes 85 | water_block.name = "water_base" 86 | water_block.polygon = vecs 87 | water_block.color = COR 88 | 89 | area.name = "water_area" 90 | 91 | col.name = "water_col" 92 | col.polygon = water_block.polygon 93 | 94 | #adicionar os custom nodes ao mundo 95 | self.add_child(water_block) 96 | water_block.add_child(area) 97 | area.add_child(col) 98 | 99 | #sinais 100 | area.connect("body_entered", self, "body_emerged") 101 | area.connect("body_exited", self, "body_not_emerged") 102 | 103 | #modificação de variáveis para física dinâmica 104 | for i in water_block.polygon.size(): 105 | vecs_positions.insert(i, water_block.polygon[i]) 106 | vecs_velocity.insert(i, 0) 107 | left_vec.insert(i, 0) 108 | right_vec.insert(i, 0) 109 | 110 | #indicamento de nodes filhos 111 | water = $"./water_base" 112 | _col = $"./water_base/water_area/water_col" 113 | 114 | func body_emerged(body): #acionado quando um corpo da classe RigidBody2D colide com a area da água 115 | if body is RigidBody2D: 116 | #distorção da água 117 | var force_applied = body.linear_velocity.y * 0.01 118 | 119 | var body_pos = body.position.x - self.position.x 120 | var closest_vec_pos_x = 9999999 121 | var closest_vec = 0 122 | for i in vecs_positions.size() - 2: 123 | var distance_diference = vecs_positions[i].x - body_pos 124 | if distance_diference < 0: 125 | distance_diference *= -1 126 | if distance_diference < closest_vec_pos_x: 127 | closest_vec = i 128 | closest_vec_pos_x = distance_diference 129 | vecs_velocity[closest_vec] -= force_applied 130 | 131 | body.gravity_scale *= 0.05 132 | body.linear_velocity.y /= 1.5 133 | 134 | #efeitos 135 | if droplets_material_path != null: 136 | var droplets = Particles2D.new() 137 | droplets.name = "particles" 138 | droplets.amount = 20 139 | droplets.lifetime = 2 140 | droplets.explosiveness = 1 141 | droplets.one_shot = true 142 | droplets.local_coords = false 143 | droplets.process_material = droplets_material_path 144 | 145 | droplets.global_position = Vector2(body.global_position.x, body.global_position.y + 30) 146 | droplets.rotation_degrees = -90 147 | 148 | $"..".add_child(droplets) 149 | 150 | droplets.visibility_rect = Rect2(Vector2(-900, -2000), Vector2(9999, 9999)) 151 | 152 | pass 153 | 154 | func body_not_emerged(body): 155 | if body is RigidBody2D: 156 | body.gravity_scale *= 10 157 | 158 | func _draw(): #desenho de polígono para visualização pelo editor 159 | var vecs = PoolVector2Array([]) 160 | var color = PoolColorArray([]) 161 | if Engine.is_editor_hint(): 162 | vecs = PoolVector2Array([Vector2(0, -ALTURA), Vector2(LARGURA, -ALTURA), Vector2(LARGURA, 0), Vector2(0, 0)]) 163 | color = PoolColorArray([Color(1.0, 1.0, 1.0, 0.4), Color(1.0, 1.0, 1.0, 0.4), Color(1.0, 1.0, 1.0, 0.4), Color(1.0, 1.0, 1.0, 0.4)]) 164 | 165 | draw_polygon(vecs, color) 166 | 167 | 168 | 169 | -------------------------------------------------------------------------------- /addons/DYNAMIC_WATER/dynamic_water_plugin.gd: -------------------------------------------------------------------------------- 1 | tool 2 | extends EditorPlugin 3 | 4 | func _enter_tree(): 5 | add_custom_type("dynamic water", "Node2D", preload("res://addons/DYNAMIC_WATER/dynamic_water.gd"), preload("res://addons/DYNAMIC_WATER/icon.png")) 6 | 7 | func _exit_tree(): 8 | remove_custom_type("dynamic water") 9 | 10 | -------------------------------------------------------------------------------- /addons/DYNAMIC_WATER/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghsoares/dynamic_water_plugin/24d27a5901f33d6717555e181369b32c91a0870c/addons/DYNAMIC_WATER/icon.png -------------------------------------------------------------------------------- /addons/DYNAMIC_WATER/icon.png.import: -------------------------------------------------------------------------------- 1 | [remap] 2 | 3 | importer="texture" 4 | type="StreamTexture" 5 | path="res://.import/icon.png-7c1e58275ae1e3cfa6ce13114b746973.stex" 6 | 7 | [deps] 8 | 9 | source_file="res://addons/DYNAMIC_WATER/icon.png" 10 | source_md5="c8df361fbd9cfe39f8bef817b3fb8528" 11 | 12 | dest_files=[ "res://.import/icon.png-7c1e58275ae1e3cfa6ce13114b746973.stex" ] 13 | dest_md5="113df9723beae7c27e073d9a2e593469" 14 | 15 | [params] 16 | 17 | compress/mode=0 18 | compress/lossy_quality=0.7 19 | compress/hdr_mode=0 20 | compress/normal_map=0 21 | flags/repeat=0 22 | flags/filter=true 23 | flags/mipmaps=false 24 | flags/anisotropic=false 25 | flags/srgb=2 26 | process/fix_alpha_border=true 27 | process/premult_alpha=false 28 | process/HDR_as_SRGB=false 29 | stream=false 30 | size_limit=0 31 | detect_3d=true 32 | svg/scale=1.0 33 | -------------------------------------------------------------------------------- /addons/DYNAMIC_WATER/plugin.cfg: -------------------------------------------------------------------------------- 1 | [plugin] 2 | 3 | name = "dynamic water" 4 | description = "now you can use a custom node that create a polygonal dynamic water almostly fully customizable!!" 5 | author = "Gabriel Henrique P. Soares" 6 | version = "1.0" 7 | script = "dynamic_water_plugin.gd" -------------------------------------------------------------------------------- /icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghsoares/dynamic_water_plugin/24d27a5901f33d6717555e181369b32c91a0870c/icon.png -------------------------------------------------------------------------------- /instructions.txt: -------------------------------------------------------------------------------- 1 | --PT-BR-- 2 | Primeiramente, muito obrigado por ter baixado gratuitamente esse plugin!! 3 | 4 | 5 | 6 | De nada, mas quero saber como usar... 7 | 8 | -Primeiramente, você tem que inserir a pasta "addons" no diretório raiz de seu projeto no Godot 3.0; 9 | 10 | -Depois, ativa o plugin nas opções do projeto, na aba "Plugins", irá aparecer o nome do plugin, mude a opção "status" para "active" ou "ativo"; 11 | 12 | -A partir de agora, você já tem disponível no seu projeto, um novo node, chamado "dynamic water", podendo adicioná-lo na cena. 13 | 14 | 15 | 16 | Beleza, mas não aparece nada!! 17 | 18 | -Ainda não está aparecendo nada pois precisa mudar as opções "WIDTH" (largura) e "HEIGHT" (altura). 19 | 20 | 21 | 22 | Boa!! agora é só executar a cena e... 23 | 24 | -Tenha calma meu jovem!! Caso você for executar, tudo que verá é apenas um bloco branco extático; 25 | 26 | -Para melhorar a aparência da água, mude a propriedade "COLOR" (cor) da água, para torná-la transparente e azul; 27 | 28 | 29 | 30 | Agora sim, é só executar a cena e... 31 | 32 | -Espera!! falta as propriedades físicas da água!!; 33 | 34 | -"TENSION" (TENSÃO) muda o quão elastico a água fica; 35 | 36 | -"DAMPING" (AMORTECIMENTO) muda o quão rápido a água perde energia; 37 | 38 | -"PASSES" muda o número de vértices que será dispersado a energia; 39 | 40 | -"DISPERSION" (DISPERSÃO) muda o quanto de energia será dispersado; 41 | 42 | 43 | 44 | Agora não falta mais nenhuma propriedade, então já posso executar e... A água não se meche? 45 | 46 | -A água não se mexe pois a única maneira na qual a água interage é por corpos da classe RigidBody2D, 47 | pois as variáveis de deslocação da onda é calculada pela velocidade linear exclusivo do RigidBody2D; 48 | 49 | -Agora sim!! Ao executar a cena e colocar de alguma forma um RigidBody2D com colisão, ao "mergulhar" na água, formará ondas que comportarão 50 | de forma diferente a partir das propriedades físicas. 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /preview_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghsoares/dynamic_water_plugin/24d27a5901f33d6717555e181369b32c91a0870c/preview_1.png -------------------------------------------------------------------------------- /preview_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghsoares/dynamic_water_plugin/24d27a5901f33d6717555e181369b32c91a0870c/preview_2.png -------------------------------------------------------------------------------- /preview_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghsoares/dynamic_water_plugin/24d27a5901f33d6717555e181369b32c91a0870c/preview_3.png -------------------------------------------------------------------------------- /tests/.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghsoares/dynamic_water_plugin/24d27a5901f33d6717555e181369b32c91a0870c/tests/.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex -------------------------------------------------------------------------------- /tests/.import/icon.png-7c1e58275ae1e3cfa6ce13114b746973.stex: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghsoares/dynamic_water_plugin/24d27a5901f33d6717555e181369b32c91a0870c/tests/.import/icon.png-7c1e58275ae1e3cfa6ce13114b746973.stex -------------------------------------------------------------------------------- /tests/CollisionPolygon2D.gd: -------------------------------------------------------------------------------- 1 | extends CollisionPolygon2D 2 | 3 | func _ready(): 4 | self.polygon = $"../../Polygon2D".polygon 5 | pass 6 | -------------------------------------------------------------------------------- /tests/addons/DYNAMIC_WATER/demo_droplets_particles_materials/water_droplets.tres: -------------------------------------------------------------------------------- 1 | [gd_resource type="ParticlesMaterial" load_steps=3 format=2] 2 | 3 | [sub_resource type="Gradient" id=1] 4 | 5 | offsets = PoolRealArray( 0, 1 ) 6 | colors = PoolColorArray( 0.46431, 0.617333, 0.628906, 1, 0.370789, 0.505328, 0.527344, 0 ) 7 | 8 | [sub_resource type="GradientTexture" id=2] 9 | 10 | flags = 4 11 | gradient = SubResource( 1 ) 12 | width = 2048 13 | 14 | [resource] 15 | 16 | render_priority = 0 17 | trail_divisor = 1 18 | emission_shape = 0 19 | flag_align_y = false 20 | flag_rotate_y = false 21 | flag_disable_z = true 22 | spread = 20.0 23 | flatness = 0.0 24 | gravity = Vector3( 0, 300, 0 ) 25 | initial_velocity = 400.0 26 | initial_velocity_random = 0.3 27 | angular_velocity = 0.0 28 | angular_velocity_random = 0.0 29 | orbit_velocity = 0.0 30 | orbit_velocity_random = 0.0 31 | linear_accel = 0.0 32 | linear_accel_random = 0.0 33 | radial_accel = 0.0 34 | radial_accel_random = 0.0 35 | tangential_accel = 0.0 36 | tangential_accel_random = 0.0 37 | damping = 0.0 38 | damping_random = 0.0 39 | angle = 0.0 40 | angle_random = 0.0 41 | scale = 3.0 42 | scale_random = 1.0 43 | color_ramp = SubResource( 2 ) 44 | hue_variation = 0.0 45 | hue_variation_random = 0.0 46 | anim_speed = 0.0 47 | anim_speed_random = 0.0 48 | anim_offset = 0.0 49 | anim_offset_random = 0.0 50 | anim_loop = false 51 | _sections_unfolded = [ "Color", "Initial Velocity" ] 52 | 53 | -------------------------------------------------------------------------------- /tests/addons/DYNAMIC_WATER/dynamic_water.gd: -------------------------------------------------------------------------------- 1 | tool 2 | extends Node2D 3 | 4 | #variáveis modificáveis pelo editor 5 | export (float) var ALTURA = 0 6 | export (float) var LARGURA = 0 7 | export (float) var RESOLUCAO = 1 8 | export (Color) var COR = Color(1.0, 1.0, 1.0, 1.0) 9 | export (ParticlesMaterial) var droplets_material_path 10 | 11 | export (float) var TENSAO = 0.025 12 | export (float) var AMORTECIMENTO = 0.001 13 | export (int) var PASSES = 1 14 | export (float) var DISPERSAO = 0.01 15 | export (float) var force_multiplyier = 0.01 16 | export (int) var NUMBER_OF_VECS_TO_APPLY_FORCE = 1 17 | 18 | #variáveis não modificáveis 19 | var vecs_positions = [] 20 | var vecs_velocity = [] 21 | var left_vec = [] 22 | var right_vec = [] 23 | 24 | var water 25 | var area 26 | var _col 27 | 28 | 29 | func _ready(): #função chamado na execução do node 30 | if Engine.is_editor_hint() == false: 31 | create_water_block() 32 | set_process(true) 33 | 34 | func _process(delta): #função chamada todo frame 35 | if Engine.is_editor_hint() == false: 36 | _dynamic_physics() 37 | else: 38 | update() 39 | 40 | func _dynamic_physics(): #função responsável pela física dinâmica da água 41 | for i in vecs_positions.size() - 2: 42 | var target_y = -ALTURA - vecs_positions[i].y 43 | vecs_velocity[i] += (TENSAO * target_y) - (AMORTECIMENTO * vecs_velocity[i]) 44 | vecs_positions[i].y += vecs_velocity[i] 45 | 46 | water.polygon[i] = vecs_positions[i] 47 | 48 | #dispersão 49 | for i in vecs_positions.size() - 2: 50 | left_vec[i] = 0 51 | right_vec[i] = 0 52 | 53 | for j in PASSES: 54 | for i in vecs_positions.size() - 2: 55 | if i > 0: 56 | left_vec[i] = DISPERSAO * (vecs_positions[i].y - vecs_positions[i - 1].y) 57 | vecs_velocity[i - 1] += left_vec[i] 58 | if i < vecs_positions.size() - 3: 59 | right_vec[i] = DISPERSAO * (vecs_positions[i].y - vecs_positions[i + 1].y) 60 | vecs_velocity[i + 1] += right_vec[i] 61 | for i in vecs_positions.size() - 2: 62 | if i > 0: 63 | vecs_positions[i - 1].y += left_vec[i] 64 | if i < vecs_positions.size() - 3: 65 | vecs_positions[i + 1].y += right_vec[i] 66 | 67 | func create_water_block(): #criação da água 68 | #criação de variáveis de custom nodes 69 | var water_block = Polygon2D.new() 70 | var area = Area2D.new() 71 | var col = CollisionPolygon2D.new() 72 | 73 | #criação de variáveis de valores 74 | var distance_beetween_vecs = LARGURA / RESOLUCAO 75 | var vecs = PoolVector2Array([]) 76 | 77 | vecs.insert(0, Vector2(0, -ALTURA)) 78 | 79 | for i in RESOLUCAO: 80 | vecs.insert(i+1, Vector2(distance_beetween_vecs * (i + 1),-ALTURA)) 81 | 82 | vecs.insert(RESOLUCAO + 1, Vector2(LARGURA, 0)) 83 | vecs.insert(RESOLUCAO + 2, Vector2(0, 0)) 84 | 85 | #designação de variáveis aos custom nodes 86 | water_block.name = "water_base" 87 | water_block.polygon = vecs 88 | water_block.color = COR 89 | 90 | area.name = "water_area" 91 | 92 | col.name = "water_col" 93 | col.polygon = water_block.polygon 94 | 95 | #adicionar os custom nodes ao mundo 96 | self.add_child(water_block) 97 | water_block.add_child(area) 98 | area.add_child(col) 99 | 100 | #sinais 101 | area.connect("body_entered", self, "body_emerged") 102 | area.connect("body_exited", self, "body_not_emerged") 103 | 104 | #modificação de variáveis para física dinâmica 105 | for i in water_block.polygon.size(): 106 | vecs_positions.insert(i, water_block.polygon[i]) 107 | vecs_velocity.insert(i, 0) 108 | left_vec.insert(i, 0) 109 | right_vec.insert(i, 0) 110 | 111 | #indicamento de nodes filhos 112 | water = $"./water_base" 113 | _col = $"./water_base/water_area/water_col" 114 | 115 | func body_emerged(body): #acionado quando um corpo da classe RigidBody2D colide com a area da água 116 | if body is RigidBody2D: 117 | #distorção da água 118 | var force_applied = -body.linear_velocity.y * force_multiplyier 119 | 120 | var body_pos = body.position.x - self.position.x 121 | var closest_vec_pos_x = 9999999 122 | var closest_vec = 0 123 | for i in vecs_positions.size() - 2: 124 | var distance_diference = vecs_positions[i].x - body_pos 125 | if distance_diference < 0: 126 | distance_diference *= -1 127 | if distance_diference < closest_vec_pos_x: 128 | closest_vec = i 129 | closest_vec_pos_x = distance_diference 130 | 131 | vecs_velocity[closest_vec] -= force_applied 132 | 133 | for i in NUMBER_OF_VECS_TO_APPLY_FORCE: 134 | if closest_vec - i > -vecs_velocity.size(): 135 | vecs_velocity[closest_vec - i] -= force_applied 136 | if closest_vec + i < vecs_velocity.size(): 137 | vecs_velocity[closest_vec + i] -= force_applied 138 | 139 | 140 | body.gravity_scale *= 0.05 141 | body.linear_velocity.y /= 1.5 142 | 143 | #efeitos 144 | if droplets_material_path != null: 145 | var droplets = Particles2D.new() 146 | droplets.name = "particles" 147 | droplets.amount = 20 148 | droplets.lifetime = 2 149 | droplets.explosiveness = 1 150 | droplets.one_shot = true 151 | droplets.local_coords = false 152 | droplets.process_material = droplets_material_path 153 | 154 | droplets.global_position = Vector2(body.global_position.x, body.global_position.y + 30) 155 | droplets.rotation_degrees = -90 156 | 157 | $"..".add_child(droplets) 158 | 159 | droplets.visibility_rect = Rect2(Vector2(-900, -2000), Vector2(9999, 9999)) 160 | 161 | pass 162 | 163 | func body_not_emerged(body): 164 | if body is RigidBody2D: 165 | #distorção da água 166 | var force_applied = -body.linear_velocity.y * force_multiplyier 167 | 168 | var body_pos = body.position.x - self.position.x 169 | var closest_vec_pos_x = 9999999 170 | var closest_vec = 0 171 | for i in vecs_positions.size() - 2: 172 | var distance_diference = vecs_positions[i].x - body_pos 173 | if distance_diference < 0: 174 | distance_diference *= -1 175 | if distance_diference < closest_vec_pos_x: 176 | closest_vec = i 177 | closest_vec_pos_x = distance_diference 178 | 179 | vecs_velocity[closest_vec] -= force_applied 180 | 181 | for i in NUMBER_OF_VECS_TO_APPLY_FORCE: 182 | if closest_vec - i > -vecs_velocity.size(): 183 | vecs_velocity[closest_vec - i] -= force_applied 184 | if closest_vec + i < vecs_velocity.size(): 185 | vecs_velocity[closest_vec + i] -= force_applied 186 | 187 | body.gravity_scale /= 0.05 188 | # if body is RigidBody2D: 189 | # body.gravity_scale *= 10 190 | 191 | func _draw(): #desenho de polígono para visualização pelo editor 192 | var vecs = PoolVector2Array([]) 193 | var color = PoolColorArray([]) 194 | if Engine.is_editor_hint(): 195 | vecs = PoolVector2Array([Vector2(0, -ALTURA), Vector2(LARGURA, -ALTURA), Vector2(LARGURA, 0), Vector2(0, 0)]) 196 | color = PoolColorArray([Color(1.0, 1.0, 1.0, 0.4), Color(1.0, 1.0, 1.0, 0.4), Color(1.0, 1.0, 1.0, 0.4), Color(1.0, 1.0, 1.0, 0.4)]) 197 | 198 | draw_polygon(vecs, color) 199 | 200 | #func _create_timer(time_in_seconds): 201 | 202 | 203 | 204 | 205 | -------------------------------------------------------------------------------- /tests/addons/DYNAMIC_WATER/dynamic_water_plugin.gd: -------------------------------------------------------------------------------- 1 | tool 2 | extends EditorPlugin 3 | 4 | func _enter_tree(): 5 | add_custom_type("dynamic water", "Node2D", preload("res://addons/DYNAMIC_WATER/dynamic_water.gd"), preload("res://addons/DYNAMIC_WATER/icon.png")) 6 | 7 | func _exit_tree(): 8 | remove_custom_type("dynamic water") 9 | 10 | -------------------------------------------------------------------------------- /tests/addons/DYNAMIC_WATER/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghsoares/dynamic_water_plugin/24d27a5901f33d6717555e181369b32c91a0870c/tests/addons/DYNAMIC_WATER/icon.png -------------------------------------------------------------------------------- /tests/addons/DYNAMIC_WATER/icon.png.import: -------------------------------------------------------------------------------- 1 | [remap] 2 | 3 | importer="texture" 4 | type="StreamTexture" 5 | path="res://.import/icon.png-7c1e58275ae1e3cfa6ce13114b746973.stex" 6 | 7 | [deps] 8 | 9 | source_file="res://addons/DYNAMIC_WATER/icon.png" 10 | source_md5="c8df361fbd9cfe39f8bef817b3fb8528" 11 | 12 | dest_files=[ "res://.import/icon.png-7c1e58275ae1e3cfa6ce13114b746973.stex" ] 13 | dest_md5="113df9723beae7c27e073d9a2e593469" 14 | 15 | [params] 16 | 17 | compress/mode=0 18 | compress/lossy_quality=0.7 19 | compress/hdr_mode=0 20 | compress/normal_map=0 21 | flags/repeat=0 22 | flags/filter=true 23 | flags/mipmaps=false 24 | flags/anisotropic=false 25 | flags/srgb=2 26 | process/fix_alpha_border=true 27 | process/premult_alpha=false 28 | process/HDR_as_SRGB=false 29 | stream=false 30 | size_limit=0 31 | detect_3d=true 32 | svg/scale=1.0 33 | -------------------------------------------------------------------------------- /tests/addons/DYNAMIC_WATER/plugin.cfg: -------------------------------------------------------------------------------- 1 | [plugin] 2 | 3 | name = "dynamic water" 4 | description = "now you can use a custom node that create a polygonal dynamic water almostly fully customizable!!" 5 | author = "Gabriel Henrique P. Soares" 6 | version = "1.0" 7 | script = "dynamic_water_plugin.gd" -------------------------------------------------------------------------------- /tests/default_env.tres: -------------------------------------------------------------------------------- 1 | [gd_resource type="Environment" load_steps=2 format=2] 2 | 3 | [sub_resource type="ProceduralSky" id=1] 4 | 5 | radiance_size = 4 6 | sky_top_color = Color( 0.0470588, 0.454902, 0.976471, 1 ) 7 | sky_horizon_color = Color( 0.556863, 0.823529, 0.909804, 1 ) 8 | sky_curve = 0.25 9 | sky_energy = 1.0 10 | ground_bottom_color = Color( 0.101961, 0.145098, 0.188235, 1 ) 11 | ground_horizon_color = Color( 0.482353, 0.788235, 0.952941, 1 ) 12 | ground_curve = 0.01 13 | ground_energy = 1.0 14 | sun_color = Color( 1, 1, 1, 1 ) 15 | sun_latitude = 35.0 16 | sun_longitude = 0.0 17 | sun_angle_min = 1.0 18 | sun_angle_max = 100.0 19 | sun_curve = 0.05 20 | sun_energy = 16.0 21 | texture_size = 2 22 | 23 | [resource] 24 | 25 | background_mode = 2 26 | background_sky = SubResource( 1 ) 27 | background_sky_custom_fov = 0.0 28 | background_color = Color( 0, 0, 0, 1 ) 29 | background_energy = 1.0 30 | background_canvas_max_layer = 0 31 | ambient_light_color = Color( 0, 0, 0, 1 ) 32 | ambient_light_energy = 1.0 33 | ambient_light_sky_contribution = 1.0 34 | fog_enabled = false 35 | fog_color = Color( 0.5, 0.6, 0.7, 1 ) 36 | fog_sun_color = Color( 1, 0.9, 0.7, 1 ) 37 | fog_sun_amount = 0.0 38 | fog_depth_enabled = true 39 | fog_depth_begin = 10.0 40 | fog_depth_curve = 1.0 41 | fog_transmit_enabled = false 42 | fog_transmit_curve = 1.0 43 | fog_height_enabled = false 44 | fog_height_min = 0.0 45 | fog_height_max = 100.0 46 | fog_height_curve = 1.0 47 | tonemap_mode = 0 48 | tonemap_exposure = 1.0 49 | tonemap_white = 1.0 50 | auto_exposure_enabled = false 51 | auto_exposure_scale = 0.4 52 | auto_exposure_min_luma = 0.05 53 | auto_exposure_max_luma = 8.0 54 | auto_exposure_speed = 0.5 55 | ss_reflections_enabled = false 56 | ss_reflections_max_steps = 64 57 | ss_reflections_fade_in = 0.15 58 | ss_reflections_fade_out = 2.0 59 | ss_reflections_depth_tolerance = 0.2 60 | ss_reflections_roughness = true 61 | ssao_enabled = false 62 | ssao_radius = 1.0 63 | ssao_intensity = 1.0 64 | ssao_radius2 = 0.0 65 | ssao_intensity2 = 1.0 66 | ssao_bias = 0.01 67 | ssao_light_affect = 0.0 68 | ssao_color = Color( 0, 0, 0, 1 ) 69 | ssao_quality = 0 70 | ssao_blur = 3 71 | ssao_edge_sharpness = 4.0 72 | dof_blur_far_enabled = false 73 | dof_blur_far_distance = 10.0 74 | dof_blur_far_transition = 5.0 75 | dof_blur_far_amount = 0.1 76 | dof_blur_far_quality = 1 77 | dof_blur_near_enabled = false 78 | dof_blur_near_distance = 2.0 79 | dof_blur_near_transition = 1.0 80 | dof_blur_near_amount = 0.1 81 | dof_blur_near_quality = 1 82 | glow_enabled = false 83 | glow_levels/1 = false 84 | glow_levels/2 = false 85 | glow_levels/3 = true 86 | glow_levels/4 = false 87 | glow_levels/5 = true 88 | glow_levels/6 = false 89 | glow_levels/7 = false 90 | glow_intensity = 0.8 91 | glow_strength = 1.0 92 | glow_bloom = 0.0 93 | glow_blend_mode = 2 94 | glow_hdr_threshold = 1.0 95 | glow_hdr_scale = 2.0 96 | glow_bicubic_upscale = false 97 | adjustment_enabled = false 98 | adjustment_brightness = 1.0 99 | adjustment_contrast = 1.0 100 | adjustment_saturation = 1.0 101 | 102 | -------------------------------------------------------------------------------- /tests/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghsoares/dynamic_water_plugin/24d27a5901f33d6717555e181369b32c91a0870c/tests/icon.png -------------------------------------------------------------------------------- /tests/icon.png.import: -------------------------------------------------------------------------------- 1 | [remap] 2 | 3 | importer="texture" 4 | type="StreamTexture" 5 | path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" 6 | 7 | [deps] 8 | 9 | source_file="res://icon.png" 10 | source_md5="ae7e641067601e2184afcade49abd283" 11 | 12 | dest_files=[ "res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" ] 13 | dest_md5="84511021bbc8c9d37c7f0f4d181de883" 14 | 15 | [params] 16 | 17 | compress/mode=0 18 | compress/lossy_quality=0.7 19 | compress/hdr_mode=0 20 | compress/normal_map=0 21 | flags/repeat=0 22 | flags/filter=true 23 | flags/mipmaps=false 24 | flags/anisotropic=false 25 | flags/srgb=2 26 | process/fix_alpha_border=true 27 | process/premult_alpha=false 28 | process/HDR_as_SRGB=false 29 | stream=false 30 | size_limit=0 31 | detect_3d=true 32 | svg/scale=1.0 33 | -------------------------------------------------------------------------------- /tests/project.godot: -------------------------------------------------------------------------------- 1 | ; Engine configuration file. 2 | ; It's best edited using the editor UI and not directly, 3 | ; since the parameters that go here are not all obvious. 4 | ; 5 | ; Format: 6 | ; [section] ; section goes between [] 7 | ; param=value ; assign values to parameters 8 | 9 | config_version=3 10 | 11 | [application] 12 | 13 | config/name="tweaks" 14 | config/icon="res://icon.png" 15 | 16 | [editor_plugins] 17 | 18 | enabled=PoolStringArray( "DYNAMIC_WATER" ) 19 | 20 | [input] 21 | 22 | left=[ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":65,"unicode":0,"echo":false,"script":null) 23 | ] 24 | right=[ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":68,"unicode":0,"echo":false,"script":null) 25 | ] 26 | jump=[ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":32,"unicode":0,"echo":false,"script":null) 27 | ] 28 | 29 | [rendering] 30 | 31 | environment/default_environment="res://default_env.tres" 32 | -------------------------------------------------------------------------------- /tests/scenes/Player.tscn: -------------------------------------------------------------------------------- 1 | [gd_scene load_steps=4 format=2] 2 | 3 | [ext_resource path="res://scripts/Player.gd" type="Script" id=1] 4 | [ext_resource path="res://icon.png" type="Texture" id=2] 5 | 6 | [sub_resource type="RectangleShape2D" id=1] 7 | 8 | custom_solver_bias = 0.0 9 | extents = Vector2( 32, 32 ) 10 | 11 | [node name="Player" type="RigidBody2D"] 12 | 13 | input_pickable = false 14 | collision_layer = 1 15 | collision_mask = 1 16 | mode = 2 17 | mass = 1.0 18 | friction = 1.0 19 | bounce = 0.0 20 | gravity_scale = 1.0 21 | custom_integrator = false 22 | continuous_cd = 0 23 | contacts_reported = 0 24 | contact_monitor = false 25 | sleeping = false 26 | can_sleep = true 27 | linear_velocity = Vector2( 0, 0 ) 28 | linear_damp = -1.0 29 | angular_velocity = 0.0 30 | angular_damp = -1.0 31 | script = ExtResource( 1 ) 32 | acceleration = 10.0 33 | max_speed = 500.0 34 | desacceleration = 10.0 35 | jump_force = null 36 | 37 | [node name="Sprite" type="Sprite" parent="." index="0"] 38 | 39 | texture = ExtResource( 2 ) 40 | 41 | [node name="CollisionShape2D" type="CollisionShape2D" parent="." index="1"] 42 | 43 | shape = SubResource( 1 ) 44 | 45 | [node name="Camera2D" type="Camera2D" parent="." index="2"] 46 | 47 | anchor_mode = 1 48 | rotating = false 49 | current = true 50 | zoom = Vector2( 1, 1 ) 51 | limit_left = -10000000 52 | limit_top = -10000000 53 | limit_right = 10000000 54 | limit_bottom = 10000000 55 | limit_smoothed = false 56 | drag_margin_h_enabled = true 57 | drag_margin_v_enabled = true 58 | smoothing_enabled = true 59 | smoothing_speed = 5.0 60 | offset_v = 0.0 61 | offset_h = 0.0 62 | drag_margin_left = 0.0 63 | drag_margin_top = 0.0 64 | drag_margin_right = 0.0 65 | drag_margin_bottom = 0.0 66 | editor_draw_screen = true 67 | editor_draw_limits = false 68 | editor_draw_drag_margin = false 69 | _sections_unfolded = [ "Smoothing" ] 70 | 71 | 72 | -------------------------------------------------------------------------------- /tests/scenes/world.tscn: -------------------------------------------------------------------------------- 1 | [gd_scene load_steps=6 format=2] 2 | 3 | [ext_resource path="res://CollisionPolygon2D.gd" type="Script" id=1] 4 | [ext_resource path="res://addons/DYNAMIC_WATER/dynamic_water.gd" type="Script" id=2] 5 | [ext_resource path="res://addons/DYNAMIC_WATER/icon.png" type="Texture" id=3] 6 | [ext_resource path="res://addons/DYNAMIC_WATER/demo_droplets_particles_materials/water_droplets.tres" type="Material" id=4] 7 | [ext_resource path="res://scenes/Player.tscn" type="PackedScene" id=5] 8 | 9 | [node name="ROOT" type="Node" index="0"] 10 | 11 | [node name="Polygon2D" type="Polygon2D" parent="." index="0"] 12 | 13 | z_index = 1 14 | polygon = PoolVector2Array( -20, 610, 280, 610, 310, 530, 360, 470, 450, 430, 840, 430, 840, -10, 950, -10, 950, 680, -90, 680, -90, -10, -20, -10 ) 15 | uv = PoolVector2Array( ) 16 | color = Color( 1, 1, 1, 1 ) 17 | vertex_colors = PoolColorArray( ) 18 | offset = Vector2( 0, 0 ) 19 | antialiased = false 20 | texture = null 21 | texture_offset = Vector2( 0, 0 ) 22 | texture_scale = Vector2( 1, 1 ) 23 | texture_rotation_degrees = 0.0 24 | invert_enable = false 25 | invert_border = 100.0 26 | _sections_unfolded = [ "Z Index" ] 27 | 28 | [node name="StaticBody2D" type="StaticBody2D" parent="." index="1"] 29 | 30 | editor/display_folded = true 31 | input_pickable = false 32 | collision_layer = 1 33 | collision_mask = 1 34 | constant_linear_velocity = Vector2( 0, 0 ) 35 | constant_angular_velocity = 0.0 36 | friction = 1.0 37 | bounce = 0.0 38 | 39 | [node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="StaticBody2D" index="0"] 40 | 41 | build_mode = 0 42 | polygon = PoolVector2Array( ) 43 | script = ExtResource( 1 ) 44 | 45 | [node name="dynamic water" type="Node2D" parent="." index="2"] 46 | 47 | position = Vector2( -30, 610 ) 48 | script = ExtResource( 2 ) 49 | _sections_unfolded = [ "Z Index" ] 50 | __meta__ = { 51 | "_editor_icon": ExtResource( 3 ) 52 | } 53 | ALTURA = 120.0 54 | LARGURA = 400.0 55 | RESOLUCAO = 100.0 56 | COR = Color( 0.519226, 0.707031, 0.698228, 0.77349 ) 57 | droplets_material_path = ExtResource( 4 ) 58 | TENSAO = 0.1 59 | AMORTECIMENTO = 0.02 60 | PASSES = 4 61 | DISPERSAO = 0.1 62 | force_multiplyier = 0.01 63 | NUMBER_OF_VECS_TO_APPLY_FORCE = 5 64 | 65 | [node name="Player" parent="." index="3" instance=ExtResource( 5 )] 66 | 67 | position = Vector2( 562.852, 285.601 ) 68 | z_index = -1 69 | friction = 0.0 70 | bounce = 1.0 71 | gravity_scale = 30.0 72 | _sections_unfolded = [ "Z Index" ] 73 | acceleration = 50.0 74 | jump_force = 1000.0 75 | 76 | 77 | -------------------------------------------------------------------------------- /tests/scripts/Player.gd: -------------------------------------------------------------------------------- 1 | extends RigidBody2D 2 | 3 | export (float) var acceleration = 1.0 4 | export (float) var max_speed = 300.0 5 | export (float) var desacceleration = 1.0 6 | export (float) var jump_force 7 | 8 | var is_in_air = true 9 | 10 | func _ready(): 11 | if jump_force == null: 12 | jump_force = gravity_scale * 10 13 | 14 | func _physics_process(delta): 15 | _move() 16 | _jump() 17 | 18 | func _move(): 19 | var SPEED = Vector2() 20 | if Input.is_action_pressed("left") and linear_velocity.x > -max_speed: 21 | SPEED.x -= 1 * acceleration 22 | elif Input.is_action_pressed("right") and linear_velocity.x < max_speed: 23 | SPEED.x += 1 * acceleration 24 | elif (Input.is_action_pressed("left") == false and Input.is_action_pressed("right") == false): 25 | if linear_velocity.x > 0: 26 | linear_velocity.x -= desacceleration 27 | elif linear_velocity.x < 0: 28 | linear_velocity.x += desacceleration 29 | 30 | linear_velocity += SPEED 31 | 32 | func _jump(): 33 | if linear_velocity.y == 0: 34 | is_in_air = false 35 | else: 36 | is_in_air = true 37 | 38 | if is_in_air == false and Input.is_action_just_pressed("jump"): 39 | linear_velocity.y -= jump_force 40 | --------------------------------------------------------------------------------