From ed53d1b1902201d1964a34acf536ab8096e4f3a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20H=C3=BCbner?= Date: Sat, 12 Aug 2017 18:02:52 +0200 Subject: [PATCH] incredible --- Asteroid.tscn | 2 +- Bullet.tscn | 2 +- Drawer.gd | 2 +- EnemyGrunt.gd | 17 +++++++++-- EnemyGrunt.tscn | 5 ++-- Game.tscn | 6 ++-- Missile.gd | 59 ++++++++++++++++++++++++++++++++++++++ Missile.tscn | 58 +++++++++++++++++++++++++++++++++++++ MissileImpact.gd | 29 +++++++++++++++++++ MissileImpact.tscn | 45 +++++++++++++++++++++++++++++ Player.gd | 6 ++++ Player.tscn | 18 ++++++++++-- PowerStation.tscn | 4 +-- raw/exhaust.png.flags | 2 ++ raw/missile_one.ase | 3 ++ raw/missile_one.png | Bin 0 -> 101 bytes raw/missile_one.png.flags | 2 ++ 17 files changed, 245 insertions(+), 15 deletions(-) create mode 100644 Missile.gd create mode 100644 Missile.tscn create mode 100644 MissileImpact.gd create mode 100644 MissileImpact.tscn create mode 100644 raw/exhaust.png.flags create mode 100644 raw/missile_one.ase create mode 100644 raw/missile_one.png create mode 100644 raw/missile_one.png.flags diff --git a/Asteroid.tscn b/Asteroid.tscn index 87b192c..e80237b 100644 --- a/Asteroid.tscn +++ b/Asteroid.tscn @@ -6,7 +6,7 @@ [sub_resource type="RectangleShape2D" id=1] custom_solver_bias = 0.0 -extents = Vector2( 12.234, 13.1952 ) +extents = Vector2( 13.3341, 13.1952 ) [node name="Asteroid" type="KinematicBody2D"] diff --git a/Bullet.tscn b/Bullet.tscn index 1e5d693..b85fdfe 100644 --- a/Bullet.tscn +++ b/Bullet.tscn @@ -16,7 +16,7 @@ shapes/0/shape = SubResource( 1 ) shapes/0/transform = Matrix32( 1, 0, 0, 1, 0, 0 ) shapes/0/trigger = false collision/layers = 2 -collision/mask = 1 +collision/mask = 2 collision/margin = 0.08 script/script = ExtResource( 1 ) diff --git a/Drawer.gd b/Drawer.gd index 7bce580..6b9ff8b 100644 --- a/Drawer.gd +++ b/Drawer.gd @@ -35,5 +35,5 @@ func _draw(): draw_rect(Rect2(s_x, s_y, 2, 2), Color(1, 1, 1)) elif ent.type() == "PowerStation": draw_rect(Rect2(s_x, s_y, 4, 4), Color(0, 0, 1)) - elif ent.type() == "EnemyGrunt": + elif ent.type() == "Enemy": draw_rect(Rect2(s_x, s_y, 2, 2), Color(1, 0, 0)) \ No newline at end of file diff --git a/EnemyGrunt.gd b/EnemyGrunt.gd index 6922485..1660913 100644 --- a/EnemyGrunt.gd +++ b/EnemyGrunt.gd @@ -1,5 +1,7 @@ extends KinematicBody2D +var ExplosionEffect = load("res://ExplosionEffect.tscn") + const km = preload("Kinematic.gd") var grunt_max_speed = 256 # pixels per second @@ -7,6 +9,8 @@ var grunt_arrive_radius = 64 var grunt_arrive_speed = 1 var grunt_rot_speed = deg2rad(22.5) # degrees per second +var health = 100 + var cur_kinematic var steering var s_seek @@ -15,7 +19,6 @@ var s_arrive func _ready(): var t = get_tree().get_root().get_node("Game/MinimapControl").register_entity(self) set_fixed_process(true) - set_process(true) cur_kinematic = km.Kinematic.new(self, grunt_max_speed) steering = km.Steering.new() @@ -27,8 +30,15 @@ func _ready(): s_seek.set_target(player) s_arrive.set_target(player) +func on_explode(): + # create explosion effect + var new_ee = ExplosionEffect.instance() + get_tree().get_root().add_child(new_ee) + new_ee.set_global_pos(get_global_pos()) + queue_free() + func do_damage(v): - pass + health -= v func type(): return "Enemy" @@ -38,6 +48,9 @@ func _fixed_process(delta): s_arrive.get_steering(steering) cur_kinematic.update(steering, delta) + if health <= 0: + on_explode() + func _process(delta): pass # rotate(grunt_rot_speed * delta) diff --git a/EnemyGrunt.tscn b/EnemyGrunt.tscn index 17cd992..3c012fe 100644 --- a/EnemyGrunt.tscn +++ b/EnemyGrunt.tscn @@ -11,13 +11,14 @@ extents = Vector2( 8.55915, 8.40247 ) [node name="EnemyGrunt" type="KinematicBody2D"] +transform/pos = Vector2( 0.12851, 0 ) transform/scale = Vector2( 2, 2 ) input/pickable = false shapes/0/shape = SubResource( 1 ) shapes/0/transform = Matrix32( 1, 0, 0, 1, 0, 0 ) shapes/0/trigger = false -collision/layers = 3 -collision/mask = 1 +collision/layers = 2 +collision/mask = 2 collision/margin = 0.08 script/script = ExtResource( 1 ) diff --git a/Game.tscn b/Game.tscn index de40a35..e11f5f3 100644 --- a/Game.tscn +++ b/Game.tscn @@ -7,7 +7,7 @@ [ext_resource path="res://Player.tscn" type="PackedScene" id=5] [ext_resource path="res://raw/space.png" type="Texture" id=6] [ext_resource path="res://EnemyGrunt.tscn" type="PackedScene" id=7] -[ext_resource path="res://BulletImpact.tscn" type="PackedScene" id=8] +[ext_resource path="res://Missile.tscn" type="PackedScene" id=8] [node name="Game" type="Node"] @@ -72,8 +72,6 @@ region_rect = Rect2( 0, 0, 8192, 8192 ) transform/pos = Vector2( 127.878, -20.3627 ) transform/scale = Vector2( 1.5, 1.5 ) -[node name="BulletImpact" parent="." instance=ExtResource( 8 )] - -transform/pos = Vector2( 53.4955, -25.9372 ) +[node name="Missile" parent="." instance=ExtResource( 8 )] diff --git a/Missile.gd b/Missile.gd new file mode 100644 index 0000000..8bc90b9 --- /dev/null +++ b/Missile.gd @@ -0,0 +1,59 @@ +extends KinematicBody2D + +const km = preload("Kinematic.gd") +var MissileImpact = load("res://MissileImpact.tscn") + +var missile_max_speed = 384 # pixels per second +var missile_arrive_radius = 64 +var missile_arrive_speed = 1 +var missile_rot_speed = deg2rad(22.5) # degrees per second +var missile_dmg = 100 + +var cur_kinematic +var steering +var s_seek +var s_arrive + +func _ready(): + set_fixed_process(true) + + cur_kinematic = km.Kinematic.new(self, missile_max_speed) + steering = km.Steering.new() + + s_seek = km.Seek.new(self) + s_arrive = km.Arrive.new(self, missile_arrive_radius, missile_arrive_speed) + + var player = get_tree().get_root().get_node("Game/Player") + s_seek.set_target(player) + s_arrive.set_target(player) + +func on_impact(e): + + # create bullet impact + var new_mi = MissileImpact.instance() + # e.add_child(new_mi) + get_tree().get_root().add_child(new_mi) + #new_bi.set_global_pos(get_collision_pos() + velocity/2) + new_mi.set_scale(Vector2(1.5, 1.5)) # when missile, larger effect + new_mi.set_global_pos(get_collision_pos()) + + # align along "hit normal, the lazy way" + new_mi.set_global_rot((-get_collision_normal()).angle()) + + # new_bi.rotate(deg2rad(180)) + + # damage and free + e.do_damage(missile_dmg) + queue_free() + +func _fixed_process(delta): + s_seek.get_steering(steering) + s_arrive.get_steering(steering) + cur_kinematic.update(steering, delta) + + if is_colliding(): + var e = get_collider() + on_impact(e) + +func type(): + return "Missile" diff --git a/Missile.tscn b/Missile.tscn new file mode 100644 index 0000000..4051777 --- /dev/null +++ b/Missile.tscn @@ -0,0 +1,58 @@ +[gd_scene load_steps=4 format=1] + +[ext_resource path="res://Missile.gd" type="Script" id=1] +[ext_resource path="res://raw/missile_one.png" type="Texture" id=2] + +[sub_resource type="RectangleShape2D" id=1] + +custom_solver_bias = 0.0 +extents = Vector2( 0.531269, 3.07443 ) + +[node name="Missile" type="KinematicBody2D"] + +transform/scale = Vector2( 2, 2 ) +input/pickable = false +shapes/0/shape = SubResource( 1 ) +shapes/0/transform = Matrix32( 1, 0, 0, 1, 0, 0 ) +shapes/0/trigger = false +collision/layers = 2 +collision/mask = 3 +collision/margin = 0.08 +script/script = ExtResource( 1 ) + +[node name="Sprite" type="Sprite" parent="."] + +texture = ExtResource( 2 ) + +[node name="Particles2D" type="Particles2D" parent="."] + +transform/pos = Vector2( 0, 2.5151 ) +config/amount = 128 +config/lifetime = 2.0 +config/process_mode = 1 +config/local_space = false +params/direction = 0.0 +params/spread = 12.0 +params/linear_velocity = 10.0 +params/spin_velocity = 0.0 +params/orbit_velocity = 0.0 +params/gravity_direction = 0.0 +params/gravity_strength = 9.8 +params/radial_accel = 0.0 +params/tangential_accel = 0.0 +params/damping = 0.0 +params/initial_angle = 0.0 +params/initial_size = 2.0 +params/final_size = 0.0 +params/hue_variation = 0.0 +params/anim_speed_scale = 1.0 +params/anim_initial_pos = 0.0 +color/color = Color( 1, 0.984375, 0, 1 ) + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] + +shape = SubResource( 1 ) +trigger = false +_update_shape_index = 0 + + diff --git a/MissileImpact.gd b/MissileImpact.gd new file mode 100644 index 0000000..ec2af49 --- /dev/null +++ b/MissileImpact.gd @@ -0,0 +1,29 @@ +extends Node2D + +onready var sprite = get_node("Sprite") +onready var ps = get_node("Particles2D") + +var current_time = 0 +var frames_per_second = 0.05 +var total_time = 0 +var done = false + +func _ready(): + set_process(true) + total_time = sprite.get_hframes() * frames_per_second + 1.5 # 4 extra seconds for particle blast + ps.set_process(false) + +func _process(delta): + + ps.set_process(true) + + if not int(current_time / frames_per_second) >= sprite.get_hframes() - 1: + sprite.set_frame(int(current_time / frames_per_second)) + elif not done: + sprite.hide() + done = true + + current_time += delta + + if current_time >= total_time: + queue_free() \ No newline at end of file diff --git a/MissileImpact.tscn b/MissileImpact.tscn new file mode 100644 index 0000000..337c713 --- /dev/null +++ b/MissileImpact.tscn @@ -0,0 +1,45 @@ +[gd_scene load_steps=4 format=1] + +[ext_resource path="res://MissileImpact.gd" type="Script" id=1] +[ext_resource path="res://raw/bullet_impact.png" type="Texture" id=2] +[ext_resource path="res://raw/exhaust.png" type="Texture" id=3] + +[node name="MissileImpact" type="Node2D"] + +script/script = ExtResource( 1 ) + +[node name="Sprite" type="Sprite" parent="."] + +texture = ExtResource( 2 ) +hframes = 5 + +[node name="Particles2D" type="Particles2D" parent="."] + +transform/pos = Vector2( 0.130829, -3.26887 ) +transform/rot = -180.0 +config/amount = 32 +config/lifetime = 4.0 +config/time_scale = 2.0 +config/process_mode = 1 +config/explosiveness = 0.1 +config/texture = ExtResource( 3 ) +params/direction = 0.0 +params/spread = 60.0 +params/linear_velocity = 25.0 +params/spin_velocity = 0.0 +params/orbit_velocity = 0.0 +params/gravity_direction = 0.0 +params/gravity_strength = 9.8 +params/radial_accel = 0.0 +params/tangential_accel = 0.0 +params/damping = 0.0 +params/initial_angle = 0.0 +params/initial_size = 1.0 +params/final_size = 0.0 +params/hue_variation = 0.0 +params/anim_speed_scale = 1.0 +params/anim_initial_pos = 0.0 +randomness/orbit_velocity = 10.0 +randomness/gravity_direction = 1.0 + + diff --git a/Player.gd b/Player.gd index 5a583d9..60e31e3 100644 --- a/Player.gd +++ b/Player.gd @@ -22,6 +22,12 @@ func _ready(): set_fixed_process(true) left_particles.set_emitting(false) right_particles.set_emitting(false) + +func type(): + return "Player" + +func do_damage(v): + pass func turn_towards(delta, pos): diff --git a/Player.tscn b/Player.tscn index a9c1856..3712ae3 100644 --- a/Player.tscn +++ b/Player.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=6 format=1] +[gd_scene load_steps=7 format=1] [ext_resource path="res://Player.gd" type="Script" id=1] [ext_resource path="res://img/player_ship.tex" type="Texture" id=2] @@ -6,11 +6,19 @@ [ext_resource path="res://raw/exhaust.png" type="Texture" id=4] [ext_resource path="res://ThrusterScript.gd" type="Script" id=5] +[sub_resource type="RectangleShape2D" id=1] + +custom_solver_bias = 0.0 +extents = Vector2( 14.9829, 14.1367 ) + [node name="Player" type="KinematicBody2D"] transform/scale = Vector2( 2, 2 ) input/pickable = false -collision/layers = 3 +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 script/script = ExtResource( 1 ) @@ -176,4 +184,10 @@ drag_margin/top = 0.2 drag_margin/right = 0.2 drag_margin/bottom = 0.2 +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] + +shape = SubResource( 1 ) +trigger = false +_update_shape_index = 0 + diff --git a/PowerStation.tscn b/PowerStation.tscn index 4f4748b..1eccf59 100644 --- a/PowerStation.tscn +++ b/PowerStation.tscn @@ -14,8 +14,8 @@ input/pickable = false shapes/0/shape = SubResource( 1 ) shapes/0/transform = Matrix32( 2, 0, 0, 2, 0, 0 ) shapes/0/trigger = false -collision/layers = 3 -collision/mask = 1 +collision/layers = 2 +collision/mask = 2 collision/margin = 0.08 script/script = ExtResource( 1 ) diff --git a/raw/exhaust.png.flags b/raw/exhaust.png.flags new file mode 100644 index 0000000..226e8a3 --- /dev/null +++ b/raw/exhaust.png.flags @@ -0,0 +1,2 @@ +filter=false +gen_mipmaps=false diff --git a/raw/missile_one.ase b/raw/missile_one.ase new file mode 100644 index 0000000..db45251 --- /dev/null +++ b/raw/missile_one.ase @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:72fdb3eee3991f7895c275b8dc88ad290fa7b99a4e9972fc3b0c2f38b00a4838 +size 546 diff --git a/raw/missile_one.png b/raw/missile_one.png new file mode 100644 index 0000000000000000000000000000000000000000..a43a15b81576d9181e547ddd6ec4d098c86411fb GIT binary patch literal 101 zcmeAS@N?(olHy`uVBq!ia0vp^%s|Y>!3H9qs_+0Q9Zwg>5RRFp#}|q+2#7Eos7?zA zaopJE>XXkMzi4OKg0F%T6sEs=`iuRIDKp=U=d6Z4Yq=tU`WQT2{an^LB{Ts5e_0#< literal 0 HcmV?d00001 diff --git a/raw/missile_one.png.flags b/raw/missile_one.png.flags new file mode 100644 index 0000000..226e8a3 --- /dev/null +++ b/raw/missile_one.png.flags @@ -0,0 +1,2 @@ +filter=false +gen_mipmaps=false