added dropplet water, grenade, states, animation, YAYAY
This commit is contained in:
1 parent
f36db7cd2a
commit
5418f512cd
67 files changed
+1150
-52
No files matched your search
@@ -0,0 +1,22 @@
|
||||
shader_type canvas_item;
|
||||
|
||||
// Use the captured screen texture from the BackBufferCopy
|
||||
uniform sampler2D screen_texture : hint_screen_texture, filter_linear_mipmap;
|
||||
|
||||
uniform float threshold : hint_range(0.0, 2.0) = 0.5;
|
||||
uniform float smoothness : hint_range(0.0, 1.0) = 0.02;
|
||||
uniform vec4 fluid_color : source_color = vec4(0.2, 0.5, 1.0, 1.0);
|
||||
|
||||
void fragment() {
|
||||
// 1. Grab the pixel from the 'screen' behind this ColorRect
|
||||
vec4 screen_color = texture(screen_texture, SCREEN_UV);
|
||||
|
||||
// 2. Read the brightness (density)
|
||||
float density = screen_color.r;
|
||||
|
||||
// 3. Apply the threshold/cutoff
|
||||
float alpha = smoothstep(threshold, threshold + smoothness, density);
|
||||
|
||||
// 4. Output the fluid
|
||||
COLOR = vec4(fluid_color.rgb, alpha * fluid_color.a);
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://bvte4ugmua4n3
|
||||
@@ -1,6 +1,10 @@
|
||||
class_name SceneManager extends Node2D
|
||||
@onready var game = $".."
|
||||
@onready var crates = $"../Crates"
|
||||
var grenade = preload("res://Scenes/grenade.tscn")
|
||||
var dropplet = preload("res://Scenes/dropplet.tscn")
|
||||
const DROP_PT_X = 93
|
||||
const DROP_PT_Y = 301
|
||||
|
||||
func _ready() -> void:
|
||||
print("Hello")
|
||||
@@ -25,3 +29,15 @@ func updateCrates()->void:
|
||||
_crateTotal +=1
|
||||
print("Number of crates"+str(_crateTotal))
|
||||
game.totalCrates(_crateTotal)
|
||||
|
||||
func makeGrenade(_grenadePostion, _grenadeDirection):
|
||||
print("SM wants to make a grenade")
|
||||
var myGrenade:Grenade = grenade.instantiate()
|
||||
owner.add_child(myGrenade)
|
||||
myGrenade.transform = _grenadePostion
|
||||
myGrenade.apply_central_impulse(Vector2(_grenadeDirection, -1)*200)
|
||||
func addDropplet():
|
||||
var myDropplet = dropplet.instantiate()
|
||||
$"../FluidContainer".add_child(myDropplet)
|
||||
myDropplet.global_position = Vector2(DROP_PT_X, DROP_PT_Y)
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
extends RigidBody2D
|
||||
|
||||
func _physics_process(_delta):
|
||||
# This only works if Contact Monitor is ON and Max Contacts > 0
|
||||
var bodies = get_colliding_bodies()
|
||||
|
||||
for body in bodies:
|
||||
if body is RigidBody2D:
|
||||
var dir = global_position.direction_to(body.global_position)
|
||||
var dist = global_position.distance_to(body.global_position)
|
||||
|
||||
# Surface Tension: Pull them together if they are touching
|
||||
# We use a negative force to pull towards 'self'
|
||||
var strength = 200.0
|
||||
var force = -dir * strength * (1.0 - dist / 64.0)
|
||||
|
||||
# Apply to the other body (or apply to self)
|
||||
body.apply_central_force(force)
|
||||
@@ -0,0 +1 @@
|
||||
uid://w8ctpjxlfoih
|
||||
@@ -0,0 +1,44 @@
|
||||
extends Node2D
|
||||
|
||||
@export var max_droplets: int = 100
|
||||
@export var spawn_rate: float = 0.1
|
||||
var spawn_timer: float = 0.1
|
||||
|
||||
func _physics_process(delta):
|
||||
var mm_node = $MultiMeshInstance2D
|
||||
var mm = mm_node.multimesh
|
||||
|
||||
# 1. Get all current RigidBody2D children
|
||||
var fluid_bodies = get_children().filter(func(node): return node is RigidBody2D)
|
||||
|
||||
# 2. FORCE MultiMesh to match the current body count
|
||||
# This is why they weren't 'registering'—the MultiMesh slot didn't exist yet!
|
||||
if mm.instance_count != fluid_bodies.size():
|
||||
mm.instance_count = fluid_bodies.size()
|
||||
|
||||
# 3. Visual Sync
|
||||
for i in range(fluid_bodies.size()):
|
||||
var body = fluid_bodies[i]
|
||||
# Subtract the container's position so particles don't "drift"
|
||||
var t = Transform2D(0.0, body.global_position - global_position)
|
||||
mm.set_instance_transform_2d(i, t)
|
||||
|
||||
# 4. Interaction (Surface Tension)
|
||||
for i in range(fluid_bodies.size()):
|
||||
for j in range(i + 1, fluid_bodies.size()):
|
||||
var b1 = fluid_bodies[i]
|
||||
var b2 = fluid_bodies[j]
|
||||
var dist_vec = b1.global_position - b2.global_position
|
||||
var dist = dist_vec.length()
|
||||
|
||||
if dist < 40.0:
|
||||
var force = dist_vec.normalized() * 5.0
|
||||
b1.apply_central_force(-force)
|
||||
b2.apply_central_force(force)
|
||||
|
||||
# 5. Spawning
|
||||
spawn_timer += delta
|
||||
if spawn_timer >= spawn_rate and fluid_bodies.size() < max_droplets:
|
||||
%SceneManager.addDropplet()
|
||||
mm.instance_count = fluid_bodies.size()
|
||||
spawn_timer = 0.0
|
||||
@@ -0,0 +1 @@
|
||||
uid://nhqfqpjecvt8
|
||||
@@ -0,0 +1,23 @@
|
||||
class_name Grenade extends RigidBody2D
|
||||
|
||||
var timer = Timer.new()
|
||||
|
||||
func _ready():
|
||||
add_child(timer)
|
||||
|
||||
timer.wait_time = 2
|
||||
|
||||
timer.one_shot = true
|
||||
timer.connect("timeout", explode)
|
||||
timer.start()
|
||||
|
||||
func explode():
|
||||
print("HEHEHE EXPLODE TIME")
|
||||
self.queue_free()
|
||||
|
||||
|
||||
func _on_body_entered(body):
|
||||
print("collision with grenade")
|
||||
if body.is_in_group("Destructable"):
|
||||
body.queue_free()
|
||||
explode()
|
||||
@@ -0,0 +1 @@
|
||||
uid://jrqdl3mm7rly
|
||||
+27
-1
@@ -1,13 +1,17 @@
|
||||
class_name Player extends CharacterBody2D
|
||||
@onready var right_cast = $RightCast
|
||||
@onready var left_cast = $LeftCast
|
||||
|
||||
@onready var right_spawn = $RightSpawn
|
||||
@onready var left_spawn = $LeftSpawn
|
||||
@onready var player_graphic = $PlayerGraphic
|
||||
|
||||
const SPEED = 300.0
|
||||
const JUMP_VELOCITY = -400.0
|
||||
var direction
|
||||
enum FaceDirection{LEFT, RIGHT}
|
||||
var facing:FaceDirection = FaceDirection.RIGHT
|
||||
enum State{IDLE,RUNNING}
|
||||
var currentState:State = State.IDLE
|
||||
|
||||
var pushTarget:RigidBody2D
|
||||
var pushEnabled:bool = false
|
||||
@@ -15,10 +19,15 @@ var pushEnabled:bool = false
|
||||
func _physics_process(delta: float) -> void:
|
||||
handle_input()
|
||||
handle_movement(delta)
|
||||
handle_state()
|
||||
handle_animation()
|
||||
move_and_slide()
|
||||
handle_collisions()
|
||||
|
||||
func handle_input()->void:
|
||||
if Input.is_action_just_pressed("Chuck"):
|
||||
print("Chuck the chicken (inside joke)")
|
||||
%SceneManager.makeGrenade(right_spawn.global_transform, 1)
|
||||
if Input.is_action_just_pressed("Force Push") && pushEnabled:
|
||||
if not pushTarget is RigidBody2D:
|
||||
return
|
||||
@@ -39,8 +48,10 @@ func handle_input()->void:
|
||||
direction = Input.get_axis("ui_left", "ui_right")
|
||||
if direction<0:
|
||||
facing = FaceDirection.LEFT
|
||||
player_graphic.flip_h = true
|
||||
if direction>0:
|
||||
facing = FaceDirection.RIGHT
|
||||
player_graphic.flip_h = false
|
||||
|
||||
func handle_movement(delta)->void:
|
||||
# Add the gravity.
|
||||
@@ -74,3 +85,18 @@ func handle_collisions()->void:
|
||||
if c.get_collider() is RigidBody2D:
|
||||
#deliver the impact
|
||||
c.get_collider().apply_central_impulse(-c.get_normal() * 100)
|
||||
|
||||
|
||||
|
||||
func handle_state():
|
||||
match currentState:
|
||||
State.IDLE when velocity.x != 0:
|
||||
currentState = State.RUNNING
|
||||
State.RUNNING when velocity.x == 0:
|
||||
currentState = State.IDLE
|
||||
func handle_animation():
|
||||
match currentState:
|
||||
State.IDLE:
|
||||
player_graphic.play("idle")
|
||||
State.RUNNING:
|
||||
player_graphic.play("Run")
|
||||
Reference in new issue
Block a user