Droplets

All topics about ZGameEditor goes here.

Moderator: Moderators

Post Reply
User avatar
rrTea
Posts: 475
Joined: Sat Feb 15, 2014 9:54 am

Droplets

Post by rrTea »

I'm trying to make a model (that can move at different speeds and in different directions) drop some stuff where it passes. Right now I'm doing it like this (this is for one direction only):

Code: Select all

<?xml version="1.0" encoding="iso-8859-1" ?>
<ZApplication Name="App" Caption="ZGameEditor application" ClearColor="0.502 0.502 1 1" ScreenMode="0" Camera="cam_Front" ViewportRatio="3" FileVersion="2">
  <OnLoaded>
    <SpawnModel Model="m_Dropper" Position="-21 0 0" UseSpawnerPosition="255"/>
  </OnLoaded>
  <OnRender>
    <UseMaterial Material="mat_Wireframe"/>
    <RenderNet XCount="20" YCount="11">
      <RenderVertexExpression>
<![CDATA[//Update each vertex.
//Vertex : current vertex
//TexCoord : current texture coordinate
//Color : current vertex color

Vertex.X *= (this.XCount+1)*2;
Vertex.Y *= (this.YCount+1)*2;]]>
      </RenderVertexExpression>
    </RenderNet>
  </OnRender>
  <Content>
    <Camera Name="cam_Front" Kind="1" Position="0 0 10" OrthoZoom="12"/>
    <Material Name="mat_Color" Shading="1" Light="0"/>
    <Material Name="mat_Wireframe" Shading="2" Light="0"/>
    <Mesh Name="mesh_Rectangle">
      <Producers>
        <MeshBox Grid2DOnly="255"/>
      </Producers>
    </Mesh>
    <Model Name="m_Dropper" Velocity="4 0 0">
      <Definitions>
        <Variable Name="DropPoint" Type="1"/>
      </Definitions>
      <OnSpawn>
        <ZExpression Expression="DropPoint = CurrentModel.Position.X+1;"/>
      </OnSpawn>
      <OnUpdate>
        <Condition Comment="Drop?">
          <Expression>
<![CDATA[return
(
CurrentModel.Position.X > DropPoint
);]]>
          </Expression>
          <OnTrue>
            <ZExpression>
              <Expression>
<![CDATA[m_Droplet.Position.X = DropPoint;
m_Droplet.Position.Y = CurrentModel.Position.Y;

DropPoint += 2;]]>
              </Expression>
            </ZExpression>
            <SpawnModel Model="m_Droplet"/>
          </OnTrue>
        </Condition>
        <Condition Comment="Out of screen? (remove)">
          <Expression>
<![CDATA[return (
CurrentModel.Position.X > 21
);]]>
          </Expression>
          <OnTrue>
            <ZExpression>
              <Expression>
<![CDATA[CurrentModel.Position.X = 0-21;
DropPoint = CurrentModel.Position.X + 2;]]>
              </Expression>
            </ZExpression>
            <RemoveModel/>
          </OnTrue>
        </Condition>
      </OnUpdate>
      <OnRender>
        <UseMaterial Material="mat_Color"/>
        <RenderSetColor Color="1 0 1 1"/>
        <RenderMesh Mesh="mesh_Rectangle"/>
      </OnRender>
    </Model>
    <Model Name="m_Droplet" Position="12 0 0">
      <OnRender>
        <UseMaterial Material="mat_Wireframe"/>
        <RenderSetColor Color="1 0 0.502 1"/>
        <RenderMesh Mesh="mesh_Rectangle"/>
      </OnRender>
    </Model>
  </Content>
</ZApplication>
This works perfectly but I'm not happy that this method checks the drop point on every frame and has to be adapted for all 4 directions. I mean it's not a huge waste but surely there is a better way to do it... Maybe by using a timer, for example if I could just calculate the time between two points based on the velocity of the moving "Dropper" object?
Post Reply