diff --git a/base/scenes/player.tscn b/base/scenes/player.tscn index 7be3938..60ffbd8 100644 --- a/base/scenes/player.tscn +++ b/base/scenes/player.tscn @@ -25,7 +25,7 @@ tracks/0/keys = { [sub_resource type="Animation" id="Animation_8sdfx"] resource_name = "shoot" -length = 0.20001 +length = 0.30001 step = 0.1 tracks/0/type = "value" tracks/0/imported = false @@ -39,6 +39,20 @@ tracks/0/keys = { "update": 1, "values": [ExtResource("2_7ptt8"), ExtResource("3_1w3ab"), ExtResource("4_gt0rj")] } +tracks/1/type = "method" +tracks/1/imported = false +tracks/1/enabled = true +tracks/1/path = NodePath("../..") +tracks/1/interp = 1 +tracks/1/loop_wrap = true +tracks/1/keys = { +"times": PackedFloat32Array(0.3), +"transitions": PackedFloat32Array(1), +"values": [{ +"args": [], +"method": &"shoot_animation_ended" +}] +} [sub_resource type="Animation" id="Animation_ma1q3"] resource_name = "static" diff --git a/base/scenes/rooms/test.tscn b/base/scenes/rooms/test.tscn index 0659c14..6a29623 100644 --- a/base/scenes/rooms/test.tscn +++ b/base/scenes/rooms/test.tscn @@ -37,3 +37,7 @@ size = Vector3(0.2, 3.98877, 3.95068) [node name="CSGBox3D3" type="CSGBox3D" parent="CSGCombiner3D"] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 1.82441, 0.835289, 0.522302) size = Vector3(0.2, 4, 4) + +[node name="SpotLight3D" type="SpotLight3D" parent="."] +transform = Transform3D(1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 0, 2.6, 0) +spot_angle = 90.0 diff --git a/base/scripts/player/command_queue.gd b/base/scripts/player/command_queue.gd index d7d4aa0..47b402c 100644 --- a/base/scripts/player/command_queue.gd +++ b/base/scripts/player/command_queue.gd @@ -15,8 +15,8 @@ enum Command { SMOKE } -signal command_pushed(Side, Command) -signal command_popped(Side, Command) +signal command_pushed(sides: Array[CommandQueue.Side], commands: Array[CommandQueue.Command]) +signal command_popped(commands: Array[CommandQueue.Command]) ## Human-readable hand numbers. You could even make extra hands with it, if you wish enum Side { LEFT, RIGHT } @@ -32,21 +32,26 @@ func _init() -> void: var arr: Array[Command] = [] command_queue[side] = arr -func push(commands: Array[Command], sides: Array[Side]): - for i in range(len(commands)): - command_queue[sides[i]].push_back(commands[i]) - command_pushed.emit(sides[i], commands[i]) +## Add command to queue and signal about it +func push(commands: Array[CommandQueue.Command], sides: Array[CommandQueue.Side]): + assert(sides.size() == Side.size()) + for i in range(commands.size()): + command_queue[sides[i]].push_back(commands[i]) + command_pushed.emit(sides, commands) + +## Remove first command from queue and signal about it func pop(): # Checking if stack is actually empty (arrays must have same size) if command_queue[Side.LEFT].size() == 0: return + var commands = [] for side in Side.values(): - var command = command_queue[side].pop_front() - command_popped.emit(side, command) + commands.push_back(command_queue[side].pop_front()) + command_popped.emit(commands) -func current_command(side: Side): - var command = command_queue[side].front() - if command == null: +func current_command(side: CommandQueue.Side): + if command_queue[side].is_empty(): return DEFAULT_COMMAND + var command = command_queue[side].front() return command diff --git a/base/scripts/player/player.gd b/base/scripts/player/player.gd index 300b2cd..99d627e 100644 --- a/base/scripts/player/player.gd +++ b/base/scripts/player/player.gd @@ -12,10 +12,25 @@ var queue: CommandQueue = CommandQueue.new() # Called when the node enters the scene tree for the first time. func _ready() -> void: + queue.command_pushed.connect(on_queue_command_pushed) + queue.command_popped.connect(on_queue_command_popped) weapon_player.current_animation = "static" Input.mouse_mode = Input.MOUSE_MODE_CAPTURED +func _process(_delta: float) -> void: + # TODO: use proper weapon system, this is just for testing command queue + if Input.is_action_pressed("shoot") \ + and queue.current_command(CommandQueue.Side.RIGHT) \ + == CommandQueue.DEFAULT_COMMAND: + queue.push([ + CommandQueue.Command.NONE, + CommandQueue.Command.SHOOT + ], [ + CommandQueue.Side.LEFT, + CommandQueue.Side.RIGHT + ]) + # Called every frame. 'delta' is the elapsed time since the previous frame. func _physics_process(delta: float) -> void: var direction = Vector3.ZERO @@ -38,3 +53,54 @@ func _input(event): ) camera.rotation.x = new_rotation rotation.y -= event.relative.x * horizontal_sensivity + +func on_queue_command_pushed(sides, commands): + for i in sides.size(): + match sides[i]: + CommandQueue.Side.LEFT: + handle_new_left_command(commands[i]) + CommandQueue.Side.RIGHT: + handle_new_right_command(commands[i]) + +func handle_new_left_command(command: CommandQueue.Command): + match command: + CommandQueue.Command.NONE: + pass + _: + print('New command %s is not implemented for left hand.' % str(command)) + +func handle_new_right_command(command: CommandQueue.Command): + match command: + CommandQueue.Command.NONE: + pass + CommandQueue.Command.SHOOT: + weapon_player.play('shoot') + _: + print('New command %s is not implemented for right hand.' % str(command)) + +func shoot_animation_ended(): + queue.pop() + +func on_queue_command_popped(commands): + for i in CommandQueue.Side.size(): + match CommandQueue.Side.values()[i]: + CommandQueue.Side.LEFT: + handle_ended_left_command(commands[i]) + CommandQueue.Side.RIGHT: + handle_ended_right_command(commands[i]) + +func handle_ended_left_command(command: CommandQueue.Command): + match command: + CommandQueue.Command.NONE: + pass + _: + print('Ended command %s is not implemented for left hand.' % str(command)) + +func handle_ended_right_command(command: CommandQueue.Command): + match command: + CommandQueue.Command.NONE: + pass + CommandQueue.Command.SHOOT: + weapon_player.play('static') + _: + print('Ended command %s is not implemented for right hand.' % str(command)) diff --git a/project.godot b/project.godot index c1a93af..93d21f5 100644 --- a/project.godot +++ b/project.godot @@ -41,6 +41,11 @@ move_right={ "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":68,"key_label":0,"unicode":100,"location":0,"echo":false,"script":null) ] } +shoot={ +"deadzone": 0.2, +"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":1,"position":Vector2(189, 15),"global_position":Vector2(198, 63),"factor":1.0,"button_index":1,"canceled":false,"pressed":true,"double_click":false,"script":null) +] +} [layer_names]