Cleanup
parent
52e3db3041
commit
2295db0e42
|
@ -9,6 +9,9 @@ extends CharacterBody3D
|
|||
@export var dash_action := "dash"
|
||||
@export var bomb_action := "bomp"
|
||||
|
||||
@export var coloring_sprite_path : NodePath
|
||||
@export var coloring_bomb_sprite_path : NodePath
|
||||
|
||||
@onready var geometry = $Geometry
|
||||
|
||||
signal bomb_triggered
|
||||
|
@ -16,15 +19,27 @@ signal bomb_triggered
|
|||
var angle = 0
|
||||
var is_dashing = false
|
||||
var dash_time = 0
|
||||
var bomb_time = 0
|
||||
var coloring_sprite : Sprite2D
|
||||
var coloring_bomb_sprite : Sprite2D
|
||||
|
||||
const SPEED = 5.0
|
||||
const JUMP_VELOCITY = 4.5
|
||||
const DASH_SPEED: float = 20
|
||||
const DASH_DURATION: float = 0.2
|
||||
const BOMB_DURATION: float = 0.1
|
||||
|
||||
# Get the gravity from the project settings to be synced with RigidBody nodes.
|
||||
var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
|
||||
|
||||
func _ready():
|
||||
coloring_sprite = get_node(coloring_sprite_path)
|
||||
coloring_bomb_sprite = get_node(coloring_bomb_sprite_path)
|
||||
coloring_sprite.modulate = color
|
||||
coloring_sprite.visible = true
|
||||
coloring_bomb_sprite.modulate = color
|
||||
coloring_bomb_sprite.visible = false
|
||||
|
||||
func _physics_process(delta):
|
||||
# Add the gravity.
|
||||
if not is_on_floor():
|
||||
|
@ -34,8 +49,15 @@ func _physics_process(delta):
|
|||
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
|
||||
velocity.y = JUMP_VELOCITY
|
||||
|
||||
if Input.is_action_just_pressed(bomb_action):
|
||||
emit_signal("bomb_triggered", self)
|
||||
if bomb_time > 0:
|
||||
bomb_time -= delta
|
||||
if bomb_time <= 0:
|
||||
coloring_bomb_sprite.visible = false
|
||||
bomb_time = 0
|
||||
else:
|
||||
if Input.is_action_just_pressed(bomb_action):
|
||||
coloring_bomb_sprite.visible = true;
|
||||
bomb_time = BOMB_DURATION
|
||||
|
||||
# Get the input direction and handle the movement/deceleration.
|
||||
# As good practice, you should replace UI actions with custom gameplay actions.
|
||||
|
@ -51,7 +73,7 @@ func _physics_process(delta):
|
|||
velocity.z = move_toward(velocity.z, 0, SPEED)
|
||||
geometry.global_basis = Basis.from_euler(Vector3(0, -angle, 0))
|
||||
|
||||
if Input.is_action_just_pressed("dash_p1"):
|
||||
if Input.is_action_just_pressed(dash_action):
|
||||
is_dashing = true;
|
||||
dash_time = DASH_DURATION
|
||||
|
||||
|
@ -66,3 +88,10 @@ func _physics_process(delta):
|
|||
is_dashing = false
|
||||
|
||||
move_and_slide()
|
||||
|
||||
coloring_sprite.global_position = calc_coloring_position()
|
||||
coloring_bomb_sprite.global_position = coloring_sprite.global_position
|
||||
|
||||
func calc_coloring_position():
|
||||
var result = Vector2 (global_position.x * 10 + 500, global_position.z * 10 + 500)
|
||||
return result;
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
[gd_scene load_steps=4 format=3 uid="uid://bfyjtfdko3l7o"]
|
||||
|
||||
[ext_resource type="Script" path="res://entities/Player.gd" id="1_w5gy0"]
|
||||
|
||||
[sub_resource type="BoxMesh" id="BoxMesh_yle83"]
|
||||
size = Vector3(0.24, 0.75, 0.24)
|
||||
|
||||
[sub_resource type="CylinderShape3D" id="CylinderShape3D_rwgp3"]
|
||||
height = 0.75
|
||||
radius = 0.15
|
||||
|
||||
[node name="Player1" type="CharacterBody3D"]
|
||||
collision_layer = 5
|
||||
collision_mask = 7
|
||||
script = ExtResource("1_w5gy0")
|
||||
move_right_action = "move_right_p1"
|
||||
move_left_action = "move_left_p1"
|
||||
move_down_action = "move_down_p1"
|
||||
move_up_action = "move_up_p1"
|
||||
dash_action = "dash_p1"
|
||||
bomb_action = "bomb_p1"
|
||||
|
||||
[node name="Geometry" type="MeshInstance3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.472544, 0)
|
||||
mesh = SubResource("BoxMesh_yle83")
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.496337, 0)
|
||||
shape = SubResource("CylinderShape3D_rwgp3")
|
|
@ -57,6 +57,36 @@ bomb_p1={
|
|||
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":80,"key_label":0,"unicode":113,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
move_up_p2={
|
||||
"deadzone": 0.5,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194320,"key_label":0,"unicode":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
move_down_p2={
|
||||
"deadzone": 0.5,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194322,"key_label":0,"unicode":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
move_left_p2={
|
||||
"deadzone": 0.5,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194319,"key_label":0,"unicode":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
move_right_p2={
|
||||
"deadzone": 0.5,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194321,"key_label":0,"unicode":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
dash_p2={
|
||||
"deadzone": 0.5,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194440,"key_label":0,"unicode":50,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
bomb_p2={
|
||||
"deadzone": 0.5,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194441,"key_label":0,"unicode":51,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
|
||||
[layer_names]
|
||||
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
extends Node3D
|
||||
|
||||
@onready var player1: CharacterBody3D = $Player1
|
||||
@onready var camera: Camera3D = $Camera3D
|
||||
@onready var level: Node3D = $Level
|
||||
@onready var world_coloring_viewport: SubViewport = $WorldColoringViewport
|
||||
@onready var world_coloring_player1_texture_rect: TextureRect = $WorldColoringViewport/Player1TextureRect
|
||||
@onready var world_coloring_player1_sprite: Sprite2D = $WorldColoringViewport/Player1Sprite
|
||||
@onready var world_coloring_player1_bomb_sprite: Sprite2D = $WorldColoringViewport/Player1BombSprite
|
||||
|
||||
@onready var player1: CharacterBody3D = $Player1
|
||||
@onready var player2: CharacterBody3D = $Player2
|
||||
|
||||
var camera_offset: Vector3;
|
||||
var world_coloring_material: ShaderMaterial
|
||||
|
@ -18,11 +17,6 @@ func _ready():
|
|||
world_coloring_material = load("res://materials/WorldColoringMaterialPass.tres")
|
||||
world_coloring_material.set_shader_parameter("world_color_texture", world_coloring_viewport.get_texture())
|
||||
|
||||
world_coloring_player1_sprite.modulate = player1.color
|
||||
world_coloring_player1_bomb_sprite.modulate = player1.color
|
||||
|
||||
player1.connect("bomb_triggered", player_bomb_triggered)
|
||||
|
||||
apply_world_coloring_recursive(level)
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
|
@ -31,13 +25,8 @@ func _process(_delta):
|
|||
pass
|
||||
|
||||
func _physics_process(_delta):
|
||||
world_coloring_player1_sprite.global_position = player_position_to_world_coloring_position(player1.global_position)
|
||||
world_coloring_material.set_shader_parameter("world_color_texture", world_coloring_viewport.get_texture())
|
||||
|
||||
func player_position_to_world_coloring_position(player_position: Vector3):
|
||||
var result = Vector2 (player_position.x * 10 + 500, player_position.z * 10 + 500)
|
||||
return result;
|
||||
|
||||
func apply_world_coloring_recursive (node):
|
||||
for child in node.get_children():
|
||||
var mesh_instance := child as MeshInstance3D
|
||||
|
@ -52,7 +41,3 @@ func assign_world_coloring_pass(mesh_instance: MeshInstance3D) -> void:
|
|||
return
|
||||
|
||||
material.next_pass = world_coloring_material
|
||||
|
||||
func player_bomb_triggered(player):
|
||||
world_coloring_player1_bomb_sprite.global_position = player_position_to_world_coloring_position(player.global_position)
|
||||
world_coloring_player1_bomb_sprite.visible = true
|
||||
|
|
|
@ -1,19 +1,11 @@
|
|||
[gd_scene load_steps=16 format=3 uid="uid://b1nm5h3yccr16"]
|
||||
[gd_scene load_steps=13 format=3 uid="uid://b1nm5h3yccr16"]
|
||||
|
||||
[ext_resource type="Script" path="res://entities/Player.gd" id="1_ca7jo"]
|
||||
[ext_resource type="Script" path="res://scenes/World.gd" id="1_gtcjp"]
|
||||
[ext_resource type="Texture2D" uid="uid://cek45oeqv3jvj" path="res://assets/textures/test_world_color_texture_viewport.png" id="3_bvxb7"]
|
||||
[ext_resource type="PackedScene" uid="uid://bfyjtfdko3l7o" path="res://entities/Player.tscn" id="2_a343a"]
|
||||
[ext_resource type="Texture2D" uid="uid://bnsrnuuq28p4d" path="res://assets/textures/player_draw_mask.png" id="4_dipd5"]
|
||||
[ext_resource type="Material" uid="uid://bg3dawo5kkosg" path="res://materials/GrassNoiseMaterial.tres" id="4_pseda"]
|
||||
[ext_resource type="Texture2D" uid="uid://vcebfpqo2ko7" path="res://assets/textures/player_bomb_mask.png" id="5_17c1g"]
|
||||
|
||||
[sub_resource type="BoxMesh" id="BoxMesh_yle83"]
|
||||
size = Vector3(0.24, 0.75, 0.24)
|
||||
|
||||
[sub_resource type="CylinderShape3D" id="CylinderShape3D_rwgp3"]
|
||||
height = 0.75
|
||||
radius = 0.15
|
||||
|
||||
[sub_resource type="Environment" id="Environment_f3jci"]
|
||||
ambient_light_source = 3
|
||||
ambient_light_color = Color(0.521569, 0.521569, 0.521569, 1)
|
||||
|
@ -38,23 +30,21 @@ size = Vector3(100, 2, 100)
|
|||
[node name="World" type="Node3D"]
|
||||
script = ExtResource("1_gtcjp")
|
||||
|
||||
[node name="Player1" type="CharacterBody3D" parent="."]
|
||||
collision_mask = 3
|
||||
script = ExtResource("1_ca7jo")
|
||||
move_right_action = "move_right_p1"
|
||||
move_left_action = "move_left_p1"
|
||||
move_down_action = "move_down_p1"
|
||||
move_up_action = "move_up_p1"
|
||||
dash_action = "dash_p1"
|
||||
bomb_action = "bomb_p1"
|
||||
[node name="Player1" parent="." instance=ExtResource("2_a343a")]
|
||||
coloring_sprite_path = NodePath("../WorldColoringViewport/Player1Sprite")
|
||||
coloring_bomb_sprite_path = NodePath("../WorldColoringViewport/Player1BombSprite")
|
||||
|
||||
[node name="Geometry" type="MeshInstance3D" parent="Player1"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.472544, 0)
|
||||
mesh = SubResource("BoxMesh_yle83")
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="Player1"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.496337, 0)
|
||||
shape = SubResource("CylinderShape3D_rwgp3")
|
||||
[node name="Player2" parent="." instance=ExtResource("2_a343a")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 1.63193, 0, 0)
|
||||
color = Color(0.878431, 0, 0.980392, 1)
|
||||
move_right_action = "move_right_p2"
|
||||
move_left_action = "move_left_p2"
|
||||
move_down_action = "move_down_p2"
|
||||
move_up_action = "move_up_p2"
|
||||
dash_action = "dash_p2"
|
||||
bomb_action = "bomb_p2"
|
||||
coloring_sprite_path = NodePath("../WorldColoringViewport/Player2Sprite")
|
||||
coloring_bomb_sprite_path = NodePath("../WorldColoringViewport/Player2BombSprite")
|
||||
|
||||
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
|
||||
environment = SubResource("Environment_f3jci")
|
||||
|
@ -79,36 +69,18 @@ size = Vector2i(1000, 1000)
|
|||
render_target_clear_mode = 1
|
||||
render_target_update_mode = 4
|
||||
|
||||
[node name="TextureRect" type="TextureRect" parent="WorldColoringViewport"]
|
||||
visible = false
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
texture = ExtResource("3_bvxb7")
|
||||
|
||||
[node name="Player1TextureRect" type="TextureRect" parent="WorldColoringViewport"]
|
||||
visible = false
|
||||
anchors_preset = 8
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
offset_left = -20.0
|
||||
offset_top = -20.0
|
||||
offset_right = 20.0
|
||||
offset_bottom = 20.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
size_flags_horizontal = 4
|
||||
size_flags_vertical = 4
|
||||
texture = ExtResource("4_dipd5")
|
||||
|
||||
[node name="Player1Sprite" type="Sprite2D" parent="WorldColoringViewport"]
|
||||
texture = ExtResource("4_dipd5")
|
||||
|
||||
[node name="Player1BombSprite" type="Sprite2D" parent="WorldColoringViewport"]
|
||||
visible = false
|
||||
texture = ExtResource("5_17c1g")
|
||||
|
||||
[node name="Player2Sprite" type="Sprite2D" parent="WorldColoringViewport"]
|
||||
texture = ExtResource("4_dipd5")
|
||||
|
||||
[node name="Player2BombSprite" type="Sprite2D" parent="WorldColoringViewport"]
|
||||
visible = false
|
||||
texture = ExtResource("5_17c1g")
|
||||
|
||||
[node name="Level" type="Node3D" parent="."]
|
||||
|
|
Loading…
Reference in New Issue