spawns, bullets, factory
This commit is contained in:
parent
ad3d83e5bd
commit
eac97fda20
16
Scenes/bullet.tscn
Normal file
16
Scenes/bullet.tscn
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
[gd_scene load_steps=3 format=3 uid="uid://clevnux6u2ybx"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" uid="uid://bsrl75gqbvfkf" path="res://Scripts/bullet.gd" id="1_xjght"]
|
||||||
|
|
||||||
|
[sub_resource type="RectangleShape2D" id="RectangleShape2D_oduel"]
|
||||||
|
size = Vector2(6, 4)
|
||||||
|
|
||||||
|
[node name="Bullet" type="Area2D"]
|
||||||
|
script = ExtResource("1_xjght")
|
||||||
|
metadata/_edit_group_ = true
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||||
|
shape = SubResource("RectangleShape2D_oduel")
|
||||||
|
debug_color = Color(0.997962, 0, 0.153889, 0.42)
|
||||||
|
|
||||||
|
[connection signal="body_entered" from="." to="." method="_on_body_entered"]
|
11
Scenes/crate.tscn
Normal file
11
Scenes/crate.tscn
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
[gd_scene load_steps=2 format=3 uid="uid://cjlmg7kqu5u5t"]
|
||||||
|
|
||||||
|
[sub_resource type="RectangleShape2D" id="RectangleShape2D_m3ihr"]
|
||||||
|
|
||||||
|
[node name="Crate" type="RigidBody2D" groups=["pushables", "shootables"]]
|
||||||
|
rotation = -0.54389
|
||||||
|
metadata/_edit_group_ = true
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||||
|
shape = SubResource("RectangleShape2D_m3ihr")
|
||||||
|
debug_color = Color(0.783958, 0.434081, 7.70092e-07, 0.42)
|
@ -1,21 +1,28 @@
|
|||||||
[gd_scene load_steps=8 format=3 uid="uid://c3nfwlo4i3hne"]
|
[gd_scene load_steps=11 format=3 uid="uid://c3nfwlo4i3hne"]
|
||||||
|
|
||||||
[ext_resource type="Script" path="res://Scripts/gamecontroller.gd" id="1_llgwy"]
|
[ext_resource type="Script" uid="uid://bt6s0tpg6lrha" path="res://Scripts/gamecontroller.gd" id="1_llgwy"]
|
||||||
[ext_resource type="Script" path="res://Scripts/character_1.gd" id="1_xvmse"]
|
[ext_resource type="Script" uid="uid://bukc3pev3h3fq" path="res://Scripts/scene_manager.gd" id="2_1l0tm"]
|
||||||
[ext_resource type="PackedScene" uid="uid://8e4lo2w8tmxq" path="res://Scenes/trigger.tscn" id="2_ja4if"]
|
[ext_resource type="PackedScene" uid="uid://8e4lo2w8tmxq" path="res://Scenes/trigger.tscn" id="2_ja4if"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://cjlmg7kqu5u5t" path="res://Scenes/crate.tscn" id="2_wowpa"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://c5qsdhrjyxbr1" path="res://Scenes/player.tscn" id="2_wrm1d"]
|
||||||
|
[ext_resource type="Script" uid="uid://b7utyaqyc131x" path="res://Scripts/crate.gd" id="3_i6g32"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://clevnux6u2ybx" path="res://Scenes/bullet.tscn" id="6_i6g32"]
|
||||||
|
|
||||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_ejxeh"]
|
[sub_resource type="RectangleShape2D" id="RectangleShape2D_ejxeh"]
|
||||||
size = Vector2(54, 20)
|
size = Vector2(54, 20)
|
||||||
|
|
||||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_m3ihr"]
|
|
||||||
|
|
||||||
[sub_resource type="WorldBoundaryShape2D" id="WorldBoundaryShape2D_0uq2f"]
|
[sub_resource type="WorldBoundaryShape2D" id="WorldBoundaryShape2D_0uq2f"]
|
||||||
|
|
||||||
[sub_resource type="CircleShape2D" id="CircleShape2D_4vo57"]
|
[sub_resource type="RectangleShape2D" id="RectangleShape2D_1l0tm"]
|
||||||
|
size = Vector2(6, 4)
|
||||||
|
|
||||||
[node name="Game" type="Node2D"]
|
[node name="Game" type="Node2D"]
|
||||||
script = ExtResource("1_llgwy")
|
script = ExtResource("1_llgwy")
|
||||||
|
|
||||||
|
[node name="SceneManager" type="Node2D" parent="."]
|
||||||
|
unique_name_in_owner = true
|
||||||
|
script = ExtResource("2_1l0tm")
|
||||||
|
|
||||||
[node name="Platform" type="StaticBody2D" parent="."]
|
[node name="Platform" type="StaticBody2D" parent="."]
|
||||||
position = Vector2(213, 228)
|
position = Vector2(213, 228)
|
||||||
metadata/_edit_group_ = true
|
metadata/_edit_group_ = true
|
||||||
@ -23,23 +30,9 @@ metadata/_edit_group_ = true
|
|||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Platform"]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="Platform"]
|
||||||
shape = SubResource("RectangleShape2D_ejxeh")
|
shape = SubResource("RectangleShape2D_ejxeh")
|
||||||
|
|
||||||
[node name="Crate 1" type="RigidBody2D" parent="."]
|
[node name="Crate" parent="." instance=ExtResource("2_wowpa")]
|
||||||
position = Vector2(177, 34)
|
position = Vector2(177, 34)
|
||||||
rotation = -0.54389
|
script = ExtResource("3_i6g32")
|
||||||
metadata/_edit_group_ = true
|
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Crate 1"]
|
|
||||||
shape = SubResource("RectangleShape2D_m3ihr")
|
|
||||||
debug_color = Color(0.783958, 0.434081, 7.70092e-07, 0.42)
|
|
||||||
|
|
||||||
[node name="Crate 2" type="RigidBody2D" parent="."]
|
|
||||||
position = Vector2(224, 36)
|
|
||||||
rotation = -0.54389
|
|
||||||
metadata/_edit_group_ = true
|
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Crate 2"]
|
|
||||||
shape = SubResource("RectangleShape2D_m3ihr")
|
|
||||||
debug_color = Color(0.783958, 0.434081, 7.70092e-07, 0.42)
|
|
||||||
|
|
||||||
[node name="Ground" type="StaticBody2D" parent="."]
|
[node name="Ground" type="StaticBody2D" parent="."]
|
||||||
position = Vector2(214, 284)
|
position = Vector2(214, 284)
|
||||||
@ -48,17 +41,17 @@ metadata/_edit_group_ = true
|
|||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Ground"]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="Ground"]
|
||||||
shape = SubResource("WorldBoundaryShape2D_0uq2f")
|
shape = SubResource("WorldBoundaryShape2D_0uq2f")
|
||||||
|
|
||||||
[node name="Character 1" type="CharacterBody2D" parent="."]
|
[node name="Player" parent="." instance=ExtResource("2_wrm1d")]
|
||||||
position = Vector2(191, 195)
|
position = Vector2(191, 195)
|
||||||
script = ExtResource("1_xvmse")
|
|
||||||
metadata/_edit_group_ = true
|
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Character 1"]
|
|
||||||
position = Vector2(21, 4)
|
|
||||||
shape = SubResource("CircleShape2D_4vo57")
|
|
||||||
debug_color = Color(0.021275, 0.650889, 0, 0.42)
|
|
||||||
|
|
||||||
[node name="Area2D" parent="." instance=ExtResource("2_ja4if")]
|
[node name="Area2D" parent="." instance=ExtResource("2_ja4if")]
|
||||||
position = Vector2(279, 218)
|
position = Vector2(279, 218)
|
||||||
|
|
||||||
|
[node name="Bullet" parent="." instance=ExtResource("6_i6g32")]
|
||||||
|
position = Vector2(101, 87)
|
||||||
|
|
||||||
|
[node name="CollisionShape2D2" type="CollisionShape2D" parent="Bullet"]
|
||||||
|
shape = SubResource("RectangleShape2D_1l0tm")
|
||||||
|
debug_color = Color(0.997962, 0, 0.153889, 0.42)
|
||||||
|
|
||||||
[connection signal="areaTriggerSignal" from="Area2D" to="." method="_on_trigger"]
|
[connection signal="areaTriggerSignal" from="Area2D" to="." method="_on_trigger"]
|
||||||
|
29
Scenes/player.tscn
Normal file
29
Scenes/player.tscn
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
[gd_scene load_steps=3 format=3 uid="uid://c5qsdhrjyxbr1"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" uid="uid://crc2khytlo6r" path="res://Scripts/character_1.gd" id="1_v0iea"]
|
||||||
|
|
||||||
|
[sub_resource type="CircleShape2D" id="CircleShape2D_4vo57"]
|
||||||
|
|
||||||
|
[node name="Player" type="CharacterBody2D"]
|
||||||
|
position = Vector2(-21, -4)
|
||||||
|
script = ExtResource("1_v0iea")
|
||||||
|
metadata/_edit_group_ = true
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||||
|
position = Vector2(21, 4)
|
||||||
|
shape = SubResource("CircleShape2D_4vo57")
|
||||||
|
debug_color = Color(0.021275, 0.650889, 0, 0.42)
|
||||||
|
|
||||||
|
[node name="Left Cast" type="RayCast2D" parent="."]
|
||||||
|
position = Vector2(21, 4)
|
||||||
|
target_position = Vector2(-45, 0)
|
||||||
|
|
||||||
|
[node name="Right Cast" type="RayCast2D" parent="."]
|
||||||
|
position = Vector2(21, 4)
|
||||||
|
target_position = Vector2(45, 0)
|
||||||
|
|
||||||
|
[node name="RightSpawn" type="Node2D" parent="."]
|
||||||
|
metadata/_edit_group_ = true
|
||||||
|
|
||||||
|
[node name="LeftSpawn" type="Node2D" parent="."]
|
||||||
|
metadata/_edit_group_ = true
|
@ -1,6 +1,6 @@
|
|||||||
[gd_scene load_steps=3 format=3 uid="uid://8e4lo2w8tmxq"]
|
[gd_scene load_steps=3 format=3 uid="uid://8e4lo2w8tmxq"]
|
||||||
|
|
||||||
[ext_resource type="Script" path="res://Scripts/trigger.gd" id="1_ax848"]
|
[ext_resource type="Script" uid="uid://chxs44jhw6xor" path="res://Scripts/trigger.gd" id="1_ax848"]
|
||||||
|
|
||||||
[sub_resource type="CircleShape2D" id="CircleShape2D_8rju3"]
|
[sub_resource type="CircleShape2D" id="CircleShape2D_8rju3"]
|
||||||
|
|
||||||
|
18
Scripts/bullet.gd
Normal file
18
Scripts/bullet.gd
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
class_name Bullet extends Area2D
|
||||||
|
|
||||||
|
var speed:float = 700
|
||||||
|
signal bulletDamageSignal(body, bullet)
|
||||||
|
|
||||||
|
|
||||||
|
func setSpeed(value:float):
|
||||||
|
speed = value
|
||||||
|
|
||||||
|
func _physics_process(delta:float) -> void:
|
||||||
|
position += transform.x * speed * delta
|
||||||
|
|
||||||
|
|
||||||
|
func _on_body_entered(body: Node2D) -> void:
|
||||||
|
print("Bullet hitting")
|
||||||
|
if body.is_in_group("shootables"):
|
||||||
|
print("This is shootable")
|
||||||
|
bulletDamageSignal.emit(body, self)
|
1
Scripts/bullet.gd.uid
Normal file
1
Scripts/bullet.gd.uid
Normal file
@ -0,0 +1 @@
|
|||||||
|
uid://bsrl75gqbvfkf
|
@ -1,29 +1,84 @@
|
|||||||
class_name Player extends CharacterBody2D
|
class_name Player extends CharacterBody2D
|
||||||
|
|
||||||
|
@onready var left_cast: RayCast2D = $"Left Cast"
|
||||||
|
@onready var right_cast: RayCast2D = $"Right Cast"
|
||||||
|
@onready var left_spawn: Node2D = $LeftSpawn
|
||||||
|
@onready var right_spawn: Node2D = $RightSpawn
|
||||||
|
|
||||||
|
|
||||||
const SPEED = 300.0
|
const SPEED = 300.0
|
||||||
const JUMP_VELOCITY = -400.0
|
const JUMP_VELOCITY = -400.0
|
||||||
|
var direction
|
||||||
|
enum FaceDirection{LEFT, RIGHT}
|
||||||
|
var facing:FaceDirection = FaceDirection.RIGHT
|
||||||
|
|
||||||
|
var pushTarget
|
||||||
|
var pushEnabled := false
|
||||||
|
|
||||||
func _physics_process(delta: float) -> void:
|
func _physics_process(delta: float) -> void:
|
||||||
# Add the gravity.
|
# Add the gravity.
|
||||||
if not is_on_floor():
|
|
||||||
velocity += get_gravity() * delta
|
|
||||||
|
|
||||||
# Handle jump.
|
|
||||||
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
|
handle_input()
|
||||||
velocity.y = JUMP_VELOCITY
|
handle_movement(delta)
|
||||||
|
move_and_slide()
|
||||||
# Get the input direction and handle the movement/deceleration.
|
handle_collisions()
|
||||||
# As good practice, you should replace UI actions with custom gameplay actions.
|
|
||||||
var direction := Input.get_axis("ui_left", "ui_right")
|
func handle_movement(delta):
|
||||||
if direction:
|
if direction:
|
||||||
velocity.x = direction * SPEED
|
velocity.x = direction * SPEED
|
||||||
else:
|
else:
|
||||||
velocity.x = move_toward(velocity.x, 0, SPEED)
|
velocity.x = move_toward(velocity.x, 0, SPEED)
|
||||||
|
|
||||||
move_and_slide()
|
if not is_on_floor():
|
||||||
|
velocity += get_gravity() * delta
|
||||||
|
|
||||||
|
func handle_input():
|
||||||
|
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
|
||||||
|
velocity.y = JUMP_VELOCITY
|
||||||
|
direction = Input.get_axis("ui_left", "ui_right")
|
||||||
|
if direction < 0:
|
||||||
|
facing = FaceDirection.LEFT
|
||||||
|
if direction > 0:
|
||||||
|
facing = FaceDirection.RIGHT
|
||||||
|
if Input.is_action_just_pressed("shove") && pushEnabled:
|
||||||
|
var shoveDirection:int
|
||||||
|
match facing:
|
||||||
|
FaceDirection.RIGHT:
|
||||||
|
shoveDirection = 1
|
||||||
|
FaceDirection.LEFT:
|
||||||
|
shoveDirection = -1
|
||||||
|
pushTarget.apply_central_impulse(Vector2(shoveDirection,0)*700)
|
||||||
|
if Input.is_action_just_pressed("shoot"):
|
||||||
|
print("Ima shoot")
|
||||||
|
match facing:
|
||||||
|
FaceDirection.RIGHT:
|
||||||
|
print("shoot to right")
|
||||||
|
%SceneManager.makeBullet(right_spawn.global_transform, 700)
|
||||||
|
FaceDirection.LEFT:
|
||||||
|
%SceneManager.makeBullet(left_spawn.global_transform, -700)
|
||||||
|
|
||||||
|
func handle_collisions():
|
||||||
for i in get_slide_collision_count():
|
for i in get_slide_collision_count():
|
||||||
var c = get_slide_collision(i)
|
var c = get_slide_collision(i)
|
||||||
if c.get_collider() is RigidBody2D:
|
if c.get_collider() is RigidBody2D:
|
||||||
c.get_collider().apply_central_impulse(-c.get_normal() * 100)
|
c.get_collider().apply_central_impulse(-c.get_normal() * 100)
|
||||||
|
|
||||||
|
if right_cast.is_colliding() && facing ==FaceDirection.RIGHT:
|
||||||
|
print("RC is colliding")
|
||||||
|
var collider = right_cast.get_collider()
|
||||||
|
if collider is Node && collider is RigidBody2D && collider.is_in_group("pushables"):
|
||||||
|
pushTarget = collider
|
||||||
|
pushEnabled = true
|
||||||
|
|
||||||
|
if left_cast.is_colliding() && facing==FaceDirection.LEFT:
|
||||||
|
var collider = left_cast.get_collider()
|
||||||
|
if collider is Node && collider is RigidBody2D:
|
||||||
|
pushTarget = collider
|
||||||
|
pushEnabled = true
|
||||||
|
|
||||||
|
|
||||||
|
if not right_cast.is_colliding() && not left_cast.is_colliding():
|
||||||
|
pushEnabled = false
|
||||||
|
|
||||||
|
1
Scripts/character_1.gd.uid
Normal file
1
Scripts/character_1.gd.uid
Normal file
@ -0,0 +1 @@
|
|||||||
|
uid://crc2khytlo6r
|
1
Scripts/crate.gd
Normal file
1
Scripts/crate.gd
Normal file
@ -0,0 +1 @@
|
|||||||
|
class_name Crate extends RigidBody2D
|
1
Scripts/crate.gd.uid
Normal file
1
Scripts/crate.gd.uid
Normal file
@ -0,0 +1 @@
|
|||||||
|
uid://b7utyaqyc131x
|
@ -15,3 +15,7 @@ func _on_trigger(effect: Variant, body: Variant) -> void:
|
|||||||
print("GC sees trigger "+effect)
|
print("GC sees trigger "+effect)
|
||||||
if not body is Player:
|
if not body is Player:
|
||||||
body.queue_free()
|
body.queue_free()
|
||||||
|
|
||||||
|
func bulletDamage(body, bullet):
|
||||||
|
print("GC knows about bullet hit")
|
||||||
|
body.queue_free()
|
||||||
|
1
Scripts/gamecontroller.gd.uid
Normal file
1
Scripts/gamecontroller.gd.uid
Normal file
@ -0,0 +1 @@
|
|||||||
|
uid://bt6s0tpg6lrha
|
34
Scripts/scene_manager.gd
Normal file
34
Scripts/scene_manager.gd
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
class_name SceneManager extends Node2D
|
||||||
|
var bulletArray = []
|
||||||
|
var totalAllowedBullets = 7
|
||||||
|
var bullet = preload("res://Scenes/bullet.tscn")
|
||||||
|
@onready var game: 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
|
||||||
|
|
||||||
|
# makes and recycles bullets
|
||||||
|
func bulletFactory():
|
||||||
|
var myBullet:Bullet
|
||||||
|
if bulletArray.size() < totalAllowedBullets:
|
||||||
|
#make a new bullet
|
||||||
|
myBullet = bullet.instantiate()
|
||||||
|
myBullet.bulletDamageSignal.connect(game.bulletDamage)
|
||||||
|
owner.add_child(myBullet)
|
||||||
|
else:
|
||||||
|
myBullet = bulletArray.pop_back()
|
||||||
|
|
||||||
|
bulletArray.push_front(myBullet)
|
||||||
|
return myBullet
|
||||||
|
|
||||||
|
func makeBullet(position, speed):
|
||||||
|
var someBullet = bulletFactory()
|
||||||
|
someBullet.setSpeed(speed)
|
||||||
|
#position the bullet
|
||||||
|
someBullet.transform = position
|
1
Scripts/scene_manager.gd.uid
Normal file
1
Scripts/scene_manager.gd.uid
Normal file
@ -0,0 +1 @@
|
|||||||
|
uid://bukc3pev3h3fq
|
1
Scripts/trigger.gd.uid
Normal file
1
Scripts/trigger.gd.uid
Normal file
@ -0,0 +1 @@
|
|||||||
|
uid://chxs44jhw6xor
|
@ -12,5 +12,18 @@ config_version=5
|
|||||||
|
|
||||||
config/name="LSSJulyGameTTL"
|
config/name="LSSJulyGameTTL"
|
||||||
run/main_scene="res://Scenes/game.tscn"
|
run/main_scene="res://Scenes/game.tscn"
|
||||||
config/features=PackedStringArray("4.3", "Forward Plus")
|
config/features=PackedStringArray("4.4", "Forward Plus")
|
||||||
config/icon="res://icon.svg"
|
config/icon="res://icon.svg"
|
||||||
|
|
||||||
|
[input]
|
||||||
|
|
||||||
|
shove={
|
||||||
|
"deadzone": 0.2,
|
||||||
|
"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":90,"key_label":0,"unicode":122,"location":0,"echo":false,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
shoot={
|
||||||
|
"deadzone": 0.2,
|
||||||
|
"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":70,"key_label":0,"unicode":102,"location":0,"echo":false,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user