Bombs push other players, tweaked level

main
Martin Felis 2024-01-28 01:14:56 +01:00
parent e1ec72e83e
commit d096da71a4
9 changed files with 120 additions and 16 deletions

32
entities/BombEmitter.gd Normal file
View File

@ -0,0 +1,32 @@
class_name BombEmitter extends Node3D
@onready var collision_area : Area3D = $'Area3D'
const EXPLOSION_PUSH_SPEED: float = 8
var owning_player: Player = null
var processed = false
# Called when the node enters the scene tree for the first time.
func _ready():
collision_area.connect("body_entered", on_body_enter)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _physics_process(delta):
if processed:
queue_free()
processed = true
func on_body_enter(body: Node3D):
var player : Player = body as Player
if player and player != owning_player:
var vector_to_player: Vector3 = player.global_position - global_position
var length: float = vector_to_player.length()
if length > 0.01:
print ("Bomb pushes player " + str(player))
var direction : Vector3 = vector_to_player / length
player.explosion_influence = 1
player.explosion_velocity = direction * EXPLOSION_PUSH_SPEED

17
entities/BombEmitter.tscn Normal file
View File

@ -0,0 +1,17 @@
[gd_scene load_steps=3 format=3 uid="uid://dx6fxak21icvs"]
[ext_resource type="Script" path="res://entities/BombEmitter.gd" id="1_110pt"]
[sub_resource type="CylinderShape3D" id="CylinderShape3D_7yhwp"]
height = 0.5
radius = 3.0
[node name="BombEmitter" type="Node3D"]
script = ExtResource("1_110pt")
[node name="Area3D" type="Area3D" parent="."]
collision_layer = 0
collision_mask = 4
[node name="CollisionShape3D" type="CollisionShape3D" parent="Area3D"]
shape = SubResource("CylinderShape3D_7yhwp")

View File

@ -15,7 +15,7 @@ class_name Player extends CharacterBody3D
@onready var geometry: MeshInstance3D = $Geometry @onready var geometry: MeshInstance3D = $Geometry
@onready var collision: CollisionShape3D = $CollisionShape3D @onready var collision: CollisionShape3D = $CollisionShape3D
signal bomb_triggered var bomb_emitter_scene = preload("res://entities/BombEmitter.tscn")
enum PlayerState { enum PlayerState {
Alive = 0, Alive = 0,
@ -31,6 +31,8 @@ var state_last : PlayerState = PlayerState.Dead
var radius = 0.15 var radius = 0.15
var angle = 0 var angle = 0
var is_dashing = false var is_dashing = false
var explosion_velocity: Vector3 = Vector3.ZERO
var explosion_influence: float = 0
var dash_time = 0 var dash_time = 0
var bomb_time = 0 var bomb_time = 0
var coloring_sprite : Sprite2D var coloring_sprite : Sprite2D
@ -43,6 +45,7 @@ const DASH_ENERGY: float = 40
const BOMB_DURATION: float = 0.1 const BOMB_DURATION: float = 0.1
const BOMB_ENERGY: float = 60 const BOMB_ENERGY: float = 60
const ENERGY_REPLENISH_RATE: float = 0.5; const ENERGY_REPLENISH_RATE: float = 0.5;
const EXPLOSION_INFLUENCE_REDUCTION_RATE: float = 10.0;
# Get the gravity from the project settings to be synced with RigidBody nodes. # Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity = ProjectSettings.get_setting("physics/3d/default_gravity") var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
@ -125,6 +128,10 @@ func _physics_process(delta):
if dash_time <= 0: if dash_time <= 0:
is_dashing = false is_dashing = false
if explosion_influence > 0:
velocity += explosion_velocity
explosion_influence = max (0, explosion_influence - EXPLOSION_INFLUENCE_REDUCTION_RATE * delta)
move_and_slide() move_and_slide()
coloring_sprite.global_position = calc_coloring_position() coloring_sprite.global_position = calc_coloring_position()
@ -152,3 +159,7 @@ func on_drop_bomb():
coloring_bomb_sprite.visible = true; coloring_bomb_sprite.visible = true;
bomb_time = BOMB_DURATION bomb_time = BOMB_DURATION
energy = max (0, energy - BOMB_ENERGY) energy = max (0, energy - BOMB_ENERGY)
var bomb_emitter : BombEmitter = bomb_emitter_scene.instantiate()
bomb_emitter.global_position = global_position
get_parent_node_3d().add_child(bomb_emitter)

View File

@ -35,6 +35,13 @@ ui_cancel={
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":1,"pressure":0.0,"pressed":true,"script":null) , Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":1,"pressure":0.0,"pressed":true,"script":null)
] ]
} }
ui_menu={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194370,"physical_keycode":0,"key_label":0,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":6,"pressure":0.0,"pressed":true,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":6,"pressure":0.0,"pressed":true,"script":null)
]
}
move_up_p1={ move_up_p1={
"deadzone": 0.5, "deadzone": 0.5,
"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":-1.0,"script":null) "events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":-1.0,"script":null)

View File

@ -60,6 +60,7 @@ script = ExtResource("4_2tdl1")
world_path = NodePath("../Viewport/World") world_path = NodePath("../Viewport/World")
[node name="GameStartupWidgets" type="Panel" parent="GameUI"] [node name="GameStartupWidgets" type="Panel" parent="GameUI"]
visible = false
layout_mode = 1 layout_mode = 1
anchors_preset = 15 anchors_preset = 15
anchor_right = 1.0 anchor_right = 1.0
@ -110,9 +111,10 @@ theme_override_constants/shadow_offset_x = 20
theme_override_constants/shadow_offset_y = 20 theme_override_constants/shadow_offset_y = 20
theme_override_constants/outline_size = 40 theme_override_constants/outline_size = 40
theme_override_font_sizes/font_size = 160 theme_override_font_sizes/font_size = 160
text = "CLASH" text = "DASH"
[node name="Label3" type="Label" parent="GameUI/GameStartupWidgets/Logo"] [node name="Label3" type="Label" parent="GameUI/GameStartupWidgets/Logo"]
layout_mode = 0
offset_left = -142.0 offset_left = -142.0
offset_top = -107.871 offset_top = -107.871
offset_right = 182.0 offset_right = 182.0
@ -126,6 +128,7 @@ theme_override_font_sizes/font_size = 160
text = "BOOM" text = "BOOM"
[node name="Label4" type="Label" parent="GameUI/GameStartupWidgets/Logo"] [node name="Label4" type="Label" parent="GameUI/GameStartupWidgets/Logo"]
layout_mode = 0
offset_left = -219.0 offset_left = -219.0
offset_top = 12.1293 offset_top = 12.1293
offset_right = 120.0 offset_right = 120.0
@ -139,6 +142,7 @@ theme_override_font_sizes/font_size = 160
text = "COLOR" text = "COLOR"
[node name="Label5" type="Label" parent="GameUI/GameStartupWidgets/Logo"] [node name="Label5" type="Label" parent="GameUI/GameStartupWidgets/Logo"]
layout_mode = 0
offset_left = -34.0 offset_left = -34.0
offset_top = 97.0 offset_top = 97.0
offset_right = 305.0 offset_right = 305.0
@ -152,7 +156,6 @@ theme_override_font_sizes/font_size = 160
text = "CLASH" text = "CLASH"
[node name="GameFinishedWidgets" type="Panel" parent="GameUI"] [node name="GameFinishedWidgets" type="Panel" parent="GameUI"]
visible = false
layout_mode = 1 layout_mode = 1
anchors_preset = 15 anchors_preset = 15
anchor_right = 1.0 anchor_right = 1.0
@ -181,6 +184,11 @@ theme_override_font_sizes/font_size = 120
text = "Game Over!" text = "Game Over!"
horizontal_alignment = 1 horizontal_alignment = 1
[node name="WinnerLabel" type="Label" parent="GameUI/GameFinishedWidgets/VBoxContainer"]
layout_mode = 2
text = "Player 1 wins"
horizontal_alignment = 1
[node name="HBoxContainer" type="HBoxContainer" parent="GameUI/GameFinishedWidgets/VBoxContainer"] [node name="HBoxContainer" type="HBoxContainer" parent="GameUI/GameFinishedWidgets/VBoxContainer"]
layout_mode = 2 layout_mode = 2
alignment = 1 alignment = 1

View File

@ -14,6 +14,7 @@ extends Control
@onready var time_left_label : Label = $'GameRunningWidgets/TimeWidgets/TimeLeftLabel' @onready var time_left_label : Label = $'GameRunningWidgets/TimeWidgets/TimeLeftLabel'
@onready var winner_label : Label = $'GameFinishedWidgets/VBoxContainer/WinnerLabel'
@onready var player1_stats_points : Label = $'GameFinishedWidgets/VBoxContainer/HBoxContainer/Player1Stats/Points' @onready var player1_stats_points : Label = $'GameFinishedWidgets/VBoxContainer/HBoxContainer/Player1Stats/Points'
@onready var player2_stats_points : Label = $'GameFinishedWidgets/VBoxContainer/HBoxContainer/Player2Stats/Points' @onready var player2_stats_points : Label = $'GameFinishedWidgets/VBoxContainer/HBoxContainer/Player2Stats/Points'
@ -49,17 +50,24 @@ func _process(_delta):
player1_score_label.text = str(world.players[0].score) player1_score_label.text = str(world.players[0].score)
player1_energy_progressbar.value = world.players[0].energy player1_energy_progressbar.value = world.players[0].energy
player1_stats_points.text = str(world.players[0].score) player1_stats_points.text = str(world.players[0].score)
var winner_player : Player = world.players[0]
if player2_widgets.visible: if player2_widgets.visible:
player2_score_label.text = str(world.players[1].score) player2_score_label.text = str(world.players[1].score)
player2_energy_progressbar.value = world.players[1].energy player2_energy_progressbar.value = world.players[1].energy
player2_stats_points.text = str(world.players[1].score) player2_stats_points.text = str(world.players[1].score)
if world.players[1].score > world.players[0].score:
winner_player = world.players[1]
winner_label.add_theme_color_override("font_color", winner_player.color)
winner_label.text = winner_player.name + " wins!"
func _input(event): func _input(event):
if event.is_action_pressed("ui_accept"): if event.is_action_pressed("ui_accept"):
if world.game_state == World.GameState.Startup: if world.game_state == World.GameState.Startup:
world.game_state = World.GameState.Running world.game_state = World.GameState.Running
if event.is_action_pressed("ui_cancel"): if event.is_action_pressed("ui_menu"):
if world.game_state == World.GameState.Finished: if world.game_state == World.GameState.Finished:
world.game_state = World.GameState.Startup world.game_state = World.GameState.Startup

View File

@ -1,8 +1,9 @@
[gd_scene load_steps=4 format=3 uid="uid://7a2ma10hq0qa"] [gd_scene load_steps=5 format=3 uid="uid://7a2ma10hq0qa"]
[ext_resource type="PackedScene" uid="uid://b08dmcbgq6jyd" path="res://scenes/PlatformParts/rectangle_platform_big.tscn" id="1_g3vn8"] [ext_resource type="PackedScene" uid="uid://b08dmcbgq6jyd" path="res://scenes/PlatformParts/rectangle_platform_big.tscn" id="1_g3vn8"]
[ext_resource type="PackedScene" uid="uid://deod1xpjlgljl" path="res://scenes/PlatformParts/heptagon_platform_small.tscn" id="2_cf5t4"] [ext_resource type="PackedScene" uid="uid://deod1xpjlgljl" path="res://scenes/PlatformParts/heptagon_platform_small.tscn" id="2_cf5t4"]
[ext_resource type="PackedScene" uid="uid://0fxjod84sli" path="res://scenes/PlatformParts/heptagon_platform_medium.tscn" id="3_3twio"] [ext_resource type="PackedScene" uid="uid://0fxjod84sli" path="res://scenes/PlatformParts/heptagon_platform_medium.tscn" id="3_3twio"]
[ext_resource type="PackedScene" uid="uid://c62j3c1n688uw" path="res://scenes/Wall.tscn" id="4_2reix"]
[node name="Platforms" type="Node3D"] [node name="Platforms" type="Node3D"]
@ -40,3 +41,9 @@ transform = Transform3D(0.820272, 0, -0.571974, 0, 1, 0, 0.571974, 0, 0.820272,
[node name="HeptagonPlatform11" parent="." instance=ExtResource("3_3twio")] [node name="HeptagonPlatform11" parent="." instance=ExtResource("3_3twio")]
transform = Transform3D(0.975802, 0, -0.218654, 0, 1, 0, 0.218654, 0, 0.975802, -1.66098, 1.19209e-07, -2.16745) transform = Transform3D(0.975802, 0, -0.218654, 0, 1, 0, 0.218654, 0, 0.975802, -1.66098, 1.19209e-07, -2.16745)
[node name="Wall" parent="." instance=ExtResource("4_2reix")]
transform = Transform3D(-0.00234742, 0, 0.999989, 0, 1, 0, -0.499994, 0, -0.00469485, -2.99675, 0, 0.787979)
[node name="Wall2" parent="." instance=ExtResource("4_2reix")]
transform = Transform3D(0.6, 0, 0, 0, 1, 0, 0, 0, 1, -1.71071, 0, 1.61891)

View File

@ -1,4 +1,6 @@
[gd_scene load_steps=4 format=3 uid="uid://0lrpepyejfxg"] [gd_scene load_steps=5 format=3 uid="uid://0lrpepyejfxg"]
[ext_resource type="PackedScene" uid="uid://c62j3c1n688uw" path="res://scenes/Wall.tscn" id="1_pf85c"]
[sub_resource type="BoxShape3D" id="BoxShape3D_p0rqu"] [sub_resource type="BoxShape3D" id="BoxShape3D_p0rqu"]
size = Vector3(4, 1, 0.4) size = Vector3(4, 1, 0.4)
@ -23,16 +25,7 @@ shape = SubResource("BoxShape3D_p0rqu")
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5, 0) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5, 0)
mesh = SubResource("BoxMesh_237xr") mesh = SubResource("BoxMesh_237xr")
[node name="Wall2" type="StaticBody3D" parent="."] [node name="Wall2" parent="." instance=ExtResource("1_pf85c")]
transform = Transform3D(0.674444, 0, -0.738326, 0, 1, 0, 0.738326, 0, 0.674444, -1.89943, 0, 1.2094)
[node name="CollisionShape3D" type="CollisionShape3D" parent="Wall2"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5, 0)
shape = SubResource("BoxShape3D_p0rqu")
[node name="MeshInstance3D" type="MeshInstance3D" parent="Wall2"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5, 0)
mesh = SubResource("BoxMesh_237xr")
[node name="Wall3" type="StaticBody3D" parent="."] [node name="Wall3" type="StaticBody3D" parent="."]
transform = Transform3D(-0.367962, 0, -0.929841, 0, 1, 0, 0.929841, 0, -0.367962, 6.83599, 0, 3.24005) transform = Transform3D(-0.367962, 0, -0.929841, 0, 1, 0, 0.929841, 0, -0.367962, 6.83599, 0, 3.24005)

21
scenes/Wall.tscn Normal file
View File

@ -0,0 +1,21 @@
[gd_scene load_steps=4 format=3 uid="uid://c62j3c1n688uw"]
[sub_resource type="BoxShape3D" id="BoxShape3D_p0rqu"]
size = Vector3(4, 1, 0.4)
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_mr6ph"]
albedo_color = Color(0.670588, 0.262745, 0.262745, 1)
[sub_resource type="BoxMesh" id="BoxMesh_237xr"]
material = SubResource("StandardMaterial3D_mr6ph")
size = Vector3(4, 1, 0.4)
[node name="Wall" type="StaticBody3D"]
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5, 0)
shape = SubResource("BoxShape3D_p0rqu")
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5, 0)
mesh = SubResource("BoxMesh_237xr")