diff --git a/scenes/bullet.tscn b/scenes/bullet.tscn index cb0e651..e22ed6f 100644 --- a/scenes/bullet.tscn +++ b/scenes/bullet.tscn @@ -6,8 +6,9 @@ [sub_resource type="RectangleShape2D" id="RectangleShape2D_5nukh"] size = Vector2(4, 16) -[node name="Bullet" type="Area2D" groups=["projectile"]] +[node name="Bullet" type="Area2D" groups=["bullet"]] position = Vector2(0, -8) +collision_layer = 2 collision_mask = 2 script = ExtResource("1_jyq7a") diff --git a/scenes/comet.gd b/scenes/comet.gd index 8107618..cc14a10 100644 --- a/scenes/comet.gd +++ b/scenes/comet.gd @@ -1,24 +1,48 @@ extends Area2D -# TODO: Have a list of "sizes" a comet can be # TODO: Have speeds be determined on a rage based on its "size" # TODO: Provide a specific score based on the "size" # TODO: Have the comet spawn 2 of the next "size" when hit # TODO: Have the comet disapear if shot at is smallest "size" -@export var movement_speed := 600 + +enum SIZE {SMALL, MEDIUM, LARGE} + +@export var current_size : SIZE = SIZE.LARGE + +var size_data = { + SIZE.SMALL : {"Scale": 0.5, "Speed-Multi": 1.5}, + SIZE.MEDIUM : {"Scale": 1.0, "Speed-Multi": 1.0}, + SIZE.LARGE : {"Scale": 2.5, "Speed-Multi": 0.5} +} + + +var movement_speed : int +var movement_speed_min : int = 100 +var movement_speed_max : int = 500 +var movement_direciton := Vector2.UP var rotation_speed : int var rotaion_direction : int + func _ready() -> void: - rotaion_direction = randi_range(-1, 1) - rotation_speed = randi_range(50, 250) + movement_speed = randi_range(movement_speed_min, movement_speed_max) + movement_speed *= size_data[current_size]["Speed-Multi"] + + rotaion_direction = randi_range(0, 1) + if rotaion_direction < 1: + rotaion_direction = -1 + rotation_speed = randi_range(50, 150) + rotate(randi_range(0, 360)) + + self.scale *= size_data[current_size]["Scale"] func _physics_process(delta: float) -> void: - rotate(deg_to_rad(rotaion_direction * rotation_speed * delta)) + $CollisionPolygon2D.rotate(deg_to_rad(rotaion_direction * rotation_speed * delta)) + $Sprite2D.rotate(deg_to_rad(rotaion_direction * rotation_speed * delta)) - # TODO: Add "floating in space" movement + position += movement_direciton.rotated(rotation) * movement_speed * delta # Screen Wrap var viewport_size := get_viewport_rect().size @@ -27,6 +51,10 @@ func _physics_process(delta: float) -> void: func _on_body_entered(body: Node2D) -> void: print(body) - # TODO: Add "explosion" logic if bullet hits me + if body.is_in_group("bullet"): + explode() if body.is_in_group("ship"): body.crash() + +func explode() -> void: + queue_free() diff --git a/scenes/comet.tscn b/scenes/comet.tscn index 2a59d20..5d2f2fd 100644 --- a/scenes/comet.tscn +++ b/scenes/comet.tscn @@ -4,6 +4,7 @@ [ext_resource type="Script" path="res://scenes/comet.gd" id="1_33qxe"] [node name="Comet" type="Area2D"] +collision_layer = 3 script = ExtResource("1_33qxe") [node name="Sprite2D" type="Sprite2D" parent="."] diff --git a/scenes/game.tscn b/scenes/game.tscn index 8b05707..00253ed 100644 --- a/scenes/game.tscn +++ b/scenes/game.tscn @@ -25,3 +25,14 @@ position = Vector2(622, 309) [node name="Comet" parent="." instance=ExtResource("2_b37uv")] position = Vector2(276, 249) +current_size = 1 + +[node name="Comet2" parent="." instance=ExtResource("2_b37uv")] +position = Vector2(439, 459) + +[node name="Comet3" parent="." instance=ExtResource("2_b37uv")] +position = Vector2(834, 136) +current_size = 0 + +[node name="Comet4" parent="." instance=ExtResource("2_b37uv")] +position = Vector2(938, 402) diff --git a/scripts/bullet.gd b/scripts/bullet.gd index 1109c5a..2965116 100644 --- a/scripts/bullet.gd +++ b/scripts/bullet.gd @@ -1,6 +1,6 @@ extends Area2D -# TODO: Tweak speed and LifeTimer values +# FIXME: Tweak speed and LifeTimer values @export var speed := 1400.00 var direction := Vector2.UP diff --git a/scripts/ship.gd b/scripts/ship.gd index 91cbcc7..4249390 100644 --- a/scripts/ship.gd +++ b/scripts/ship.gd @@ -1,7 +1,8 @@ extends CharacterBody2D # TODO: Add the ability to "warp" -# TODO: Tweak speed and shoot time values +# FIXME: Tweak speed and shoot time values +# FIXME: Tweak Ship's scale const BULLET = preload("res://scenes/bullet.tscn") @@ -41,7 +42,7 @@ func fire_gun(pos : Vector2, rot : float) -> void: bullet.position = pos bullet.rotation = rot $Projectiles.add_child(bullet) - $ShootSounds.play() + $ShootSound.play() can_shoot = false $ShotCooldown.start()