Trivial Solutions
                    The LoseThos 64-bit PC Operating System
File:/LT/Apps/AfterEgypt/Horeb.CPZ
This, and all LoseThos files, are public domain.  Do whatever you like.
God is watching; God is just; God is never out-done in generosity.  He talks!

LoseThos code compiles with the 64-bit LoseThos compiler/assembler I wrote.
Boot the LoseThos CD and you can compile it.  Not in Kansas anymore!

Click here for preliminary compiler information you need.






    <1>/* Graphics Not Rendered in HTML */




    <2>/* Graphics Not Rendered in HTML */









    <3>/* Graphics Not Rendered in HTML */




















    <4>/* Graphics Not Rendered in HTML */



I64 vx,vz;
F64 theta;
BoolI8 horeb_done;

#define NUM_OBJS        256

#define NUM_WEIGHED_IMGS        8
U8 *imgs[NUM_WEIGHED_IMGS]={<1>,<1>,<2>,<2>,<3>,<4>,<4>,<4>};

class Object
{
  I32 x,y,z;
  I64 x1,y1,z1;
  BoolI8 sym,pad[3];
  U8 *img;
} objs[NUM_OBJS];


I64 ObjCompare(Object *o1,Object *o2)
{
  return o2->z1-o1->z1;
}

U0 DrawHoreb(TaskStruct *task,GrBitMap *base)
{
  I64 i,j,x,y,z,
      w=task->win_pixel_width,
      h=task->win_pixel_height,r[16],
      cx=w>>1,cy=h>>1;
  F64 s;
  Object *o_sort[NUM_OBJS],*tempo;

  GrIdentEqu(r);
  GrRotYEqu(r,-theta);
  GrRotXEqu(r,77*pi/180);

  //Sun
  x=vx; y=0; z=1000000+vz;
  GrRot(r,&x,&y,&z);
  s=100.0/(AbsI64(z)+50);
  if (y<0) {
    base->color=BROWN;
    GrCircle(base,s*x+cx,15,15);
    base->color=YELLOW;
    GrFloodFill(base,s*x+cx,15);
  }

  for (i=0;i<NUM_OBJS;i++) {
    tempo=&objs[i];
    o_sort[i]=tempo;
    tempo->x1=tempo->x+vx; tempo->y1=tempo->y; tempo->z1=tempo->z+vz;
    GrRot(r,&tempo->x1,&tempo->y1,&tempo->z1);
  }
  QSortU64(o_sort,NUM_OBJS,&ObjCompare);

  for (i=0;i<NUM_OBJS;i++) {
    tempo=o_sort[i];
    if (tempo->z1<0) break;
    s=100.0/(AbsI64(tempo->z1)+50);
    GrIdentEqu(base->r);
    GrScaleMatEqu(base->r,s*2);
    GrSetRotMat(base,base->r);
    base->flags|=BMF_TRANSFORMATION;
    if (tempo->sym) {
      base->flags|=BMF_SYMMETRY|BMF_JUST_MIRROR;
      GrSetSymmetry(base,s*tempo->x1+cx,s*tempo->y1+h,s*tempo->x1+cx,s*tempo->y1+h+10);
    }
    GrElemsPlot3b(base,s*tempo->x1+cx,s*tempo->y1+h,0,tempo->img);
    base->flags&=~(BMF_SYMMETRY|BMF_JUST_MIRROR);
    if (o_sort[i]==objs) { //draw burning bush
      base->x=s*tempo->x1+cx;
      base->y=s*tempo->y1+h;
      base->z=0;
      for (j=0;j<100;j++) {
        if (j&1)
          base->color=RED;
        else
          base->color=LTRED;
        GrLine3(base,Rand*10-5,-10,0,Rand*30-15,-Rand*30-10,0);
      }
      if (SqrI64(s*tempo->x1)+SqrI64(s*tempo->y1)<300*300)
        horeb_done=TRUE;
    }
  }

  if (Blink(,tP(task))) {
    base->color=LTRED;
    GrPutS(base,cx-21*FONT_WIDTH/2,cy-FONT_HEIGHT/2,"Find the Burning Bush.");
  }
}

U0 Init()
{
  Object *tempo;
  I64 i;
  for (i=0;i<NUM_OBJS;i++) {
    tempo=&objs[i];
    tempo->x=RandU32&0x1FFF-0x1000;
    tempo->y=0;
    tempo->z=RandU32&0x1FFF-0x1000;
    tempo->sym=RandU16&1;
    tempo->img=imgs[i%NUM_WEIGHED_IMGS];
  }
  vx=0; vz=0; theta=0;
  horeb_done=FALSE;
}

U0 Horeb()
{
  U64 ch,sc;
  MenuPush(
  "File {"
  "  Abort(,CH_SHIFT_ESC);"
  "  Exit(,CH_ESC);"
  "}"
  "Play {"
  "  Restart(,CH_CR);"
  "  Forward(,,SC_CURSOR_UP);"
  "  Backward(,,SC_CURSOR_DOWN);"
  "  Left(,,SC_CURSOR_LEFT);"
  "  Right(,,SC_CURSOR_RIGHT);"
      "}"
      );
  SettingsPush(Fs,TSF_SAME_SONG); //See SettingsPush
  try {
    Fs->win_inhibit=WIF_ALL-WIF_GRAB_SCROLL-WIF_MENU;
    WordStat(OFF);
    WinMax;
    WinBorder(OFF);
    Preempt(OFF);

    PutS("$CL$$BG,LTCYAN$");
    CrLf(6);
    PutS("$BG,YELLOW$");
    CrLf(30);
    PutBibleVerse("Exodus,3:1",21);
    Init;
    Fs->draw_it=&DrawHoreb;
    while (!horeb_done) {
      while (ScanKey(&ch,&sc))
        switch (ch) {
          case 0:
            switch (sc.u8[0]) {
              case SC_CURSOR_LEFT:
                theta-=pi/100;
                break;
              case SC_CURSOR_RIGHT:
                theta+=pi/100;
                break;
              case SC_CURSOR_UP:
                vx-=40*Sin(theta);
                vz-=40*Cos(theta);
                break;
              case SC_CURSOR_DOWN:
                vx+=40*Sin(theta);
                vz+=40*Cos(theta);
                break;
            }
            break;
          case CH_CR:
            Init;
            break;
          case CH_SHIFT_ESC:
          case CH_ESC:
            goto hr_done;
        }
      WinSync;
    }
hr_done: //Don't goto out of try
  } catch
    Fs->catch_except=TRUE;
  SettingsPop(Fs,TSF_SAME_SONG);
  LtfClear;
  PutS("$BG$");
  MenuPop;
}

//This is so I can use this file stand alone
//or as a component of a program.
#if IncludeDepth<2
Horeb;
#endif
Historical capture: 2011-10-22. Home | Power on LoseThos | Sources and changes