phase 2 ai shooting
This commit is contained in:
@@ -5,11 +5,28 @@ var revolver: Node3D
|
||||
func _ready() -> void:
|
||||
revolver = GameManager.get_enemy_revolver()
|
||||
GameManager.state_changed.connect(on_state_changed)
|
||||
|
||||
func on_state_changed():
|
||||
if GameManager.current_state == GameManager.GameState.PLAYER2_GUN_LOAD:
|
||||
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():
|
||||
if revolver == null:
|
||||
revolver = GameManager.get_enemy_revolver()
|
||||
|
||||
@@ -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:
|
||||
if event.is_action_released("left_mouse_click"):
|
||||
GameManager.bullet_selected.emit(self)
|
||||
|
||||
|
||||
func shoot():
|
||||
if is_live:
|
||||
print("Ammo was live")
|
||||
else:
|
||||
print("Ammo not live")
|
||||
pass
|
||||
|
||||
@@ -5,6 +5,9 @@ signal bullet_selected(object)
|
||||
signal state_changed
|
||||
|
||||
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 bullets: Array
|
||||
|
||||
@@ -75,7 +78,7 @@ func end_turn():
|
||||
if check_unloaded_bullets():
|
||||
if is_player1_loaded and is_player2_loaded:
|
||||
print("Phase 2")
|
||||
|
||||
get_phase2_player_start()
|
||||
else:
|
||||
set_state(GameState.PLAYER2_UNLOAD)
|
||||
func get_enemy_revolver() -> Node3D:
|
||||
|
||||
@@ -3,10 +3,9 @@ var start_pos: Vector2
|
||||
|
||||
func _ready() -> void:
|
||||
start_pos = self.position
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if event.is_action_released("left_mouse_click"):
|
||||
self.position = Vector2(1000.0,1000.0)
|
||||
self.position = Vector2(1000.0,1000.0)
|
||||
GameManager.state_changed.connect(on_state_changed)
|
||||
|
||||
func on_state_changed():
|
||||
pass
|
||||
if GameManager.current_state == GameManager.GameState.PLAYER1_UNLOAD:
|
||||
self.position = start_pos
|
||||
|
||||
@@ -58,6 +58,7 @@ func on_bullet_reached():
|
||||
current_round += 1
|
||||
timer.start()
|
||||
func shoot():
|
||||
loaded_bullets[current_round].shoot()
|
||||
pass
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user