static body, rigid bodies, character body, area 2d, timer
This commit is contained in:
commit
14f739c428
10 files changed
+206
No files matched your search
@@ -0,0 +1,9 @@
|
||||
extends Area2D
|
||||
signal alert
|
||||
|
||||
|
||||
func _on_body_entered(body):
|
||||
print("Trigger detected object")
|
||||
if body.is_in_group("box"):
|
||||
print("this is a box")
|
||||
alert.emit(body)
|
||||
@@ -0,0 +1,30 @@
|
||||
extends Node2D
|
||||
var totalBoxes = 3
|
||||
var timer:= Timer.new()
|
||||
var countdown = 10
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
add_child(timer)
|
||||
timer.wait_time = 1
|
||||
timer.one_shot = false
|
||||
timer.connect("timeout", secondCounter)
|
||||
timer.start()
|
||||
|
||||
func secondCounter():
|
||||
print("one second")
|
||||
countdown -=1
|
||||
if countdown <=0:
|
||||
print("you lose")
|
||||
get_tree().reload_current_scene()
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta):
|
||||
pass
|
||||
|
||||
func _on_trigger_alert(body):
|
||||
totalBoxes -=1
|
||||
body.queue_free()
|
||||
if totalBoxes <=0:
|
||||
print("you won")
|
||||
get_tree().reload_current_scene()
|
||||
@@ -0,0 +1,33 @@
|
||||
extends CharacterBody2D
|
||||
|
||||
|
||||
const SPEED = 300.0
|
||||
const JUMP_VELOCITY = -400.0
|
||||
@export var PUSH_FORCE = 90
|
||||
|
||||
# Get the gravity from the project settings to be synced with RigidBody nodes.
|
||||
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
|
||||
|
||||
|
||||
func _physics_process(delta):
|
||||
# Add the gravity.
|
||||
if not is_on_floor():
|
||||
velocity.y += gravity * delta
|
||||
|
||||
# Handle jump.
|
||||
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
|
||||
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)
|
||||
|
||||
move_and_slide()
|
||||
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() * PUSH_FORCE)
|
||||
Reference in new issue
Block a user