So I made a little test, but I'm not sure about the method, nor how to shift an array in ZGE...
So it's not working as some waypoints are disappearing during the shift... What do I do wrong?
Code: Select all
<?xml version="1.0" encoding="iso-8859-1" ?>
<ZApplication Name="App" Caption="ZGameEditor application" FileVersion="2">
<OnLoaded>
<ZExpression>
<Expression>
<![CDATA[points.SizeDim1 = 0;
ship.Translate.X = 0;
ship.Translate.Y = -4;]]>
</Expression>
</ZExpression>
</OnLoaded>
<OnUpdate>
<ZExpression>
<Expression>
<![CDATA[time += App.DeltaTime;
// Append to array
if (time > 0.6)
{
time = 0;
points.SizeDim1++;
points[points.SizeDim1-1] = vector2(random(0,5), 5);
}
// Move everything
//for(int i = 0; i < points.SizeDim1; i++)
for (int i = points.SizeDim1-1; i >= 0; i--)
{
points[i].Y -= 0.1;
if (points[i].Y < -5)
{
// Shift array ???
for (int j = points.SizeDim1-1; j >= 1; j--)
{
points[j-1] = points[j];
}
points.SizeDim1--;
trace(intToStr(points.SizeDim1));
}
}
// move ship
if (points.SizeDim1)
{
int p = 0;
while (ship.Translate.Y > points[p].Y) p ++;
ship.Translate.X += (points[p].X - ship.Translate.X) * 0.04;
ship.Translate.Y += (points[p].Y - ship.Translate.Y) * 0.001;
}]]>
</Expression>
</ZExpression>
</OnUpdate>
<OnRender>
<Repeat Name="repeat">
<OnIteration>
<ZExpression>
<Expression>
<![CDATA[int i = repeat.Iteration;
transform.translate.X = points[i].X;
transform.translate.Y = points[i].Y;]]>
</Expression>
</ZExpression>
<RenderTransformGroup Name="transform" Translate="1.2062 2.5 0">
<Children>
<RenderSprite/>
</Children>
</RenderTransformGroup>
</OnIteration>
<WhileExp>
<![CDATA[//this.Iteration=current iteration nr. Return false to end loop.
return this.Iteration < points.SizeDim1;]]>
</WhileExp>
</Repeat>
<RenderTransformGroup Name="ship" Translate="1.0845 -0.0736 0">
<Children>
<RenderSetColor Color="1 0 0 1"/>
<RenderSprite/>
</Children>
</RenderTransformGroup>
</OnRender>
<Content>
<Array Name="points" Type="6" SizeDim1="31"/>
<Variable Name="time"/>
</Content>
</ZApplication>