void
update_touchscreen (void)
{
  static int graffiti = 0;
  struct MW_UID_MESSAGE m;
  int x, y, k, kh, btns = 0;
  touchPosition pos;
  char c;

  /* update keypad & touchscreen */
  scanKeys ();
  pos = touchReadXY ();
  x = pos.px;
  y = pos.py;
  k = keysDown ();
  kh = keysHeld ();

  /* check for character recognition */
  if ((kh & KEY_L) || (kh & KEY_R)) {
    graffiti = 1;
    c = PA_CheckLetter ((kh & KEY_TOUCH ? 1 : 0), x, y);
    if (c) {
      /* signal the console driver */
      console_push (c);
      if (kbd_queue_id != 0) {
        /* send the read character */
        m.type = MV_UID_KBD;
        m.m.kbd.code = c;
        m.m.kbd.modifiers = 0;
        m.m.kbd.mode = MV_KEY_MODE_ASCII;
        rtems_message_queue_send (kbd_queue_id, (void *) &m,
                                  sizeof (struct MW_UID_MESSAGE));
      }
    }
  } else {
    if (graffiti == 1) {
      x = old_x;
      y = old_y;
    }
    graffiti = 0;
  }

  if (mou_queue_id == 0)
    return;

  if (hand == 1) {
    if (k & KEY_LEFT) {
      btns = MV_BUTTON_LEFT;
    }
    if (k & KEY_RIGHT) {
      btns = MV_BUTTON_RIGHT;
    }
  } else {
    if (k & KEY_A) {
      btns = MV_BUTTON_LEFT;
    }
    if (k & KEY_B) {
      btns = MV_BUTTON_RIGHT;
    }
  }

  if (!((kh & KEY_L) || (kh & KEY_R)) && (kh & KEY_TOUCH)
      && (x != old_x || y != old_y || btns)) {
    /* send the read position */
    m.type = MV_UID_ABS_POS;
    old_btns = m.m.pos.btns = btns;
    old_x = m.m.pos.x = x;
    old_y = m.m.pos.y = y;
    m.m.pos.z = 0;
    rtems_message_queue_send (mou_queue_id, (void *) &m,
                              sizeof (struct MW_UID_MESSAGE));
  }
}
Beispiel #2
0
//---------------------------------------------------------------------------------
int main(void) {
//---------------------------------------------------------------------------------
	int min_x  = 4096 , min_y  = 4096, max_x  = 0, max_y   = 0;
	int min_px = 4096 , min_py = 4096, max_px = 0 , max_py = 0;
	touchPosition touch;

	// put the main screen on the bottom lcd
	lcdMainOnBottom();

	initOAM();
   
   //set the video mode
    videoSetMode(  MODE_0_2D | 
                   DISPLAY_SPR_ACTIVE |		//turn on sprites
                   DISPLAY_BG0_ACTIVE |		//turn on background 0
                   DISPLAY_SPR_1D			//this is used when in tile mode
                    );

	int i;
	
	// Sprite initialisation
	for(i = 0; i < 256; i++)
		SPRITE_PALETTE[i] = ((u16*)ballpalette_bin)[i];

	for(i = 0; i< 32*16; i++)
		SPRITE_GFX[i] = ((u16*)balldata_bin)[i];

 
	consoleInit(0, 0,BgType_Text4bpp, BgSize_T_256x256, 31,0, true, true); 
 
	iprintf("\x1b[4;8HTouch Screen Test");
	iprintf("\x1b[15;4HRight Shoulder toggles");
 
	while(1) {

		swiWaitForVBlank();
		updateOAM();

		// read the button states
		scanKeys();

		// read the touchscreen coordinates
		touchRead(&touch);
		
		int pressed = keysDown();	// buttons pressed this loop
		int held = keysHeld();		// buttons currently held

		// Right Shoulder button toggles the mode
		if ( pressed & KEY_R) TouchType ^= SINGLE;

		// Start button exits the app
		if ( pressed & KEY_START) break;

		iprintf("\x1b[14;4HTouch mode: %s",TouchType==CONTINUOUS?"CONTINUOUS ":"SINGLE SHOT");

		iprintf("\x1b[6;5HTouch x = %04X, %04X\n", touch.rawx, touch.px);
		iprintf("\x1b[7;5HTouch y = %04X, %04X\n", touch.rawy, touch.py);		

		iprintf("\x1b[0;18Hkeys: %08X\n", keysHeld());
		iprintf("\x1b[9;10HFrame %d\n", frame);

		if ( TouchType == SINGLE && !(pressed & KEY_TOUCH) ) continue;

		if ( !(held & KEY_TOUCH) || touch.rawx == 0 || touch.rawy == 0) continue;
		
		iprintf("\x1b[12;12H(%d,%d)      ",touch.px,touch.py);

		if ( touch.rawx > max_x)		max_x = touch.rawx;
		if ( touch.rawy > max_y)		max_y = touch.rawy;
		if ( touch.px > max_px)	max_px = touch.px;
		if ( touch.py > max_py)	max_py = touch.py;

		if ( touch.rawx < min_x)		min_x = touch.rawx;
		if ( touch.rawy < min_y)		min_y = touch.rawy;
		if ( touch.px < min_px)	min_px = touch.px;
		if ( touch.py < min_py)	min_py = touch.py;

		iprintf("\x1b[0;0H(%d,%d)      ",min_px,min_py);
		iprintf("\x1b[1;0H(%d,%d)      ",min_x,min_y);
		iprintf("\x1b[22;21H(%d,%d)",max_x,max_y);
		iprintf("\x1b[23;23H(%d,%d)",max_px,max_py);

		OAMCopy[0].attribute[2] = 0;
		OAMCopy[0].attribute[1] = ATTR1_SIZE_32 |((touch.px - 16) & 0x01FF);
		OAMCopy[0].attribute[0] = ATTR0_COLOR_256 | ATTR0_SQUARE | ((touch.py -16) & 0x00FF);
		
	}
	
 
	return 0;
}
//---------------------------------------------------------------------------------
int main(void) {
//---------------------------------------------------------------------------------
	Wifi_InitDefault(false);
	
	consoleDemoInit(); 

	//Keyboard* kb = keyboardDemoInit();
	//kb->OnKeyPressed = keyPressed;

	while(1);

	{
		int status = ASSOCSTATUS_DISCONNECTED;

		consoleClear();

		Wifi_AccessPoint* ap = findAP();

		iprintf("Connecting to %s\n", ap->ssid);

		//this tells the wifi lib to use dhcp for everything
		Wifi_SetIP(0,0,0,0,0);	

		Wifi_ConnectAP(ap, WEPMODE_NONE, 0, 0);

		while(status != ASSOCSTATUS_ASSOCIATED && status != ASSOCSTATUS_CANNOTCONNECT) {
			int oldStatus = status;

			status = Wifi_AssocStatus();

			iprintf("%s", oldStatus != status ? ASSOCSTATUS_STRINGS[status] : ".");

			scanKeys();

			if(keysDown() & KEY_B) break;
			
			swiWaitForVBlank();
		}
		consoleClear();
		consoleSetWindow(NULL, 0,0,32,10);

		char url[256];

		if(status == ASSOCSTATUS_ASSOCIATED) {
			while(1) {
				u32 ip = Wifi_GetIP();

				iprintf("ip: [%i.%i.%i.%i]", (ip ) & 0xFF, (ip >> 8) & 0xFF, (ip >> 16) & 0xFF, (ip >> 24) & 0xFF);

				scanf("%s", url);

				struct hostent *host = gethostbyname(url);

				if(host)
					iprintf("IP (%s) : %s\n",  url, inet_ntoa(*(struct in_addr *)host->h_addr_list[0]));
				else
					iprintf("Could not resolve\n");

				scanKeys();

				if(keysDown() & KEY_B) break;

				swiWaitForVBlank();
			}
		}
	}
	return 0;
}
Beispiel #4
0
int main()
{
	float scrollPos = 0.0f;
	float scrollDir = 0.0f
	const float scrollFriction = 0.9f;
	const float clampFriction = 0.9f;
	int  dragAnchor = 0;
	bool draging = false;
	int prevDragAnchor = 0;
	
	float maxScrollPos = 100;
	
	while (1)
	{
		scanKeys();
		
		// process input
		int down = keysDown();
		int up   = keysUp();
		
		touchPosition touchPos;
		touchRead(&touchPos);
		
		if (down & KEY_TOUCH)
		{
			// always stop when tapping the screen
			scrollDir = 0.0f;
			
			if (touchPos.px < SCREEN_WIDTH / 2)
			{
				prevDragAnchor = dragAnchour = touchPos.py;
				draging = true;
			}
			else
			{
				int canvasPos = touchPos.py - scrollPos;
				int entry = canvasPos / ENTRY_HEIGHT;
				selectEntry(entry);
			}
		}
		else if (up & KEY_TOUCH)
		{
			draging = false;
		}
		
		// animate
		if (!draging)
		{
			scrollPos += scrollDir;
			scrollDir *= scrollFriction;
			if (fabs(scrollDir) < 0.01f) scrollDir = 0.0f;
			
			if (scrollPos < 0.0f)
			{
				// clamp to start
				scrollDir = 0.0f;
				scrollPos *= clampFriction;
			}
			else if (scrollPos > maxScrollPos)
			{
				// clamp to end
				scrollDir = 0.0f;
				scrollPos = scrollPos + (maxScrollPos - scrollPos) * clampFriction;
			}
			
			setScroll(int(scrollPos));
		}
		else
		{
			setScroll(touchPos.py - dragAnchor);
			
			// track scrollDir
			scrollDir += touchPos.py - prevDragAnchor;
			scrollDir *= scrollFriction;
			prevDragAnchor = dragAnchor;
		}
		
		swiWaitForVBlank();
	}
}
Beispiel #5
0
int hwMainFunc(void* userData)
{
	CGrf* bootSplash = new CGrf();
	if (!bootSplash)
		return ERR_NOMEM;

	if (!bootSplash->Load(GUI_ASSET_DIR "/bootsplash.grf"))
	{
		delete bootSplash;
		return ERR_NOLOAD;
	}

	setBrightness(3, -16);

	videoSetMode(MODE_3_2D);
	int bg = bgInit(2, BgType_Text8bpp, BgSize_T_256x256, 0, 1);

	dmaCopy(bootSplash->gfxData, bgGetGfxPtr(bg), MemChunk_GetSize(bootSplash->gfxData));
	dmaCopy(bootSplash->mapData, bgGetMapPtr(bg), MemChunk_GetSize(bootSplash->mapData));
	dmaCopy(bootSplash->palData, BG_PALETTE,      MemChunk_GetSize(bootSplash->palData));
	delete bootSplash;

	LoadApps();
	if (!g_appCount) return ERR_NOAPPS;
	LoadFileTypes();

	if (!(background.Load(GUI_ASSET_DIR "/background.grf") &&
		dummy.Load(GUI_ASSET_DIR "/dummy.grf") &&
		selection.Load(GUI_ASSET_DIR "/selection.grf") &&
		topscr.Load(GUI_ASSET_DIR "/topscr.grf") &&
		defappicon.Load(GUI_ASSET_DIR "/dummyapp.grf") &&
		fiGenericFile.Load(GUI_ASSET_DIR "/genericfile.grf") &&
		fiConflictFile.Load(GUI_ASSET_DIR "/conflictfile.grf") &&
		font.Load("tahoma", 10)))
		return ERR_NOLOAD;

	for (int q = 0; q < 92; q ++)
	{
		if (q < 16)
			setBrightness(3, q-16);
		if (q >= (92-16-1))
			setBrightness(3, q-(92-16-1));
		if (keysDown()) break;
		swiWaitForVBlank();
		scanKeys();
	}

	setBrightness(3, 0);
	swiWaitForVBlank();
	DSVideoReset();
	videoInit();
	EnableGuiMon();

	for (;;)
	{
		swiWaitForVBlank();
		scanKeys();
		oamUpdate(&oamMain);
		oamUpdate(&oamSub);
		bgUpdate();

		if (g_curApp)
			RunAppVBlank();
		else if (!MainVBlank())
			break;
		RunBgProcess();
	}

	DisableGuiMon();
	return 0;
}
//---------------------------------------------------------------------------------
Wifi_AccessPoint* findAP(void){
	//---------------------------------------------------------------------------------

	int selected = 0;  
	int i;
	int count = 0;

	static Wifi_AccessPoint ap;

	Wifi_ScanMode(); //this allows us to search for APs

	while(!(keysDown() & KEY_A))
	{
		scanKeys();

		//find out how many APs there are in the area
		count = Wifi_GetNumAP();

		consoleClear();

		iprintf("Number of APs found: %d\n", count);

		//display the APs to the user
		for(i = 0; i < count; i++)
		{
			Wifi_AccessPoint ap;

			Wifi_GetAPData(i, &ap);

			// display the name of the AP
			iprintf("%s %s Wep:%s Sig:%i\n", 
				i == selected ? "*" : " ", 
				ap.ssid, 
				ap.flags & WFLAG_APDATA_WEP ? "Yes " : "No ",
				ap.rssi * 100 / 0xD0);

		}

		//move the selection asterick
		if(keysDown() & KEY_UP)
		{
			selected--;
			if(selected < 0)
			{
				selected = 0;
			}
		}

		if(keysDown()&KEY_DOWN)
		{
			selected++;
			if(selected >= count) 
			{
				selected = count - 1;
			}
		}

		swiWaitForVBlank();
	}

	//user has made a choice so grab the ap and return it
	Wifi_GetAPData(selected, &ap);

	return &ap;
}
Beispiel #7
0
	void Game::operate()
	{
		if (is_started)
		{
			//debug:racket operation
			if (keysHeld() & KEY_LEFT)
			{
				racket.Move(-3, 0);
			}
			else if (keysHeld() & KEY_RIGHT)
			{
				racket.Move(3, 0);
			}
			else if (keysHeld() & KEY_TOUCH)
			{
				touchPosition touch;
				touchRead(&touch);
				int temp = touch.px - (racket.GetX() + racket.GetWidth() / 2);
				if (temp != 0)
				{
					if (temp >= 10 || temp <= -10)
					{
						temp /= 10;
						if (temp < 0)
						{
							--temp;
							if (temp < -3)
							{
								temp = -3;
							}
						}
						else
						{
							++temp;
							if (temp > 3)
							{
								temp = 3;
							}
						}
					}
					else if (temp > 0)
					{
						temp = 1;
					}
					else if (temp < 0)
					{
						temp = -1;
					}
				}
				racket.Move(temp, 0);
			}
		}
		else
		{
			if ((keysDown() & KEY_TOUCH) == 0 && (keysHeld() & KEY_TOUCH))
			{
				touchPosition touch;
				touchRead(&touch);
				ball.SetAngle(std::atan2(
					static_cast<int>(touch.py) + 192 - ball.GetY(),
					static_cast<int>(touch.px) - ball.GetX()
					));
			}
			else if (keysHeld() & KEY_LEFT)
			{
				ball.SetAngle(ball.GetAngle() - M_PI / 90);
			}
			else if (keysHeld() & KEY_RIGHT)
			{
				ball.SetAngle(ball.GetAngle() + M_PI / 90);
			}
			if (ball.GetAngle() > 0.0)
			{
				ball.SetAngle(-ball.GetAngle());
			}
			//30度制限
			if (ball.GetAngle() > -M_PI / 6)
			{
				ball.SetAngle(-M_PI / 6);
			}
			else if (ball.GetAngle() < -M_PI * 5 / 6)
			{
				ball.SetAngle(-M_PI * 5 / 6);
			}
			ball.SetSpeed(0.0);
			ball.MoveTo(
				racket.GetX() + racket.GetWidth() / 2,
				racket.GetY() - racket.GetHeight() / 2 - ball.GetRadius()
				);
			if (keysDown() & (KEY_A | KEY_UP))
			{
				is_started = true;
				ball.SetSpeed(2.0);
			}
			else if (keysDown() & KEY_TOUCH)
			{
				touchPosition touch;
				touchRead(&touch);
				Shape::Point p_touch(
					static_cast<int>(touch.px),
					static_cast<int>(touch.py + 192)
					);
				Shape::Circle c_ball(
					ball.GetX(), ball.GetY(), ball.GetRadius()
					);
				if (p_touch.IsCollide(c_ball))
				{
					is_started = true;
					ball.SetSpeed(2.0);
				}
			}
		}
	}
Beispiel #8
0
static bool MainVBlank()
{
	renderTopLines();
	updAppList();

	word_t kDown = keysDown();
	TouchPos pos;

	// Page moving code
	do
	{
		int disp = 0;
		if (kDown & KEY_LEFT) disp = -1;
		else if (kDown & KEY_RIGHT) disp = +1;
		else if (kDown & KEY_UP) disp = -6;
		else if (kDown & KEY_DOWN) disp = +6;
		else if (kDown & KEY_TOUCH)
		{
			if (pos.InRegion(0, 48, 8, 64*2+8)) disp = -1;
			else if (pos.InRegion(256-8, 48, 8, 64*2+8)) disp = +1;
		}

		if (!disp) break;

		int oldPage = page;

		page += disp;
		int nPages = bump.GetBumpCount();

		while (page < 0) page += nPages;
		while (page >= nPages) page -= nPages;

		if (page == oldPage)
			break;

		unloadPageIcons(oldPage);

		bump.SelectBump(page);
		updCursor();
		loadPageIcons();
	} while(0);

	// Selection code
	if (kDown & KEY_TOUCH) do
	{
		bool bFound = false;

		for (int i = 0; i < 6; i ++)
		{
			int xPos = 16 + (i % 3) * (64+16);
			int yPos = 48 + (i / 3) * (64+8);
			if (pos.InRegion(xPos, yPos, 64, 64))
			{
				int touchedApp = page*6 + i;
				if (touchedApp == selectedApp)
					executeApp();
				else if (g_appData[touchedApp].IsLoaded())
				{
					selectedApp = touchedApp;
					updCursor();
				}
				bFound = true;
				break;
			}
		}

		if (bFound) break;

		for (int i = 0; i < g_appList.GetCount(); i ++)
		{
			if (!pos.InRegion(64+(i*(16+8)), 16, 16, 16))
				continue;

			SwitchToApp(i);
			return true;
		}
	} while(0);

	if (kDown & KEY_A)
		executeApp();

#ifdef ALLOW_EXIT
	if (g_appList.GetCount() == 0 && (kDown & KEY_START))
		return false;
#endif

	return true;
}
int BndsTicketView::exec()
{
      string t;
      char str [50];
      int res;
      BndsTicketsListView *btlv;
      
      /// Muestra la pantalla.
      show();
  
      while(1) {

	  swiWaitForVBlank();

	  scanKeys();

  	  /// Procesa los eventos de la pantalla tactil.
	  int itemSelected = g_video->eventTemplateListB();

	  
	  if (keysDown() & KEY_LEFT) {
	      previousPage();
	  } else if (keysDown() & KEY_RIGHT) {
	      nextPage();
	  } else if (keysDown() & KEY_L) {
	      /// Vuelta a la pantalla anterior.
	      g_video->resetBgSub();
	      break;
	  } else if (keysDown() & KEY_R) {
	      /// Seleccionar mesa y enviar.
	      itemSelected = -10;	    
	  } else if (keysDown() & KEY_UP) {
	      itemSelected = -6;
	  } else if (keysDown() & KEY_DOWN) {
	      itemSelected = -7;
	  } // end if


  
	  switch (itemSelected) {
	    case -1:
		/// Necesita repintarse.
		show();
		break;
	    case -2:
		if (m_currentLine == 0) break;
		
		/// Boton - cantidad.
		m_currentTicketLine->setQuantityArticle(m_currentTicketLine->quantityArticle() - 1);

		/// Si la cantidad es <= 0 entonces se borra la linea de ticket.
		if (m_currentTicketLine->quantityArticle() <= 0) {

		  m_ticket->removeTicketLine( m_currentTicketLine );
		  /// Establece el numero de items a mostrar en la lista.
		  setTotalItems( m_ticket->ticketLines().size() );
		  
		} // end if

		m_ticket->recalculeTotal();
		show();
		break;
	    case -3:
		if (m_currentLine == 0) break;
		
		/// Boton + cantidad.
		m_currentTicketLine->setQuantityArticle(m_currentTicketLine->quantityArticle() + 1);
		m_ticket->recalculeTotal();
		show();
		break;
	    case -4:
		if (m_currentLine == 0) break;
		
		/// Boton borrar linea
		m_ticket->removeTicketLine( m_currentTicketLine );
		/// Establece el numero de items a mostrar en la lista.
		setTotalItems( m_ticket->ticketLines().size() );
		m_ticket->recalculeTotal();
		show();
		break;
	    case -5:
		/// Boton anterior.
		/// Vuelta a la pantalla anterior.
		g_video->resetBgSub();
		return 0;
		break;
	    case -6:
		/// Dibuja boton 'Sube linea'.
		lineUp();
		break;
	    case -7:
		/// Dibuja boton 'Baja linea'.
		lineDown();
		break;
	    case -10:
		/// Seleccionar mesa y enviar.
		g_video->resetBgMain();
		g_video->resetBgSub();

		/// Primero cambiar el nombre al ticket. Despues enviar los datos.
		
		/// TODO: Provisionalmente genera 40 mesas (40 nombres de tickets).
		/// luego comprueba que el nombre no exista en la base de datos (se esta usando).
		/// muestra la lista completa, pero solo deja elegir los que esten disponibles.
		btlv = new BndsTicketsListView();
		res = btlv->exec();
		delete btlv;
		
		/// TODO: manera nada adecuada de conseguir el nombre del ticket seleccionado.
		sprintf(str,"%i", res);
		t = string("MESA ") + string(str);
		
		m_ticket->setNomTicket(t);
		
		/// TODO: tecla provisional. Enviar ticket.
		g_db->saveTicket();
		m_ticket->clearTicket(); 
		setTotalItems( m_ticket->ticketLines().size() );
		m_ticket->setNomTicket(m_ticket->defaultTicketName());
		return 0;
		break;
	    case 2:
		break;
	  } // end switch

	  
      } // end while

    return 0;
}
Beispiel #10
0
void midicctrack::loadsavepress(void) {

	touchPosition touch;
	
	if (keysDown() & KEY_TOUCH){

		touchRead(&touch);
		
		int yval = (touch.py / 8);
		int xval = (touch.px / 8);

		if ((yval == 5) && (xval < 23))
		{
			if ((xval > 6) && (xval < 10))
			{
				activerow = 11;
			}
			else if ((xval > 15) && (xval < 19))
			{
				activerow = 12;
			}
	
		}
		else if ((xval > 2) && (xval < 11) && (yval > 6) && (yval < 11))
		{
			currentmode = filebrowse;
			settingsfileloader();
			currentmode = loadsave;
		}
		else if ((xval > 2) && (xval < 11) && (yval > 12) && (yval < 17))
		{
			settingsfilesaver();
		}
		else if ((xval > 11) && (xval < 20) && (yval > 6) && (yval < 11))
		{
			currentmode = filebrowse;
			patternfileloader();
			currentmode = loadsave;
		}
		else if ((xval > 11) && (xval < 20) && (yval > 12) && (yval < 17))
		{
			patternfilesaver();
		}
		else if ((xval > 23) && (xval < 30) && (yval > 1) && (yval < 9))
		{
			xval = (xval / 2);
			yval = (yval / 2);
				
			if (yval == 1)
			{
				if (xval == 12)
				{
					editoption(100);
				}
				else if (xval == 13)
				{
					editoption(10);
				}
				else if (xval == 14)
				{
					editoption(1);
				}
			}
			else if (yval == 3)
			{
				if (xval == 12)
				{
					editoption(-100);
				}
				else if (xval == 13)
				{
					editoption(-10);
				}
				else if (xval == 14)
				{
					editoption(-1);
				}
			}
		}
	}
}
Beispiel #11
0
void midicctrack::optionspress(void) {
	
	touchPosition touch;
	
	if (keysDown() & KEY_TOUCH){

		touchRead(&touch);
		
		int yval = (touch.py / 8);
		int xval = (touch.px / 8);

		if ((xval > 1) && (xval < 23) && (yval > 1) && (yval < 21))
		{
			
			if (yval == 5) {
				activerow = 1;
			}
			else if (yval == 8) {
				activerow = 2;
			}
			else if (yval == 9) {
				activerow = 3;
			}
			else if (yval == 10) {
				activerow = 4;
			}
			else if (yval == 11) {
				activerow = 5;
			}
			else if (yval == 12) {
				activerow = 6;
			}
			else if (yval == 13) {
				activerow = 7;
			}
			else if (yval == 14) {
				activerow = 8;
			}
			else if (yval == 15) {
				activerow = 9;
			}
			
			if ((xval > 13) && (xval < 17)) {
				activecolumn = 0;
			}
			else if ((xval > 18) && (xval < 21)) {
				activecolumn = 1;
			}
			
			
		} else  if ((xval > 23) && (xval < 30) && (yval > 1) && (yval < 9))
		{
			xval = (xval / 2);
			yval = (yval / 2);
				
			if (yval == 1)
			{
				if (xval == 12)
				{
					editoption(100);
				}
				else if (xval == 13)
				{
					editoption(10);
				}
				else if (xval == 14)
				{
					editoption(1);
				}
			}
			else if (yval == 3)
			{
				if (xval == 12)
				{
					editoption(-100);
				}
				else if (xval == 13)
				{
					editoption(-10);
				}
				else if (xval == 14)
				{
					editoption(-1);
				}
			}
		}
	}
}
Beispiel #12
0
void handleInput(Ship * ship, MathVector2D<int> * moonPos,
                 SpriteInfo * moonInfo, touchPosition * touch) {

    /* Handle up and down parts of D-Pad. */
    if (keysDown() & KEY_UP) {
        // Play our sound only when the button is initially pressed
        mmEffect(SFX_THRUST);
    }
    if (keysHeld() & KEY_UP) {
        //accelerate ship
        ship->accelerate();
    } else if (keysHeld() & KEY_DOWN) {
        //reverse ship direction
        ship->reverseTurn();
    }

    /* Handle left and right parts of D-Pad. */
    if (keysHeld() & KEY_LEFT) {
        //rotate counter clockwise
        ship->turnCounterClockwise();
    } else if (keysHeld() & KEY_RIGHT) {
        //rotate clockwise
        ship->turnClockwise();
    }

    /*
     *  Handle the touch screen.
     *
     *  This is basically some fancy pants junk to enable grabbing and moving
     *  of the moon. It isn't essential to know how this code works to
     *  understand how to reach values from the touch screen, but it was cool
     *  enough that I wanted to put it in the case study.
     */
    static MathVector2D<int> moonGrip;
    if (keysDown() & KEY_TOUCH) {
        /* Record the grip */
        moonGrip.x = touch->px;
        moonGrip.y = touch->py;
    } else if (keysHeld() & KEY_TOUCH) {
        int newX = moonPos->x + touch->px - moonGrip.x;
        int newY = moonPos->y + touch->py - moonGrip.y;

        /* Prevent dragging off the screen. */
        if (newX < 0) {
            moonPos->x = 0;
        } else if (newX > (SCREEN_WIDTH - moonInfo->width)) {
            moonPos->x = SCREEN_WIDTH - moonInfo->width;
        } else {
            moonPos->x = newX;
        }
        if (newY < 0) {
            moonPos->y = 0;
        } else if (newY > (SCREEN_HEIGHT - moonInfo->height)) {
            moonPos->y = SCREEN_HEIGHT - moonInfo->height;
        } else {
            moonPos->y = newY;
        }

        /* Record the grip again. */
        moonGrip.x = touch->px;
        moonGrip.y = touch->py;
    }
}
Beispiel #13
0
void process_keys() {
	if (game.cooldown <= 0) {
		scanKeys();
		u32 keys = keysHeld();
		u32 down = keysDown();
		touchPosition touch = touchReadXY();

		if (down & KEY_START) {
			new_game();
			return;
		}

		if (down & KEY_SELECT) {
			test_map();

			torch.buf.scroll.x = game.player.x - 16;
			torch.buf.scroll.y = game.player.y - 12;
			torch.buf.bounded(torch.buf.scroll.x, torch.buf.scroll.y);
			torch.dirty_screen();
			torch.reset_luminance();

			return;
		}

		if (down & KEY_X) {
			inventory(); return;
		}
		if (down & KEY_L) {
			overview(); return;
		}

		if (down & KEY_TOUCH && touch.px != 0 && touch.py != 0) {
			if (!(keys & KEY_R) && game.player.projectile) {
				game.player.chuck(torch.buf.scroll.x + touch.px/8,
													torch.buf.scroll.y + touch.py/8);
			}
			return;
		}

		if (down & KEY_R) {
			printf("Saving... ");
			fflush(stdout);
			game.save("blah.adrift");
			printf("done\n");
			printf("Loading... ");
			fflush(stdout);
			game.load("blah.adrift");
			printf("done\n");
		}

		if (keys & KEY_Y) {
			if (get_items()) return;
		}

		DIRECTION dir = 0;
		if (keys & KEY_RIGHT)
			dir |= D_EAST;
		else if (keys & KEY_LEFT)
			dir |= D_WEST;
		if (keys & KEY_DOWN)
			dir |= D_SOUTH;
		else if (keys & KEY_UP)
			dir |= D_NORTH;

		if (dir) {
			game.player.moveDir(dir, keys & KEY_B);
			return;
		}

		if (down & KEY_A) {
			seek_and_destroy();
			if (!game.player.target) {
				// no monsters in range
				for (int x = game.player.x-1; x <= game.player.x+1; x++) {
					for (int y = game.player.y-1; y <= game.player.y+1; y++) {
						Object *o = game.map.at(x,y)->objects.head();
						if (!o) continue;
						if (o->type == VENDING_MACHINE) {
							if (game.player.x == x+D_DX[o->orientation] && game.player.y == y+D_DY[o->orientation]) {
								iprintf("You kick the vending machine. ");
								if (o->quantity > 0 && rand4() < 5) {
									if (rand4() & 1) {
										iprintf("Clunk! A can rolls out.\n");
										addObject(game.player.x, game.player.y, CAN_OF_STEWED_BEEF);
									} else {
										iprintf("Clunk! A bottle rolls out.\n");
										addObject(game.player.x, game.player.y, BOTTLE_OF_WATER);
									}
									o->quantity--;
								} else {
									iprintf("Nothing happens.\n");
								}
								game.cooldown += 5;
							}
						}
					}
				}
			} else return;
		}
		if (keys & KEY_A) {
			seek_and_destroy(); return;
		}

	} else if (game.cooldown > 0)
		game.cooldown--;
}