phase 2 ai shooting

This commit is contained in:
Nikolai Fesenko
2025-08-29 20:37:25 +02:00
parent fbd75b3397
commit c0cac7919a
8 changed files with 62 additions and 33 deletions

View File

@@ -73,7 +73,7 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.162003, -0.0193229, 0.0082
transform = Transform3D(-4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, 0.0599972, 3.68584, -2.25251) transform = Transform3D(-4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, 0.0599972, 3.68584, -2.25251)
[node name="enemy_revolver" parent="." instance=ExtResource("4_jjvhh")] [node name="enemy_revolver" parent="." instance=ExtResource("4_jjvhh")]
transform = Transform3D(0.1, 0, 0, 0, -0.1, -8.74228e-09, 0, 8.74228e-09, -0.1, 0.354285, 4.2476, -0.496572) transform = Transform3D(0.1, 0, 0, 0, -0.1, -1.50996e-08, 0, 1.50996e-08, -0.1, 0.354285, 4.2476, -0.496572)
[node name="MainGame" parent="." instance=ExtResource("6_21xkr")] [node name="MainGame" parent="." instance=ExtResource("6_21xkr")]

View File

@@ -9,6 +9,7 @@ anchor_right = 1.0
anchor_bottom = 1.0 anchor_bottom = 1.0
grow_horizontal = 2 grow_horizontal = 2
grow_vertical = 2 grow_vertical = 2
mouse_filter = 1
[node name="HBoxContainer" type="HBoxContainer" parent="."] [node name="HBoxContainer" type="HBoxContainer" parent="."]
layout_mode = 1 layout_mode = 1

View File

@@ -5,11 +5,28 @@ var revolver: Node3D
func _ready() -> void: func _ready() -> void:
revolver = GameManager.get_enemy_revolver() revolver = GameManager.get_enemy_revolver()
GameManager.state_changed.connect(on_state_changed) GameManager.state_changed.connect(on_state_changed)
func on_state_changed(): func on_state_changed():
if GameManager.current_state == GameManager.GameState.PLAYER2_GUN_LOAD: if GameManager.current_state == GameManager.GameState.PLAYER2_GUN_LOAD:
make_turn() make_turn()
elif GameManager.current_state == GameManager.GameState.PLAYER2_UNLOAD:
unload()
func unload():
print("Unload")
var choices = GameManager.PlayerChoice.values()
var choice = choices.pick_random()
GameManager.player_phase2_choice = choice
print(GameManager.player_phase2_choice)
if GameManager.PlayerChoice.SHOOT_SELF == choice:
print("I will shoot myself")
revolver.rotation_degrees = Vector3(180,180,0)
else:
print("I will shoot opponent")
revolver.rotation_degrees = Vector3(180,0,0)
revolver.current_round = 0
for i in range(0, 6, 1):
revolver.shoot()
revolver.current_round = i
func make_turn(): func make_turn():
if revolver == null: if revolver == null:
revolver = GameManager.get_enemy_revolver() revolver = GameManager.get_enemy_revolver()

View File

@@ -34,3 +34,11 @@ func on_target_reached():
func _on_static_body_3d_input_event(camera: Node, event: InputEvent, event_position: Vector3, normal: Vector3, shape_idx: int) -> void: func _on_static_body_3d_input_event(camera: Node, event: InputEvent, event_position: Vector3, normal: Vector3, shape_idx: int) -> void:
if event.is_action_released("left_mouse_click"): if event.is_action_released("left_mouse_click"):
GameManager.bullet_selected.emit(self) GameManager.bullet_selected.emit(self)
func shoot():
if is_live:
print("Ammo was live")
else:
print("Ammo not live")
pass

View File

@@ -5,6 +5,9 @@ signal bullet_selected(object)
signal state_changed signal state_changed
enum GameState { PLAYER1_GUN_LOAD, PLAYER2_GUN_LOAD, GUN_ANIMATION, PLAYER1_UNLOAD,PLAYER2_UNLOAD} enum GameState { PLAYER1_GUN_LOAD, PLAYER2_GUN_LOAD, GUN_ANIMATION, PLAYER1_UNLOAD,PLAYER2_UNLOAD}
enum PlayerChoice {SHOOT_SELF, SHOOT_OPPONENT}
var player_phase2_choice
var current_state = GameState.PLAYER1_GUN_LOAD var current_state = GameState.PLAYER1_GUN_LOAD
var bullets: Array var bullets: Array
@@ -75,7 +78,7 @@ func end_turn():
if check_unloaded_bullets(): if check_unloaded_bullets():
if is_player1_loaded and is_player2_loaded: if is_player1_loaded and is_player2_loaded:
print("Phase 2") print("Phase 2")
get_phase2_player_start()
else: else:
set_state(GameState.PLAYER2_UNLOAD) set_state(GameState.PLAYER2_UNLOAD)
func get_enemy_revolver() -> Node3D: func get_enemy_revolver() -> Node3D:

View File

@@ -3,10 +3,9 @@ var start_pos: Vector2
func _ready() -> void: func _ready() -> void:
start_pos = self.position start_pos = self.position
self.position = Vector2(1000.0,1000.0)
func _input(event: InputEvent) -> void: GameManager.state_changed.connect(on_state_changed)
if event.is_action_released("left_mouse_click"):
self.position = Vector2(1000.0,1000.0)
func on_state_changed(): func on_state_changed():
pass if GameManager.current_state == GameManager.GameState.PLAYER1_UNLOAD:
self.position = start_pos

View File

@@ -58,6 +58,7 @@ func on_bullet_reached():
current_round += 1 current_round += 1
timer.start() timer.start()
func shoot(): func shoot():
loaded_bullets[current_round].shoot()
pass pass

View File

@@ -5,7 +5,7 @@ content_margin_left = 6.0
content_margin_top = 5.0 content_margin_top = 5.0
content_margin_right = 6.0 content_margin_right = 6.0
content_margin_bottom = 5.0 content_margin_bottom = 5.0
bg_color = Color(0, 0, 0, nan) bg_color = Color(0, 0, 0, 0.145098)
border_width_left = 1 border_width_left = 1
border_width_top = 1 border_width_top = 1
border_width_right = 1 border_width_right = 1
@@ -25,7 +25,7 @@ content_margin_left = 4.0
content_margin_top = 4.0 content_margin_top = 4.0
content_margin_right = 4.0 content_margin_right = 4.0
content_margin_bottom = 4.0 content_margin_bottom = 4.0
bg_color = Color(0, 0, 0, 0) bg_color = Color(0, 0, 0, 0.290196)
border_color = Color(0.25098, 0.266667, 0.298039, 1) border_color = Color(0.25098, 0.266667, 0.298039, 1)
corner_radius_top_left = 3 corner_radius_top_left = 3
corner_radius_top_right = 3 corner_radius_top_right = 3
@@ -35,17 +35,17 @@ corner_detail = 3
anti_aliasing = false anti_aliasing = false
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_qm4uc"] [sub_resource type="StyleBoxFlat" id="StyleBoxFlat_qm4uc"]
bg_color = Color(0, 0, 0, nan) bg_color = Color(0, 0, 0, 0.145098)
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_kmfvt"] [sub_resource type="StyleBoxFlat" id="StyleBoxFlat_kmfvt"]
bg_color = Color(0, 0, 0, 0) bg_color = Color(0, 0, 0, 0.580392)
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_1tn6y"] [sub_resource type="StyleBoxFlat" id="StyleBoxFlat_1tn6y"]
content_margin_left = 4.0 content_margin_left = 4.0
content_margin_top = 6.0 content_margin_top = 6.0
content_margin_right = 4.0 content_margin_right = 4.0
content_margin_bottom = 4.0 content_margin_bottom = 4.0
bg_color = Color(0, 0, 0, 0) bg_color = Color(0, 0, 0, 0.580392)
corner_radius_top_left = 3 corner_radius_top_left = 3
corner_radius_top_right = 3 corner_radius_top_right = 3
corner_radius_bottom_right = 3 corner_radius_bottom_right = 3
@@ -57,7 +57,7 @@ content_margin_left = 4.0
content_margin_top = 0.0 content_margin_top = 0.0
content_margin_right = 4.0 content_margin_right = 4.0
content_margin_bottom = 4.0 content_margin_bottom = 4.0
bg_color = Color(0, 0, 0, 0) bg_color = Color(0, 0, 0, 0.580392)
corner_radius_bottom_right = 3 corner_radius_bottom_right = 3
corner_radius_bottom_left = 3 corner_radius_bottom_left = 3
anti_aliasing = false anti_aliasing = false
@@ -66,7 +66,7 @@ anti_aliasing = false
bg_color = Color(0.617575, 0.626378, 0.219465, 1) bg_color = Color(0.617575, 0.626378, 0.219465, 1)
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_wrepn"] [sub_resource type="StyleBoxFlat" id="StyleBoxFlat_wrepn"]
bg_color = Color(0, 0, 0, 0) bg_color = Color(0, 0, 0, 0.580392)
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_4qoyy"] [sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_4qoyy"]
@@ -84,7 +84,7 @@ content_margin_left = 2.0
content_margin_top = 0.0 content_margin_top = 0.0
content_margin_right = 2.0 content_margin_right = 2.0
content_margin_bottom = 0.0 content_margin_bottom = 0.0
bg_color = Color(0, 0, 0, 0) bg_color = Color(0, 0, 0, 0.580392)
corner_radius_top_left = 3 corner_radius_top_left = 3
corner_radius_top_right = 3 corner_radius_top_right = 3
corner_radius_bottom_right = 3 corner_radius_bottom_right = 3
@@ -109,7 +109,7 @@ content_margin_left = 6.0
content_margin_top = 4.0 content_margin_top = 4.0
content_margin_right = 6.0 content_margin_right = 6.0
content_margin_bottom = 5.0 content_margin_bottom = 5.0
bg_color = Color(0, 0, 0, nan) bg_color = Color(0, 0, 0, 0.145098)
border_width_bottom = 2 border_width_bottom = 2
border_color = Color(0.113725, 0.133333, 0.160784, 1) border_color = Color(0.113725, 0.133333, 0.160784, 1)
corner_radius_top_left = 3 corner_radius_top_left = 3
@@ -122,7 +122,7 @@ content_margin_left = 6.0
content_margin_top = 4.0 content_margin_top = 4.0
content_margin_right = 6.0 content_margin_right = 6.0
content_margin_bottom = 5.0 content_margin_bottom = 5.0
bg_color = Color(0, 0, 0, nan) bg_color = Color(0, 0, 0, 0.145098)
border_width_bottom = 2 border_width_bottom = 2
border_color = Color(0.113725, 0.133333, 0.160784, 1) border_color = Color(0.113725, 0.133333, 0.160784, 1)
corner_radius_top_left = 3 corner_radius_top_left = 3
@@ -135,7 +135,7 @@ content_margin_left = 6.0
content_margin_top = 5.0 content_margin_top = 5.0
content_margin_right = 6.0 content_margin_right = 6.0
content_margin_bottom = 5.0 content_margin_bottom = 5.0
bg_color = Color(0, 0, 0, nan) bg_color = Color(0, 0, 0, 0.145098)
border_color = Color(0.501961, 0.501961, 0.501961, 1) border_color = Color(0.501961, 0.501961, 0.501961, 1)
corner_radius_top_left = 3 corner_radius_top_left = 3
corner_radius_top_right = 3 corner_radius_top_right = 3
@@ -149,7 +149,7 @@ content_margin_left = 6.0
content_margin_top = 5.0 content_margin_top = 5.0
content_margin_right = 6.0 content_margin_right = 6.0
content_margin_bottom = 5.0 content_margin_bottom = 5.0
bg_color = Color(0, 0, 0, nan) bg_color = Color(0, 0, 0, 0.145098)
border_color = Color(0.501961, 0.501961, 0.501961, 1) border_color = Color(0.501961, 0.501961, 0.501961, 1)
corner_radius_top_left = 3 corner_radius_top_left = 3
corner_radius_top_right = 3 corner_radius_top_right = 3
@@ -163,7 +163,7 @@ content_margin_left = 4.0
content_margin_top = 4.0 content_margin_top = 4.0
content_margin_right = 4.0 content_margin_right = 4.0
content_margin_bottom = 4.0 content_margin_bottom = 4.0
bg_color = Color(0, 0, 0, nan) bg_color = Color(0, 0, 0, 0.145098)
border_width_left = 1 border_width_left = 1
border_width_top = 1 border_width_top = 1
border_width_right = 1 border_width_right = 1
@@ -181,7 +181,7 @@ content_margin_left = 11.0
content_margin_top = 5.0 content_margin_top = 5.0
content_margin_right = 11.0 content_margin_right = 11.0
content_margin_bottom = 5.0 content_margin_bottom = 5.0
bg_color = Color(0, 0, 0, 0) bg_color = Color(0, 0, 0, 0.290196)
corner_radius_top_left = 3 corner_radius_top_left = 3
corner_radius_top_right = 3 corner_radius_top_right = 3
corner_detail = 3 corner_detail = 3
@@ -192,7 +192,7 @@ content_margin_left = 11.0
content_margin_top = 5.0 content_margin_top = 5.0
content_margin_right = 11.0 content_margin_right = 11.0
content_margin_bottom = 5.0 content_margin_bottom = 5.0
bg_color = Color(0, 0, 0, 0) bg_color = Color(0, 0, 0, 0.580392)
border_width_top = 2 border_width_top = 2
border_color = Color(0.44, 0.73, 0.98, 1) border_color = Color(0.44, 0.73, 0.98, 1)
corner_detail = 3 corner_detail = 3
@@ -203,7 +203,7 @@ content_margin_left = 11.0
content_margin_top = 5.0 content_margin_top = 5.0
content_margin_right = 11.0 content_margin_right = 11.0
content_margin_bottom = 5.0 content_margin_bottom = 5.0
bg_color = Color(0, 0, 0, 0) bg_color = Color(0, 0, 0, 0.290196)
corner_radius_top_left = 3 corner_radius_top_left = 3
corner_radius_top_right = 3 corner_radius_top_right = 3
corner_detail = 3 corner_detail = 3
@@ -214,7 +214,7 @@ content_margin_left = 4.0
content_margin_top = 6.0 content_margin_top = 6.0
content_margin_right = 4.0 content_margin_right = 4.0
content_margin_bottom = 4.0 content_margin_bottom = 4.0
bg_color = Color(0, 0, 0, 0) bg_color = Color(0, 0, 0, 0.580392)
border_color = Color(0.900808, 0.647855, 0.245012, 1) border_color = Color(0.900808, 0.647855, 0.245012, 1)
corner_radius_bottom_right = 3 corner_radius_bottom_right = 3
corner_radius_bottom_left = 3 corner_radius_bottom_left = 3
@@ -226,7 +226,7 @@ content_margin_left = 11.0
content_margin_top = 5.0 content_margin_top = 5.0
content_margin_right = 11.0 content_margin_right = 11.0
content_margin_bottom = 5.0 content_margin_bottom = 5.0
bg_color = Color(0, 0, 0, 0) bg_color = Color(0, 0, 0, 0.290196)
corner_radius_top_left = 3 corner_radius_top_left = 3
corner_radius_top_right = 3 corner_radius_top_right = 3
corner_detail = 3 corner_detail = 3
@@ -237,7 +237,7 @@ content_margin_left = 11.0
content_margin_top = 5.0 content_margin_top = 5.0
content_margin_right = 11.0 content_margin_right = 11.0
content_margin_bottom = 5.0 content_margin_bottom = 5.0
bg_color = Color(0, 0, 0, 0) bg_color = Color(0, 0, 0, 0.580392)
border_width_top = 2 border_width_top = 2
border_color = Color(0.44, 0.73, 0.98, 1) border_color = Color(0.44, 0.73, 0.98, 1)
corner_detail = 3 corner_detail = 3
@@ -248,7 +248,7 @@ content_margin_left = 11.0
content_margin_top = 5.0 content_margin_top = 5.0
content_margin_right = 11.0 content_margin_right = 11.0
content_margin_bottom = 5.0 content_margin_bottom = 5.0
bg_color = Color(0, 0, 0, 0) bg_color = Color(0, 0, 0, 0.290196)
corner_radius_top_left = 3 corner_radius_top_left = 3
corner_radius_top_right = 3 corner_radius_top_right = 3
corner_detail = 3 corner_detail = 3
@@ -270,7 +270,7 @@ content_margin_left = 4.0
content_margin_top = 6.0 content_margin_top = 6.0
content_margin_right = 4.0 content_margin_right = 4.0
content_margin_bottom = 4.0 content_margin_bottom = 4.0
bg_color = Color(0, 0, 0, 0) bg_color = Color(0, 0, 0, 0.290196)
corner_radius_bottom_right = 3 corner_radius_bottom_right = 3
corner_radius_bottom_left = 3 corner_radius_bottom_left = 3
corner_detail = 3 corner_detail = 3
@@ -281,7 +281,7 @@ content_margin_left = 11.0
content_margin_top = 5.0 content_margin_top = 5.0
content_margin_right = 11.0 content_margin_right = 11.0
content_margin_bottom = 5.0 content_margin_bottom = 5.0
bg_color = Color(0, 0, 0, 0) bg_color = Color(0, 0, 0, 0.580392)
border_width_top = 2 border_width_top = 2
border_color = Color(0.44, 0.73, 0.98, 1) border_color = Color(0.44, 0.73, 0.98, 1)
anti_aliasing = false anti_aliasing = false
@@ -294,7 +294,7 @@ content_margin_left = 6.0
content_margin_top = 4.0 content_margin_top = 4.0
content_margin_right = 6.0 content_margin_right = 6.0
content_margin_bottom = 5.0 content_margin_bottom = 5.0
bg_color = Color(0, 0, 0, nan) bg_color = Color(0, 0, 0, 0.145098)
border_width_bottom = 2 border_width_bottom = 2
border_color = Color(0.113725, 0.133333, 0.160784, 1) border_color = Color(0.113725, 0.133333, 0.160784, 1)
corner_radius_top_left = 3 corner_radius_top_left = 3
@@ -307,7 +307,7 @@ content_margin_left = 6.0
content_margin_top = 4.0 content_margin_top = 4.0
content_margin_right = 6.0 content_margin_right = 6.0
content_margin_bottom = 5.0 content_margin_bottom = 5.0
bg_color = Color(0, 0, 0, nan) bg_color = Color(0, 0, 0, 0.145098)
border_width_bottom = 2 border_width_bottom = 2
border_color = Color(0.113725, 0.133333, 0.160784, 1) border_color = Color(0.113725, 0.133333, 0.160784, 1)
corner_radius_top_left = 3 corner_radius_top_left = 3