Rosetta Code: ZGE

All topics about ZGameEditor goes here.

Moderator: Moderators

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

Rosetta Code: ZGE

Post by rrTea »

I have been busy with moving and other things so didn't have much time to work on my ZGE project(s). In order to keep in touch I decided to work on something super small / contained / (hopefully) fun and so on.

So, writing some Rosetta Code examples in ZGE sounded like the appropriate course of action! I'll post them here :)

For those who do not know, Rosetta Code compares how are certain tasks (very varied in nature) accomplished in different programming languages (from Z80 assembly to BBC Basic to C++ to Python and so on, regardless of fashion). Obviously some examples are not meant to be written in ZGE (for example any task that involves printing or FTP) but many tasks are platform independent, like "100 prisoners", "RPG attributes generator", "Happy numbers" and so on. Full list: https://rosettacode.org/wiki/Category:Programming_Tasks
Last edited by rrTea on Sun Dec 27, 2020 10:51 am, edited 3 times in total.
User avatar
rrTea
Posts: 475
Joined: Sat Feb 15, 2014 9:54 am

Rosetta Code: 100 Doors

Post by rrTea »

https://rosettacode.org/wiki/100_doors#
There are 100 doors in a row that are all initially closed.

You make 100 passes by the doors.

The first time through, visit every door and toggle the door (if the door is closed, open it; if it is open, close it).
The second time, only visit every 2nd door (door #2, #4, #6, ...), and toggle it.
The third time, visit every 3rd door (door #3, #6, #9, ...), etc, until you only visit the 100th door.

Task
Answer the question: what state are the doors in after the last pass? Which are open, which are closed?
Edit: cleaned it up a bit.

Code: Select all

<?xml version="1.0" encoding="iso-8859-1" ?>
<ZApplication Name="App" Caption="ZGameEditor application" FileVersion="2">
  <OnLoaded>
    <ZExpression Comment="Clear console" Expression="trace ( chr(12) );"/>
    <ZExpression Comment="Toggle doors">
      <Expression>
<![CDATA[int S,L;//step, loop

for (S = 1; S<=arr_Hotel.SizeDim1; S++)
    {
    L = S-1;
    while ( L<arr_Hotel.SizeDim1 )
          {
          arr_Hotel[L] = 1-arr_Hotel[L];
          L+=S;
          }
    }]]>
      </Expression>
    </ZExpression>
    <ZExpression Comment="Closing">
      <Expression>
<![CDATA[for (int D = 0; D<arr_Hotel.SizeDim1; D++)
    {
    if (arr_Hotel[D]){trace( "Door closed: " + intToStr(D+1));}
    arr_Hotel[D] = 0;
    }

quit();]]>
      </Expression>
    </ZExpression>
  </OnLoaded>
  <Content>
    <Array Name="arr_Hotel" Type="4" SizeDim1="100"/>
  </Content>
</ZApplication>
User avatar
rrTea
Posts: 475
Joined: Sat Feb 15, 2014 9:54 am

Rosetta Code: Yin and Yang

Post by rrTea »

https://rosettacode.org/wiki/Yin_and_yang
Create a function that given a variable representing size, generates a Yin and yang also known as a Taijitu symbol scaled to that size.

Generate and display the symbol generated for two different (small) sizes.
For this task I just used some examples from Kjell. I mean it would have probably been better if I did it with Bitmap Expression (I probably failed the task since I didn't really use any functions here) but this is somewhat close too and it nicely shows off ZGE features :D

Code: Select all

<?xml version="1.0" encoding="iso-8859-1" ?>
<ZApplication Name="App" Caption="ZGameEditor application" ClearColor="0.502 0.502 0.502 1" FileVersion="2">
  <OnRender>
    <UseMaterial Material="Material1"/>
    <Repeat Count="2">
      <OnIteration>
        <RenderMesh Mesh="mesh_Circle"/>
        <RenderTransformGroup Scale="0.5 0.5 1" Translate="0 -0.5 0">
          <Children>
            <RenderSetColor Color="0 0 0 1"/>
            <RenderMesh Mesh="mesh_Circle"/>
          </Children>
        </RenderTransformGroup>
        <RenderTransformGroup>
          <Children>
            <RenderSetColor Color="0 0 0 1"/>
            <RenderMesh Mesh="mesh_CircleHalf"/>
          </Children>
        </RenderTransformGroup>
        <RenderTransformGroup Scale="0.5 0.5 1" Translate="0 0.5 0">
          <Children>
            <RenderSetColor Color="1 1 1 1"/>
            <RenderMesh Mesh="mesh_Circle"/>
          </Children>
        </RenderTransformGroup>
        <RenderTransformGroup Scale="0.15 0.15 1" Translate="0 0.5 0">
          <Children>
            <RenderSetColor Color="0 0 0 1"/>
            <RenderMesh Mesh="mesh_Circle"/>
          </Children>
        </RenderTransformGroup>
        <RenderTransformGroup Scale="0.15 0.15 1" Translate="0 -0.5 0">
          <Children>
            <RenderSetColor Color="1 1 1 1"/>
            <RenderMesh Mesh="mesh_Circle"/>
          </Children>
        </RenderTransformGroup>
        <RenderTransform Scale="2 2 1" Translate="4 0 0"/>
      </OnIteration>
    </Repeat>
  </OnRender>
  <Content>
    <Material Name="Material1" Shading="1" Light="0"/>
    <Mesh Name="mesh_Circle">
      <Producers>
        <MeshBox Name="CircleGrid" XCount="8" Grid2DOnly="255"/>
        <MeshExpression AutoNormals="0">
          <Expression>
<![CDATA[//

float i, j, s, a;

i = CircleGrid.XCount+1;
j = i+1;
s = V.Y > 0 ? 1 : -1;
a = (V.X+1/i*s)*PI*(0.5-0.5/j);

V.X = sin(a);
V.Y = cos(a)*s;]]>
          </Expression>
        </MeshExpression>
      </Producers>
    </Mesh>
    <Mesh Name="mesh_CircleHalf">
      <Producers>
        <MeshBox Name="CircleGrid1" XCount="8" Grid2DOnly="255"/>
        <MeshExpression AutoNormals="0">
          <Expression>
<![CDATA[//


V.X *= 0.5;
V.X += 0.5;


float i, j, s, a;

i = CircleGrid1.XCount+1;
j = i+1;
s = V.Y > 0 ? 1 : -1;
a = (V.X+1/i*s)*PI*(0.5-0.5/j);

V.X = sin(a);
V.Y = cos(a)*s;]]>
          </Expression>
        </MeshExpression>
        <MeshTransform Rotation="0 0 0.05"/>
      </Producers>
    </Mesh>
  </Content>
</ZApplication>
User avatar
rrTea
Posts: 475
Joined: Sat Feb 15, 2014 9:54 am

Rosetta Code: Guess the number

Post by rrTea »

https://rosettacode.org/wiki/Guess_the_number
Write a program where the program chooses a number between 1 and 10.

A player is then prompted to enter a guess. If the player guesses wrong, then the prompt appears again until the guess is correct.

When the player has made a successful guess the computer will issue a "Well guessed!" message, and the program exits.

A conditional loop may be used to repeat the guessing until the user is correct.
It's always interesting (to me :) ) to see how exactly would a task like this be implemented in ZGE. In this case reading the input shows off ZGE's character very nicely.

Code: Select all

<?xml version="1.0" encoding="iso-8859-1" ?>
<ZApplication Name="App" Caption="ZGameEditor application" FileVersion="2">
  <OnLoaded>
    <ZExpression>
      <Expression>
<![CDATA[KeypressCheck = 0;
KeypressCheck_buffer = 0;

TargetNumber = ceil(rnd()*10);

trace("Press a number key (not on number pad).");]]>
      </Expression>
    </ZExpression>
  </OnLoaded>
  <OnUpdate>
    <ZExpression>
      <Expression>
<![CDATA[KeypressCheck_buffer = KeypressCheck;
KeypressCheck = 0;]]>
      </Expression>
    </ZExpression>
    <KeyPress Name="kpr_Numbers" Comment="Check input" Keys="1234567890">
      <OnPressed>
        <ZExpression Expression="KeypressCheck = 1;"/>
      </OnPressed>
    </KeyPress>
    <Condition Comment="Key pressed?" Expression="return ( KeypressCheck == 1 &amp;&amp; KeypressCheck_buffer == 0 );">
      <OnTrue>
        <ZExpression>
          <Expression>
<![CDATA[if ( kpr_Numbers.KeyIndex+1 == TargetNumber )
     {
     trace("Well guessed!");
     quit();
     }
else {
     trace ("Input: " + intToStr( kpr_Numbers.KeyIndex +1) );
     }]]>
          </Expression>
        </ZExpression>
      </OnTrue>
    </Condition>
  </OnUpdate>
  <Content>
    <Variable Name="TargetNumber" Type="4"/>
    <Variable Name="KeypressCheck" Type="4"/>
    <Variable Name="KeypressCheck_buffer" Type="4"/>
  </Content>
</ZApplication>
Post Reply