diff --git a/Asteroid.gd b/Asteroid.gd index 965c33e..4d33670 100644 --- a/Asteroid.gd +++ b/Asteroid.gd @@ -6,6 +6,7 @@ var rot_vel = 0 var max_vel = 6 # pixels per second? var max_rot_vel = 2.5 # degrees per second +var health = 100 func _ready(): randomize() @@ -28,6 +29,9 @@ func wrap(v, v_min, v_max): return v_min - 1 else: return v + +func explode(): + queue_free() func _fixed_process(delta): @@ -36,6 +40,14 @@ func _fixed_process(delta): # cur_pos.y = wrap(cur_pos.y, 1, get_viewport().get_rect().size.y) # set_pos(cur_pos) + if is_colliding(): + var e = get_collider() + if e.type() == "Bullet": + health -= 25 + + if health <= 0: + explode() + self.move(velocity) self.rotate(rot_vel) diff --git a/Asteroid.tscn b/Asteroid.tscn index 48f8ffe..d17819e 100644 --- a/Asteroid.tscn +++ b/Asteroid.tscn @@ -1,11 +1,19 @@ -[gd_scene load_steps=3 format=1] +[gd_scene load_steps=4 format=1] [ext_resource path="res://Asteroid.gd" type="Script" id=1] [ext_resource path="res://raw/asteroid.png" type="Texture" id=2] +[sub_resource type="RectangleShape2D" id=1] + +custom_solver_bias = 0.0 +extents = Vector2( 25.1672, 26.3172 ) + [node name="Asteroid" type="KinematicBody2D"] input/pickable = false +shapes/0/shape = SubResource( 1 ) +shapes/0/transform = Matrix32( 1, 0, 0, 1, -0.17482, 3.67132 ) +shapes/0/trigger = false collision/layers = 1 collision/mask = 1 collision/margin = 0.08 @@ -15,4 +23,11 @@ script/script = ExtResource( 1 ) texture = ExtResource( 2 ) +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] + +transform/pos = Vector2( -0.17482, 3.67132 ) +shape = SubResource( 1 ) +trigger = false +_update_shape_index = 0 + diff --git a/Bullet.gd b/Bullet.gd index 4e9902b..8991070 100644 --- a/Bullet.gd +++ b/Bullet.gd @@ -11,9 +11,17 @@ func _ready(): func fire(delta, vel, dir, speed): velocity = (vel.length() * dir + (dir * speed * delta)) sprite.rotate(dir.angle()) + +func type(): + return "Enemy" func _fixed_process(delta): + move(velocity) lifetime -= delta + + if is_colliding(): + var e = get_collider() + if lifetime <= 0: queue_free() \ No newline at end of file diff --git a/Bullet.tscn b/Bullet.tscn index 0ce5212..3a38543 100644 --- a/Bullet.tscn +++ b/Bullet.tscn @@ -1,11 +1,19 @@ -[gd_scene load_steps=3 format=1] +[gd_scene load_steps=4 format=1] [ext_resource path="res://Bullet.gd" type="Script" id=1] [ext_resource path="res://raw/simple_bullet.png" type="Texture" id=2] +[sub_resource type="RectangleShape2D" id=1] + +custom_solver_bias = 0.0 +extents = Vector2( 0.99762, 3.98857 ) + [node name="Bullet" type="KinematicBody2D"] input/pickable = false +shapes/0/shape = SubResource( 1 ) +shapes/0/transform = Matrix32( 1, 0, 0, 1, 0, 0 ) +shapes/0/trigger = false collision/layers = 1 collision/mask = 1 collision/margin = 0.08 @@ -15,4 +23,10 @@ script/script = ExtResource( 1 ) texture = ExtResource( 2 ) +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] + +shape = SubResource( 1 ) +trigger = false +_update_shape_index = 0 + diff --git a/EnemyGrunt.gd b/EnemyGrunt.gd index daa258a..2db49ad 100644 --- a/EnemyGrunt.gd +++ b/EnemyGrunt.gd @@ -1,6 +1,7 @@ extends KinematicBody2D var grunt_rot_speed = deg2rad(22.5) # degrees per second +var current_target = null func _ready(): var t = get_tree() diff --git a/img/player_ship.tex b/img/player_ship.tex index 924833b..0593476 100644 --- a/img/player_ship.tex +++ b/img/player_ship.tex @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:ee80f8310c0716d3d0f917da317607e0d9a20fa40ef02c9981f17d1f62bbe44e -size 934 +oid sha256:19ae97544f084ae4390b575fbd44134e69ba056ca0993a50cdcda21008c5555c +size 950 diff --git a/raw/player_ship.ase b/raw/player_ship.ase index a00e5f2..7ce9af1 100644 --- a/raw/player_ship.ase +++ b/raw/player_ship.ase @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:4f8b9553f7da9e0500ddfe73a11dcf865060d559fd6c9b929e1bed2aff6c13df -size 720 +oid sha256:ca8e9d7504871a709af802f1057b1454f32629118ec00f754a84d9ebfd4c0dae +size 732 diff --git a/raw/player_ship.png b/raw/player_ship.png index 0f8c4df..1d3f68d 100644 Binary files a/raw/player_ship.png and b/raw/player_ship.png differ diff --git a/raw/power_station.ase b/raw/power_station.ase index 53041e0..2b3e68e 100644 --- a/raw/power_station.ase +++ b/raw/power_station.ase @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:ec423b64d26fc631e98da5910e9f22e0e758e12836a3e6409fac3d76ecc1f6ae -size 1188 +oid sha256:47c369c1ae588c03991289f61ea8f4ee12f1027a071f98bc6d383b1fdf15eb25 +size 1262 diff --git a/raw/power_station.png b/raw/power_station.png index 0323016..5fd8951 100644 Binary files a/raw/power_station.png and b/raw/power_station.png differ