diff --git a/project.godot b/project.godot index abe8224..f4789b9 100644 --- a/project.godot +++ b/project.godot @@ -39,24 +39,54 @@ window/stretch/aspect="keep" shoot_0={ "deadzone": 0.5, -"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777232,"unicode":0,"echo":false,"script":null) +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":65,"unicode":0,"echo":false,"script":null) ] } shoot_1={ "deadzone": 0.5, -"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777234,"unicode":0,"echo":false,"script":null) +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":84,"unicode":0,"echo":false,"script":null) ] } -shield_red={ +shield_red_on={ "deadzone": 0.5, -"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":81,"unicode":0,"echo":false,"script":null) +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":80,"unicode":0,"echo":false,"script":null) + ] +} +shield_blue_on={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":85,"unicode":0,"echo":false,"script":null) + ] +} +shield_red_off={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":88,"unicode":0,"echo":false,"script":null) + ] +} +shield_blue_off={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":73,"unicode":0,"echo":false,"script":null) ] } -shield_blue={ +walk_right_on={ "deadzone": 0.5, "events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":69,"unicode":0,"echo":false,"script":null) ] } +walk_right_off={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":82,"unicode":0,"echo":false,"script":null) + ] +} +walk_left_on={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":81,"unicode":0,"echo":false,"script":null) + ] +} +walk_left_off={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":87,"unicode":0,"echo":false,"script":null) + ] +} [rendering] diff --git a/sheep/sheep.gd b/sheep/sheep.gd index 974721a..eeb6fd2 100644 --- a/sheep/sheep.gd +++ b/sheep/sheep.gd @@ -14,29 +14,44 @@ const TWOSHOT_INTERVAL = 0.1 var timeout_cannons = [0, 0] var last_projectile +var is_moving_left = false +var is_moving_right = false + func _ready(): $Shield.connect("blocked", self, "emit_signal", ["blocked"]) -func process_input(): +func _move(): velocity = Vector2() var left_border = Global.PLAYER_PADDING_HORIZONTAL.x var right_border = get_viewport_rect().size.x - Global.PLAYER_PADDING_HORIZONTAL.y - if Input.is_action_pressed('ui_right') && position.x < right_border: + if is_moving_right && position.x < right_border: velocity.x += 1 - if Input.is_action_pressed('ui_left') && position.x > left_border: + + if is_moving_left && position.x > left_border: velocity.x -= 1 - if (Input.is_action_pressed('ui_right') && position.x >= right_border) || (Input.is_action_pressed('ui_left') && position.x <= left_border): + velocity = velocity.normalized() * speed + + if (is_moving_right && position.x >= right_border) || (is_moving_left && position.x <= left_border): if not $RobotSheepPlayer.playing: $RobotSheepPlayer.play() + +func _input(_event): + if Input.is_action_just_pressed("walk_right_on"): + is_moving_right = true + elif Input.is_action_just_pressed('walk_right_off'): + is_moving_right = false + + if Input.is_action_just_pressed('walk_left_on'): + is_moving_left = true + elif Input.is_action_just_pressed('walk_left_off'): + is_moving_left = false if Input.is_action_just_pressed("shoot_0"): shoot(0) if Input.is_action_just_pressed("shoot_1") and not Global.useAutoCrits: shoot(1) - - velocity = velocity.normalized() * speed func was_shot_recently(cannon_index): return Global.useAutoCrits or timeout_cannons[cannon_index] >= CANNON_TIMEOUT - TWOSHOT_INTERVAL @@ -68,8 +83,7 @@ func shoot(cannon_index): func _physics_process(delta): - process_input() - + _move() timeout_cannons[0] -= delta timeout_cannons[1] -= delta diff --git a/sheep/shield.gd b/sheep/shield.gd index 17cd0af..e7ec218 100644 --- a/sheep/shield.gd +++ b/sheep/shield.gd @@ -10,6 +10,9 @@ var colors = [1, 4] if Global.useFourColors else [1, 2.5, 4] signal shield_changed signal blocked +var shield_red_on = false +var shield_blue_on = false + func is_blocked(projectile): var projectile_color = projectile.get_modulate() var color = get_modulate() @@ -24,10 +27,19 @@ func is_blocked(projectile): func block_registered(): emit_signal("blocked") -func _process(_delta): +func _input(_delta): + if Input.is_action_just_pressed("shield_red_on"): + shield_red_on = true + if Input.is_action_just_pressed("shield_red_off"): + shield_red_on =false + if Input.is_action_just_pressed("shield_blue_on"): + shield_blue_on = true + if Input.is_action_just_pressed("shield_blue_off"): + shield_blue_on = false + if Global.useFourColors: - r_index = 1 if Input.is_action_pressed("shield_red") else 0 - b_index = 1 if Input.is_action_pressed("shield_blue") else 0 + r_index = 1 if shield_red_on else 0 + b_index = 1 if shield_blue_on else 0 $"../..".emit_signal("shield_changed", true, r_index) $"../..".emit_signal("shield_changed", false, b_index) else: