working force push, working bullets
This commit is contained in:
parent
2b8c206abc
commit
7ee32c14d2
@ -20,3 +20,16 @@ config/icon="res://icon.svg"
|
||||
folder_colors={
|
||||
"res://scripts/": "green"
|
||||
}
|
||||
|
||||
[input]
|
||||
|
||||
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":83,"key_label":0,"unicode":115,"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":88,"key_label":0,"unicode":120,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
|
@ -3,7 +3,7 @@
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_dbirr"]
|
||||
size = Vector2(30, 32)
|
||||
|
||||
[node name="RigidBody2D" type="RigidBody2D" groups=["box"]]
|
||||
[node name="RigidBody2D" type="RigidBody2D" groups=["box", "shootable"]]
|
||||
position = Vector2(531, 339)
|
||||
rotation = 2.64233
|
||||
metadata/_edit_group_ = true
|
||||
|
16
novembergame/scenes/bullet.tscn
Normal file
16
novembergame/scenes/bullet.tscn
Normal file
@ -0,0 +1,16 @@
|
||||
[gd_scene load_steps=3 format=3 uid="uid://02fr3rb7e6s2"]
|
||||
|
||||
[ext_resource type="Script" path="res://scripts/bullet.gd" id="1_kc7iu"]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_m2rb6"]
|
||||
size = Vector2(11, 7)
|
||||
|
||||
[node name="Area2D" type="Area2D"]
|
||||
script = ExtResource("1_kc7iu")
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
position = Vector2(0.5, -0.5)
|
||||
shape = SubResource("RectangleShape2D_m2rb6")
|
||||
debug_color = Color(0.366555, 0.610522, 0.244131, 0.42)
|
||||
|
||||
[connection signal="body_entered" from="." to="." method="_on_body_entered"]
|
26
novembergame/scenes/character.tscn
Normal file
26
novembergame/scenes/character.tscn
Normal file
@ -0,0 +1,26 @@
|
||||
[gd_scene load_steps=3 format=3 uid="uid://cjqhmd3158nb7"]
|
||||
|
||||
[ext_resource type="Script" path="res://scripts/dudecontroller.gd" id="1_u27sl"]
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_pg3nc"]
|
||||
radius = 18.1108
|
||||
|
||||
[node name="CharacterBody2D" type="CharacterBody2D" groups=["player"]]
|
||||
script = ExtResource("1_u27sl")
|
||||
metadata/_edit_group_ = true
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
shape = SubResource("CircleShape2D_pg3nc")
|
||||
debug_color = Color(0.178776, 0.565003, 0.825276, 0.42)
|
||||
|
||||
[node name="RightRay" type="RayCast2D" parent="."]
|
||||
target_position = Vector2(28, 0)
|
||||
|
||||
[node name="LeftRay" type="RayCast2D" parent="."]
|
||||
target_position = Vector2(-29, -1)
|
||||
|
||||
[node name="RightTarget" type="Node2D" parent="."]
|
||||
position = Vector2(23, -11)
|
||||
|
||||
[node name="LeftTarget" type="Node2D" parent="."]
|
||||
position = Vector2(-24, -10)
|
@ -1,21 +1,24 @@
|
||||
[gd_scene load_steps=8 format=3 uid="uid://cmh68gsfunmwa"]
|
||||
[gd_scene load_steps=9 format=3 uid="uid://cmh68gsfunmwa"]
|
||||
|
||||
[ext_resource type="Script" path="res://scripts/dudecontroller.gd" id="1_14xrk"]
|
||||
[ext_resource type="Script" path="res://scripts/scene_manager.gd" id="1_obwxw"]
|
||||
[ext_resource type="PackedScene" uid="uid://cjqhmd3158nb7" path="res://scenes/character.tscn" id="1_p32ky"]
|
||||
[ext_resource type="Script" path="res://scripts/trigger.gd" id="2_tsnf5"]
|
||||
[ext_resource type="PackedScene" uid="uid://dm71h7adhhf8u" path="res://scenes/box.tscn" id="3_pi0u1"]
|
||||
[ext_resource type="PackedScene" uid="uid://02fr3rb7e6s2" path="res://scenes/bullet.tscn" id="4_7pxts"]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_rcjag"]
|
||||
size = Vector2(84, 12)
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_pg3nc"]
|
||||
radius = 18.1108
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_supj4"]
|
||||
|
||||
[sub_resource type="WorldBoundaryShape2D" id="WorldBoundaryShape2D_c5gsu"]
|
||||
|
||||
[node name="Game" type="Node2D"]
|
||||
|
||||
[node name="SceneManager" type="Node" parent="."]
|
||||
unique_name_in_owner = true
|
||||
script = ExtResource("1_obwxw")
|
||||
|
||||
[node name="Platform" type="StaticBody2D" parent="."]
|
||||
position = Vector2(523, 407)
|
||||
metadata/_edit_group_ = true
|
||||
@ -37,14 +40,7 @@ metadata/_edit_group_ = true
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Platform3"]
|
||||
shape = SubResource("RectangleShape2D_rcjag")
|
||||
|
||||
[node name="CharacterBody2D" type="CharacterBody2D" parent="."]
|
||||
position = Vector2(504, 382)
|
||||
script = ExtResource("1_14xrk")
|
||||
metadata/_edit_group_ = true
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="CharacterBody2D"]
|
||||
shape = SubResource("CircleShape2D_pg3nc")
|
||||
debug_color = Color(0.178776, 0.565003, 0.825276, 0.42)
|
||||
[node name="CharacterBody2D" parent="." instance=ExtResource("1_p32ky")]
|
||||
|
||||
[node name="Area2D" type="Area2D" parent="."]
|
||||
position = Vector2(519, 464)
|
||||
@ -72,4 +68,7 @@ metadata/_edit_group_ = true
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="StaticBody2D"]
|
||||
shape = SubResource("WorldBoundaryShape2D_c5gsu")
|
||||
|
||||
[node name="Area2D2" parent="." instance=ExtResource("4_7pxts")]
|
||||
position = Vector2(244, 348)
|
||||
|
||||
[connection signal="body_entered" from="Area2D" to="Area2D" method="_on_body_entered"]
|
||||
|
17
novembergame/scripts/bullet.gd
Normal file
17
novembergame/scripts/bullet.gd
Normal file
@ -0,0 +1,17 @@
|
||||
class_name Bullet extends Area2D
|
||||
|
||||
var speed = 750
|
||||
# did I hit anyone?
|
||||
signal hit(bullet, body)
|
||||
|
||||
func setSpeed(speedValue):
|
||||
speed = speedValue
|
||||
|
||||
func _physics_process(delta):
|
||||
position += transform.x * speed * delta
|
||||
|
||||
|
||||
func _on_body_entered(body: Node2D) -> void:
|
||||
print("Bullet hit something")
|
||||
if not body.is_in_group("player"):
|
||||
hit.emit(self, body)
|
@ -4,6 +4,18 @@ extends CharacterBody2D
|
||||
const SPEED = 300.0
|
||||
const JUMP_VELOCITY = -400.0
|
||||
const BUMPFORCE = 50
|
||||
const PUSHFORCE = 750
|
||||
|
||||
@onready var right_ray: RayCast2D = $RightRay
|
||||
@onready var left_ray: RayCast2D = $LeftRay
|
||||
|
||||
var faceLeft = false
|
||||
|
||||
var pushTarget
|
||||
var pushLeftEnabled = false
|
||||
var pushRightEnabled = false
|
||||
@onready var right_target: Node2D = $RightTarget
|
||||
@onready var left_target: Node2D = $LeftTarget
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
@ -18,12 +30,59 @@ func _physics_process(delta: float) -> void:
|
||||
# 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")
|
||||
if Input.is_action_just_pressed("shove") && pushRightEnabled && faceLeft == false:
|
||||
print("Shove a box")
|
||||
pushTarget.apply_central_impulse(Vector2(1,0) * PUSHFORCE * 2 )
|
||||
pushRightEnabled = false
|
||||
|
||||
if Input.is_action_just_pressed("shove") && faceLeft == true && pushLeftEnabled == true:
|
||||
pushTarget.apply_central_impulse(Vector2(-1,0) * PUSHFORCE *2 )
|
||||
pushLeftEnabled = false
|
||||
|
||||
if Input.is_action_just_pressed("shoot"):
|
||||
print("Shoot a bullet")
|
||||
var myBullet = %SceneManager.bulletFactory()
|
||||
if not faceLeft:
|
||||
myBullet.transform = right_target.global_transform
|
||||
myBullet.setSpeed(750)
|
||||
if faceLeft ==true:
|
||||
myBullet.transform = left_target.global_transform
|
||||
myBullet.setSpeed(-750)
|
||||
|
||||
if direction:
|
||||
velocity.x = direction * SPEED
|
||||
if direction >0:
|
||||
faceLeft = false
|
||||
if direction < 0:
|
||||
faceLeft = true
|
||||
else:
|
||||
velocity.x = move_toward(velocity.x, 0, SPEED)
|
||||
|
||||
move_and_slide()
|
||||
if right_ray.is_colliding():
|
||||
print("Something is on my right")
|
||||
if not faceLeft:
|
||||
var collider = right_ray.get_collider()
|
||||
if collider is Node:
|
||||
if collider.is_in_group("box"):
|
||||
print("This is a pushable box")
|
||||
pushTarget = collider
|
||||
pushRightEnabled = true
|
||||
else:
|
||||
pushRightEnabled = false
|
||||
|
||||
if left_ray.is_colliding():
|
||||
if faceLeft:
|
||||
var collider = left_ray.get_collider()
|
||||
if collider is Node:
|
||||
if collider.is_in_group("box"):
|
||||
pushTarget = collider
|
||||
pushLeftEnabled = true
|
||||
else:
|
||||
pushLeftEnabled = false
|
||||
|
||||
|
||||
|
||||
for i in get_slide_collision_count():
|
||||
var c = get_slide_collision(i)
|
||||
if c.get_collider() is RigidBody2D:
|
||||
|
30
novembergame/scripts/scene_manager.gd
Normal file
30
novembergame/scripts/scene_manager.gd
Normal file
@ -0,0 +1,30 @@
|
||||
extends Node
|
||||
|
||||
var bulletsFiredTotal :=0
|
||||
var bulletsMadeTotal :=0
|
||||
var bulletArray:Array = []
|
||||
|
||||
var bullet = preload("res://scenes/bullet.tscn")
|
||||
|
||||
func bulletFactory():
|
||||
print("Make a bullet at the factory")
|
||||
var mybullet
|
||||
|
||||
#how many bullets have been made
|
||||
if bulletArray.size() < 4:
|
||||
#make a new bullet
|
||||
mybullet = bullet.instantiate()
|
||||
mybullet.connect("hit", onBulletHit)
|
||||
owner.add_child(mybullet)
|
||||
else:
|
||||
mybullet = bulletArray.pop_back()
|
||||
bulletArray.push_front(mybullet)
|
||||
bulletsMadeTotal += 1
|
||||
return mybullet
|
||||
|
||||
func onBulletHit(bullet, body):
|
||||
print("Scene Manager knows a bullet hit something")
|
||||
bullet.setSpeed(0)
|
||||
if body.is_in_group("shootable"):
|
||||
print("explode this thing")
|
||||
body.queue_free()
|
Loading…
Reference in New Issue
Block a user