mirror of
https://github.com/DerTyp7/TopDownShooter-Godot.git
synced 2025-10-29 04:42:12 +01:00
Fix collider and add waves
This commit is contained in:
10
Bullet.gd
10
Bullet.gd
@@ -9,5 +9,15 @@ func _ready():
|
|||||||
destroy_timer.start()
|
destroy_timer.start()
|
||||||
destroy_timer.connect("timeout", _on_destroy_timer_timeout)
|
destroy_timer.connect("timeout", _on_destroy_timer_timeout)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func _on_destroy_timer_timeout():
|
func _on_destroy_timer_timeout():
|
||||||
queue_free()
|
queue_free()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#func _on_body_entered(body):
|
||||||
|
# print("---------------")
|
||||||
|
# print(body.name)
|
||||||
|
# if "Bullet" not in body.name:
|
||||||
|
# queue_free()
|
||||||
|
|||||||
15
Bullet.tscn
15
Bullet.tscn
@@ -1,13 +1,17 @@
|
|||||||
[gd_scene load_steps=4 format=3 uid="uid://day7or3kp8x5u"]
|
[gd_scene load_steps=5 format=3 uid="uid://day7or3kp8x5u"]
|
||||||
|
|
||||||
[ext_resource type="Script" path="res://Bullet.gd" id="1_0l6ar"]
|
[ext_resource type="Script" path="res://Bullet.gd" id="1_0l6ar"]
|
||||||
[ext_resource type="Texture2D" uid="uid://dafsi3dqavgnb" path="res://Untitled.png" id="1_cjg2r"]
|
[ext_resource type="Texture2D" uid="uid://dafsi3dqavgnb" path="res://Untitled.png" id="1_cjg2r"]
|
||||||
|
|
||||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_suj8m"]
|
[sub_resource type="RectangleShape2D" id="RectangleShape2D_suj8m"]
|
||||||
size = Vector2(8, 8)
|
size = Vector2(4, 4)
|
||||||
|
|
||||||
|
[sub_resource type="RectangleShape2D" id="RectangleShape2D_uncb7"]
|
||||||
|
size = Vector2(6, 6)
|
||||||
|
|
||||||
[node name="Bullet" type="RigidBody2D"]
|
[node name="Bullet" type="RigidBody2D"]
|
||||||
gravity_scale = 0.0
|
gravity_scale = 0.0
|
||||||
|
continuous_cd = 1
|
||||||
script = ExtResource("1_0l6ar")
|
script = ExtResource("1_0l6ar")
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||||
@@ -17,3 +21,10 @@ shape = SubResource("RectangleShape2D_suj8m")
|
|||||||
position = Vector2(-2.38419e-07, -2.38419e-07)
|
position = Vector2(-2.38419e-07, -2.38419e-07)
|
||||||
scale = Vector2(0.4, 0.4)
|
scale = Vector2(0.4, 0.4)
|
||||||
texture = ExtResource("1_cjg2r")
|
texture = ExtResource("1_cjg2r")
|
||||||
|
|
||||||
|
[node name="Area2D" type="Area2D" parent="."]
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
|
||||||
|
shape = SubResource("RectangleShape2D_uncb7")
|
||||||
|
|
||||||
|
[connection signal="body_entered" from="." to="." method="_on_body_entered"]
|
||||||
|
|||||||
17
Enemy.gd
17
Enemy.gd
@@ -4,6 +4,7 @@ var speed: float = 100.0
|
|||||||
var motion: Vector2 = Vector2.ZERO
|
var motion: Vector2 = Vector2.ZERO
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
|
set_meta("dead", false)
|
||||||
pass
|
pass
|
||||||
|
|
||||||
func _physics_process(delta):
|
func _physics_process(delta):
|
||||||
@@ -15,8 +16,18 @@ func _physics_process(delta):
|
|||||||
move_and_collide(motion * delta)
|
move_and_collide(motion * delta)
|
||||||
|
|
||||||
|
|
||||||
func _on_area_2d_body_entered(body):
|
#func _on_area_2d_body_entered(body):
|
||||||
|
# print("Bullet hit")
|
||||||
|
# print(body.name)
|
||||||
|
# if "Bullet" in body.name:
|
||||||
|
# set_meta("dead", true)
|
||||||
|
# queue_free()
|
||||||
|
|
||||||
|
|
||||||
|
func _on_area_2d_area_entered(area):
|
||||||
print("Bullet hit")
|
print("Bullet hit")
|
||||||
print(body.name)
|
print(area.get_parent().name)
|
||||||
if "Bullet" in body.name:
|
if "Bullet" in area.get_parent().name:
|
||||||
|
set_meta("dead", true)
|
||||||
|
area.get_parent().queue_free()
|
||||||
queue_free()
|
queue_free()
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ size = Vector2(0.203555, 2.52986)
|
|||||||
|
|
||||||
[node name="Enemy" type="CharacterBody2D"]
|
[node name="Enemy" type="CharacterBody2D"]
|
||||||
script = ExtResource("1_cnaxx")
|
script = ExtResource("1_cnaxx")
|
||||||
|
metadata/dead = false
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||||
shape = SubResource("RectangleShape2D_aukek")
|
shape = SubResource("RectangleShape2D_aukek")
|
||||||
@@ -22,9 +23,9 @@ texture = ExtResource("1_026jc")
|
|||||||
[node name="Area2D" type="Area2D" parent="."]
|
[node name="Area2D" type="Area2D" parent="."]
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
|
||||||
position = Vector2(-2.38419e-07, 0)
|
position = Vector2(1.19209e-07, 5.96046e-08)
|
||||||
rotation = -3.14159
|
rotation = -3.14159
|
||||||
scale = Vector2(58.952, -4.74335)
|
scale = Vector2(58.952, -4.74335)
|
||||||
shape = SubResource("RectangleShape2D_53hbt")
|
shape = SubResource("RectangleShape2D_53hbt")
|
||||||
|
|
||||||
[connection signal="body_entered" from="Area2D" to="." method="_on_area_2d_body_entered"]
|
[connection signal="area_entered" from="Area2D" to="." method="_on_area_2d_area_entered"]
|
||||||
|
|||||||
44
EnemySpawner.gd
Normal file
44
EnemySpawner.gd
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
extends Node
|
||||||
|
|
||||||
|
var Enemy = preload("res://Enemy.tscn")
|
||||||
|
|
||||||
|
var wave = 0;
|
||||||
|
var enemyList = []
|
||||||
|
var spawnpoints = [[20, 80], [50, 120],[90, 170],[500, 50]]
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
nextWave()
|
||||||
|
pass # Replace with function body.
|
||||||
|
|
||||||
|
func _process(delta):
|
||||||
|
var i = 0
|
||||||
|
for enemy in enemyList:
|
||||||
|
if not enemy || enemy.get_meta("dead") == true:
|
||||||
|
enemyList.remove_at(i)
|
||||||
|
i = i + 1;
|
||||||
|
|
||||||
|
if len(enemyList) == 0:
|
||||||
|
nextWave()
|
||||||
|
|
||||||
|
func spawnEnemies(count):
|
||||||
|
var i = 0;
|
||||||
|
while i < count:
|
||||||
|
print("spawn enemy")
|
||||||
|
var enemyInstance = Enemy.instantiate()
|
||||||
|
enemyInstance.name = "Enemy" + str(randf())
|
||||||
|
enemyInstance.position = Vector2(spawnpoints.pick_random()[0] + i, spawnpoints.pick_random()[1] + i)
|
||||||
|
get_parent().call_deferred("add_child", enemyInstance)
|
||||||
|
enemyList.append(enemyInstance)
|
||||||
|
i = i+1;
|
||||||
|
|
||||||
|
func startWave():
|
||||||
|
print("start wave")
|
||||||
|
if wave == 0:
|
||||||
|
spawnEnemies(1)
|
||||||
|
else:
|
||||||
|
spawnEnemies(wave * 3)
|
||||||
|
|
||||||
|
|
||||||
|
func nextWave():
|
||||||
|
wave = wave+1;
|
||||||
|
startWave()
|
||||||
6
Enemy_spawner.tscn
Normal file
6
Enemy_spawner.tscn
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
[gd_scene load_steps=2 format=3 uid="uid://drc844kmvl3xa"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" path="res://EnemySpawner.gd" id="1_d3ir5"]
|
||||||
|
|
||||||
|
[node name="EnemySpawner" type="Node"]
|
||||||
|
script = ExtResource("1_d3ir5")
|
||||||
14
main.tscn
14
main.tscn
@@ -2,18 +2,23 @@
|
|||||||
|
|
||||||
[ext_resource type="Script" path="res://Player.gd" id="1_6ke6x"]
|
[ext_resource type="Script" path="res://Player.gd" id="1_6ke6x"]
|
||||||
[ext_resource type="Texture2D" uid="uid://dafsi3dqavgnb" path="res://Untitled.png" id="2_w1il1"]
|
[ext_resource type="Texture2D" uid="uid://dafsi3dqavgnb" path="res://Untitled.png" id="2_w1il1"]
|
||||||
[ext_resource type="PackedScene" uid="uid://dkbgu7ghl048y" path="res://Enemy.tscn" id="3_geuud"]
|
[ext_resource type="PackedScene" uid="uid://drc844kmvl3xa" path="res://Enemy_spawner.tscn" id="4_vhwqp"]
|
||||||
|
|
||||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_fs1q0"]
|
[sub_resource type="RectangleShape2D" id="RectangleShape2D_fs1q0"]
|
||||||
size = Vector2(10, 10)
|
size = Vector2(10, 10)
|
||||||
|
|
||||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_tqqca"]
|
[sub_resource type="ShaderMaterial" id="ShaderMaterial_tqqca"]
|
||||||
|
|
||||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_my1x2"]
|
[sub_resource type="RectangleShape2D" id="RectangleShape2D_1cb75"]
|
||||||
size = Vector2(14, 14)
|
size = Vector2(14, 14)
|
||||||
|
|
||||||
[node name="World" type="Node2D"]
|
[node name="World" type="Node2D"]
|
||||||
|
|
||||||
|
[node name="Camera2D" type="Camera2D" parent="."]
|
||||||
|
zoom = Vector2(1.5, 1.5)
|
||||||
|
|
||||||
|
[node name="EnemySpawner" parent="." instance=ExtResource("4_vhwqp")]
|
||||||
|
|
||||||
[node name="Player" type="CharacterBody2D" parent="."]
|
[node name="Player" type="CharacterBody2D" parent="."]
|
||||||
script = ExtResource("1_6ke6x")
|
script = ExtResource("1_6ke6x")
|
||||||
|
|
||||||
@@ -33,9 +38,6 @@ offset = Vector2(45.275, 0)
|
|||||||
[node name="Area2D" type="Area2D" parent="Player"]
|
[node name="Area2D" type="Area2D" parent="Player"]
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Player/Area2D"]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="Player/Area2D"]
|
||||||
shape = SubResource("RectangleShape2D_my1x2")
|
shape = SubResource("RectangleShape2D_1cb75")
|
||||||
|
|
||||||
[node name="Enemy" parent="." instance=ExtResource("3_geuud")]
|
|
||||||
position = Vector2(246, 135)
|
|
||||||
|
|
||||||
[connection signal="body_entered" from="Player/Area2D" to="Player" method="_on_area_2d_body_entered"]
|
[connection signal="body_entered" from="Player/Area2D" to="Player" method="_on_area_2d_body_entered"]
|
||||||
|
|||||||
Reference in New Issue
Block a user