added pipes and interact blocks
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
extends RigidBody2D
|
||||
|
||||
@onready var animated_sprite_2d = $AnimatedSprite2D
|
||||
|
||||
func _ready():
|
||||
animated_sprite_2d.play("default")
|
||||
|
||||
func _on_activate_body_entered(body):
|
||||
queue_free()
|
||||
@@ -0,0 +1,14 @@
|
||||
extends RigidBody2D
|
||||
@onready var animated_sprite_2d = $AnimatedSprite2D
|
||||
|
||||
var destroyed = false
|
||||
|
||||
func _ready():
|
||||
animated_sprite_2d.play("idle")#
|
||||
|
||||
func _on_activate_body_entered(body):
|
||||
if destroyed:
|
||||
return
|
||||
|
||||
destroyed = true
|
||||
animated_sprite_2d.play("destroy")
|
||||
@@ -0,0 +1,6 @@
|
||||
extends Area2D
|
||||
|
||||
@export var target: Vector2
|
||||
|
||||
func get_target():
|
||||
return target
|
||||
+58
-2
@@ -1,13 +1,42 @@
|
||||
extends CharacterBody2D
|
||||
@onready var animated_sprite_2d = $AnimatedSprite2D
|
||||
@onready var camera_2d = $Camera2D
|
||||
@onready var color_rect = $Camera2D/ColorRect
|
||||
@onready var pipe_timer = $pipe_timer
|
||||
@onready var pipe_timer_half = $pipe_timer_half
|
||||
|
||||
|
||||
const SPEED = 130.0
|
||||
const JUMP_VELOCITY = -350.0
|
||||
const JUMP_VELOCITY = -360.0
|
||||
var on_pipe = false
|
||||
var right_pipe = false
|
||||
var left_pipe = false
|
||||
var pipe = null
|
||||
var pipe_target = null
|
||||
|
||||
|
||||
# Get the gravity from the project settings to be synced with RigidBody nodes.
|
||||
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
|
||||
var on_pause = false
|
||||
|
||||
func _ready():
|
||||
color_rect.visible = false
|
||||
|
||||
func _process(delta):
|
||||
# set camera
|
||||
if position.y <= 32:
|
||||
camera_2d.limit_bottom = 32
|
||||
camera_2d.limit_top = -1000000
|
||||
else:
|
||||
camera_2d.limit_bottom = 272
|
||||
camera_2d.limit_top = 32
|
||||
|
||||
# check pipe
|
||||
if on_pipe and Input.is_action_just_pressed("crawl") and is_on_floor() or right_pipe and Input.is_action_pressed("move_right"):
|
||||
color_rect.visible = true
|
||||
pipe_timer.start()
|
||||
pipe_timer_half.start()
|
||||
pipe_target = pipe.get_target()
|
||||
|
||||
func _physics_process(delta):
|
||||
# Add the gravity.
|
||||
@@ -15,12 +44,15 @@ func _physics_process(delta):
|
||||
velocity.y += gravity * delta
|
||||
|
||||
# Handle jump.
|
||||
if Input.is_action_just_pressed("jump") and is_on_floor():
|
||||
if not on_pause and Input.is_action_just_pressed("jump") and is_on_floor():
|
||||
velocity.y = JUMP_VELOCITY
|
||||
|
||||
# get input
|
||||
var direction = Input.get_axis("move_left", "move_right")
|
||||
|
||||
if on_pause:
|
||||
direction = 0
|
||||
|
||||
# face direction
|
||||
if direction < 0:
|
||||
animated_sprite_2d.flip_h = true
|
||||
@@ -42,3 +74,27 @@ func _physics_process(delta):
|
||||
velocity.x = move_toward(velocity.x, 0, SPEED)
|
||||
|
||||
move_and_slide()
|
||||
|
||||
|
||||
func _on_pipedetector_area_entered(area):
|
||||
on_pipe = true
|
||||
pipe = area
|
||||
|
||||
func _on_pipedetector_area_exited(area):
|
||||
on_pipe = false
|
||||
|
||||
func _on_pipedetector_right_area_entered(area):
|
||||
right_pipe = true
|
||||
pipe = area
|
||||
|
||||
func _on_pipedetector_right_area_exited(area):
|
||||
right_pipe = false
|
||||
|
||||
|
||||
func _on_pipe_timer_timeout():
|
||||
on_pause = false
|
||||
color_rect.visible = false
|
||||
|
||||
|
||||
func _on_pipe_timer_half_timeout():
|
||||
position = pipe_target
|
||||
|
||||
Reference in New Issue
Block a user