bullet factory, push attack
This commit is contained in:
		
							parent
							
								
									b5e5db7ef1
								
							
						
					
					
						commit
						de7312cf8e
					
				
							
								
								
									
										17
									
								
								ahmedgg/bullet.gd
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								ahmedgg/bullet.gd
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,17 @@
 | 
			
		||||
class_name Bullet extends Area2D
 | 
			
		||||
 | 
			
		||||
var speed = 750
 | 
			
		||||
 | 
			
		||||
signal hit(bullet, body)
 | 
			
		||||
 | 
			
		||||
func setSpeed(value):
 | 
			
		||||
	speed = value
 | 
			
		||||
	
 | 
			
		||||
#animation
 | 
			
		||||
func _physics_process(delta: float) -> void:
 | 
			
		||||
	position +=transform.x*speed*delta
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
func _on_body_entered(body: Node2D) -> void:
 | 
			
		||||
		print ("bullet collision")
 | 
			
		||||
		hit.emit(self, body)
 | 
			
		||||
@ -21,3 +21,26 @@ folder_colors={
 | 
			
		||||
"res://scenes/": "green",
 | 
			
		||||
"res://scripts/": "pink"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
[input]
 | 
			
		||||
 | 
			
		||||
left={
 | 
			
		||||
"deadzone": 0.5,
 | 
			
		||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":65,"key_label":0,"unicode":97,"location":0,"echo":false,"script":null)
 | 
			
		||||
]
 | 
			
		||||
}
 | 
			
		||||
right={
 | 
			
		||||
"deadzone": 0.5,
 | 
			
		||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":68,"key_label":0,"unicode":100,"location":0,"echo":false,"script":null)
 | 
			
		||||
]
 | 
			
		||||
}
 | 
			
		||||
shove={
 | 
			
		||||
"deadzone": 0.5,
 | 
			
		||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":76,"key_label":0,"unicode":108,"location":0,"echo":false,"script":null)
 | 
			
		||||
]
 | 
			
		||||
}
 | 
			
		||||
shoot={
 | 
			
		||||
"deadzone": 0.5,
 | 
			
		||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":77,"key_label":0,"unicode":109,"location":0,"echo":false,"script":null)
 | 
			
		||||
]
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -1,57 +1,26 @@
 | 
			
		||||
[gd_scene load_steps=9 format=3 uid="uid://c7psh8jpkkc6x"]
 | 
			
		||||
[gd_scene load_steps=10 format=3 uid="uid://c7psh8jpkkc6x"]
 | 
			
		||||
 | 
			
		||||
[ext_resource type="Script" path="res://scripts/game controller.gd" id="1_pcysq"]
 | 
			
		||||
[ext_resource type="Script" path="res://scripts/trigger.gd" id="1_tp4vr"]
 | 
			
		||||
[ext_resource type="Script" path="res://scripts/Player.gd" id="2_o8d6o"]
 | 
			
		||||
 | 
			
		||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_nynyi"]
 | 
			
		||||
size = Vector2(96, 20)
 | 
			
		||||
 | 
			
		||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_gv8hf"]
 | 
			
		||||
 | 
			
		||||
[sub_resource type="WorldBoundaryShape2D" id="WorldBoundaryShape2D_ukrrp"]
 | 
			
		||||
[ext_resource type="PackedScene" uid="uid://b0d1gs2knc2l8" path="res://scenes/player.tscn" id="3_70p4h"]
 | 
			
		||||
[ext_resource type="PackedScene" uid="uid://dg6vhq7diydcj" path="res://scenes/bullet.tscn" id="4_vo7vc"]
 | 
			
		||||
[ext_resource type="Script" path="res://scripts/scene_manager.gd" id="5_w3sh3"]
 | 
			
		||||
 | 
			
		||||
[sub_resource type="CircleShape2D" id="CircleShape2D_785vb"]
 | 
			
		||||
radius = 88.1419
 | 
			
		||||
 | 
			
		||||
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_wfabo"]
 | 
			
		||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_nynyi"]
 | 
			
		||||
size = Vector2(96, 20)
 | 
			
		||||
 | 
			
		||||
[sub_resource type="WorldBoundaryShape2D" id="WorldBoundaryShape2D_ukrrp"]
 | 
			
		||||
 | 
			
		||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_gv8hf"]
 | 
			
		||||
 | 
			
		||||
[node name="AhmedGG" type="Node2D"]
 | 
			
		||||
script = ExtResource("1_pcysq")
 | 
			
		||||
 | 
			
		||||
[node name="StaticBody2D" type="StaticBody2D" parent="."]
 | 
			
		||||
position = Vector2(296, 246)
 | 
			
		||||
metadata/_edit_group_ = true
 | 
			
		||||
 | 
			
		||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="StaticBody2D"]
 | 
			
		||||
shape = SubResource("RectangleShape2D_nynyi")
 | 
			
		||||
 | 
			
		||||
[node name="RigidBody2D" type="RigidBody2D" parent="."]
 | 
			
		||||
position = Vector2(307, 34)
 | 
			
		||||
rotation = 0.785398
 | 
			
		||||
metadata/_edit_group_ = true
 | 
			
		||||
 | 
			
		||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="RigidBody2D"]
 | 
			
		||||
shape = SubResource("RectangleShape2D_gv8hf")
 | 
			
		||||
debug_color = Color(0.850993, 0.368517, 0.134324, 0.42)
 | 
			
		||||
 | 
			
		||||
[node name="RigidBody2D2" type="RigidBody2D" parent="."]
 | 
			
		||||
position = Vector2(247, 100)
 | 
			
		||||
rotation = 1.33752
 | 
			
		||||
metadata/_edit_group_ = true
 | 
			
		||||
 | 
			
		||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="RigidBody2D2"]
 | 
			
		||||
shape = SubResource("RectangleShape2D_gv8hf")
 | 
			
		||||
debug_color = Color(0.850993, 0.368517, 0.134324, 0.42)
 | 
			
		||||
 | 
			
		||||
[node name="StaticBody2D2" type="StaticBody2D" parent="."]
 | 
			
		||||
 | 
			
		||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="StaticBody2D2"]
 | 
			
		||||
position = Vector2(295, 431)
 | 
			
		||||
shape = SubResource("WorldBoundaryShape2D_ukrrp")
 | 
			
		||||
 | 
			
		||||
[node name="Trigger" type="Area2D" parent="."]
 | 
			
		||||
position = Vector2(387, 339)
 | 
			
		||||
position = Vector2(400, 339)
 | 
			
		||||
script = ExtResource("1_tp4vr")
 | 
			
		||||
metadata/_edit_group_ = true
 | 
			
		||||
 | 
			
		||||
@ -59,37 +28,99 @@ metadata/_edit_group_ = true
 | 
			
		||||
shape = SubResource("CircleShape2D_785vb")
 | 
			
		||||
debug_color = Color(0.489643, 0.4608, 0.929032, 0.42)
 | 
			
		||||
 | 
			
		||||
[node name="CharacterBody2D" type="CharacterBody2D" parent="."]
 | 
			
		||||
position = Vector2(279, 68)
 | 
			
		||||
script = ExtResource("2_o8d6o")
 | 
			
		||||
[node name="level" type="Node2D" parent="."]
 | 
			
		||||
 | 
			
		||||
[node name="StaticBody2D" type="StaticBody2D" parent="level"]
 | 
			
		||||
position = Vector2(296, 246)
 | 
			
		||||
metadata/_edit_group_ = true
 | 
			
		||||
 | 
			
		||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="CharacterBody2D"]
 | 
			
		||||
shape = SubResource("CapsuleShape2D_wfabo")
 | 
			
		||||
debug_color = Color(0.416871, 0.601139, 0.192736, 0.42)
 | 
			
		||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="level/StaticBody2D"]
 | 
			
		||||
shape = SubResource("RectangleShape2D_nynyi")
 | 
			
		||||
 | 
			
		||||
[node name="StaticBody2D3" type="StaticBody2D" parent="."]
 | 
			
		||||
position = Vector2(388, 223)
 | 
			
		||||
[node name="StaticBody2D2" type="StaticBody2D" parent="level"]
 | 
			
		||||
 | 
			
		||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="level/StaticBody2D2"]
 | 
			
		||||
position = Vector2(295, 431)
 | 
			
		||||
shape = SubResource("WorldBoundaryShape2D_ukrrp")
 | 
			
		||||
 | 
			
		||||
[node name="StaticBody2D3" type="StaticBody2D" parent="level"]
 | 
			
		||||
position = Vector2(394, 228)
 | 
			
		||||
metadata/_edit_group_ = true
 | 
			
		||||
 | 
			
		||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="StaticBody2D3"]
 | 
			
		||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="level/StaticBody2D3"]
 | 
			
		||||
rotation = -0.412146
 | 
			
		||||
shape = SubResource("RectangleShape2D_nynyi")
 | 
			
		||||
 | 
			
		||||
[node name="StaticBody2D4" type="StaticBody2D" parent="level"]
 | 
			
		||||
position = Vector2(109, 358)
 | 
			
		||||
metadata/_edit_group_ = true
 | 
			
		||||
 | 
			
		||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="level/StaticBody2D4"]
 | 
			
		||||
shape = SubResource("RectangleShape2D_nynyi")
 | 
			
		||||
 | 
			
		||||
[node name="StaticBody2D5" type="StaticBody2D" parent="level"]
 | 
			
		||||
position = Vector2(182, 299)
 | 
			
		||||
metadata/_edit_group_ = true
 | 
			
		||||
 | 
			
		||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="level/StaticBody2D5"]
 | 
			
		||||
shape = SubResource("RectangleShape2D_nynyi")
 | 
			
		||||
 | 
			
		||||
[node name="StaticBody2D6" type="StaticBody2D" parent="level"]
 | 
			
		||||
position = Vector2(161, 225)
 | 
			
		||||
metadata/_edit_group_ = true
 | 
			
		||||
 | 
			
		||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="level/StaticBody2D6"]
 | 
			
		||||
shape = SubResource("RectangleShape2D_nynyi")
 | 
			
		||||
 | 
			
		||||
[node name="crates" type="Node2D" parent="."]
 | 
			
		||||
 | 
			
		||||
[node name="RigidBody2D" type="RigidBody2D" parent="crates"]
 | 
			
		||||
position = Vector2(307, 34)
 | 
			
		||||
rotation = 0.785398
 | 
			
		||||
metadata/_edit_group_ = true
 | 
			
		||||
 | 
			
		||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="crates/RigidBody2D"]
 | 
			
		||||
shape = SubResource("RectangleShape2D_gv8hf")
 | 
			
		||||
debug_color = Color(0.850993, 0.368517, 0.134324, 0.42)
 | 
			
		||||
 | 
			
		||||
[node name="RigidBody2D2" type="RigidBody2D" parent="crates"]
 | 
			
		||||
position = Vector2(247, 100)
 | 
			
		||||
rotation = 1.33752
 | 
			
		||||
metadata/_edit_group_ = true
 | 
			
		||||
 | 
			
		||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="crates/RigidBody2D2"]
 | 
			
		||||
shape = SubResource("RectangleShape2D_gv8hf")
 | 
			
		||||
debug_color = Color(0.850993, 0.368517, 0.134324, 0.42)
 | 
			
		||||
 | 
			
		||||
[node name="RigidBody2D3" type="RigidBody2D" parent="crates"]
 | 
			
		||||
position = Vector2(355, 185)
 | 
			
		||||
rotation = 2.67504
 | 
			
		||||
scale = Vector2(1, 1)
 | 
			
		||||
shape = SubResource("RectangleShape2D_nynyi")
 | 
			
		||||
 | 
			
		||||
[node name="StaticBody2D4" type="StaticBody2D" parent="."]
 | 
			
		||||
position = Vector2(180, 364)
 | 
			
		||||
metadata/_edit_group_ = true
 | 
			
		||||
 | 
			
		||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="StaticBody2D4"]
 | 
			
		||||
shape = SubResource("RectangleShape2D_nynyi")
 | 
			
		||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="crates/RigidBody2D3"]
 | 
			
		||||
shape = SubResource("RectangleShape2D_gv8hf")
 | 
			
		||||
debug_color = Color(0.850993, 0.368517, 0.134324, 0.42)
 | 
			
		||||
 | 
			
		||||
[node name="StaticBody2D5" type="StaticBody2D" parent="."]
 | 
			
		||||
position = Vector2(235, 291)
 | 
			
		||||
[node name="RigidBody2D4" type="RigidBody2D" parent="crates"]
 | 
			
		||||
position = Vector2(138.409, 137.33)
 | 
			
		||||
rotation = -0.933105
 | 
			
		||||
scale = Vector2(1, 1)
 | 
			
		||||
metadata/_edit_group_ = true
 | 
			
		||||
 | 
			
		||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="StaticBody2D5"]
 | 
			
		||||
shape = SubResource("RectangleShape2D_nynyi")
 | 
			
		||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="crates/RigidBody2D4"]
 | 
			
		||||
shape = SubResource("RectangleShape2D_gv8hf")
 | 
			
		||||
debug_color = Color(0.850993, 0.368517, 0.134324, 0.42)
 | 
			
		||||
 | 
			
		||||
[node name="CharacterBody2D" parent="." instance=ExtResource("3_70p4h")]
 | 
			
		||||
position = Vector2(407, 65)
 | 
			
		||||
 | 
			
		||||
[node name="Area2D" parent="." instance=ExtResource("4_vo7vc")]
 | 
			
		||||
position = Vector2(-95, 221)
 | 
			
		||||
 | 
			
		||||
[node name="SceneManager" type="Node" parent="."]
 | 
			
		||||
unique_name_in_owner = true
 | 
			
		||||
script = ExtResource("5_w3sh3")
 | 
			
		||||
 | 
			
		||||
[connection signal="areatrigger" from="Trigger" to="." method="_on_trigger_areatrigger"]
 | 
			
		||||
[connection signal="body_entered" from="Trigger" to="Trigger" method="_on_body_entered"]
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										15
									
								
								ahmedgg/scenes/bullet.tscn
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								ahmedgg/scenes/bullet.tscn
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,15 @@
 | 
			
		||||
[gd_scene load_steps=3 format=3 uid="uid://dg6vhq7diydcj"]
 | 
			
		||||
 | 
			
		||||
[ext_resource type="Script" path="res://bullet.gd" id="1_oufr4"]
 | 
			
		||||
 | 
			
		||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_5fful"]
 | 
			
		||||
size = Vector2(8, 2)
 | 
			
		||||
 | 
			
		||||
[node name="Area2D" type="Area2D"]
 | 
			
		||||
script = ExtResource("1_oufr4")
 | 
			
		||||
 | 
			
		||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
 | 
			
		||||
shape = SubResource("RectangleShape2D_5fful")
 | 
			
		||||
debug_color = Color(0.900724, 0.259856, 0.444017, 0.42)
 | 
			
		||||
 | 
			
		||||
[connection signal="body_entered" from="." to="." method="_on_body_entered"]
 | 
			
		||||
							
								
								
									
										39
									
								
								ahmedgg/scenes/player.tscn
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								ahmedgg/scenes/player.tscn
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,39 @@
 | 
			
		||||
[gd_scene load_steps=4 format=3 uid="uid://b0d1gs2knc2l8"]
 | 
			
		||||
 | 
			
		||||
[ext_resource type="Script" path="res://scripts/Player.gd" id="1_rdo8w"]
 | 
			
		||||
 | 
			
		||||
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_wfabo"]
 | 
			
		||||
 | 
			
		||||
[sub_resource type="GDScript" id="GDScript_46ryu"]
 | 
			
		||||
script/source = "extends Node2D
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# Called when the node enters the scene tree for the first time.
 | 
			
		||||
func _ready() -> void:
 | 
			
		||||
	pass # Replace with function body.
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
 | 
			
		||||
func _process(delta: float) -> void:
 | 
			
		||||
	pass
 | 
			
		||||
"
 | 
			
		||||
 | 
			
		||||
[node name="CharacterBody2D" type="CharacterBody2D"]
 | 
			
		||||
script = ExtResource("1_rdo8w")
 | 
			
		||||
 | 
			
		||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
 | 
			
		||||
shape = SubResource("CapsuleShape2D_wfabo")
 | 
			
		||||
debug_color = Color(0.416871, 0.601139, 0.192736, 0.42)
 | 
			
		||||
 | 
			
		||||
[node name="right_RayCast2D" type="RayCast2D" parent="."]
 | 
			
		||||
target_position = Vector2(27, 0)
 | 
			
		||||
 | 
			
		||||
[node name="left_RayCast2D" type="RayCast2D" parent="."]
 | 
			
		||||
target_position = Vector2(-27, 0)
 | 
			
		||||
 | 
			
		||||
[node name="rightTarget_Node2D" type="Node2D" parent="."]
 | 
			
		||||
position = Vector2(21, -20)
 | 
			
		||||
 | 
			
		||||
[node name="leftTarget_Node2D" type="Node2D" parent="."]
 | 
			
		||||
position = Vector2(15, -20)
 | 
			
		||||
script = SubResource("GDScript_46ryu")
 | 
			
		||||
@ -3,6 +3,19 @@ extends CharacterBody2D
 | 
			
		||||
 | 
			
		||||
const SPEED = 300.0
 | 
			
		||||
const JUMP_VELOCITY = -400.0
 | 
			
		||||
const PUSH_FORCE = 500
 | 
			
		||||
 | 
			
		||||
var faceLeft=false
 | 
			
		||||
var pushRightEnabled = false
 | 
			
		||||
var pushLeftEnabled = false
 | 
			
		||||
var pushTarget
 | 
			
		||||
@onready var right_target: Node2D = $rightTarget_Node2D
 | 
			
		||||
@onready var left_target: Node2D = $leftTarget_Node2D
 | 
			
		||||
 | 
			
		||||
@onready var right_cast: RayCast2D = $right_RayCast2D
 | 
			
		||||
@onready var left_cast: RayCast2D = $left_RayCast2D
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
func _physics_process(delta: float) -> void:
 | 
			
		||||
@ -10,20 +23,60 @@ func _physics_process(delta: float) -> void:
 | 
			
		||||
	if not is_on_floor():
 | 
			
		||||
		velocity += get_gravity() * delta
 | 
			
		||||
 | 
			
		||||
	# Handle jump.
 | 
			
		||||
	# Handle jump.right_cast
 | 
			
		||||
	if Input.is_action_just_pressed("ui_accept") and is_on_floor():
 | 
			
		||||
		velocity.y = JUMP_VELOCITY
 | 
			
		||||
 | 
			
		||||
	# Get the input direction and handle the movement/deceleration.
 | 
			
		||||
	# As good practice, you should replace UI actions with custom gameplay actions.
 | 
			
		||||
	var direction := Input.get_axis("ui_left", "ui_right")
 | 
			
		||||
	var direction := Input.get_axis("left", "right")
 | 
			
		||||
	if Input.is_action_just_pressed("shove") && pushRightEnabled && faceLeft==false:
 | 
			
		||||
		pushTarget.apply_central_impulse(Vector2(1,0)*PUSH_FORCE)
 | 
			
		||||
		pushRightEnabled=false
 | 
			
		||||
	
 | 
			
		||||
	if Input.is_action_just_pressed("shove") && pushLeftEnabled && faceLeft==true:
 | 
			
		||||
		pushTarget.apply_central_impulse(Vector2(-1,0)* PUSH_FORCE)
 | 
			
		||||
		pushLeftEnabled = false
 | 
			
		||||
	
 | 
			
		||||
	#shoot attack
 | 
			
		||||
	if Input.is_action_just_pressed("shoot"):
 | 
			
		||||
		if faceLeft == false:
 | 
			
		||||
			%SceneManager.makeBullet(right_target.global_transform,700)
 | 
			
		||||
		if faceLeft == true:
 | 
			
		||||
			%SceneManager.makeBullet(left_target.global_transform,-700)
 | 
			
		||||
 | 
			
		||||
	
 | 
			
		||||
	
 | 
			
		||||
	if direction:
 | 
			
		||||
		velocity.x = direction * SPEED
 | 
			
		||||
	else:
 | 
			
		||||
		velocity.x = move_toward(velocity.x, 0, SPEED)
 | 
			
		||||
	if direction<0:
 | 
			
		||||
		faceLeft=true
 | 
			
		||||
	if direction>0:
 | 
			
		||||
		faceLeft=false
 | 
			
		||||
		
 | 
			
		||||
 | 
			
		||||
	move_and_slide()
 | 
			
		||||
	if right_cast.is_colliding():
 | 
			
		||||
		print("something on my right")
 | 
			
		||||
		var collider=right_cast.get_collider()
 | 
			
		||||
		if collider is Node:
 | 
			
		||||
			if collider is RigidBody2D:
 | 
			
		||||
				print("shove this crate")
 | 
			
		||||
				#record that we can shove right
 | 
			
		||||
				pushRightEnabled = true
 | 
			
		||||
				#record what object we shove
 | 
			
		||||
				pushTarget = collider
 | 
			
		||||
	if left_cast.is_colliding():
 | 
			
		||||
		var collider = left_cast.get_collider()
 | 
			
		||||
		if collider is Node:
 | 
			
		||||
			if collider is RigidBody2D:
 | 
			
		||||
				pushLeftEnabled = true
 | 
			
		||||
				pushTarget = collider
 | 
			
		||||
	
 | 
			
		||||
	for i in get_slide_collision_count():
 | 
			
		||||
		var c=get_slide_collision(i)
 | 
			
		||||
		if c.get_collider() is RigidBody2D:
 | 
			
		||||
			c.get_collider().apply_central_impulse(-c.get_normal() * 60)
 | 
			
		||||
			
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										31
									
								
								ahmedgg/scripts/scene_manager.gd
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								ahmedgg/scripts/scene_manager.gd
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,31 @@
 | 
			
		||||
extends Node
 | 
			
		||||
 | 
			
		||||
var bulletsFiredTotal = 0
 | 
			
		||||
var bulletsMadeTotal = 0
 | 
			
		||||
var bulletArray = []
 | 
			
		||||
 | 
			
		||||
var bullet = preload("res://scenes/bullet.tscn")
 | 
			
		||||
 | 
			
		||||
# Bullet factor - makes bullets
 | 
			
		||||
func bulletFactory():
 | 
			
		||||
	var mybullet
 | 
			
		||||
	if bulletArray.size()<4:
 | 
			
		||||
		print("new bullet at factory")
 | 
			
		||||
		mybullet = bullet.instantiate()
 | 
			
		||||
		mybullet.connect("hit", bulletHit)
 | 
			
		||||
	else:
 | 
			
		||||
		mybullet = bulletArray.pop_back()
 | 
			
		||||
		print("recycled bullet")
 | 
			
		||||
	bulletArray.push_front(mybullet)
 | 
			
		||||
	return mybullet
 | 
			
		||||
 | 
			
		||||
# Order desk for bullets
 | 
			
		||||
 | 
			
		||||
func makeBullet(position,speed):
 | 
			
		||||
	print("make a bullet")
 | 
			
		||||
	var newBullet = bulletFactory()
 | 
			
		||||
	owner.add_child(newBullet)
 | 
			
		||||
	newBullet.setSpeed(speed)
 | 
			
		||||
	newBullet.transform = position
 | 
			
		||||
func bulletHit(bullet, body):
 | 
			
		||||
	print("tell game controller we hit something")
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user