working force push working bullets
This commit is contained in:
parent
112f7ec7ee
commit
c1ff1f0a01
@ -20,3 +20,18 @@ 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)
|
||||
, 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":4194438,"key_label":0,"unicode":48,"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)
|
||||
, 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":4194439,"key_label":0,"unicode":49,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
|
@ -3,7 +3,7 @@
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_c58s7"]
|
||||
size = Vector2(46, 42)
|
||||
|
||||
[node name="RigidBody2D" type="RigidBody2D" groups=["box"]]
|
||||
[node name="RigidBody2D" type="RigidBody2D" groups=["box", "shootable"]]
|
||||
position = Vector2(588, 292)
|
||||
rotation = 0.837162
|
||||
metadata/_edit_group_ = true
|
||||
|
15
novembergame/scenes/bullet.tscn
Normal file
15
novembergame/scenes/bullet.tscn
Normal file
@ -0,0 +1,15 @@
|
||||
[gd_scene load_steps=3 format=3 uid="uid://e4o5ja1w0gph"]
|
||||
|
||||
[ext_resource type="Script" path="res://scripts/bullet.gd" id="1_mqe8j"]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_y4ewo"]
|
||||
size = Vector2(6, 2)
|
||||
|
||||
[node name="Area2D" type="Area2D"]
|
||||
script = ExtResource("1_mqe8j")
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
shape = SubResource("RectangleShape2D_y4ewo")
|
||||
debug_color = Color(0.341018, 0.620642, 0.0617414, 0.42)
|
||||
|
||||
[connection signal="body_entered" from="." to="." method="_on_body_entered"]
|
27
novembergame/scenes/character.tscn
Normal file
27
novembergame/scenes/character.tscn
Normal file
@ -0,0 +1,27 @@
|
||||
[gd_scene load_steps=3 format=3 uid="uid://b6vk2imhuhv0j"]
|
||||
|
||||
[ext_resource type="Script" path="res://scripts/dudecontroller.gd" id="1_esbkk"]
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_drde1"]
|
||||
radius = 23.0
|
||||
|
||||
[node name="CharacterBody2D" type="CharacterBody2D" groups=["player"]]
|
||||
script = ExtResource("1_esbkk")
|
||||
metadata/_edit_group_ = true
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
rotation = -0.0421956
|
||||
shape = SubResource("CircleShape2D_drde1")
|
||||
debug_color = Color(0.459127, 0.454101, 0.981072, 0.42)
|
||||
|
||||
[node name="RightRay" type="RayCast2D" parent="."]
|
||||
target_position = Vector2(36, 0)
|
||||
|
||||
[node name="LeftRay" type="RayCast2D" parent="."]
|
||||
target_position = Vector2(-36, 0)
|
||||
|
||||
[node name="RightTarget" type="Node2D" parent="."]
|
||||
position = Vector2(23, -16)
|
||||
|
||||
[node name="LeftTarget" type="Node2D" parent="."]
|
||||
position = Vector2(-23, -16)
|
@ -1,21 +1,24 @@
|
||||
[gd_scene load_steps=8 format=3 uid="uid://dmk3hbsrqhgad"]
|
||||
[gd_scene load_steps=9 format=3 uid="uid://dmk3hbsrqhgad"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://flumvyk8tafw" path="res://scenes/box.tscn" id="1_ixp3c"]
|
||||
[ext_resource type="Script" path="res://scripts/dudecontroller.gd" id="1_pin1i"]
|
||||
[ext_resource type="Script" path="res://scripts/scene_manager.gd" id="1_sylse"]
|
||||
[ext_resource type="PackedScene" uid="uid://b6vk2imhuhv0j" path="res://scenes/character.tscn" id="1_umdfo"]
|
||||
[ext_resource type="Script" path="res://scripts/trigger.gd" id="2_e4xab"]
|
||||
[ext_resource type="PackedScene" uid="uid://e4o5ja1w0gph" path="res://scenes/bullet.tscn" id="4_7436f"]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_mhewf"]
|
||||
size = Vector2(102, 12)
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_drde1"]
|
||||
radius = 23.0
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_0jo0r"]
|
||||
|
||||
[sub_resource type="WorldBoundaryShape2D" id="WorldBoundaryShape2D_jsnkw"]
|
||||
|
||||
[node name="Game" type="Node2D"]
|
||||
|
||||
[node name="SceneManager" type="Node" parent="."]
|
||||
unique_name_in_owner = true
|
||||
script = ExtResource("1_sylse")
|
||||
|
||||
[node name="Platform" type="StaticBody2D" parent="."]
|
||||
position = Vector2(584, 454)
|
||||
metadata/_edit_group_ = true
|
||||
@ -51,15 +54,7 @@ metadata/_edit_group_ = true
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Platform5"]
|
||||
shape = SubResource("RectangleShape2D_mhewf")
|
||||
|
||||
[node name="CharacterBody2D" type="CharacterBody2D" parent="."]
|
||||
position = Vector2(589, 426)
|
||||
script = ExtResource("1_pin1i")
|
||||
metadata/_edit_group_ = true
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="CharacterBody2D"]
|
||||
rotation = -0.0421956
|
||||
shape = SubResource("CircleShape2D_drde1")
|
||||
debug_color = Color(0.459127, 0.454101, 0.981072, 0.42)
|
||||
[node name="CharacterBody2D" parent="." instance=ExtResource("1_umdfo")]
|
||||
|
||||
[node name="Area2D" type="Area2D" parent="."]
|
||||
position = Vector2(576, 533)
|
||||
@ -72,7 +67,7 @@ shape = SubResource("RectangleShape2D_0jo0r")
|
||||
debug_color = Color(0.774214, 0.233911, 0.917118, 0.42)
|
||||
|
||||
[node name="RigidBody2D" parent="." instance=ExtResource("1_ixp3c")]
|
||||
position = Vector2(627, 304)
|
||||
position = Vector2(699, 304)
|
||||
|
||||
[node name="RigidBody2D2" parent="." instance=ExtResource("1_ixp3c")]
|
||||
position = Vector2(586, 229)
|
||||
@ -87,4 +82,7 @@ metadata/_edit_group_ = true
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="StaticBody2D"]
|
||||
shape = SubResource("WorldBoundaryShape2D_jsnkw")
|
||||
|
||||
[node name="Area2D2" parent="." instance=ExtResource("4_7436f")]
|
||||
position = Vector2(207, 491)
|
||||
|
||||
[connection signal="body_entered" from="Area2D" to="Area2D" method="_on_body_entered"]
|
||||
|
27
novembergame/scripts/bullet.gd
Normal file
27
novembergame/scripts/bullet.gd
Normal file
@ -0,0 +1,27 @@
|
||||
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: float) -> void:
|
||||
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)
|
||||
|
||||
|
||||
|
||||
# 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
|
@ -4,6 +4,18 @@ extends CharacterBody2D
|
||||
const SPEED = 300.0
|
||||
const JUMP_VELOCITY = -400.0
|
||||
const BUMP_FORCE = 50
|
||||
const PUSH_FORCE = 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:
|
||||
# Add the gravity.
|
||||
@ -17,12 +29,58 @@ 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) * PUSH_FORCE * 2)
|
||||
pushRightEnabled = false
|
||||
|
||||
if Input.is_action_just_pressed("shove") && faceLeft == true && pushLeftEnabled == true:
|
||||
pushTarget.apply_central_impulse(Vector2(-1,0) * PUSH_FORCE * 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:
|
||||
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():
|
||||
print("Something is on my left")
|
||||
if faceLeft:
|
||||
var collider = left_ray.get_collider()
|
||||
if collider is Node:
|
||||
if collider.is_in_group("box"):
|
||||
print("This is a pushable box")
|
||||
pushTarget = collider
|
||||
pushLeftEnabled = true
|
||||
else:
|
||||
pushLeftEnabled = false
|
||||
|
||||
for i in get_slide_collision_count():
|
||||
var c = get_slide_collision(i)
|
||||
|
31
novembergame/scripts/scene_manager.gd
Normal file
31
novembergame/scripts/scene_manager.gd
Normal file
@ -0,0 +1,31 @@
|
||||
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 bullet 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