forked from team-sg/hero-mark-2
make turtles use super slime logic instead (fixes #146)
This commit is contained in:
parent
298e31c5d5
commit
071ff439b9
1 changed files with 30 additions and 27 deletions
|
@ -14,8 +14,6 @@ export (SpikeDirection) var spike_direction: int = SpikeDirection.BOTH
|
|||
var can_spike: bool = true
|
||||
var spike_tween: SceneTreeTween
|
||||
|
||||
# index of the current spike position to check for
|
||||
onready var current_spike_position: int = 0
|
||||
onready var sprite: Sprite = $"%Sprite"
|
||||
onready var spike_shape: CollisionShape2D = $"%SpikeShape"
|
||||
|
||||
|
@ -24,14 +22,9 @@ func _ready() -> void:
|
|||
if Engine.editor_hint:
|
||||
return
|
||||
|
||||
# positions must be in order
|
||||
spike_positions.sort()
|
||||
# scale to be in tiles
|
||||
for i in spike_positions.size():
|
||||
# scale to be in tiles
|
||||
spike_positions[i] = spike_positions[i] * 8.0
|
||||
# should start with the first positive spike position
|
||||
if spike_positions[i] < 0.0:
|
||||
current_spike_position = i + 1
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
# update debug graphics in editor
|
||||
|
@ -52,26 +45,36 @@ func _physics_process(delta: float) -> void:
|
|||
# use positions in correct axis
|
||||
var pos = position.x if move_direction == Direction.HORIZONTAL else position.y
|
||||
var pos_start = startpos.x if move_direction == Direction.HORIZONTAL else startpos.y
|
||||
# only spike if matching direction
|
||||
if spike_direction == SpikeDirection.LEFT and sign(direction) == 1.0:
|
||||
return
|
||||
if spike_direction == SpikeDirection.RIGHT and sign(direction) == -1.0:
|
||||
return
|
||||
# spike if close enough to an activation point
|
||||
for spike_pos in spike_positions:
|
||||
if abs(pos_start + spike_pos - pos) <= 2.0:
|
||||
spike()
|
||||
break
|
||||
# slightly different logic depending on forward/backwards unfortunately :I
|
||||
match sign(direction):
|
||||
1.0:
|
||||
# make sure there are any positions left to check in this direction
|
||||
if current_spike_position < spike_positions.size():
|
||||
# check if passed the spike position
|
||||
if pos >= pos_start + spike_positions[current_spike_position]:
|
||||
# move on to next position
|
||||
current_spike_position += 1
|
||||
if spike_direction != SpikeDirection.LEFT:
|
||||
spike()
|
||||
-1.0:
|
||||
# make sure there are still positions left in this direction
|
||||
if current_spike_position - 1 >= 0:
|
||||
# check if passed the position
|
||||
if pos <= pos_start + spike_positions[current_spike_position - 1]:
|
||||
# move on to next (previous because backwards) position
|
||||
current_spike_position -= 1
|
||||
if spike_direction != SpikeDirection.RIGHT:
|
||||
spike()
|
||||
# match sign(direction):
|
||||
# 1.0:
|
||||
# # make sure there are any positions left to check in this direction
|
||||
# if current_spike_position < spike_positions.size():
|
||||
# # check if passed the spike position
|
||||
# if pos >= pos_start + spike_positions[current_spike_position]:
|
||||
# # move on to next position
|
||||
# current_spike_position += 1
|
||||
# if spike_direction != SpikeDirection.LEFT:
|
||||
# spike()
|
||||
# -1.0:
|
||||
# # make sure there are still positions left in this direction
|
||||
# if current_spike_position - 1 >= 0:
|
||||
# # check if passed the position
|
||||
# if pos <= pos_start + spike_positions[current_spike_position - 1]:
|
||||
# # move on to next (previous because backwards) position
|
||||
# current_spike_position -= 1
|
||||
# if spike_direction != SpikeDirection.RIGHT:
|
||||
# spike()
|
||||
|
||||
## performs the spike animation
|
||||
func spike() -> void:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue