added levels
This commit is contained in:
parent
9ae78abd7d
commit
d6906dc6a2
10 changed files with 176 additions and 9 deletions
|
@ -4,6 +4,7 @@ extends CharacterBody2D
|
|||
@export var gravity = 50
|
||||
var jump_count = 1
|
||||
@export var jump_strength = 100
|
||||
@export var jump_strength_large = 400
|
||||
var is_touching_floor : bool = true
|
||||
var jump_buffer_timer : float
|
||||
var coyote_timer : float = 0.2
|
||||
|
@ -30,6 +31,15 @@ func _unhandled_input(event):
|
|||
elif nearest_block.scale == Vector2(1.0, 1.0) and self.scale == Vector2(1.0, 1.0):
|
||||
nearest_block.scale_down()
|
||||
scale_up_player()
|
||||
else:
|
||||
var nearest_enemy = find_nearest_enemy()
|
||||
if nearest_enemy:
|
||||
if nearest_enemy.scale == Vector2(1, 1) and self.scale == Vector2(2.0, 2.0):
|
||||
nearest_enemy.scale = Vector2(2,2)
|
||||
scale_down_player()
|
||||
elif nearest_enemy.scale == Vector2(2, 2) and self.scale == Vector2(1.0, 1.0):
|
||||
nearest_enemy.scale = Vector2(1,1)
|
||||
scale_up_player()
|
||||
|
||||
|
||||
func get_input(delta):
|
||||
|
@ -74,10 +84,22 @@ func _physics_process(delta):
|
|||
get_input(delta)
|
||||
velocity.y += gravity
|
||||
move_and_slide()
|
||||
if(get_slide_collision_count() > 0):
|
||||
for i in get_slide_collision_count():
|
||||
var box = get_slide_collision(i).get_collider() as Box
|
||||
if scale.x == 2:
|
||||
if box and velocity.y >= 0:
|
||||
box.velocity.x = velocity.x*0.8
|
||||
else:
|
||||
if box and velocity.y >= 0 and box.scale.x < 2:
|
||||
box.velocity.x = velocity.x*0.8
|
||||
update_data_link()
|
||||
|
||||
func Jump():
|
||||
velocity.y = -1 * jump_strength
|
||||
if scale.x == 1:
|
||||
velocity.y = -1 * jump_strength
|
||||
else :
|
||||
velocity.y = -1 * jump_strength_large
|
||||
jump_count = 0
|
||||
is_touching_floor = false
|
||||
|
||||
|
@ -103,6 +125,16 @@ func find_nearest_block() -> Node2D:
|
|||
closest_block = block
|
||||
return closest_block
|
||||
|
||||
func find_nearest_enemy() -> Node2D:
|
||||
var closest_distance = max_link_distance
|
||||
var closest_block: Node2D = null
|
||||
for block in get_tree().get_nodes_in_group("enemy"):
|
||||
var distance = global_position.distance_to(block.global_position)
|
||||
if distance <= closest_distance:
|
||||
closest_distance = distance
|
||||
closest_block = block
|
||||
return closest_block
|
||||
|
||||
func start_scaling(target_node: Node2D, scale_value: Vector2):
|
||||
var tween = create_tween()
|
||||
tween.tween_property(target_node, "scale", scale_value, scale_duration)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue