superslime rev2
This commit is contained in:
parent
dab7b58504
commit
c7a310c0a4
3 changed files with 52 additions and 11 deletions
|
@ -9,6 +9,9 @@ export var direction: float = 1.0
|
|||
export var speed: float = 50.0
|
||||
export var jump_distance: float = 0.0
|
||||
export var jump_speed: float = 50.0
|
||||
export (Array, float) var bottom_jumps: Array = [] setget _set_bottom_jumps
|
||||
export (Array, float) var top_jumps: Array = [] setget _set_top_jumps
|
||||
export var detect_player: bool = false
|
||||
|
||||
var _jumping: bool = false
|
||||
var _jump_direction: float = -1.0
|
||||
|
@ -24,6 +27,10 @@ func _ready() -> void:
|
|||
left_boundary *= 8.0
|
||||
right_boundary *= 8.0
|
||||
jump_distance *= 8.0
|
||||
for i in bottom_jumps.size():
|
||||
bottom_jumps[i] *= 8.0
|
||||
for i in top_jumps.size():
|
||||
top_jumps[i] *= 8.0
|
||||
detect_player_cast.cast_to = Vector2(0.0, -jump_distance)
|
||||
speed *= Game.enemy_speed_factor
|
||||
|
||||
|
@ -31,8 +38,14 @@ func _ready() -> void:
|
|||
func _physics_process(delta: float) -> void:
|
||||
if Engine.editor_hint:
|
||||
return
|
||||
# check for player and jump
|
||||
if detect_player_cast.is_colliding():
|
||||
# check for jump point
|
||||
var jump_points = bottom_jumps if sign(_jump_direction) == -1.0 else top_jumps
|
||||
for x in jump_points:
|
||||
if abs(hitbox.position.x - x) <= 2.0:
|
||||
_jumping = true
|
||||
break
|
||||
# check for player
|
||||
if detect_player and detect_player_cast.is_colliding():
|
||||
_jumping = true
|
||||
# move if not jumping
|
||||
if _jumping:
|
||||
|
@ -55,8 +68,8 @@ func _physics_process(delta: float) -> void:
|
|||
sprite.flip_h = true
|
||||
elif hitbox.position.x <= -left_boundary:
|
||||
hitbox.position.x = -left_boundary
|
||||
direction = 1.0
|
||||
sprite.flip_h = false
|
||||
direction = 1.0
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
|
@ -78,12 +91,36 @@ func _draw() -> void:
|
|||
Vector2(right_boundary * 8.0 + 8.0, -jump_distance * 8.0 - 4.0),
|
||||
Color(0.4, 0.2, 0.6, 0.75), 1.01, false
|
||||
)
|
||||
# jump line
|
||||
draw_line(
|
||||
Vector2(4.0, 4.0),
|
||||
Vector2(4.0, -jump_distance * 8.0 - 4.0),
|
||||
Color(0.4, 0.2, 0.6, 0.75), 1.01, false
|
||||
)
|
||||
# jump lines
|
||||
for x in bottom_jumps:
|
||||
draw_line(
|
||||
Vector2(x * 8.0, 4.0),
|
||||
Vector2(x * 8.0, -jump_distance * 4.0),
|
||||
Color(1.0, 0.0, 0.0, 0.75), 1.01, false
|
||||
)
|
||||
draw_circle(Vector2(x * 8.0, 4.0), 2.0, Color.red)
|
||||
for x in top_jumps:
|
||||
draw_line(
|
||||
Vector2(x * 8.0, -jump_distance * 8.0 - 4.0),
|
||||
Vector2(x * 8.0, -jump_distance * 4.0),
|
||||
Color(1.0, 0.0, 0.0, 0.75), 1.01, false
|
||||
)
|
||||
draw_circle(Vector2(x * 8.0, -jump_distance * 8.0 - 4.0), 2.0, Color.red)
|
||||
# draw_line(
|
||||
# Vector2(4.0, 4.0),
|
||||
# Vector2(4.0, -jump_distance * 8.0 - 4.0),
|
||||
# Color(0.4, 0.2, 0.6, 0.75), 1.01, false
|
||||
# )
|
||||
|
||||
|
||||
func _set_bottom_jumps(value: Array) -> void:
|
||||
bottom_jumps = value
|
||||
update()
|
||||
|
||||
|
||||
func _set_top_jumps(value: Array) -> void:
|
||||
top_jumps = value
|
||||
update()
|
||||
|
||||
|
||||
func die() -> void:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue