From 3ad6004836d6d844c2b6d88cc3ad5ef2faa46c0b Mon Sep 17 00:00:00 2001 From: Melon Bread Date: Mon, 13 May 2024 20:31:41 -0400 Subject: [PATCH] Ship can now warp --- project.godot | 15 +++++++++++++++ scenes/ship.tscn | 4 ++++ scripts/bullet.gd | 2 -- scripts/game.gd | 1 - scripts/ship.gd | 24 +++++++++++++++++++++--- 5 files changed, 40 insertions(+), 6 deletions(-) diff --git a/project.godot b/project.godot index 956d53d..4bdcc85 100644 --- a/project.godot +++ b/project.godot @@ -34,6 +34,21 @@ ui_accept={ , Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":0,"pressure":0.0,"pressed":true,"script":null) ] } +ui_select={ +"deadzone": 0.5, +"events": [Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":3,"pressure":0.0,"pressed":false,"script":null) +, 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":32,"physical_keycode":0,"key_label":0,"unicode":32,"echo":false,"script":null) +, 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":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":1,"canceled":false,"pressed":false,"double_click":false,"script":null) +] +} +ui_cancel={ +"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":4194305,"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":1,"pressure":0.0,"pressed":true,"script":null) +, 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":4194328,"key_label":0,"unicode":0,"echo":false,"script":null) +, 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":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":2,"canceled":false,"pressed":false,"double_click":false,"script":null) +] +} ui_left={ "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":4194319,"physical_keycode":0,"key_label":0,"unicode":0,"echo":false,"script":null) diff --git a/scenes/ship.tscn b/scenes/ship.tscn index 8dfc4e9..1527314 100644 --- a/scenes/ship.tscn +++ b/scenes/ship.tscn @@ -78,6 +78,9 @@ polygon = PackedVector2Array(-3, -31, 4, -31, 32, 28, 32, 33, 28, 33, 1, 16, -24 wait_time = 0.5 one_shot = true +[node name="WarpCooldown" type="Timer" parent="."] +one_shot = true + [node name="Gun" type="Marker2D" parent="."] position = Vector2(0, -33) @@ -95,3 +98,4 @@ libraries = { } [connection signal="timeout" from="ShotCooldown" to="." method="_on_shot_cooldown_timeout"] +[connection signal="timeout" from="WarpCooldown" to="." method="_on_warp_cooldown_timeout"] diff --git a/scripts/bullet.gd b/scripts/bullet.gd index 2965116..07148d5 100644 --- a/scripts/bullet.gd +++ b/scripts/bullet.gd @@ -1,7 +1,5 @@ extends Area2D -# FIXME: Tweak speed and LifeTimer values - @export var speed := 1400.00 var direction := Vector2.UP diff --git a/scripts/game.gd b/scripts/game.gd index 20a06e5..83322f9 100644 --- a/scripts/game.gd +++ b/scripts/game.gd @@ -1,6 +1,5 @@ extends Node2D -# TODO: Make a small title screen that starts before the game scene # TODO: MAYBE track high score in a file & show it on HUD # TODO: MAYBE make ufo enemey that randomly flies in from ones sode to the other diff --git a/scripts/ship.gd b/scripts/ship.gd index 3b72977..b19ee61 100644 --- a/scripts/ship.gd +++ b/scripts/ship.gd @@ -1,6 +1,5 @@ extends CharacterBody2D -# TODO: Add the ability to "warp" # FIXME: Tweak speed and floatyness4 signal crashed @@ -11,7 +10,13 @@ const BULLET = preload("res://scenes/bullet.tscn") @export var max_speed := 350.0 @export var rotation_speed := 200.0 +var viewport_size : Vector2 + var can_shoot := true +var can_warp := true + +func _ready() -> void: + viewport_size = get_viewport_rect().size func _physics_process(delta: float) -> void: # Controls @@ -21,6 +26,9 @@ func _physics_process(delta: float) -> void: if Input.is_action_pressed("ui_accept") and can_shoot: fire_gun($Gun.global_position, self.global_rotation) + if Input.is_action_pressed("ui_cancel") and can_warp: + warp() + # Movement Logic ## Accleration velocity += accleration_direction.rotated(rotation) * accleration * delta @@ -34,7 +42,6 @@ func _physics_process(delta: float) -> void: move_and_slide() # Screen Wrap - var viewport_size := get_viewport_rect().size position.x = wrap(position.x, 0, viewport_size.x) position.y = wrap(position.y, 0,viewport_size.y) @@ -47,7 +54,15 @@ func fire_gun(pos : Vector2, rot : float) -> void: can_shoot = false $ShotCooldown.start() -func crash(): +func warp() -> void: + var random_position := Vector2.ZERO + random_position.x = randf_range(0, viewport_size.x) + random_position.y = randf_range(0, viewport_size.y) + position = random_position + can_warp = false + $WarpCooldown.start() + +func crash() -> void: # TODO: Make some kind of crash animation or crashed sprite crashed.emit() $AnimationPlayer.play("crash") @@ -55,3 +70,6 @@ func crash(): func _on_shot_cooldown_timeout() -> void: can_shoot = true + +func _on_warp_cooldown_timeout() -> void: + can_warp = true