I fully understand. Hope this is better for you - it is based on Marcus's solution to my question on this subject from last March.
Code:
include "polyline.n7"
visible screen_w = 640,screen_h = 480
'Open a window
set window "Diving example",screen_w,screen_h
'enable double buffering
set redraw off
invader = [x:300,y:50,dx:1,w:32,h:16,dive_x:unset,dive_y:unset,diving:false]
##############################################################################################
####################################### GAME LOOP #########################################
##############################################################################################
do
'release the invader occasionally
timer = (timer + 1 ) % 500
if timer = 499
invader.diving = true
' This is the additional code provided by Marcus back in March
' Very simple path, just dive to the bottom center of the screen and back again.
invader.path = PolyLine([[invader.x, invader.y], [width(primary)/2, height(primary) - 20], [invader.x, invader.y]],false)
' Set traveled distance to 0.
invader.path_dist = 0
' We still need to update the diver's regular position. So when diving, the invader's position is
' stored in dive_x, dive_y. Use these coordinates when drawing and doing collision tests for a
' diving invader.
invader.dive_x = invader.x
invader.dive_y = invader.y
' EndMarcus
endif
'move the invader and keep it on screen
invader.x = invader.x + invader.dx
if invader.x > 600 or invader.x < 40 then invader.dx = - invader.dx
' Marcus code
if invader.diving = true
' Set the last control point of the path to the invaders normal position.
' A problem here is that the regular invaders move vertically with huge steps. This
' doesn't look good for the movement of a diver. So rather than doing this:
'invaders[i].path.ModifyControlPoint(2, invaders[i].x, invaders[i].y)
' , we can interpolate the y coordinate:
y = invader.path.GetControlPoint(2)[1] ' current y of the last control point.
invader.path.ModifyControlPoint(2, invader.x, y*0.95 + invader.y*0.05)
' Move 4 pixels.
invader.path_dist = invader.path_dist + 4
pos = invader.path.GetPoint(invader.path_dist, true)
' Still on path?
if pos
invader.dive_x = pos[0]
invader.dive_y = pos[1]
' No longer diving.
else
invader.diving = false
endif
endif
' EndMarcus
'clear the screen
set color 255,255,255
cls
set color 0,0,0
'draw the invader as a solid rectangle - only show an outline when diving to see
'where the original path would have been
if invader.diving = false
draw rect invader.x,invader.y,invader.w,invader.h,true
else
draw rect invader.x,invader.y,invader.w,invader.h,false
draw rect invader.dive_x,invader.dive_y,invader.w,invader.h,true
endif
'copy back buffer to the screen
redraw
'cap FPS to 60
fwait 60
until keydown(KEY_ESCAPE)