raycasts, scene manager, magic push
This commit is contained in:
1 parent
c6c6031782
commit
5d34946622
13 files changed
+194
-53
No files matched your search
@@ -0,0 +1 @@
|
||||
class_name Cube extends RigidBody2D
|
||||
@@ -0,0 +1 @@
|
||||
uid://bsqvllp6h53jr
|
||||
+7
-5
@@ -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))
|
||||
+34
-15
@@ -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
|
||||
#deliver the impact
|
||||
c.get_collider().apply-central-impulse(-c.get_normal() * 100)
|
||||
if c.get_collider() is RigidBody2D:
|
||||
#deliver the impact
|
||||
c.get_collider().apply_central_impulse(-c.get_normal() * 100)
|
||||
@@ -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))
|
||||
|
||||
@@ -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)
|
||||
Reference in new issue
Block a user