stuff
This commit is contained in:
parent
77eb50f69e
commit
abd5200f21
14
Scenes/Crate.tscn
Normal file
14
Scenes/Crate.tscn
Normal file
@ -0,0 +1,14 @@
|
||||
[gd_scene load_steps=3 format=3 uid="uid://lwju71dirkcy"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://diuug3xgjo1se" path="res://scripts/crate.gd" id="1_qgfyo"]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_r8wv2"]
|
||||
|
||||
[node name="Crate" type="RigidBody2D" groups=["pushable"]]
|
||||
rotation = 0.90108
|
||||
script = ExtResource("1_qgfyo")
|
||||
metadata/_edit_group_ = true
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
shape = SubResource("RectangleShape2D_r8wv2")
|
||||
debug_color = Color(0.875314, 0.341029, 0.122297, 0.42)
|
15
Scenes/bullet.tscn
Normal file
15
Scenes/bullet.tscn
Normal file
@ -0,0 +1,15 @@
|
||||
[gd_scene load_steps=3 format=3 uid="uid://vycud8mssmb3"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://doxxkkrf00ef2" path="res://scripts/bullet.gd" id="1_xjght"]
|
||||
|
||||
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_4mw4s"]
|
||||
|
||||
[node name="bullet" type="Area2D"]
|
||||
script = ExtResource("1_xjght")
|
||||
metadata/_edit_group_ = true
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
rotation = 1.58879
|
||||
shape = SubResource("CapsuleShape2D_4mw4s")
|
||||
|
||||
[connection signal="body_entered" from="." to="." method="_on_body_entered"]
|
25
Scenes/player.tscn
Normal file
25
Scenes/player.tscn
Normal file
@ -0,0 +1,25 @@
|
||||
[gd_scene load_steps=3 format=3 uid="uid://c5uf1o0s4syv7"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://bxlrsqltut2xn" path="res://scripts/Player.gd" id="1_v0iea"]
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_ag0er"]
|
||||
|
||||
[node name="Player" type="CharacterBody2D"]
|
||||
script = ExtResource("1_v0iea")
|
||||
metadata/_edit_group_ = true
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
shape = SubResource("CircleShape2D_ag0er")
|
||||
debug_color = Color(3.08037e-06, 0.641589, 0.331866, 0.42)
|
||||
|
||||
[node name="RightCast" type="RayCast2D" parent="."]
|
||||
target_position = Vector2(48, 0)
|
||||
|
||||
[node name="LeftCast" type="RayCast2D" parent="."]
|
||||
target_position = Vector2(-47, 0)
|
||||
|
||||
[node name="BulletSpawnPointRight" type="Node2D" parent="."]
|
||||
position = Vector2(16, -5)
|
||||
|
||||
[node name="BulletSpawnPointLeft" type="Node2D" parent="."]
|
||||
position = Vector2(-16, -5)
|
@ -1,21 +1,23 @@
|
||||
[gd_scene load_steps=8 format=3 uid="uid://ibkufgrwjwro"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://buhkldpol3slp" path="res://scripts/gamecontroller.gd" id="1_3d84a"]
|
||||
[ext_resource type="Script" uid="uid://bxlrsqltut2xn" path="res://scripts/Player.gd" id="1_r8wv2"]
|
||||
[ext_resource type="PackedScene" uid="uid://4a4u47173cyb" path="res://Scenes/trigger.tscn" id="2_lptsb"]
|
||||
[ext_resource type="Script" uid="uid://bo0opwq3l73ec" path="res://scripts/scene_manager.gd" id="2_t43dh"]
|
||||
[ext_resource type="PackedScene" uid="uid://lwju71dirkcy" path="res://Scenes/Crate.tscn" id="3_u2cf2"]
|
||||
[ext_resource type="PackedScene" uid="uid://c5uf1o0s4syv7" path="res://Scenes/player.tscn" id="4_f0he5"]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_ag0er"]
|
||||
size = Vector2(82, 20)
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_r8wv2"]
|
||||
|
||||
[sub_resource type="WorldBoundaryShape2D" id="WorldBoundaryShape2D_ag0er"]
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_ag0er"]
|
||||
|
||||
[node name="Game" type="Node2D"]
|
||||
script = ExtResource("1_3d84a")
|
||||
|
||||
[node name="SCENEMANAGER" type="Node2D" parent="."]
|
||||
unique_name_in_owner = true
|
||||
script = ExtResource("2_t43dh")
|
||||
|
||||
[node name="StaticBody2D" type="StaticBody2D" parent="."]
|
||||
position = Vector2(113, 130)
|
||||
metadata/_edit_group_ = true
|
||||
@ -23,23 +25,11 @@ metadata/_edit_group_ = true
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="StaticBody2D"]
|
||||
shape = SubResource("RectangleShape2D_ag0er")
|
||||
|
||||
[node name="RigidBody2D" type="RigidBody2D" parent="."]
|
||||
[node name="Crate1" parent="." instance=ExtResource("3_u2cf2")]
|
||||
position = Vector2(128, 41)
|
||||
rotation = 0.90108
|
||||
metadata/_edit_group_ = true
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="RigidBody2D"]
|
||||
shape = SubResource("RectangleShape2D_r8wv2")
|
||||
debug_color = Color(0.875314, 0.341029, 0.122297, 0.42)
|
||||
|
||||
[node name="RigidBody2D2" type="RigidBody2D" parent="."]
|
||||
position = Vector2(114, -1)
|
||||
rotation = 0.90108
|
||||
metadata/_edit_group_ = true
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="RigidBody2D2"]
|
||||
shape = SubResource("RectangleShape2D_r8wv2")
|
||||
debug_color = Color(0.875314, 0.341029, 0.122297, 0.42)
|
||||
[node name="Crate2" parent="." instance=ExtResource("3_u2cf2")]
|
||||
position = Vector2(171, 73)
|
||||
|
||||
[node name="ground" type="StaticBody2D" parent="."]
|
||||
position = Vector2(186, 270)
|
||||
@ -48,16 +38,10 @@ metadata/_edit_group_ = true
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="ground"]
|
||||
shape = SubResource("WorldBoundaryShape2D_ag0er")
|
||||
|
||||
[node name="CharacterBody2D" type="CharacterBody2D" parent="."]
|
||||
[node name="Player" parent="." instance=ExtResource("4_f0he5")]
|
||||
position = Vector2(127, 108)
|
||||
script = ExtResource("1_r8wv2")
|
||||
metadata/_edit_group_ = true
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="CharacterBody2D"]
|
||||
shape = SubResource("CircleShape2D_ag0er")
|
||||
debug_color = Color(3.08037e-06, 0.641589, 0.331866, 0.42)
|
||||
|
||||
[node name="Area2D" parent="." instance=ExtResource("2_lptsb")]
|
||||
position = Vector2(88, 86)
|
||||
position = Vector2(82, 87)
|
||||
|
||||
[connection signal="areaTriggerSignal" from="Area2D" to="." method="_on_trigger"]
|
||||
|
@ -14,3 +14,16 @@ config/name="reallygoodgame"
|
||||
run/main_scene="uid://ibkufgrwjwro"
|
||||
config/features=PackedStringArray("4.4", "Forward Plus")
|
||||
config/icon="res://icon.svg"
|
||||
|
||||
[input]
|
||||
|
||||
ForcePush={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"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":0,"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":69,"key_label":0,"unicode":101,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
|
@ -1,14 +1,35 @@
|
||||
class_name Player extends CharacterBody2D
|
||||
|
||||
const bullet_scene = preload("res://Scenes/bullet.tscn")
|
||||
|
||||
@onready var right_cast: RayCast2D = $RightCast
|
||||
@onready var left_cast: RayCast2D = $LeftCast
|
||||
@onready var bullet_spawn_point_right: Node2D = $BulletSpawnPointRight
|
||||
@onready var bullet_spawn_point_left: Node2D = $BulletSpawnPointLeft
|
||||
|
||||
const SPEED = 300.0
|
||||
const JUMP_VELOCITY = -400.0
|
||||
const PUSH_POWER = 2000
|
||||
|
||||
var direction: float
|
||||
enum FaceDirection{LEFT, RIGHT}
|
||||
var facing: FaceDirection = FaceDirection.RIGHT
|
||||
var pushTarget: Object
|
||||
var pushEnabled: bool = false
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
# Add the gravity.
|
||||
if not is_on_floor():
|
||||
velocity += get_gravity() * delta
|
||||
handle_input(delta)
|
||||
handle_movement(delta)
|
||||
handle_collisions(delta)
|
||||
|
||||
func handle_input(delta: float) -> void:
|
||||
var dir: int = 0
|
||||
match facing:
|
||||
FaceDirection.LEFT:
|
||||
dir = -1
|
||||
FaceDirection.RIGHT:
|
||||
dir = 1
|
||||
|
||||
# Handle jump.
|
||||
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
|
||||
@ -16,14 +37,56 @@ 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")
|
||||
direction = Input.get_axis("ui_left", "ui_right")
|
||||
|
||||
if direction < 0:
|
||||
facing = FaceDirection.LEFT
|
||||
elif direction > 0:
|
||||
facing = FaceDirection.RIGHT
|
||||
|
||||
if Input.is_action_just_pressed("ForcePush") && pushEnabled:
|
||||
pushTarget.apply_central_impulse(Vector2(dir, 0) * PUSH_POWER)
|
||||
|
||||
if Input.is_action_just_pressed("Shoot"):
|
||||
var spawnAt: Node2D = bullet_spawn_point_left
|
||||
if dir == 1:
|
||||
spawnAt = bullet_spawn_point_right
|
||||
|
||||
print("make a bullet")
|
||||
var b = %SCENEMANAGER.makeBullet(spawnAt.global_transform, dir)
|
||||
|
||||
func handle_movement(delta: float) -> void:
|
||||
handle_gravity(delta)
|
||||
if direction:
|
||||
velocity.x = direction * SPEED
|
||||
else:
|
||||
velocity.x = move_toward(velocity.x, 0, SPEED)
|
||||
|
||||
move_and_slide()
|
||||
|
||||
func handle_collisions(delta: float) -> void:
|
||||
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() * 100)
|
||||
|
||||
if right_cast.is_colliding() && facing == FaceDirection.RIGHT:
|
||||
var col = right_cast.get_collider()
|
||||
if col != null && col.is_in_group("pushable"):
|
||||
pushTarget = col
|
||||
pushEnabled = true
|
||||
print("right pushable")
|
||||
elif left_cast.is_colliding() && facing == FaceDirection.LEFT:
|
||||
var col = left_cast.get_collider()
|
||||
if col != null && col.is_in_group("pushable"):
|
||||
pushTarget = col
|
||||
pushEnabled = true
|
||||
print("left pushable")
|
||||
else:
|
||||
pushEnabled = false
|
||||
pushTarget = null
|
||||
|
||||
|
||||
func handle_gravity(delta: float) -> void:
|
||||
# Add the gravity.
|
||||
if not is_on_floor():
|
||||
velocity += get_gravity() * delta
|
||||
|
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(target: Node2D, bullet: Node2D)
|
||||
|
||||
func setSpeed(val: float):
|
||||
speed = val
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
position+=transform.x*speed*delta
|
||||
|
||||
func _on_body_entered(body: Node2D) -> void:
|
||||
if body is Player:
|
||||
return
|
||||
print("emit?")
|
||||
if body is Crate && visible:
|
||||
print("emit")
|
||||
bulletDamageSignal.emit(body, self)
|
1
scripts/bullet.gd.uid
Normal file
1
scripts/bullet.gd.uid
Normal file
@ -0,0 +1 @@
|
||||
uid://doxxkkrf00ef2
|
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://diuug3xgjo1se
|
@ -13,5 +13,12 @@ func _process(delta: float) -> void:
|
||||
|
||||
func _on_trigger(effect: Variant, body: Variant) -> void:
|
||||
print("GC see trigger " + effect)
|
||||
if body.name == "world-boundary":
|
||||
return
|
||||
if not body is Player:
|
||||
body.queue_free()
|
||||
|
||||
func bulletDamage(target: Node2D, bullet: Node2D):
|
||||
print("GC sees a hit")
|
||||
target.queue_free()
|
||||
bullet.visible = false
|
||||
|
33
scripts/scene_manager.gd
Normal file
33
scripts/scene_manager.gd
Normal file
@ -0,0 +1,33 @@
|
||||
class_name SCENEMANAGER extends Node2D
|
||||
|
||||
const bulletscn = preload("res://Scenes/bullet.tscn")
|
||||
@onready var game: Node2D = $".."
|
||||
|
||||
var bullets: Array[Bullet] = []
|
||||
const MAX_BULLETS = 10
|
||||
var current_bullet = 0
|
||||
|
||||
# makes and recycles bullets
|
||||
func bulletFactory() -> Bullet:
|
||||
if len(bullets) < MAX_BULLETS:
|
||||
# create new bujllet
|
||||
var b = bulletscn.instantiate()
|
||||
b.bulletDamageSignal.connect(game.bulletDamage)
|
||||
add_child(b)
|
||||
bullets.append(b)
|
||||
return b
|
||||
else:
|
||||
# recycle
|
||||
var i = current_bullet
|
||||
current_bullet = (current_bullet + 1) % MAX_BULLETS
|
||||
bullets[i].visible = true
|
||||
return bullets[i]
|
||||
|
||||
|
||||
func makeBullet(pos: Transform2D, dir: int) -> Node2D:
|
||||
var b = bulletFactory()
|
||||
# b.position = pos.get_origin()
|
||||
b.transform = pos
|
||||
b.setSpeed(dir * 700)
|
||||
return b
|
||||
|
1
scripts/scene_manager.gd.uid
Normal file
1
scripts/scene_manager.gd.uid
Normal file
@ -0,0 +1 @@
|
||||
uid://bo0opwq3l73ec
|
Loading…
Reference in New Issue
Block a user