raycasts, scene manager, magic push
This commit is contained in:
parent
c6c6031782
commit
5d34946622
18
character_body_2d.tscn
Normal file
18
character_body_2d.tscn
Normal file
@ -0,0 +1,18 @@
|
||||
[gd_scene format=3 uid="uid://cd5y08qaxwfny"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://f42eg5a0cckl" path="res://scripts/player_guy.gd" id="1_f50pn"]
|
||||
|
||||
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_80nbo"]
|
||||
|
||||
[node name="CharacterBody2D" type="CharacterBody2D" unique_id=199789825]
|
||||
script = ExtResource("1_f50pn")
|
||||
metadata/_edit_group_ = true
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=1058155484]
|
||||
shape = SubResource("CapsuleShape2D_80nbo")
|
||||
|
||||
[node name="rightcast" type="RayCast2D" parent="." unique_id=1229058621]
|
||||
target_position = Vector2(55, 0)
|
||||
|
||||
[node name="leftcast" type="RayCast2D" parent="." unique_id=1093993947]
|
||||
target_position = Vector2(-43, 0)
|
||||
16
cube.tscn
Normal file
16
cube.tscn
Normal file
@ -0,0 +1,16 @@
|
||||
[gd_scene format=3 uid="uid://d0wbtenf13iol"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://bsqvllp6h53jr" path="res://scripts/cube.gd" id="1_jbd7x"]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_80nbo"]
|
||||
size = Vector2(129, 132)
|
||||
|
||||
[node name="cube" type="RigidBody2D" unique_id=1851497894 groups=["fragile"]]
|
||||
position = Vector2(11, 12)
|
||||
script = ExtResource("1_jbd7x")
|
||||
metadata/_edit_group_ = true
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=250973730]
|
||||
position = Vector2(54.5, 56)
|
||||
shape = SubResource("RectangleShape2D_80nbo")
|
||||
debug_color = Color(0.15505362, 0.53664047, 0.94464076, 0.41960785)
|
||||
88
game.tscn
88
game.tscn
@ -1,51 +1,67 @@
|
||||
[gd_scene format=3 uid="uid://btxq5hrirovod"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://f42eg5a0cckl" path="res://scripts/player_guy.gd" id="1_80nbo"]
|
||||
[ext_resource type="Script" uid="uid://cebn6t5n1cwib" path="res://scripts/platform.gd" id="1_e2o6t"]
|
||||
[ext_resource type="Script" uid="uid://jsnpm50wknk2" path="res://scripts/game.gd" id="1_fc0e3"]
|
||||
[ext_resource type="Script" uid="uid://cxlpex21vgnla" path="res://scripts/scenemanager.gd" id="2_ryrav"]
|
||||
[ext_resource type="PackedScene" uid="uid://d0wbtenf13iol" path="res://cube.tscn" id="3_7jktm"]
|
||||
[ext_resource type="Script" uid="uid://cdxh14mtlvhl6" path="res://scripts/trigger_circle.gd" id="3_feb5d"]
|
||||
[ext_resource type="PackedScene" uid="uid://d4nnj62h6fjcq" path="res://scene/character_body_2d.tscn" id="4_ryrav"]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_mwb40"]
|
||||
size = Vector2(342, 62)
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_80nbo"]
|
||||
size = Vector2(129, 132)
|
||||
size = Vector2(368.333, 64.236694)
|
||||
|
||||
[sub_resource type="WorldBoundaryShape2D" id="WorldBoundaryShape2D_mwb40"]
|
||||
|
||||
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_80nbo"]
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_e2o6t"]
|
||||
radius = 153.83757
|
||||
|
||||
[node name="Game" type="Node2D" unique_id=1249397989]
|
||||
position = Vector2(-101, -18)
|
||||
script = ExtResource("1_fc0e3")
|
||||
|
||||
[node name="scene manager" type="Node2D" parent="." unique_id=1165789663]
|
||||
unique_name_in_owner = true
|
||||
position = Vector2(661, 24)
|
||||
scale = Vector2(0.97016877, 1.0195743)
|
||||
script = ExtResource("2_ryrav")
|
||||
|
||||
[node name="platform" type="StaticBody2D" parent="." unique_id=817692358]
|
||||
position = Vector2(528, 486)
|
||||
position = Vector2(421, 536.99994)
|
||||
script = ExtResource("1_e2o6t")
|
||||
metadata/_edit_group_ = true
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="platform" unique_id=469432658]
|
||||
shape = SubResource("RectangleShape2D_mwb40")
|
||||
|
||||
[node name="wall left" type="StaticBody2D" parent="." unique_id=1750621226]
|
||||
position = Vector2(528, 486)
|
||||
rotation = -1.5922282
|
||||
constant_linear_velocity = Vector2(20, 0)
|
||||
|
||||
[node name="wall left" type="CollisionShape2D" parent="wall left" unique_id=482160421]
|
||||
position = Vector2(148.07408, -141.85933)
|
||||
shape = SubResource("RectangleShape2D_mwb40")
|
||||
|
||||
[node name="cube" type="RigidBody2D" parent="." unique_id=1022714074]
|
||||
position = Vector2(554, 136)
|
||||
[node name="left wall" type="StaticBody2D" parent="." unique_id=1287017623]
|
||||
position = Vector2(250, 402.99994)
|
||||
rotation = 1.4884713
|
||||
script = ExtResource("1_e2o6t")
|
||||
metadata/_edit_group_ = true
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="cube" unique_id=111037541]
|
||||
position = Vector2(54.5, 56)
|
||||
shape = SubResource("RectangleShape2D_80nbo")
|
||||
debug_color = Color(0.95640117, 0, 0.540705, 0.41960785)
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="left wall" unique_id=1720529410]
|
||||
shape = SubResource("RectangleShape2D_mwb40")
|
||||
|
||||
[node name="right wall" type="StaticBody2D" parent="." unique_id=820553779]
|
||||
position = Vector2(567, 388.99994)
|
||||
rotation = -1.6017642
|
||||
script = ExtResource("1_e2o6t")
|
||||
metadata/_edit_group_ = true
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="right wall" unique_id=22403495]
|
||||
shape = SubResource("RectangleShape2D_mwb40")
|
||||
|
||||
[node name="conveyor" type="StaticBody2D" parent="." unique_id=1750621226]
|
||||
position = Vector2(261.99988, 492.00006)
|
||||
rotation = -1.5922282
|
||||
scale = Vector2(0.86305076, 3.6811934)
|
||||
constant_linear_velocity = Vector2(250, 0)
|
||||
|
||||
[node name="wall left" type="CollisionShape2D" parent="conveyor" unique_id=482160421]
|
||||
position = Vector2(231.63736, -442.00055)
|
||||
rotation = 1.6034058
|
||||
scale = Vector2(0.9552965, 0.99587345)
|
||||
shape = SubResource("RectangleShape2D_mwb40")
|
||||
|
||||
[node name="world border" type="StaticBody2D" parent="." unique_id=920368740]
|
||||
position = Vector2(563, 988)
|
||||
@ -54,20 +70,30 @@ metadata/_edit_group_ = true
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="world border" unique_id=1075301728]
|
||||
shape = SubResource("WorldBoundaryShape2D_mwb40")
|
||||
|
||||
[node name="CharacterBody2D" type="CharacterBody2D" parent="." unique_id=1928490773]
|
||||
position = Vector2(491, 38)
|
||||
script = ExtResource("1_80nbo")
|
||||
metadata/_edit_group_ = true
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="CharacterBody2D" unique_id=1078296156]
|
||||
shape = SubResource("CapsuleShape2D_80nbo")
|
||||
[node name="CharacterBody2D" parent="." unique_id=44928680 instance=ExtResource("4_ryrav")]
|
||||
position = Vector2(373, 474.99994)
|
||||
|
||||
[node name="Area2D" type="Area2D" parent="." unique_id=733267557]
|
||||
position = Vector2(881, 413)
|
||||
position = Vector2(945, 535)
|
||||
script = ExtResource("3_feb5d")
|
||||
metadata/_edit_group_ = true
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D" unique_id=762446279]
|
||||
shape = SubResource("CircleShape2D_e2o6t")
|
||||
|
||||
[node name="cube container" type="Node2D" parent="." unique_id=22976120]
|
||||
|
||||
[node name="cube" parent="cube container" unique_id=1851497894 instance=ExtResource("3_7jktm")]
|
||||
position = Vector2(366.99994, 37.99997)
|
||||
scale = Vector2(0.97196096, 1.0195743)
|
||||
|
||||
[node name="cube2" parent="cube container" unique_id=1345370216 instance=ExtResource("3_7jktm")]
|
||||
position = Vector2(348.99994, -235.00003)
|
||||
scale = Vector2(0.97196096, 1.0195743)
|
||||
|
||||
[node name="cube3" parent="cube container" unique_id=321996969 instance=ExtResource("3_7jktm")]
|
||||
position = Vector2(342.99997, -106.00003)
|
||||
scale = Vector2(0.97196096, 1.0195743)
|
||||
|
||||
[connection signal="body_entered" from="Area2D" to="Area2D" method="_on_body_entered"]
|
||||
[connection signal="triggerActiveSignal" from="Area2D" to="." method="on_trigger"]
|
||||
|
||||
@ -21,6 +21,14 @@ folder_colors={
|
||||
"res://scripts/": "blue"
|
||||
}
|
||||
|
||||
[input]
|
||||
|
||||
"magic push"={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":1,"position":Vector2(449, 17),"global_position":Vector2(458, 65),"factor":1.0,"button_index":1,"canceled":false,"pressed":true,"double_click":false,"script":null)
|
||||
]
|
||||
}
|
||||
|
||||
[physics]
|
||||
|
||||
3d/physics_engine="Jolt Physics"
|
||||
|
||||
12
scene.tscn
Normal file
12
scene.tscn
Normal file
@ -0,0 +1,12 @@
|
||||
[gd_scene format=3 uid="uid://l0eoba5u7g0w"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://f42eg5a0cckl" path="res://scripts/player_guy.gd" id="1_ulcgi"]
|
||||
|
||||
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_80nbo"]
|
||||
|
||||
[node name="CharacterBody2D" type="CharacterBody2D" unique_id=1229965105]
|
||||
script = ExtResource("1_ulcgi")
|
||||
metadata/_edit_group_ = true
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=1434220253]
|
||||
shape = SubResource("CapsuleShape2D_80nbo")
|
||||
12
scene/character_body_2d.tscn
Normal file
12
scene/character_body_2d.tscn
Normal file
@ -0,0 +1,12 @@
|
||||
[gd_scene format=3 uid="uid://d4nnj62h6fjcq"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://f42eg5a0cckl" path="res://scripts/player_guy.gd" id="1_j5628"]
|
||||
|
||||
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_80nbo"]
|
||||
|
||||
[node name="CharacterBody2D" type="CharacterBody2D" unique_id=44928680]
|
||||
script = ExtResource("1_j5628")
|
||||
metadata/_edit_group_ = true
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=547069058]
|
||||
shape = SubResource("CapsuleShape2D_80nbo")
|
||||
1
scripts/cube.gd
Normal file
1
scripts/cube.gd
Normal file
@ -0,0 +1 @@
|
||||
class_name Cube extends RigidBody2D
|
||||
1
scripts/cube.gd.uid
Normal file
1
scripts/cube.gd.uid
Normal file
@ -0,0 +1 @@
|
||||
uid://bsqvllp6h53jr
|
||||
@ -1,5 +1,6 @@
|
||||
extends Node2D
|
||||
class_name game extends Node2D
|
||||
|
||||
signal destroySignal (body)
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
@ -12,7 +13,8 @@ func _process(delta: float) -> void:
|
||||
|
||||
|
||||
func on_trigger(body: Variant, intentMessage: Variant) -> void:
|
||||
print("hello")
|
||||
if not body is Player and intentMessage == "destroy":
|
||||
if intentMessage == "destroy":
|
||||
body.queue_free()
|
||||
if body.is_in_group("fragile") and intentMessage == "destroy":
|
||||
destroySignal.emit(body)
|
||||
|
||||
func totalCube(NumberOfCube:int)->void:
|
||||
print ("gameknowscubes: "+str(NumberOfCube))
|
||||
|
||||
@ -1,32 +1,51 @@
|
||||
class_name Player extends CharacterBody2D
|
||||
@onready var rightcast: RayCast2D = $rightcast
|
||||
@onready var leftcast: RayCast2D = $leftcast
|
||||
|
||||
|
||||
|
||||
const SPEED =200.0
|
||||
const JUMP_VELOCITY = -550.0
|
||||
|
||||
const JUMP_VELOCITY = -300.0
|
||||
var direction
|
||||
enum FaceDirection{LEFT, RIGHT}
|
||||
var facing:FaceDirection = FaceDirection
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
# Add the gravity.
|
||||
handle_input()
|
||||
handle_movement(delta)
|
||||
move_and_slide()
|
||||
handle_collisions()
|
||||
|
||||
func handle_input()->void:
|
||||
if Input.is_action_just_pressed("ui_accept"):
|
||||
velocity.y = JUMP_VELOCITY
|
||||
if Input.is_action_just_pressed("magic push"):
|
||||
print ("may the force be with you")
|
||||
|
||||
# Get the input direction and handle the movement/deceleration.
|
||||
# As good practice, you should replace UI actions with custom gameplay actions.
|
||||
direction = Input.get_axis("ui_left", "ui_right")
|
||||
if direction<0:
|
||||
facing = FaceDirection.LEFT
|
||||
if direction>0:
|
||||
facing = FaceDirection.RIGHT
|
||||
|
||||
func handle_movement(delta)->void:
|
||||
if not is_on_floor():
|
||||
velocity += get_gravity() * delta
|
||||
|
||||
# Handle jump.
|
||||
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
|
||||
velocity.y = JUMP_VELOCITY
|
||||
if Input.is_action_just_pressed("ui_accept") and is_on_wall(): 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")
|
||||
if direction:
|
||||
velocity.x = direction * SPEED
|
||||
else:
|
||||
velocity.x = move_toward(velocity.x, 0, SPEED)
|
||||
|
||||
func handle_collisions()->void:
|
||||
if rightcast.is_colliding() and facing==FaceDirection.RIGHT:
|
||||
print("yay")
|
||||
move_and_slide()
|
||||
for i in get_slide_collision_count():
|
||||
var c = get_slide_collision(i)
|
||||
if c.get_collider() is RigidBody2D
|
||||
if c.get_collider() is RigidBody2D:
|
||||
#deliver the impact
|
||||
c.get_collider().apply-central-impulse(-c.get_normal() * 100)
|
||||
c.get_collider().apply_central_impulse(-c.get_normal() * 100)
|
||||
|
||||
25
scripts/scenemanager.gd
Normal file
25
scripts/scenemanager.gd
Normal file
@ -0,0 +1,25 @@
|
||||
class_name SM extends Node2D
|
||||
@onready var game: Node2D = $".."
|
||||
@onready var cube_container: Node2D = $"../cube container"
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
print("hey it's working!")
|
||||
game.destroySignal.connect(destroy)
|
||||
buildLevel()
|
||||
func buildLevel()->void:
|
||||
updateCube()
|
||||
func destroy(body)->void:
|
||||
if body is Cube:
|
||||
body.queue_free()
|
||||
func updateCube()->void:
|
||||
# make sure there are crates
|
||||
var _CubeTotal:int= 0
|
||||
if cube_container:
|
||||
for obj in cube_container.get_children():
|
||||
if obj is Cube:
|
||||
if not obj.tree_exited.is_connected(updateCube):
|
||||
obj.tree_exited.connect(updateCube)
|
||||
_CubeTotal +=1
|
||||
print ("Number of cubes: "+str(_CubeTotal))
|
||||
|
||||
1
scripts/scenemanager.gd.uid
Normal file
1
scripts/scenemanager.gd.uid
Normal file
@ -0,0 +1 @@
|
||||
uid://cxlpex21vgnla
|
||||
@ -4,7 +4,7 @@ class_name Trigger extends Area2D
|
||||
|
||||
signal triggerActiveSignal(body, intentMessage)
|
||||
|
||||
func _on_body_entered(body: CollisionObject2D) -> void:
|
||||
print ("YOU LOST >:O")
|
||||
func _on_body_entered(body: Cube) -> void:
|
||||
print ("you won! :D")
|
||||
|
||||
triggerActiveSignal.emit(body,intent)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user