fuzzyworld

godot-shooter / commit

Experimenting with adding a meteor to the game.

0a6bdc277960401ffde484d8372a9c5157518f88 · Pavel Safronov · 2023-11-05 17:46:12 -0800 · parents ba3492ae8056

Experimenting with adding a meteor to the game.
 MeteorLarge.gd   | 20 ++++++++++++++++++++
 MeteorLarge.tscn | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 World.tscn       |  7 ++++++-
 3 files changed, 75 insertions(+), 1 deletion(-)

diff --git a/MeteorLarge.gd b/MeteorLarge.gd
new file mode 100644
index 0000000..e1b28e6
--- /dev/null
+++ b/MeteorLarge.gd
@@ -0,0 +1,20 @@
+extends KinematicBody2D
+
+export var health = 5
+export var max_health = 5
+export var size = 1
+export var velocity: Vector2 = Vector2(1,1).normalized()
+
+func _ready() -> void:
+	scale = Vector2(size, size)
+
+func hurt(damage: int = 1) -> void:
+	health -= 1
+	if health <= 0:
+		kill()
+
+func kill() -> void:
+	queue_free()
+
+func _physics_process(delta: float) -> void:
+	velocity = move_and_slide(velocity)
diff --git a/MeteorLarge.tscn b/MeteorLarge.tscn
new file mode 100644
index 0000000..ba13841
--- /dev/null
+++ b/MeteorLarge.tscn
@@ -0,0 +1,49 @@
+[gd_scene load_steps=5 format=2]
+
+[ext_resource path="res://MeteorLarge.gd" type="Script" id=1]
+[ext_resource path="res://assets/kenney_simple-space/PNG/Default/meteor_large.png" type="Texture" id=2]
+
+[sub_resource type="Animation" id=1]
+length = 0.001
+tracks/0/type = "value"
+tracks/0/path = NodePath(".:modulate")
+tracks/0/interp = 1
+tracks/0/loop_wrap = true
+tracks/0/imported = false
+tracks/0/enabled = true
+tracks/0/keys = {
+"times": PoolRealArray( 0 ),
+"transitions": PoolRealArray( 1 ),
+"update": 0,
+"values": [ Color( 1, 1, 1, 1 ) ]
+}
+
+[sub_resource type="Animation" id=2]
+resource_name = "disappear"
+tracks/0/type = "value"
+tracks/0/path = NodePath(".:modulate")
+tracks/0/interp = 1
+tracks/0/loop_wrap = true
+tracks/0/imported = false
+tracks/0/enabled = true
+tracks/0/keys = {
+"times": PoolRealArray( 0, 1 ),
+"transitions": PoolRealArray( 1, 1 ),
+"update": 0,
+"values": [ Color( 1, 1, 1, 1 ), Color( 1, 1, 1, 0 ) ]
+}
+
+[node name="MeteorLarge" type="KinematicBody2D"]
+script = ExtResource( 1 )
+velocity = Vector2( 10, 10 )
+
+[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
+anims/RESET = SubResource( 1 )
+anims/disappear = SubResource( 2 )
+
+[node name="MeteorLarge" type="Sprite" parent="."]
+texture = ExtResource( 2 )
+
+[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="."]
+visible = false
+polygon = PoolVector2Array( -24, 0, -16, -15, 0, -23, 16, -15, 23, 0, 15, 16, 0, 24, -15, 16 )
diff --git a/World.tscn b/World.tscn
index 8900c59..8087daf 100644
--- a/World.tscn
+++ b/World.tscn
@@ -1,4 +1,4 @@
-[gd_scene load_steps=8 format=2]
+[gd_scene load_steps=9 format=2]
 
 [ext_resource path="res://assets/kenney_simple-space/PNG/Default/icon_crossLarge.png" type="Texture" id=1]
 [ext_resource path="res://Player.tscn" type="PackedScene" id=2]
@@ -6,6 +6,7 @@
 [ext_resource path="res://World.gd" type="Script" id=4]
 [ext_resource path="res://StarField.tscn" type="PackedScene" id=5]
 [ext_resource path="res://CharacterTheme.tres" type="Theme" id=6]
+[ext_resource path="res://MeteorLarge.tscn" type="PackedScene" id=7]
 
 [sub_resource type="CircleShape2D" id=1]
 radius = 29.0172
@@ -40,6 +41,10 @@ visible = false
 
 [node name="Environment" type="Node2D" parent="."]
 
+[node name="MeteorLarge" parent="Environment" instance=ExtResource( 7 )]
+position = Vector2( 285, 210 )
+size = 3
+
 [node name="Player" parent="." groups=["player"] instance=ExtResource( 2 )]
 position = Vector2( 513, 302 )