U0 BlackDiamond()
{
  I64 ch,sc;

  MenuPush(
  "File {"
  "  Abort(,CH_SHIFT_ESC);"
  "  Exit(,CH_ESC);"
  "}"
  "Play {"
  "  Up(,,SC_CURSOR_UP);"
  "  Down(,,SC_CURSOR_DOWN);"
  "  Left(,,SC_CURSOR_LEFT);"
  "  Right(,,SC_CURSOR_RIGHT);"
      "}"
      );
  SettingsPush; //See $LK,"SettingsPush","MN:SettingsPush"$
  WinMax;
  DocCursor;
  DocClear;
  Fs->draw_it=&DrawIt;
  WinBorder;
  WordStat;

  Init;
  try {
    do {
      if (ScanKey(&ch,&sc)) {
	switch (sc.u8[0]) {
	  case SC_CURSOR_RIGHT:
	    x+=10;
	    if (x>=GR_WIDTH) x-=GR_WIDTH;
	    break;
	  case SC_CURSOR_LEFT:
	    x-=10;
	    if (x<0) x+=GR_WIDTH;
	    break;
	  case SC_CURSOR_UP:
	    y-=10;
	    if (y<0) y+=GR_HEIGHT;
	    break;
	  case SC_CURSOR_DOWN:
	    y+=10;
	    if (y>=GR_HEIGHT) y-=GR_HEIGHT;
	    break;
	}
	//We don't want keystrokes building-up
	//in the buf.
	FlushMsgs;
      }
      y=(y+1)%GR_HEIGHT;
      cur_screen_y=(cur_screen_y+1)%(2048-GR_HEIGHT);

      Sleep(20);
    } while (ch!=CH_ESC && ch!=CH_SHIFT_ESC);
  } catch
    CatchAll;
  SettingsPop;
  MenuPop;
}
Example #2
0
/**
 * @brief   按键 子菜单
 */
void MenuKeyChild(void)
{
	// 对父菜单的相关进行常规备份,因为下面要修改菜单项和显示位置
	MenuPush();
	sMenuFrame.MenuIndex = sMenuFrame.MenuRsr->ItemIndex[sMenuItem.Item];
	MenuItemInit(sMenuFrame.MenuRsr->ItemResource[sMenuItem.Item]);
	sMenuItem.Item = 0;
	sMenuItem.Where = 0;
}
Example #3
0
U0 TheDead()
{
  I64 i,j,i1,j1,k=0,sc=0,ch=0,msg_code,p1,p2;
  Bool gun_on=FALSE;

  MenuPush(
  "File {"
  "  Abort(,CH_SHIFT_ESC);"
  "  Exit(,CH_ESC);"
  "}"
  "Play {"
  "  Fire(,CH_SPACE);"
  "  Up(,,SC_CURSOR_UP);"
  "  Down(,,SC_CURSOR_DOWN);"
      "}"
      );
  SettingsPush; //See $LK,"SettingsPush","MN:SettingsPush"$
  WinMax;
  Fs->song_task=Spawn(&SongTask,NULL,"Song",,Fs);
  WordStat;
  DocCursor;
  DocClear;
  Fs->draw_it=&DrawIt;
  WinBorder;

  try {
    do {
      if (msg_code=ScanMsg(&p1,&p2,1<<MSG_KEY_DOWN | 1<<MSG_KEY_UP)) {
      //With KEYBOARD msgs, the two msg args
      //are the scan code and ascii val for the key.
	sc=p2; ch=p1;

	if (msg_code==MSG_KEY_DOWN) {
	//The least significant byte of the scan code
	//identifies the key.
	  if (sc.u8[0]==SC_CURSOR_DOWN) {
	    y+=10;
	    if (y>GR_HEIGHT-30)
	      y=GR_HEIGHT-30;
	  } else if (sc.u8[0]==SC_CURSOR_UP) {
	    y-=10;
	    if (y<0)
	      y=0;
	  } else if (sc.u8[0]==SC_CURSOR_RIGHT ||
	      ch==CH_SPACE)
	    gun_on=TRUE;
	} else if (msg_code==MSG_KEY_UP) {
	  if (sc.u8[0]==SC_CURSOR_RIGHT ||
	      ch==CH_SPACE)
	    gun_on=FALSE;
	}
      }

      i=shots_out;
      while (i!=shots_in) {
	j=i++ &(MAX_SHOTS-1);
	sx[j]+=5;
	if (sx[j]>GR_WIDTH)
	  shots_out++;
	else {
	  i1=dead_out;
	  while (i1!=dead_in) {
	    j1=i1++ &(MAX_DEAD-1);
	    if (gy[j1]<=sy[j]<=gy[j1]+38 &&
		gx[j1]<=sx[j]<=gx[j1]+40)
	      g_dead[j1]=TRUE;
	  }
	}
      }

      if (gun_on) {
	j=shots_in&(MAX_SHOTS-1);
	sx[j]=x+32;
	sy[j]=y+14;
	shots_in++;
      }

      //This runs one out of four passes through this loop.
      if (!(k % 4)) {
	i=dead_out;
	while (i!=dead_in) {
	  j=i++ &(MAX_DEAD-1);
	  gx[j]-=1;
	  if (gx[j]<25)
	    dead_out++;
	}
      }

      //This runs one out of 150 passes through this loop.
      if (!(k%150)) {
	j=dead_in&(MAX_DEAD-1);
	gx[j]=GR_WIDTH-30;
	gy[j]=RandU32%(GR_HEIGHT-50)+25;
	g_dead[j]=FALSE;
	dead_in++;
      }
      k++;

      Sleep(10); //Swap this task-out for 10 miliseconds.
    } while (ch!=CH_ESC && ch!=CH_SHIFT_ESC);
  } catch
    CatchAll;
  SettingsPop;
  MenuPop;
}
Example #4
0
U0 MassSpringDemo()
{
  I64 msg_code,p1,p2;
  MyMass *tempm1=NULL,*tempm2=NULL;

  PopUpOk("Left-Click to place mas\n"
	  "Right-Click and drag to\n"
	  "connect with spring.\n\n"
	  "Springs are 100 pixels long.\n");
  SettingsPush; //See $LK,"SettingsPush","MN:SettingsPush"$
  WinMax;

//This Preempt() eliminates a lot of hassles.
//The concern is about changing
//que links while the winmgr task
//is updating the ode or screen.

//The Window mgr suspends this
//task while updating the ode.It
//will not be interrupted and with this
//preempt, we will not be interrupted.
//There is little downside to Preempt()
//since we will yield during GetMsg().
  Preempt(OFF);


  Fs->win_inhibit|=WIF_DBL_CLICK;
  WordStat;

  MenuPush(
"File {"
"  Abort(,CH_SHIFT_ESC);"
"  Exit(,CH_ESC);"
"}"
"Play {"
"  Restart(,'\n');"
"}"
  );

  Init;
  DocCursor;
  DocClear;
  Fs->draw_it=&DrawIt;

  try {
    while (TRUE) {
      msg_code=GetMsg(&p1,&p2,1<<MSG_IP_L_DOWN|1<<MSG_IP_R_DOWN|1<<MSG_IP_R_UP|1<<MSG_KEY_DOWN);
      switch (msg_code) {
	case MSG_IP_L_DOWN:
	  PlaceMass(p1,p2);
	  break;
	case MSG_IP_R_DOWN:
	  tempm1=MassFind(ode,p1,p2);
	  tempm2=NULL;
	  break;
	case MSG_IP_R_UP:
	  if (tempm1 && (tempm2=MassFind(ode,p1,p2)) && tempm1!=tempm2)
	    PlaceSpring(tempm1,tempm2);
	  tempm1=tempm2=NULL;
	  break;
	case MSG_KEY_DOWN:
	  switch (p1) {
	    case '\n':
	      CleanUp;
	      Init;
	      break;
	    case CH_SHIFT_ESC:
	    case CH_ESC:
	      goto ms_done;
	  }
	  break;
      }
    }
ms_done: //Don't goto out of try
    GetMsg(,,1<<MSG_KEY_UP);
  } catch
    CatchAll;
  SettingsPop;
  CleanUp;
  MenuPop;
}
U0 PullDownMenuDemo()
{
  I64 msg_code,p1,p2;
  CMenuEntry *tempse;

  MenuPush(
  "File {"
  "  Open(,'O');"
  "  Save(,'S');"
  "  Exit(,CH_SHIFT_ESC);"
  "}"
  "Edit {"
  "  Cut(,,SC_DELETE|SCF_SHIFT);"
  "  Paste(,,SC_INS|SCF_SHIFT);"
  "}"
  "Misc {"
  "  Beep(,CH_SPACE);"
  "  Opt1(MSG_CMD,M_OPTION1);"
  "  Opt2(MSG_CMD,M_OPTION2);"
  "}"
  "Help {"
  "  Help(,,0x3B0000003B);"
  "  About(,,0x23B0000023B);"
      "}");

  "A pull-down menu will appear "
  "if you move the mouse to the top "
  "of the screen.\n\n";

  do {
    msg_code=GetMsg(&p1,&p2,1<<MSG_KEY_DOWN+1<<MSG_CMD);
    "\nCmd:%d P1:%X P2:%X\n\n",msg_code,p1,p2;

    switch (msg_code) {
      case MSG_KEY_DOWN:
	switch (p1) { //ASCII
	  case CH_SPACE:
	    Beep;
	    break;
	  case 0:
	    switch (p2.u8[0]) { //p2=Scan code
	      case SC_F1:
		if (p2&SCF_SHIFT)
		  "About PullDown Demo\n";
		else
		  "Test the menu.\n";
		break;
	      case SC_DELETE:
		if (p2&SCF_SHIFT)
		  "Cut\n";
		break;
	      case SC_INS:
		if (p2&SCF_SHIFT)
		  "Paste\n";
		break;
	    }
	    break;
	}
	break;

      case MSG_CMD:
      //I Recommend making your menu
      //drive by key strokes, but you can
      //use the $LK,"MSG_CMD","MN:MSG_CMD"$ val.
	switch (p1) {
	  case M_OPTION1:
	    "Option # 1\n";
	    if (tempse=MenuEntryFind(Fs->cur_menu,"Misc/Opt1"))
	      tempse->checked=!tempse->checked;
	    break;
	  case M_OPTION2:
	    "Option # 2\n";
	    if (tempse=MenuEntryFind(Fs->cur_menu,"Misc/Opt2"))
	      tempse->checked=!tempse->checked;
	    break;
	}
	break;
    }

  } while (msg_code!=MSG_KEY_DOWN||(p1!=CH_SHIFT_ESC && p1!=CH_ESC));
  MenuPop;
}